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
, )),
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
)
90 self
._panel
.Reset (**ibus
.DEFAULT_ASYNC_HANDLERS
)
93 if self
._ibusconn
!= None:
94 self
._panel
.Destroy (**ibus
.DEFAULT_ASYNC_HANDLERS
)
98 ibus
.Object
.destroy (self
)
101 def _ibusconn_destroy_cb (self
, ibusconn
):
102 self
._ibusconn
= None
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])
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
):
139 gobject
.SIGNAL_RUN_FIRST
,
143 gobject
.SIGNAL_RUN_FIRST
,
147 gobject
.SIGNAL_RUN_FIRST
,
151 gobject
.SIGNAL_RUN_FIRST
,
154 "property-activate" : (
155 gobject
.SIGNAL_RUN_FIRST
,
157 (gobject
.TYPE_STRING
, )),
160 def set_cursor_location (self
, x
, y
, w
, h
):
163 def update_preedit (self
, text
, attrs
, cursor_pos
, visible
):
166 def update_aux_string (self
, text
, attrs
, visible
):
169 def update_lookup_table (self
, lookup_table
, visible
):
172 def register_properties (self
, props
):
175 def update_property (self
, prop
):
178 def show_language_bar (self
):
181 def hide_language_bar (self
):
187 gobject
.type_register (DummyPanel
)