WIP.
authorHuang Peng <shawn.p.huang@gmail.com>
Wed, 25 Jun 2008 12:24:31 +0000 (20:24 +0800)
committerHuang Peng <shawn.p.huang@gmail.com>
Wed, 25 Jun 2008 12:24:31 +0000 (20:24 +0800)
daemon/bus.py
daemon/engine.py
daemon/inputcontext.py
daemon/panel.py
ibus/interface/iibus.py
ibus/interface/ipanel.py
panel/languagebar.py
panel/panel.py

index ada940e..5fc27bc 100644 (file)
@@ -85,7 +85,7 @@ class IBus (ibus.Object):
                self._focused_context = context
                self._install_focused_context_handlers ()
 
-               self._panel.reset ()
+               self._panel.focus_in (context.get_id ())
                self._last_focused_context = context
                context.focus_in ()
 
@@ -97,7 +97,7 @@ class IBus (ibus.Object):
                        self._focused_context = None
 
                context.focus_out ()
-               self._panel.reset ()
+               self._panel.focus_out (context.get_id ())
 
        def reset (self, ic, dbusconn):
                context = self._lookup_context (ic, dbusconn)
@@ -132,6 +132,7 @@ class IBus (ibus.Object):
                                if factory:
                                        engine = factory.create_engine ()
                                        context.set_engine (engine)
+                       self._panel.states_changed ()
                        return True
                return False
 
@@ -290,6 +291,12 @@ class IBus (ibus.Object):
                engine = factory.create_engine ()
                self._focused_context.set_engine (engine)
 
+       def get_input_context_states (self, ic, dbusconn):
+               context = self._lookup_context (ic, dbusconn)
+               factory_path = "" if context.get_factory () == None else context.get_factory ().get_object_path ()
+               return factory_path, context.is_enabled ()
+
+
 class IBusProxy (ibus.IIBus):
        SUPPORTS_MULTIPLE_CONNECTIONS = True
 
@@ -356,3 +363,6 @@ class IBusProxy (ibus.IIBus):
        def SetFactory (self, factory_path, dbusconn):
                return self._ibus.set_factory (factory_path)
 
+       def GetInputContextStates (self, ic, dbusconn):
+               return self._ibus.get_input_context_states (ic, dbusconn)
+
index fd44111..28b2481 100644 (file)
@@ -67,6 +67,9 @@ class Engine (ibus.Object):
        def get_factory (self):
                return self._factory
 
+       def get_object_path (self):
+               return self._object_path
+
        def handle_dbus_signal (self, message):
                if message.is_signal (ibus.IBUS_ENGINE_IFACE, "CommitString"):
                        args = message.get_args_list ()
index 02271d2..3a4c339 100644 (file)
@@ -177,6 +177,11 @@ class InputContext (ibus.Object):
        def get_engine (self):
                return self._engine
 
+       def get_factory (self):
+               if self._engine:
+                       return self._engine.get_factory ()
+               return None
+
        def _engine_destroy_cb (self, engine):
                if self._engine == engine:
                        self._remove_engine_handlers ()
index 526bfc9..9189702 100644 (file)
@@ -94,6 +94,15 @@ class Panel (ibus.Object):
        def hide_language_bar (self):
                self._panel.HideLanguageBar (**ibus.DEFAULT_ASYNC_HANDLERS)
 
+       def focus_in (self, ic):
+               self._panel.FocusIn (ic, **ibus.DEFAULT_ASYNC_HANDLERS)
+
+       def focus_out (self, ic):
+               self._panel.FocusOut (ic, **ibus.DEFAULT_ASYNC_HANDLERS)
+
+       def states_changed (self):
+               self._panel.StatesChanged (**ibus.DEFAULT_ASYNC_HANDLERS)
+
        def reset (self):
                self._panel.Reset (**ibus.DEFAULT_ASYNC_HANDLERS)
 
@@ -195,6 +204,15 @@ class DummyPanel (ibus.Object):
        def hide_language_bar (self):
                pass
 
+       def focus_in (self, ic):
+               pass
+
+       def focus_out (self, ic):
+               pass
+
+       def states_changed (self):
+               pass
+
        def reset (self):
                pass
 
index 476401b..df79b36 100644 (file)
@@ -88,6 +88,9 @@ class IIBus (dbus.service.Object):
        @method (in_signature = "o")
        def SetFactory (self, factory_path, dbusconn): pass
 
+       @method (in_signature = "s", out_signature = "ob")
+       def GetInputContextStates (self, ic, dbusconn): pass
+
        #sigals
        def CommitString (self, ic, text): pass
 
