5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA 02111-1307 USA
26 class Panel (ibus.Object):
29 gobject.SIGNAL_RUN_FIRST,
33 gobject.SIGNAL_RUN_FIRST,
37 gobject.SIGNAL_RUN_FIRST,
41 gobject.SIGNAL_RUN_FIRST,
44 "property-activate" : (
45 gobject.SIGNAL_RUN_FIRST,
47 (gobject.TYPE_STRING, gobject.TYPE_INT)),
49 gobject.SIGNAL_RUN_FIRST,
51 (gobject.TYPE_STRING, )),
53 gobject.SIGNAL_RUN_FIRST,
55 (gobject.TYPE_STRING, )),
58 def __init__ (self, ibusconn, object_path):
59 ibus.Object.__init__ (self)
60 self._ibusconn = ibusconn
61 self._object_path = object_path
62 self._panel = self._ibusconn.get_object (self._object_path)
64 self._ibusconn.connect ("destroy", self._ibusconn_destroy_cb)
65 self._ibusconn.connect ("dbus-signal", self._dbus_signal_cb)
67 def set_cursor_location (self, x, y, w, h):
68 self._panel.SetCursorLocation (x, y, w, h,
69 **ibus.DEFAULT_ASYNC_HANDLERS)
71 def update_preedit (self, text, attrs, cursor_pos, visible):
72 self._panel.UpdatePreedit (text, attrs, cursor_pos, visible,
73 **ibus.DEFAULT_ASYNC_HANDLERS)
75 def update_aux_string (self, text, attrs, visible):
76 self._panel.UpdateAuxString (text, attrs, visible,
77 **ibus.DEFAULT_ASYNC_HANDLERS)
79 def update_lookup_table (self, lookup_table, visible):
80 self._panel.UpdateLookupTable (lookup_table, visible,
81 **ibus.DEFAULT_ASYNC_HANDLERS)
83 def register_properties (self, props):
84 self._panel.RegisterProperties (props,
85 **ibus.DEFAULT_ASYNC_HANDLERS)
87 def update_property (self, prop):
88 self._panel.UpdateProperties (prop,
89 **ibus.DEFAULT_ASYNC_HANDLERS)
91 def show_language_bar (self):
92 self._panel.ShowLanguageBar (**ibus.DEFAULT_ASYNC_HANDLERS)
94 def hide_language_bar (self):
95 self._panel.HideLanguageBar (**ibus.DEFAULT_ASYNC_HANDLERS)
98 self._panel.Reset (**ibus.DEFAULT_ASYNC_HANDLERS)
101 if self._ibusconn != None:
102 self._panel.Destroy (**ibus.DEFAULT_ASYNC_HANDLERS)
104 self._ibusconn = None
106 ibus.Object.destroy (self)
109 def _ibusconn_destroy_cb (self, ibusconn):
110 self._ibusconn = None
113 def _dbus_signal_cb (self, ibusconn, message):
114 if message.is_signal (ibus.IBUS_PANEL_IFACE, "PageUp"):
115 self.emit ("page-up")
116 elif message.is_signal (ibus.IBUS_PANEL_IFACE, "PageDown"):
117 self.emit ("page-down")
118 elif message.is_signal (ibus.IBUS_PANEL_IFACE, "CursorUp"):
119 self.emit ("cursor-up")
120 elif message.is_signal (ibus.IBUS_PANEL_IFACE, "CursorDown"):
121 self.emit ("cursor-down")
122 elif message.is_signal (ibus.IBUS_PANEL_IFACE, "PropertyActivate"):
123 args = message.get_args_list ()
124 self.emit ("property-activate", args[0], args[1])
125 elif message.is_signal (ibus.IBUS_PANEL_IFACE, "PropertyShow"):
126 args = message.get_args_list ()
127 self.emit ("property-show", args[0])
128 elif message.is_signal (ibus.IBUS_PANEL_IFACE, "PropertyHide"):
129 args = message.get_args_list ()
130 self.emit ("property-hide", args[0])
136 # def __lt__ (self, other):
137 # x = self.get_info ()
138 # y = other.get_info ()
139 # if x[1] < y[1]: return True
140 # if x[1] == y[1]: return x[0] < y[0]
142 # def __gt__ (self, other):
143 # x = self.get_info ()
144 # y = other.get_info ()
145 # if x[1] > y[1]: return True
146 # if x[1] == y[1]: return x[0] > y[0]
148 gobject.type_register (Panel)
150 class DummyPanel (ibus.Object):
153 gobject.SIGNAL_RUN_FIRST,
157 gobject.SIGNAL_RUN_FIRST,
161 gobject.SIGNAL_RUN_FIRST,
165 gobject.SIGNAL_RUN_FIRST,
168 "property-activate" : (
169 gobject.SIGNAL_RUN_FIRST,
171 (gobject.TYPE_STRING, )),
174 def set_cursor_location (self, x, y, w, h):
177 def update_preedit (self, text, attrs, cursor_pos, visible):
180 def update_aux_string (self, text, attrs, visible):
183 def update_lookup_table (self, lookup_table, visible):
186 def register_properties (self, props):
189 def update_property (self, prop):
192 def show_language_bar (self):
195 def hide_language_bar (self):
201 gobject.type_register (DummyPanel)