summaryrefslogtreecommitdiff
path: root/gmatheditor/gmatheditor.py
blob: f23e117d74c0240d38b9a3b8454bdef5bdfede20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
# coding=utf-8

'''
gMathEditor, mathematic expressions editor

Copyright (C) 2007 Guillaume Seguin <guillaume@segu.in>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
'''

import pygtk
pygtk.require ("2.0")

import gtk
import gmathview
import gmathselector

# FIXME: we need a kind of parser which generates this list automagically
SYMBOLS = {
    "Characters" : ["alpha", "beta", "gamma"],
    "Symbols" : ["integral", "sum", "product", "union", "intersection"],
    "Operators" : ["frac"]
}

def load_selector_symbols (selector):
    global SYMBOLS
    def load_symbol (symbol, category):
        if type (symbol) == type (()):
            selector.add_symbol (symbol[0], symbol[1], category)
        else:
            selector.add_symbol (symbol, "", category)
    def load_category_symbols ((category, symbols)):
        map (lambda symbol: load_symbol (symbol, category), symbols)
    map (load_category_symbols, SYMBOLS.items ())

class gMathEditor (gtk.Window):
    '''Mathematic expressions editor'''

    main_box        = None
    menubar         = None
    mathview        = None
    mathselector    = None
    statusbar       = None

    def __init__ (self):
        '''Initialize UI'''
        gtk.Window.__init__ (self)
        self.set_default_size (300, 200)
        self.set_title ("gMathEditor")
        self.connect ("delete-event", gtk.main_quit)

        # Main vertical box
        self.main_box = gtk.VBox ()
        self.add (self.main_box)

        # Menu bar
        self.menu_bar = gtk.MenuBar ()
        self.main_box.pack_start (self.menu_bar, False, False)

        # gMathSelector editor widget
        self.mathselector = gmathselector.MathSelector ()
        load_selector_symbols (self.mathselector)
        self.main_box.pack_start (self.mathselector, False, False)

        self.mathselector.connect ("symbol-selected", self.symbol_selected_cb)

        self.main_box.pack_start (gtk.HSeparator (), False, False)

        # gMathView editor widget
        self.mathview = gmathview.MathView ()
        self.mathview.set_editor_mode (True)
        self.main_box.pack_start (self.mathview, False, False)

        # Status bar
        self.status_bar = gtk.Statusbar ()
        self.main_box.pack_end (self.status_bar, False, False)

        self.main_box.show_all ()

    def symbol_selected_cb (self, selector, symbol):
        print symbol

if __name__ == "__main__":
    editor = gMathEditor ()
    editor.show ()
    try:
        gtk.main ()
    except KeyboardInterrupt:
        pass