index 5b830a8..1953bf0 100644 (file)
@@ -41,22 +41,22 @@ class IPanel (dbus.service.Object):
                dbus.service.method (dbus_interface = IBUS_PANE_IFACE, \
                                                        async_callbacks = ("reply_cb", "error_cb"), \
                                                        **args)
-       @method (in_signature="iiii")
+       @method (in_signature = "iiii")
        def SetCursorLocation (self, x, y, w, h): pass
 
-       @method (in_signature="svub")
+       @method (in_signature = "svub")
        def UpdatePreedit (self, text, attrs, cursor_pos, visible): pass
 
-       @method (in_signature="svb")
+       @method (in_signature = "svb")
        def UpdateAuxString (self, text, attrs, visible): pass
 
-       @method (in_signature="vb")
+       @method (in_signature = "vb")
        def UpdateLookupTable (self, lookup_table, visible): pass
 
-       @method (in_signature="v")
+       @method (in_signature = "v")
        def RegisterProperties (self, props): pass
 
-       @method (in_signature="v")
+       @method (in_signature = "v")
        def UpdateProperty (self, prop): pass
 
        @method ()
@@ -65,6 +65,15 @@ class IPanel (dbus.service.Object):
        @method ()
        def HideLanguageBar (self): pass
 
+       @method (in_signature = "s")
+       def FocusIn (self, ic): pass
+
+       @method (in_signature = "s")
+       def FocusOut (self, ic): pass
+
+       @method ()
+       def StatesChanged (self): pass
+
        @method ()
        def Reset (self): pass
 
index d4ebb9d..6aad882 100644 (file)
@@ -104,6 +104,9 @@ class LanguageBar (gtk.Toolbar):
                gtk.Toolbar.do_size_request (self, requisition)
                self._toplevel.resize (1, 1)
 
+       def set_im_icon (self, icon_name):
+               self._im_menu.set_icon_name (icon_name)
+
        def reset (self):
                self._remove_properties ()
 
index 3e5b76f..defef68 100644 (file)
@@ -34,6 +34,7 @@ class Panel (ibus.Object):
                gobject.GObject.__init__ (self)
                self._proxy = proxy
                self._ibus = _ibus
+               self._focus_ic = None
 
                # add icon search path
                icon_theme = gtk.icon_theme_get_default ()
@@ -46,7 +47,6 @@ class Panel (ibus.Object):
                                                lambda widget, prop_name, prop_state: self._proxy.PropertyActivate (prop_name, prop_state))
                self._language_bar.connect ("get-im-menu",
                                                self._get_im_menu_cb)
-               self._language_bar.show_all ()
 
                self._candidate_panel = CandidatePanel ()
                self._candidate_panel.connect ("cursor-up",
@@ -103,6 +103,38 @@ class Panel (ibus.Object):
        def update_property (self, prop):
                self._language_bar.update_property (self, prop)
 
+       def _set_im_icon (self, icon_name):
+               self._language_bar.set_im_icon (icon_name)
+               self._status_icon.set_from_icon_name (icon_name)
+
+       def focus_in (self, ic):
+               self.reset ()
+               self._focus_ic = ic
+               factory, enabled = self._ibus.GetInputContextStates (ic)
+               if not enabled:
+                       self._set_im_icon ("engine-default")
+               else:
+                       name, lang, icon, authors, credits = self._ibus.GetFactoryInfo (factory)
+                       self._set_im_icon (icon)
+               self._language_bar.show_all ()
+
+       def focus_out (self, ic):
+               self.reset ()
+               if self._focus_ic == ic:
+                       self._focus_ic = None
+                       self._language_bar.hide_all ()
+                       self._set_im_icon ("engine-default")
+
+       def states_changed (self):
+               if not self._focus_ic:
+                       return
+               factory, enabled = self._ibus.GetInputContextStates (self._focus_ic)
+               if not enabled:
+                       self._set_im_icon ("engine-default")
+               else:
+                       name, lang, icon, authors, credits = self._ibus.GetFactoryInfo (factory)
+                       self._set_im_icon (icon)
+
        def reset (self):
                self._candidate_panel.reset ()
                self._language_bar.reset ()
@@ -209,6 +241,15 @@ class PanelProxy (interface.IPanel):
                prop = ibus.property_from_dbus_value (props)
                self._panel.update_property (prop)
 
+       def FocusIn (self, ic):
+               self._panel.focus_in (ic)
+
+       def FocusOut (self, ic):
+               self._panel.focus_out (ic)
+
+       def StatesChanged (self):
+               self._panel.states_changed ()
+
        def Reset (self):
                self._panel.reset ()