Add header for sources.
[ibus.git] / ibusdaemon / panel.py
blobdbba68747dfa23f93e0683416fc0f52b2c2ecdd8
1 # vim:set noet ts=4:
3 # ibus - The Input Bus
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
22 import weakref
23 import gobject
24 import ibus
26 class Panel (ibus.Object):
27 __gsignals__ = {
28 "page-up" : (
29 gobject.SIGNAL_RUN_FIRST,
30 gobject.TYPE_NONE,
31 ()),
32 "page-down" : (
33 gobject.SIGNAL_RUN_FIRST,
34 gobject.TYPE_NONE,
35 ()),
36 "cursor-up" : (
37 gobject.SIGNAL_RUN_FIRST,
38 gobject.TYPE_NONE,
39 ()),
40 "cursor-down" : (
41 gobject.SIGNAL_RUN_FIRST,
42 gobject.TYPE_NONE,
43 ()),
44 "property-activate" : (
45 gobject.SIGNAL_RUN_FIRST,
46 gobject.TYPE_NONE,
47 (gobject.TYPE_STRING, )),
50 def __init__ (self, ibusconn, object_path):
51 ibus.Object.__init__ (self)
52 self._ibusconn = ibusconn
53 self._object_path = object_path
54 self._panel = self._ibusconn.get_object (self._object_path)
56 self._ibusconn.connect ("destroy", self._ibusconn_destroy_cb)
57 self._ibusconn.connect ("dbus-signal", self._dbus_signal_cb)
59 def set_cursor_location (self, x, y, w, h):
60 self._panel.SetCursorLocation (x, y, w, h,
61 **ibus.DEFAULT_ASYNC_HANDLERS)
63 def update_preedit (self, text, attrs, cursor_pos, visible):
64 self._panel.UpdatePreedit (text, attrs, cursor_pos, visible,
65 **ibus.DEFAULT_ASYNC_HANDLERS)
67 def update_aux_string (self, text, attrs, visible):
68 self._panel.UpdateAuxString (text, attrs, visible,
69 **ibus.DEFAULT_ASYNC_HANDLERS)
71 def update_lookup_table (self, lookup_table, visible):
72 self._panel.UpdateLookupTable (lookup_table, visible,
73 **ibus.DEFAULT_ASYNC_HANDLERS)
75 def register_properties (self, props):
76 self._panel.RegisterProperties (props,
77 **ibus.DEFAULT_ASYNC_HANDLERS)
79 def update_property (self, prop):
80 self._panel.UpdateProperties (prop,
81 **ibus.DEFAULT_ASYNC_HANDLERS)
83 def show_language_bar (self):
84 self._panel.ShowLanguageBar (**ibus.DEFAULT_ASYNC_HANDLERS)
86 def hide_language_bar (self):
87 self._panel.HideLanguageBar (**ibus.DEFAULT_ASYNC_HANDLERS)
89 def reset (self):
90 self._panel.Reset (**ibus.DEFAULT_ASYNC_HANDLERS)
92 def destroy (self):
93 if self._ibusconn != None:
94 self._panel.Destroy (**ibus.DEFAULT_ASYNC_HANDLERS)
96 self._ibusconn = None
97 self._panel = None
98 ibus.Object.destroy (self)
100 # signal callbacks
101 def _ibusconn_destroy_cb (self, ibusconn):
102 self._ibusconn = None
103 self.destroy ()
105 def _dbus_signal_cb (self, ibusconn, message):
106 if message.is_signal (ibus.IBUS_PANEL_IFACE, "PageUp"):
107 self.emit ("page-up")
108 elif message.is_signal (ibus.IBUS_PANEL_IFACE, "PageDown"):
109 self.emit ("page-down")
110 elif message.is_signal (ibus.IBUS_PANEL_IFACE, "CursorUp"):
111 self.emit ("cursor-up")
112 elif message.is_signal (ibus.IBUS_PANEL_IFACE, "CursorDown"):
113 self.emit ("cursor-down")
114 elif message.is_signal (ibus.IBUS_PANEL_IFACE, "PropertyActivate"):
115 args = message.get_args_list ()
116 self.emit ("property-activate", args[0])
117 else:
118 return False
119 return True
121 # methods for cmp
122 # def __lt__ (self, other):
123 # x = self.get_info ()
124 # y = other.get_info ()
125 # if x[1] < y[1]: return True
126 # if x[1] == y[1]: return x[0] < y[0]
128 # def __gt__ (self, other):
129 # x = self.get_info ()
130 # y = other.get_info ()
131 # if x[1] > y[1]: return True
132 # if x[1] == y[1]: return x[0] > y[0]
134 gobject.type_register (Panel)
136 class DummyPanel (ibus.Object):
137 __gsignals__ = {
138 "page-up" : (
139 gobject.SIGNAL_RUN_FIRST,
140 gobject.TYPE_NONE,
141 ()),
142 "page-down" : (
143 gobject.SIGNAL_RUN_FIRST,
144 gobject.TYPE_NONE,
145 ()),
146 "cursor-up" : (
147 gobject.SIGNAL_RUN_FIRST,
148 gobject.TYPE_NONE,
149 ()),
150 "cursor-down" : (
151 gobject.SIGNAL_RUN_FIRST,
152 gobject.TYPE_NONE,
153 ()),
154 "property-activate" : (
155 gobject.SIGNAL_RUN_FIRST,
156 gobject.TYPE_NONE,
157 (gobject.TYPE_STRING, )),
160 def set_cursor_location (self, x, y, w, h):
161 pass
163 def update_preedit (self, text, attrs, cursor_pos, visible):
164 pass
166 def update_aux_string (self, text, attrs, visible):
167 pass
169 def update_lookup_table (self, lookup_table, visible):
170 pass
172 def register_properties (self, props):
173 pass
175 def update_property (self, prop):
176 pass
178 def show_language_bar (self):
179 pass
181 def hide_language_bar (self):
182 pass
184 def reset (self):
185 pass
187 gobject.type_register (DummyPanel)