Swapping keyboards
[ejpi] / src / ejpi_glade.py
index 2ceaee6..afb2175 100755 (executable)
@@ -12,6 +12,7 @@
 @todo Expanded copy/paste (Unusure how far to go)
        @li Copy formula, value, serialized, mathml, latex?
        @li Paste serialized, value?
+@bug Has the same Maemo tab color bug as DialCentral
 
 Some useful things on Maemo
 @li http://maemo.org/api_refs/4.1/libosso-2.16-1/group__Statesave.html
@@ -41,6 +42,7 @@ from libraries import gtkpieboard
 import plugin_utils
 import history
 import gtkhistory
+import gtk_toolbox
 
 
 PLUGIN_SEARCH_PATHS = [
@@ -93,51 +95,11 @@ class ValueEntry(object):
        value = property(get_value, set_value, clear)
 
 
-class ErrorDisplay(history.ErrorReporting):
-
-       def __init__(self, widgetTree):
-               super(ErrorDisplay, self).__init__()
-               self.__errorBox = widgetTree.get_widget("errorEventBox")
-               self.__errorDescription = widgetTree.get_widget("errorDescription")
-               self.__errorClose = widgetTree.get_widget("errorClose")
-               self.__parentBox = self.__errorBox.get_parent()
-
-               self.__errorBox.connect("button_release_event", self._on_close)
-
-               self.__messages = []
-               self.__parentBox.remove(self.__errorBox)
-
-       def push_message(self, message):
-               if 0 < len(self.__messages):
-                       self.__messages.append(message)
-               else:
-                       self.__show_message(message)
-
-       def pop_message(self):
-               if 0 < len(self.__messages):
-                       self.__show_message(self.__messages[0])
-                       del self.__messages[0]
-               else:
-                       self.__hide_message()
-
-       def _on_close(self, *args):
-               self.pop_message()
-
-       def __show_message(self, message):
-               self.__errorDescription.set_text(message)
-               self.__parentBox.pack_start(self.__errorBox, False, False)
-               self.__parentBox.reorder_child(self.__errorBox, 1)
-
-       def __hide_message(self):
-               self.__errorDescription.set_text("")
-               self.__parentBox.remove(self.__errorBox)
-
-
 class Calculator(object):
 
-       __pretty_app_name__ = "e^(j pi) + 1 = 0"
+       __pretty_app_name__ = "e**(j pi) + 1 = 0"
        __app_name__ = "ejpi"
-       __version__ = "0.9.0"
+       __version__ = "0.9.4"
        __app_magic__ = 0xdeadbeef
 
        _glade_files = [
@@ -147,7 +109,8 @@ class Calculator(object):
        ]
 
        _plugin_search_paths = [
-               os.path.join(os.path.dirname(__file__), "plugins/")
+               "/usr/lib/ejpi/plugins/",
+               os.path.join(os.path.dirname(__file__), "plugins/"),
        ]
 
        _user_data = os.path.expanduser("~/.%s/" % __app_name__)
@@ -157,17 +120,21 @@ class Calculator(object):
        def __init__(self):
                self.__constantPlugins = plugin_utils.ConstantPluginManager()
                self.__constantPlugins.add_path(*self._plugin_search_paths)
-               self.__constantPlugins.enable_plugin(self.__constantPlugins.lookup_plugin("Builtin"))
-               self.__constantPlugins.enable_plugin(self.__constantPlugins.lookup_plugin("Trigonometry"))
-               self.__constantPlugins.enable_plugin(self.__constantPlugins.lookup_plugin("Computer"))
-               self.__constantPlugins.enable_plugin(self.__constantPlugins.lookup_plugin("Alphabet"))
+               for pluginName in ["Builtin", "Trigonometry", "Computer", "Alphabet"]:
+                       try:
+                               pluginId = self.__constantPlugins.lookup_plugin(pluginName)
+                               self.__constantPlugins.enable_plugin(pluginId)
+                       except:
+                               warnings.warn("Failed to load plugin %s" % pluginName)
 
                self.__operatorPlugins = plugin_utils.OperatorPluginManager()
                self.__operatorPlugins.add_path(*self._plugin_search_paths)
-               self.__operatorPlugins.enable_plugin(self.__operatorPlugins.lookup_plugin("Builtin"))
-               self.__operatorPlugins.enable_plugin(self.__operatorPlugins.lookup_plugin("Trigonometry"))
-               self.__operatorPlugins.enable_plugin(self.__operatorPlugins.lookup_plugin("Computer"))
-               self.__operatorPlugins.enable_plugin(self.__operatorPlugins.lookup_plugin("Alphabet"))
+               for pluginName in ["Builtin", "Trigonometry", "Computer", "Alphabet"]:
+                       try:
+                               pluginId = self.__operatorPlugins.lookup_plugin(pluginName)
+                               self.__operatorPlugins.enable_plugin(pluginId)
+                       except:
+                               warnings.warn("Failed to load plugin %s" % pluginName)
 
                self.__keyboardPlugins = plugin_utils.KeyboardPluginManager()
                self.__keyboardPlugins.add_path(*self._plugin_search_paths)
@@ -192,13 +159,11 @@ class Calculator(object):
                global hildon
                self._app = None
                self._isFullScreen = False
-               if hildon is not None and self.__window is gtk.Window:
-                       warnings.warn("Hildon installed but glade file not updated to work with hildon", UserWarning, 2)
-                       hildon = None
-               elif hildon is not None:
+               if hildon is not None:
                        self._app = hildon.Program()
+                       oldWindow = self._window
                        self.__window = hildon.Window()
-                       self._widgetTree.get_widget("mainLayout").reparent(self.__window)
+                       oldWindow.get_child().reparent(self.__window)
                        self._app.add_window(self.__window)
                        hildon.hildon_helper_set_thumb_scrollbar(self._widgetTree.get_widget('scrollingHistory'), True)
 
@@ -212,9 +177,9 @@ class Calculator(object):
                        self.__window.connect("key-press-event", self._on_key_press)
                        self.__window.connect("window-state-event", self._on_window_state_change)
                else:
-                       warnings.warn("No Hildon", UserWarning, 2)
+                       pass # warnings.warn("No Hildon", UserWarning, 2)
 
-               self.__errorDisplay = ErrorDisplay(self._widgetTree)
+               self.__errorDisplay = gtk_toolbox.ErrorDisplay(self._widgetTree)
                self.__userEntry = ValueEntry(self._widgetTree.get_widget("entryView"))
                self.__stackView = self._widgetTree.get_widget("historyView")
 
@@ -226,7 +191,7 @@ class Calculator(object):
                )
                self.__load_history()
 
