1# vim:set et sts=4 sw=4: 2# 3# ibus - The Input Bus 4# 5# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com> 6# Copyright (c) 2007-2010 Red Hat, Inc. 7# 8# This library is free software; you can redistribute it and/or 9# modify it under the terms of the GNU Lesser General Public 10# License as published by the Free Software Foundation; either 11# version 2.1 of the License, or (at your option) any later version. 12# 13# This library is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16# Lesser General Public License for more details. 17# 18# You should have received a copy of the GNU Lesser General Public 19# License along with this library; if not, write to the Free Software 20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 21# USA 22 23__all__ = ( 24 "PanelBase", 25 "PanelItem", 26 "PanelButton", 27 "PanelToggleButton", 28 "PanelMenu", 29 "IBUS_SERVICE_PANEL", 30 "IBUS_PATH_PANEL" 31 ) 32 33IBUS_SERVICE_PANEL = "org.freedesktop.IBus.Panel" 34IBUS_PATH_PANEL = "/org/freedesktop/IBus/Panel" 35 36from serializable import * 37from object import Object 38import interface 39import dbus 40 41class PanelItem: 42 pass 43 44class PanelButton(PanelItem): 45 pass 46 47class PanelToggleButton(PanelButton): 48 pass 49 50class PanelMenu(PanelItem): 51 pass 52 53class PanelBase(Object): 54 def __init__(self, bus): 55 super(PanelBase, self).__init__() 56 self.__bus = bus 57 self.__proxy = PanelProxy(self, bus) 58 59 def set_cursor_location(self, x, y, w, h): 60 pass 61 62 def update_preedit_text(self, text, cursor_pos, visible): 63 pass 64 65 def show_preedit_text(self): 66 pass 67 68 def hide_preedit_text(self): 69 pass 70 71 def update_auxiliary_text(self, text, visible): 72 pass 73 74 def show_auxiliary_text(self): 75 pass 76 77 def hide_auxiliary_text(self): 78 pass 79 80 def update_lookup_table(self, lookup_table, visible): 81 pass 82 83 def show_lookup_table(self): 84 pass 85 86 def hide_lookup_table(self): 87 pass 88 89 def show_candidate_window(self): 90 pass 91 92 def page_up_lookup_table(self): 93 pass 94 95 def page_down_lookup_table(self): 96 pass 97 98 def cursor_up_lookup_table(self): 99 pass 100 101 def cursor_down_lookup_table(self): 102 pass 103 104 def hide_candidate_window(self): 105 pass 106 107 def show_language_bar(self): 108 pass 109 110 def hide_language_bar(self): 111 pass 112 113 def register_properties(self, props): 114 pass 115 116 def update_property(self, prop): 117 pass 118 119 def focus_in(self, ic): 120 pass 121 122 def focus_out(self, ic): 123 pass 124 125 def state_changed(self): 126 pass 127 128 def reset(self): 129 pass 130 131 def start_setup(self): 132 pass 133 134 def page_up(self): 135 self.__proxy.PageUp() 136 137 def page_down(self): 138 self.__proxy.PageDown() 139 140 def cursor_up(self): 141 self.__proxy.CursorUp() 142 143 def cursor_down(self): 144 self.__proxy.CursorDown() 145 146 def candidate_clicked(self, index, button, state): 147 self.__proxy.CandidateClicked(index, button, state) 148 149 def property_activate(self, prop_name, prop_state): 150 prop_name = dbus.String(prop_name) 151 prop_state = dbus.Int32(prop_state) 152 self.__proxy.PropertyActivate(prop_name, prop_state) 153 154 def property_show(self, prop_name): 155 prop_name = dbus.String(prop_name) 156 self.__proxy.PropertyShow(prop_name) 157 158 def property_hide(self, prop_name): 159 prop_name = dbus.String(prop_name) 160 self.__proxy.PropertyHide(prop_name) 161 162 163class PanelProxy(interface.IPanel): 164 def __init__ (self, panel, bus): 165 super(PanelProxy, self).__init__(bus.get_dbusconn(), IBUS_PATH_PANEL) 166 self.__bus = bus 167 self.__panel = panel 168 self.__focus_ic = None 169 170 def SetCursorLocation(self, x, y, w, h): 171 self.__panel.set_cursor_location(x, y, w, h) 172 173 def UpdatePreeditText(self, text, cursor_pos, visible): 174 text = deserialize_object(text) 175 self.__panel.update_preedit_text(text, cursor_pos, visible) 176 177 def ShowPreeditText(self): 178 self.__panel.show_preedit_text() 179 180 def HidePreeditText(self): 181 self.__panel.hide_preedit_text() 182 183 def UpdateAuxiliaryText(self, text, visible): 184 text = deserialize_object(text) 185 self.__panel.update_auxiliary_text(text, visible) 186 187 def ShowAuxiliaryText(self): 188 self.__panel.show_auxiliary_text() 189 190 def HideAuxiliaryText(self): 191 self.__panel.hide_auxiliary_text() 192 193 def UpdateLookupTable(self, lookup_table, visible): 194 lookup_table = deserialize_object(lookup_table) 195 self.__panel.update_lookup_table(lookup_table, visible) 196 197 def ShowLookupTable(self): 198 self.__panel.show_lookup_table() 199 200 def HideLookupTable(self): 201 self.__panel.hide_lookup_table() 202 203 def PageUpLookupTable(self): 204 self.__panel.page_up_lookup_table() 205 206 def PageDownLookupTable(self): 207 self.__panel.page_down_lookup_table() 208 209 def CursorUpLookupTable(self): 210 self.__panel.cursor_up_lookup_table() 211 212 def CursorDownLookupTable(self): 213 self.__panel.cursor_down_lookup_table() 214 215 def ShowCandidateWindow(self): 216 self.__panel.show_candidate_window() 217 218 def HideCandidateWindow(self): 219 self.__panel.hide_candidate_window() 220 221 def ShowLanguageBar(self): 222 self.__panel.show_language_bar() 223 224 def HideLanguageBar(self): 225 self.__panel.hide_language_bar() 226 227 def RegisterProperties(self, props): 228 props = deserialize_object(props) 229 self.__panel.register_properties(props) 230 231 def UpdateProperty(self, prop): 232 prop = deserialize_object(prop) 233 self.__panel.update_property(prop) 234 235 def FocusIn(self, ic): 236 self.__panel.focus_in(ic) 237 238 def FocusOut(self, ic): 239 self.__panel.focus_out(ic) 240 241 def StateChanged(self): 242 self.__panel.state_changed() 243 244 def Reset(self): 245 self.__panel.reset() 246 247 def StartSetup(self): 248 self.__panel.start_setup() 249 250 def Destroy(self): 251 self.__panel.destroy() 252 253def test(): 254 import gtk 255 from bus import Bus 256 from inputcontext import InputContext 257 import factory 258 import attribute 259 import property 260 import text 261 import lookuptable 262 263 class TestPanel(PanelBase): 264 def __init__(self): 265 self.__bus = Bus() 266 self.__bus.connect("disconnected", gtk.main_quit) 267 super(TestPanel, self).__init__(self.__bus) 268 self.__bus.request_name(IBUS_SERVICE_PANEL, 0) 269 270 def focus_in(self, ic): 271 print "focus-in:", ic 272 context = InputContext(self.__bus, ic) 273 info = context.get_factory_info() 274 print "factory:", info.name 275 276 def focus_out(self, ic): 277 print "focus-out:", ic 278 279 def update_auxiliary_text(self, text, visible): 280 print "update-auxiliary-text:", text.text 281 282 def update_lookup_table(self, table, visible): 283 print "update-lookup-table", table 284 285 panel = TestPanel() 286 gtk.main() 287 288 289if __name__ == "__main__": 290 test() 291