Remember panel position
authorPeng Huang <shawn.p.huang@gmail.com>
Sat, 28 Nov 2009 07:38:41 +0000 (15:38 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Sat, 28 Nov 2009 07:38:41 +0000 (15:38 +0800)
data/ibus.schemas.in
setup/main.py
setup/setup.ui
ui/gtk/languagebar.py
ui/gtk/panel.py

index 019557e..466ca76 100644 (file)
       </locale>
     </schema>
     <schema>
+      <key>/schemas/desktop/ibus/panel/x</key>
+      <applyto>/desktop/ibus/panel/x</applyto>
+      <owner>ibus</owner>
+      <type>int</type>
+      <default>-1</default>
+      <locale name="C">
+        <short>Position of panel</short>
+      </locale>
+    </schema>
+    <schema>
+      <key>/schemas/desktop/ibus/panel/y</key>
+      <applyto>/desktop/ibus/panel/y</applyto>
+      <owner>ibus</owner>
+      <type>int</type>
+      <default>-1</default>
+      <locale name="C">
+        <short>Position of panel</short>
+      </locale>
+    </schema>
+    <!--
+    <schema>
+      <key>/schemas/desktop/ibus/panel/position</key>
+      <applyto>/desktop/ibus/panel/position</applyto>
+      <owner>ibus</owner>
+      <type>int</type>
+      <default>3</default>
+      <locale name="C">
+        <short>Panel position</short>
+           <long>The position of the language panel. 0 = Top left corner, 1 = Top right corner, 2 = Bottom left corner, 3 = Bottom eight corner, 4 = Custom</long>
+      </locale>
+    </schema>
+    -->
+    <schema>
       <key>/schemas/desktop/ibus/panel/lookup_table_orientation</key>
       <applyto>/desktop/ibus/panel/lookup_table_orientation</applyto>
       <owner>ibus</owner>
index f454b44..1ac0de7 100644 (file)
@@ -140,19 +140,22 @@ class Setup(object):
             self.__config.get_value("panel", "show", 1))
         self.__combobox_panel_show.connect("changed", self.__combobox_panel_show_changed_cb)
 
+        # panel position
+        self.__combobox_panel_position = self.__builder.get_object("combobox_panel_position")
+        self.__combobox_panel_position.set_active(
+            self.__config.get_value("panel", "position", 3))
+        self.__combobox_panel_position.connect("changed", self.__combobox_panel_position_changed_cb)
+
         # custom font
         self.__checkbutton_custom_font = self.__builder.get_object("checkbutton_custom_font")
         self.__checkbutton_custom_font.set_active(
             self.__config.get_value("panel", "use_custom_font", False))
         self.__checkbutton_custom_font.connect("toggled", self.__checkbutton_custom_font_toggled_cb)
 
-        self.__label_custom_font = self.__builder.get_object("label_custom_font")
         self.__fontbutton_custom_font = self.__builder.get_object("fontbutton_custom_font")
         if self.__config.get_value("panel", "use_custom_font", False):
-            self.__label_custom_font.set_sensitive(True)
             self.__fontbutton_custom_font.set_sensitive(True)
         else:
-            self.__label_custom_font.set_sensitive(False)
             self.__fontbutton_custom_font.set_sensitive(False)
         font_name = gtk.settings_get_default().get_property("gtk-font-name")
         font_name = unicode(font_name, "utf-8")
@@ -375,13 +378,16 @@ class Setup(object):
             "panel", "show",
             self.__combobox_panel_show.get_active())
 
+    def __combobox_panel_position_changed_cb(self, combobox):
+        self.__config.set_value(
+            "panel", "position",
+            self.__combobox_panel_position.get_active())
+
     def __checkbutton_custom_font_toggled_cb(self, button):
         if self.__checkbutton_custom_font.get_active():
-            self.__label_custom_font.set_sensitive(True)
             self.__fontbutton_custom_font.set_sensitive(True)
             self.__config.set_value("panel", "use_custom_font", True)
         else:
-            self.__label_custom_font.set_sensitive(False)
             self.__fontbutton_custom_font.set_sensitive(False)
             self.__config.set_value("panel", "use_custom_font", False)
 
index c2d608c..89ce5fb 100644 (file)
@@ -2,7 +2,7 @@
 <interface>
   <requires lib="gtk+" version="2.14"/>
   <!-- interface-naming-policy toplevel-contextual -->
-  <object class="GtkListStore" id="model1">
+  <object class="GtkListStore" id="model_candidates_orientation">
     <columns>
       <!-- column-name gchararray -->
       <column type="gchararray"/>
@@ -16,7 +16,7 @@
       </row>
     </data>
   </object>