-               self.__sliceStyle = gtkpie.generate_pie_style(self.__window)
+               self.__sliceStyle = gtkpie.generate_pie_style(gtk.Button())
                self.__handler = gtkpieboard.KeyboardHandler(self._on_entry_direct)
                self.__handler.register_command_handler("push", self._on_push)
                self.__handler.register_command_handler("unpush", self._on_unpush)
@@ -238,7 +203,6 @@ class Calculator(object):
                self.__builtinPlugin = self.__keyboardPlugins.keyboards["Builtin"].construct_keyboard()
                self.__builtinKeyboard = self.__builtinPlugin.setup(self.__history, self.__sliceStyle, self.__handler)
                self._widgetTree.get_widget("functionLayout").pack_start(self.__builtinKeyboard)
-               self._widgetTree.get_widget("functionLayout").reorder_child(self.__builtinKeyboard, 0)
                self.enable_plugin(self.__keyboardPlugins.lookup_plugin("Trigonometry"))
                self.enable_plugin(self.__keyboardPlugins.lookup_plugin("Computer"))
                self.enable_plugin(self.__keyboardPlugins.lookup_plugin("Alphabet"))
@@ -250,6 +214,8 @@ class Calculator(object):
                        "on_about": self._on_about_activate,
                }
                self._widgetTree.signal_autoconnect(callbackMapping)
+               self._widgetTree.get_widget("copyMenuItem").connect("activate", self._on_copy)
+               self._widgetTree.get_widget("copyEquationMenuItem").connect("activate", self._on_copy_equation)
 
                if self.__window:
                        if hildon is None:
@@ -268,7 +234,7 @@ class Calculator(object):
                        device = osso.DeviceState(self._osso)
                        device.set_device_state_callback(self._on_device_state_change, 0)
                else:
-                       warnings.warn("No OSSO", UserWarning, 2)
+                       pass # warnings.warn("No OSSO", UserWarning, 2)
 
        def display_error_message(self, msg):
                error_dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, msg)
@@ -338,11 +304,30 @@ class Calculator(object):
                        self._isFullScreen = False
 
        def _on_close(self, *args, **kwds):
+               if self._osso is not None:
+                       self._osso.close()
+
                try:
                        self.__save_history()
                finally:
                        gtk.main_quit()
 
+       def _on_copy(self, *args):
+               try:
+                       equationNode = self.__history.history.peek()
+                       result = str(equationNode.evaluate())
+                       self._clipboard.set_text(result)
+               except StandardError, e:
+                       self.__errorDisplay.push_exception()
+
+       def _on_copy_equation(self, *args):
+               try:
+                       equationNode = self.__history.history.peek()
+                       equation = str(equationNode)
+                       self._clipboard.set_text(equation)
+               except StandardError, e:
+                       self.__errorDisplay.push_exception()
+
        def _on_paste(self, *args):
                contents = self._clipboard.wait_for_text()
                self.__userEntry.append(contents)
@@ -382,9 +367,17 @@ class Calculator(object):
                dlg.set_name(self.__pretty_app_name__)
                dlg.set_version(self.__version__)
                dlg.set_copyright("Copyright 2008 - LGPL")
-               dlg.set_comments("")
-               dlg.set_website("")
-               dlg.set_authors([""])
+               dlg.set_comments("""
+ejpi A Touch Screen Optimized RPN Calculator for Maemo and Linux.
+
+How do I use this?
+The buttons are all pie-menus.  Clicking on them will give you the default (center) behavior.  If you click and hold, the menu gets displayed showing what other actions you can then perform.  While still holding, just drag in the direction of one of these actions.
+
+This is RPN, where are the swap, roll, etc operations?
+This also uses a touch screen, go ahead and feel adventerous by dragging the stack items around.
+""")
+               dlg.set_website("http://ejpi.garage.maemo.org")
+               dlg.set_authors(["Ed Page"])
                dlg.run()
                dlg.destroy()