summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2008-08-22 20:06:31 +0200
committerGuillaume Seguin <guillaume@segu.in>2008-08-22 20:06:31 +0200
commit9c1e15b337f0aae785b51da25ee532693cd75fca (patch)
tree29fe7f91364ef32bd554869cc8d87842e1dd1bb4
parent2a11adee72362de1822aa191d0d18ad521e99ee9 (diff)
downloadgmathlib-9c1e15b337f0aae785b51da25ee532693cd75fca.tar.gz
gmathlib-9c1e15b337f0aae785b51da25ee532693cd75fca.tar.bz2
* Initial gMathEditor frame
-rwxr-xr-xgmatheditor/gmatheditor.py102
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