-  <object class="GtkListStore" id="model2">
+  <object class="GtkListStore" id="model_panel_show_mode">
     <columns>
       <!-- column-name gchararray -->
       <column type="gchararray"/>
                                     <child>
                                       <object class="GtkComboBox" id="combobox_lookup_table_orientation">
                                         <property name="visible">True</property>
-                                        <property name="model">model1</property>
+                                        <property name="model">model_candidates_orientation</property>
                                         <child>
                                           <object class="GtkCellRendererText" id="renderer1"/>
                                           <attributes>
                                     <child>
                                       <object class="GtkComboBox" id="combobox_panel_show">
                                         <property name="visible">True</property>
-                                        <property name="model">model2</property>
+                                        <property name="model">model_panel_show_mode</property>
                                         <child>
                                           <object class="GtkCellRendererText" id="renderer2"/>
                                           <attributes>
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkCheckButton" id="checkbutton_show_icon_on_systray">
-                                    <property name="label" translatable="yes">Show icon on system tray</property>
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">True</property>
-                                    <property name="receives_default">False</property>
-                                    <property name="has_tooltip">True</property>
-                                    <property name="tooltip_text" translatable="yes">Show icon on system tray</property>
-                                    <property name="draw_indicator">True</property>
+                                  <object class="GtkHBox" id="hbox7">
+                                    <property name="no_show_all">True</property>
+                                    <property name="homogeneous">True</property>
+                                    <child>
+                                      <object class="GtkLabel" id="label16">
+                                        <property name="xalign">0</property>
+                                        <property name="label" translatable="yes">Language panel position:</property>
+                                        <property name="justify">right</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkComboBox" id="combobox_panel_position">
+                                        <property name="model">model_panel_position</property>
+                                        <child>
+                                          <object class="GtkCellRendererText" id="renderer3"/>
+                                          <attributes>
+                                            <attribute name="text">0</attribute>
+                                          </attributes>
+                                        </child>
+                                      </object>
+                                      <packing>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
                                   </object>
                                   <packing>
                                     <property name="position">2</property>
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkCheckButton" id="checkbutton_show_im_name">
-                                    <property name="label" translatable="yes">Show input method name on language bar</property>
+                                  <object class="GtkCheckButton" id="checkbutton_show_icon_on_systray">
+                                    <property name="label" translatable="yes">Show icon on system tray</property>
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">False</property>
-                                    <property name="tooltip_text" translatable="yes">Show input method's name on language bar when check the checkbox</property>
+                                    <property name="has_tooltip">True</property>
+                                    <property name="tooltip_text" translatable="yes">Show icon on system tray</property>
                                     <property name="draw_indicator">True</property>
                                   </object>
                                   <packing>
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkCheckButton" id="checkbutton_custom_font">
-                                    <property name="label" translatable="yes">Use custom font</property>
+                                  <object class="GtkCheckButton" id="checkbutton_show_im_name">
+                                    <property name="label" translatable="yes">Show input method name on language bar</property>
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">False</property>
-                                    <property name="tooltip_text" translatable="yes">Use custom font for language bar and candidates</property>
-                                    <property name="use_underline">True</property>
+                                    <property name="tooltip_text" translatable="yes">Show input method's name on language bar when check the checkbox</property>
                                     <property name="draw_indicator">True</property>
                                   </object>
                                   <packing>
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkHBox" id="hbox7">
+                                  <object class="GtkHBox" id="hbox9">
                                     <property name="visible">True</property>
+                                    <property name="homogeneous">True</property>
                                     <child>
-                                      <object class="GtkLabel" id="label_custom_font">
+                                      <object class="GtkCheckButton" id="checkbutton_custom_font">
+                                        <property name="label" translatable="yes">Use custom font</property>
                                         <property name="visible">True</property>
-                                        <property name="tooltip_text" translatable="yes">Font for language bar and candidates</property>
-                                        <property name="xalign">0</property>
-                                        <property name="label" translatable="yes">Custom font:</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">False</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="draw_indicator">True</property>
                                       </object>
                                       <packing>
                                         <property name="position">0</property>
                                       <object class="GtkFontButton" id="fontbutton_custom_font">
                                         <property name="visible">True</property>
                                         <property name="can_focus">True</property>
-                                        <property name="receives_default">False</property>
+                                        <property name="receives_default">True</property>
                                       </object>
                                       <packing>
                                         <property name="position">1</property>
@@ -841,4 +864,27 @@ Homepage: http://code.google.com/p/ibus
       </object>
     </child>
   </object>
+  <object class="GtkListStore" id="model_panel_position">
+    <columns>
+      <!-- column-name position -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Top left corner</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Top right corner</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Bottom left corner</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Bottom right corner</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Custom</col>
+      </row>
+    </data>
+  </object>
 </interface>
