Define mod_path in spec file.
[platform/upstream/ibus.git] / ibusdaemon / panel.py
1 # vim:set noet ts=4:
2 #
3 # ibus - The Input Bus
4 #
5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
6 #
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.
11 #
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.
16 #
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
21
22 import weakref
23 import gobject
24 import ibus
25
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, gobject.TYPE_INT)),
48                 "property-show" : (
49                         gobject.SIGNAL_RUN_FIRST,
50                         gobject.TYPE_NONE,
51                         (gobject.TYPE_STRING, )),
52                 "property-hide" : (
53                         gobject.SIGNAL_RUN_FIRST,
54                         gobject.TYPE_NONE,
55                         (gobject.TYPE_STRING, )),
56         }
57
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)
63
64                 self._ibusconn.connect ("destroy", self._ibusconn_destroy_cb)
65                 self._ibusconn.connect ("dbus-signal", self._dbus_signal_cb)
66
67         def set_cursor_location (self, x, y, w, h):
68                 self._panel.SetCursorLocation (x, y, w, h,
69                                 **ibus.DEFAULT_ASYNC_HANDLERS)
70
71         def update_preedit (self, text, attrs, cursor_pos, visible):
72                 self._panel.UpdatePreedit (text, attrs, cursor_pos, visible,
73                                 **ibus.DEFAULT_ASYNC_HANDLERS)
74
75         def update_aux_string (self, text, attrs, visible):
76                 self._panel.UpdateAuxString (text, attrs, visible,
77                                 **ibus.DEFAULT_ASYNC_HANDLERS)
78
79         def update_lookup_table (self, lookup_table, visible):
80                 self._panel.UpdateLookupTable (lookup_table, visible,
81                                 **ibus.DEFAULT_ASYNC_HANDLERS)
82
83         def register_properties (self, props):
84                 self._panel.RegisterProperties (props,
85                                 **ibus.DEFAULT_ASYNC_HANDLERS)
86
87         def update_property (self, prop):
88                 self._panel.UpdateProperties (prop,
89                                 **ibus.DEFAULT_ASYNC_HANDLERS)
90
91         def show_language_bar (self):
92                 self._panel.ShowLanguageBar (**ibus.DEFAULT_ASYNC_HANDLERS)
93
94         def hide_language_bar (self):
95                 self._panel.HideLanguageBar (**ibus.DEFAULT_ASYNC_HANDLERS)
96
97         def reset (self):
98                 self._panel.Reset (**ibus.DEFAULT_ASYNC_HANDLERS)
99
100         def destroy (self):
101                 if self._ibusconn != None:
102                         self._panel.Destroy (**ibus.DEFAULT_ASYNC_HANDLERS)
103
104                 self._ibusconn = None
105                 self._panel = None
106                 ibus.Object.destroy (self)
107
108         # signal callbacks
109         def _ibusconn_destroy_cb (self, ibusconn):
110                 self._ibusconn = None
111                 self.destroy ()
112
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])
131                 else:
132                         return False
133                 return True
134
135         # methods for cmp
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]
141         #
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]
147
148 gobject.type_register (Panel)
149
150 class DummyPanel (ibus.Object):
151         __gsignals__ = {
152                 "page-up" : (
153                         gobject.SIGNAL_RUN_FIRST,
154                         gobject.TYPE_NONE,
155                         ()),
156                 "page-down" : (
157                         gobject.SIGNAL_RUN_FIRST,
158                         gobject.TYPE_NONE,
159                         ()),
160                 "cursor-up" : (
161                         gobject.SIGNAL_RUN_FIRST,
162                         gobject.TYPE_NONE,
163                         ()),
164                 "cursor-down" : (
165                         gobject.SIGNAL_RUN_FIRST,
166                         gobject.TYPE_NONE,
167                         ()),
168                 "property-activate" : (
169                         gobject.SIGNAL_RUN_FIRST,
170                         gobject.TYPE_NONE,
171                         (gobject.TYPE_STRING, )),
172         }
173
174         def set_cursor_location (self, x, y, w, h):
175                 pass
176
177         def update_preedit (self, text, attrs, cursor_pos, visible):
178                 pass
179
180         def update_aux_string (self, text, attrs, visible):
181                 pass
182
183         def update_lookup_table (self, lookup_table, visible):
184                 pass
185
186         def register_properties (self, props):
187                 pass
188
189         def update_property (self, prop):
190                 pass
191
192         def show_language_bar (self):
193                 pass
194
195         def hide_language_bar (self):
196                 pass
197
198         def reset (self):
199                 pass
200
201 gobject.type_register (DummyPanel)