Add PanelBase class.
authorHuang Peng <shawn.p.huang@gmail.com>
Sun, 20 Jul 2008 02:33:18 +0000 (10:33 +0800)
committerHuang Peng <shawn.p.huang@gmail.com>
Sun, 20 Jul 2008 02:33:18 +0000 (10:33 +0800)
ibus/__init__.py
ibus/panel.py
panel/candidatepanel.py
panel/panel.py

index b777d60..26f54d2 100644 (file)
@@ -31,3 +31,4 @@ from lang import *
 from utility import *
 from engine import *
 from factory import *
+from panel import *
index 18cdaff..3fe085d 100644 (file)
 # Boston, MA  02111-1307  USA
 
 __all__ = (
+        "PanelBase",
         "PanelItem",
         "PanelButton",
         "PanelToggleButton",
         "PanelMenu",
     )
 
+import ibus
+from ibus import interface
+
 class PanelItem:
     pass
 
@@ -38,3 +42,140 @@ class PanelToggleButton(PanelButton):
 class PanelMenu(PanelItem):
     pass
 
+class PanelBase(ibus.Object):
+    def __init__(self, dbusconn, object_path):
+        super(PanelBase, self).__init__()
+        self.__proxy = PanelProxy(self, dbusconn, object_path)
+
+    def set_cursor_location(self, x, y, w, h):
+        pass
+
+    def update_preedit(self, text, attrs, cursor_pos, visible):
+        pass
+
+    def update_aux_string(self, text, attrs, visible):
+        pass
+
+    def update_lookup_table(self, lookup_table, visible):
+        pass
+
+    def show_candidate_window(self):
+        pass
+
+    def hide_candidate_window(self):
+        pass
+
+    def show_language_bar(self):
+        pass
+
+    def hide_language_bar(self):
+        pass
+
+    def register_properties(self, props):
+        pass
+
+    def update_property(self, prop):
+        pass
+
+    def focus_in(self, ic):
+        pass
+
+    def focus_out(self, ic):
+        pass
+
+    def states_changed(self):
+        pass
+
+    def reset(self):
+        pass
+
+    def page_up(self):
+        self.__proxy.PageUp()
+
+    def page_down(self):
+        self.__proxy.PageDown()
+
+    def cursor_up(self):
+        self.__proxy.CursorUp()
+
+    def cursor_down(self):
+        self.__proxy.CursorDown()
+
+    def property_activate(self, prop_name, prop_state):
+        self.__proxy.PropertyActivate(prop_name, prop_state)
+
+    def property_show(self, prop_name):
+        self.__proxy.PropertyShow(prop_name)
+
+    def property_hide(self, prop_name):
+        self.__proxy.PropertyHide(prop_name)
+
+
+class PanelProxy(interface.IPanel):
+    def __init__ (self, panel, dbusconn, object_path):
+        super(PanelProxy, self).__init__(dbusconn, object_path)
+        self.__dbusconn = dbusconn
+        self.__panel = panel
+
+    def SetCursorLocation(self, x, y, w, h):
+        self.__panel.set_cursor_location(x, y, w, h)
+
+    def UpdatePreedit(self, text, attrs, cursor_pos, show):
+        attrs = ibus.attr_list_from_dbus_value(attrs)
+        self.__panel.update_preedit(text, atrrs, cursor_pos, show)
+
+    def ShowPreeditString(self):
+        self.__panel.show_preedit_string()
+
+    def HidePreeditString(self):
+        self.__panel.hide_preedit_string()
+
+    def UpdateAuxString(self, text, attrs, show):
+        attrs = ibus.attr_list_from_dbus_value(attrs)
+        self.__panel.update_aux_string(text, attrs, show)
+
+    def ShowAuxString(self):
+        self.__panel.show_aux_string()
+
+    def HideAuxString(self):
+        self.__panel.hide_aux_string()
+
+    def UpdateLookupTable(self, lookup_table, show):
+        lookup_table = ibus.lookup_table_from_dbus_value(lookup_table)
+        self.__panel.update_lookup_table(lookup_table, show)
+
+    def ShowCandidateWindow(self):
+        self.__panel.show_candidate_window()
+
+    def HideCandidateWindow(self):
+        self.__panel.hide_candidate_window()
+
+    def ShowLanguageBar(self):
+        self.__panel.show_language_bar()
+
+    def HideLanguageBar(self):
+        self.__panel.hide_language_bar()
+
+    def RegisterProperties(self, props):
+        props = ibus.prop_list_from_dbus_value(props)
+        self.__panel.register_properties(props)
+
+    def UpdateProperty(self, prop):
+        prop = ibus.property_from_dbus_value(prop)
+        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()
+
+    def Destroy(self):
+        self.__panel.destroy()
+
index 78e0b1b..bbb4898 100644 (file)
@@ -87,6 +87,9 @@ class CandidateArea(gtk.HBox):
                 end_index = len(text.encode("utf8"))
                 attr = pango.AttrBackground(color.red, color.green, color.blue, 0, end_index)
                 attrs.change(attr)
+                color = self.__labels[i][1].style.text[gtk.STATE_SELECTED]
+                attr = pango.AttrForeground(color.red, color.green, color.blue, 0, end_index)
+                attrs.insert(attr)
 
             self.__labels[i][1].set_text(text)
             self.__labels[i][1].set_attributes(attrs)
index 0a9cac5..0a239d9 100644 (file)
@@ -29,10 +29,9 @@ from ibus import interface
 from languagebar import LanguageBar
 from candidatepanel import CandidatePanel
 
-class Panel(ibus.Object):
+class Panel(ibus.PanelBase):
     def __init__ (self, dbusconn, object_path, __ibus):
-        super(Panel, self).__init__()
-        self.__proxy = PanelProxy(self, dbusconn, object_path)
+        super(Panel, self).__init__(dbusconn, object_path)
         self.__ibus = __ibus
         self.__focus_ic = None
 
@@ -44,7 +43,7 @@ class Panel(ibus.Object):
 
         self.__language_bar = LanguageBar()
         self.__language_bar.connect("property-activate",
-                        lambda widget, prop_name, prop_state: self.__proxy.PropertyActivate(prop_name, prop_state))
+                        lambda widget, prop_name, prop_state: self.property_activate(prop_name, prop_state))
         self.__language_bar.connect("get-im-menu",
                         self.__get_im_menu_cb)
         self.__language_bar.focus_out()
@@ -52,9 +51,9 @@ class Panel(ibus.Object):
 
         self.__candidate_panel = CandidatePanel()
         self.__candidate_panel.connect("cursor-up",
-                        lambda widget: self.__proxy.CursorUp())
+                        lambda widget: self.cursor_up())
         self.__candidate_panel.connect("cursor-down",
-                        lambda widget: self.__proxy.CursorDown())
+                        lambda widget: self.cursor_down())
 
         self.__status_icon = gtk.StatusIcon()
         self.__status_icon.connect("popup-menu", self.__status_icon_popup_menu_cb)