index 4e7dcc6..604df12 100644 (file)
@@ -54,7 +54,10 @@ class LanguageBar(gtk.Toolbar):
             gobject.SIGNAL_RUN_LAST,
             gobject.TYPE_PYOBJECT,
             ()),
-
+        "position-changed" : (
+            gobject.SIGNAL_RUN_LAST,
+            gobject.TYPE_NONE,
+            (gobject.TYPE_INT, gobject.TYPE_INT)),
         }
 
     def __init__ (self):
@@ -80,8 +83,7 @@ class LanguageBar(gtk.Toolbar):
         except:
             w, h = root.get_size()
             self.__work_area = 0, 0, w, h
-        self.__position = self.__work_area[0] + self.__work_area[2] - 20, self.__work_area[1] + self.__work_area[3] - 20
-        self.__toplevel.move(*self.__position)
+        self.set_position(-1, -1)
 
     def __create_ui(self):
         # create move handle
@@ -125,10 +127,11 @@ class LanguageBar(gtk.Toolbar):
         x, y = self.__toplevel.get_position()
         w, h = self.__toplevel.get_size()
         self.__position = x + w, y + h
+        self.emit("position-changed", *self.__position)
 
     def __toplevel_size_allocate_cb(self, toplevel, allocation):
         x, y = self.__position
-        if x - self.__work_area[0] >= self.__work_area[2] - 80:
+        if x - self.__work_area[0] >= self.__work_area[2] - 80 or True:
             self.__toplevel.move(x - allocation.width, y - allocation.height)
 
     def __remove_properties(self):
@@ -195,6 +198,19 @@ class LanguageBar(gtk.Toolbar):
         else:
             self.focus_out()
 
+    def set_position(self, x, y):
+        if x < 0 or y < 0:
+            x = self.__work_area[0] + self.__work_area[2] - 20
+            y = self.__work_area[1] + self.__work_area[3] - 20
+        if x > self.__work_area[2]:
+            x = self.__work_area[0] + self.__work_area[2] - 20
+        if y > self.__work_area[3]:
+            y = self.__work_area[1] + self.__work_area[3] - 20
+
+        self.__position = x, y
+        w, h = self.__toplevel.get_size()
+        self.__toplevel.move(self.__position[0] - w, self.__position[1] - h)
+
     def get_show(self):
         return self.__show
 
index 08ffe4d..615eb58 100644 (file)
@@ -88,6 +88,8 @@ class Panel(ibus.PanelBase):
                         self.__get_im_menu_cb)
         self.__language_bar.connect("show-engine-about",
                         self.__show_engine_about_cb)
+        self.__language_bar.connect("position-changed",
+                        self.__position_changed_cb)
         self.__language_bar.focus_out()
         self.__language_bar.show_all()
 
@@ -113,6 +115,7 @@ class Panel(ibus.PanelBase):
 
         self.__config_load_lookup_table_orientation()
         self.__config_load_show()
+        self.__config_load_position()
         self.__config_load_custom_font()
         self.__config_load_show_icon_on_systray()
         self.__config_load_show_im_name()
@@ -264,6 +267,12 @@ class Panel(ibus.PanelBase):
         show = self.__config.get_value("panel", "show", 1)
         self.__language_bar.set_show(show)
 
+    def __config_load_position(self):
+        position = self.__config.get_value("panel", "position", 3)
+        x = self.__config.get_value("panel", "x", -1)
+        y = self.__config.get_value("panel", "y", -1)
+        self.__language_bar.set_position(x, y)
+
     def __config_load_custom_font(self):
         use_custom_font = self.__config.get_value("panel", "use_custom_font", False)
         font_name = gtk.settings_get_default().get_property("gtk-font-name")
@@ -296,6 +305,8 @@ class Panel(ibus.PanelBase):
             self.__config_load_lookup_table_orientation()
         elif name == "show":
             self.__config_load_show()
+        # elif name == "position":
+        #     self.__config_load_position()
         elif name == "use_custom_font" or name == "custom_font":
             self.__config_load_custom_font()
         elif name == "show_icon_on_systray":
@@ -387,7 +398,7 @@ class Panel(ibus.PanelBase):
         menu = self.__create_im_menu()
         return menu
 
-    def __show_engine_about_cb(self, langiagebar):
+    def __show_engine_about_cb(self, langagebar):
         try:
             engine = self.__focus_ic.get_engine()
             dlg = EngineAbout(engine)
@@ -396,6 +407,10 @@ class Panel(ibus.PanelBase):
         except:
             pass
 
+    def __position_changed_cb(self, langagebar, x, y):
+        self.__config.set_value("panel", "x", x)
+        self.__config.set_value("panel", "y", y)
+
     def __status_icon_popup_menu_cb(self, status_icon, button, active_time):
         menu = self.__create_sys_menu()
         menu.popup(None, None,