Switching from a notebook to a touch selector for keyboard selection
authorepage <eopage@byu.net>
Mon, 26 Oct 2009 12:24:04 +0000 (12:24 +0000)
committerepage <eopage@byu.net>
Mon, 26 Oct 2009 12:24:04 +0000 (12:24 +0000)
git-svn-id: file:///svnroot/ejpi/trunk@52 df6cc7de-23d0-4ae0-bb86-c17aa67b2a9d

src/ejpi.glade
src/ejpi_glade.py

index e9cbaba..b624b40 100644 (file)
               <widget class="GtkVBox" id="functionLayout">
                 <property name="visible">True</property>
                 <child>
-                  <widget class="GtkNotebook" id="pluginKeyboards">
+                  <widget class="GtkButton" id="keyboardSelectionButton">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
-                    <property name="scrollable">True</property>
+                    <property name="receives_default">True</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkHBox" id="pluginKeyboard">
+                    <property name="visible">True</property>
                     <child>
                       <placeholder/>
                     </child>
-                    <child>
-                      <widget class="GtkLabel" id="NullFunctionTab">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">None</property>
-                      </widget>
-                      <packing>
-                        <property name="tab_fill">False</property>
-                        <property name="type">tab</property>
-                      </packing>
-                    </child>
                   </widget>
                   <packing>
-                    <property name="position">0</property>
+                    <property name="position">1</property>
                   </packing>
                 </child>
                 <child>
                   </widget>
                   <packing>
                     <property name="expand">False</property>
-                    <property name="position">1</property>
+                    <property name="position">2</property>
                   </packing>
                 </child>
                 <child>
-                  <placeholder/>
+                  <widget class="GtkHBox" id="mainKeyboard">
+                    <property name="visible">True</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="position">3</property>
+                  </packing>
                 </child>
               </widget>
               <packing>
index 11a4dd2..660f313 100755 (executable)
@@ -134,7 +134,7 @@ class Calculator(object):
 
                self.__keyboardPlugins = plugin_utils.KeyboardPluginManager()
                self.__keyboardPlugins.add_path(*self._plugin_search_paths)
-               self.__activeKeyboards = {}
+               self.__activeKeyboards = []
 
                for path in self._glade_files:
                        if os.path.isfile(path):
@@ -174,6 +174,7 @@ class Calculator(object):
                self.__errorDisplay = gtk_toolbox.ErrorDisplay(self._widgetTree)
                self.__userEntry = ValueEntry(self._widgetTree.get_widget("entryView"))
                self.__stackView = self._widgetTree.get_widget("historyView")
+               self.__pluginButton = self._widgetTree.get_widget("keyboardSelectionButton")
 
                self.__historyStore = gtkhistory.GtkCalcHistory(self.__stackView)
                self.__history = history.RpnCalcHistory(
@@ -194,7 +195,7 @@ class Calculator(object):
                self.__keyboardPlugins.enable_plugin(builtinKeyboardId)
                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("mainKeyboard").pack_start(self.__builtinKeyboard)
                self.enable_plugin(self.__keyboardPlugins.lookup_plugin("Trigonometry"))
                self.enable_plugin(self.__keyboardPlugins.lookup_plugin("Computer"))
                self.enable_plugin(self.__keyboardPlugins.lookup_plugin("Alphabet"))
@@ -211,6 +212,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)
                self._widgetTree.get_widget("entryView").connect("activate", self._on_push)
+               self.__pluginButton.connect("clicked", self._on_kb_plugin_selection_button)
+
+               self._set_plugin_kb(0)
 
                hildonize.set_application_title(self._window, "%s" % constants.__pretty_app_name__)
                self._window.connect("destroy", self._on_close)
@@ -247,15 +251,30 @@ class Calculator(object):
                plugin = self.__keyboardPlugins.keyboards[pluginName].construct_keyboard()
                pluginKeyboard = plugin.setup(self.__history, self.__sliceStyle, self.__handler)
 
-               keyboardTabs = self._widgetTree.get_widget("pluginKeyboards")
-               keyboardTabs.append_page(pluginKeyboard, gtk.Label(pluginName))
-               keyboardPageNum = keyboardTabs.page_num(pluginKeyboard)
-               assert keyboardPageNum not in self.__activeKeyboards
-               self.__activeKeyboards[keyboardPageNum] = {
+               self.__activeKeyboards.append({
                        "pluginName": pluginName,
                        "plugin": plugin,
                        "pluginKeyboard": pluginKeyboard,
-               }
+               })
+
+       def _on_kb_plugin_selection_button(self, *args):
+               pluginNames = [plugin["pluginName"] for plugin in self.__activeKeyboards]
+               oldIndex = pluginNames.index(self.__pluginButton.get_label())
+               newIndex = hildonize.touch_selector(self._window, "Keyboards", pluginNames, oldIndex)
+               self._set_plugin_kb(newIndex)
+
+       def _set_plugin_kb(self, pluginIndex):
+               plugin = self.__activeKeyboards[pluginIndex]
+               self.__pluginButton.set_label(plugin["pluginName"])
+               pluginParent = self._widgetTree.get_widget("pluginKeyboard")
+               oldPluginChildren = pluginParent.get_children()
+               if oldPluginChildren:
+                       assert len(oldPluginChildren) == 1, "%r" % (oldPluginChildren, )
+                       pluginParent.remove(oldPluginChildren[0])
+                       oldPluginChildren[0].hide()
+               pluginKeyboard = plugin["pluginKeyboard"]
+               pluginParent.pack_start(pluginKeyboard)
+               pluginKeyboard.show_all()
 
        def __load_history(self):
                serialized = []