Show im name on languagebar
authorPeng Huang <shawn.p.huang@gmail.com>
Tue, 9 Jun 2009 01:08:04 +0000 (09:08 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Tue, 9 Jun 2009 01:08:04 +0000 (09:08 +0800)
setup/main.py
setup/setup.glade
ui/gtk/languagebar.py
ui/gtk/panel.py

index a00644cd10accaecf5c240c3385bbc48236b00d5..243dbac030a37b94b9babc159fc4357571a875d6 100644 (file)
@@ -156,6 +156,12 @@ class Setup(object):
         self.__fontbutton_custom_font.connect("notify::font-name", self.__fontbutton_custom_font_notify_cb)
         self.__fontbutton_custom_font.set_font_name(font_name)
 
+        # show ime name
+        self.__checkbutton_show_im_name = self.__xml.get_widget("checkbutton_show_im_name")
+        self.__checkbutton_show_im_name.set_active(
+            self.__config.get_value("panel", "show_im_name", False))
+        self.__checkbutton_show_im_name.connect("toggled", self.__checkbutton_show_im_name_toggled_cb)
+
         # init engine page
         self.__engines = self.__bus.list_engines()
         self.__combobox = EngineComboBox(self.__engines)
@@ -365,6 +371,10 @@ class Setup(object):
         font_name = unicode(font_name, "utf-8")
         self.__config.set_value("panel", "custom_font", font_name)
 
+    def __checkbutton_show_im_name_toggled_cb(self, button):
+        value = self.__checkbutton_show_im_name.get_active()
+        self.__config.set_value("panel", "show_im_name", value)
+
     def __config_value_changed_cb(self, bus, section, name, value):
         pass
 
index 1436e1cdb6e45ce248acdf64dc09ea1943d3a0a7..9202f730f12f973535ac1e9c98d60db6d1bf2567 100644 (file)
@@ -284,6 +284,18 @@ Always</property>
                                     <property name="position">1</property>
                                   </packing>
                                 </child>
+                                <child>
+                                  <widget 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="draw_indicator">True</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="position">2</property>
+                                  </packing>
+                                </child>
                                 <child>
                                   <widget class="GtkCheckButton" id="checkbutton_custom_font">
                                     <property name="label" translatable="yes">Use custom font</property>
@@ -294,7 +306,7 @@ Always</property>
                                     <property name="draw_indicator">True</property>
                                   </widget>
                                   <packing>
-                                    <property name="position">2</property>
+                                    <property name="position">3</property>
                                   </packing>
                                 </child>
                                 <child>
@@ -322,7 +334,7 @@ Always</property>
                                     </child>
                                   </widget>
                                   <packing>
-                                    <property name="position">3</property>
+                                    <property name="position">4</property>
                                   </packing>
                                 </child>
                               </widget>
index 5012733cd5ec85e09aef7c4398e5a13e84b9fdc2..9a7967732974c6ba6659544bb8e94dd5bc86022a 100644 (file)
@@ -23,6 +23,7 @@ import gtk
 import gtk.gdk as gdk
 import gobject
 import ibus
+import icon
 from handle import Handle
 from menu import menu_position
 from engineabout import EngineAbout
@@ -59,7 +60,9 @@ class LanguageBar(gtk.Toolbar):
         self.__show = 1
         self.__enabled = False
         self.__has_focus = False
-        self.set_style(gtk.TOOLBAR_ICONS)
+        self.__show_im_name = False
+        self.__im_name = None
+        self.set_style(gtk.TOOLBAR_BOTH_HORIZ)
         self.set_show_arrow(False)
         self.set_property("icon-size", ICON_SIZE)
         self.__create_ui()
@@ -87,8 +90,8 @@ class LanguageBar(gtk.Toolbar):
         handle.connect("move-end", self.__handle_move_end_cb)
 
         # create input methods menu
-        prop = ibus.Property(key = "", type = ibus.PROP_TYPE_TOGGLE, icon = "ibus", tooltip = _("Switch input method"))
-        self.__im_menu = ToggleToolButton(prop)
+        prop = ibus.Property(key = "", type = ibus.PROP_TYPE_TOGGLE, icon = "ibus", tooltip = _("Switch input method"))
+        self.__im_menu = gtk.ToggleToolButton()
         self.__im_menu.set_homogeneous(False)
         self.__im_menu.connect("toggled", self.__im_menu_toggled_cb)
         self.insert(self.__im_menu, -1)
@@ -144,7 +147,22 @@ class LanguageBar(gtk.Toolbar):
         self.__toplevel.resize(1, 1)
 
     def set_im_icon(self, icon_name):
-        self.__im_menu.set_icon_name(icon_name)
+        widget = icon.IconWidget(icon_name, 18)
+        self.__im_menu.set_icon_widget(widget)
+
+    def set_show_im_name(self, show):
+        self.__show_im_name = show
+        self.set_im_name(self.__im_name)
+        self.__im_menu.set_is_important(show)
+
+    def set_im_name(self, text):
+        self.__im_name = text
+        if text:
+            self.__im_menu.set_tooltip_text(text)
+            self.__im_menu.set_label(text)
+        else:
+            self.__im_menu.set_tooltip_text(_("Switch input method"))
+            self.__im_menu.set_label("")
 
     def reset(self):
         self.__remove_properties()
index fc5fa7003646242b6460ad48e38615f5bba36aa3..bfd2ef635fd87ae28b7f5ec228577ae9cec937a2 100644 (file)
@@ -103,6 +103,7 @@ class Panel(ibus.PanelBase):
         self.__config_load_lookup_table_orientation()
         self.__config_load_show()
         self.__config_load_custom_font()
+        self.__config_load_show_im_name()
         # self.__bus.request_name(ibus.panel.IBUS_SERVICE_PANEL, 0)
 
     def set_cursor_location(self, x, y, w, h):
@@ -177,6 +178,9 @@ class Panel(ibus.PanelBase):
         else:
             self.__status_icon.set_from_icon_name(icon_name)
 
+    def __set_im_name(self, name):
+        self.__language_bar.set_im_name(name)
+
     def focus_in(self, ic):
         self.reset()
         self.__focus_ic = ibus.InputContext(self.__bus, ic)
@@ -185,12 +189,15 @@ class Panel(ibus.PanelBase):
 
         if not enabled:
             self.__set_im_icon(self.__ibus_icon)
+            self.__set_im_name(None)
         else:
             engine = self.__focus_ic.get_engine()
             if engine:
                 self.__set_im_icon(engine.icon)
+                self.__set_im_name(engine.longname)
             else:
                 self.__set_im_icon(self.__ibus_icon)
+                self.__set_im_name(None)
         self.__language_bar.focus_in()
 
     def focus_out(self, ic):
@@ -199,6 +206,7 @@ class Panel(ibus.PanelBase):
         self.__language_bar.set_enabled(False)
         self.__language_bar.focus_out()
         self.__set_im_icon(self.__ibus_icon)
+        self.__set_im_name(None)
 
     def state_changed(self):
         if not self.__focus_ic:
@@ -210,12 +218,15 @@ class Panel(ibus.PanelBase):
         if enabled == False:
             self.reset()
             self.__set_im_icon(self.__ibus_icon)
+            self.__set_im_name(None)
         else:
             engine = self.__focus_ic.get_engine()
             if engine:
                 self.__set_im_icon(engine.icon)
+                self.__set_im_name(engine.longname)
             else:
                 self.__set_im_icon(self.__ibus_icon)
+                self.__set_im_name(None)
 
 
     def reset(self):
@@ -258,6 +269,10 @@ class Panel(ibus.PanelBase):
         settings = gtk.settings_get_default()
         gtk.rc_reset_styles(settings)
 
+    def __config_load_show_im_name(self):
+        value = self.__config.get_value("panel", "show_im_name", False)
+        self.__language_bar.set_show_im_name(value)
+
     def __config_value_changed_cb(self, bus, section, name, value):
         if section != "panel":
             return
@@ -267,6 +282,10 @@ class Panel(ibus.PanelBase):
             self.__config_load_show()
         elif name == "use_custom_font" or name == "custom_font":
             self.__config_load_custom_font()
+        elif name == "show_im_name":
+            self.__config_load_show_im_name()
+        else:
+            print >> sys.stderr, "Unknown config item [%s]" % name
 
     def __config_reloaded_cb(self, bus):
         pass