diff options
-rwxr-xr-x | gmatheditor/gmatheditor.py | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/gmatheditor/gmatheditor.py b/gmatheditor/gmatheditor.py new file mode 100755 index 0000000..f23e117 --- /dev/null +++ b/gmatheditor/gmatheditor.py @@ -0,0 +1,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 |