Remove CandidateWindow.
[ibus.git] / panel / panel.py
blob6dc6d96c58d8ca4ebd2edfbeb98dd507b1894846
1 # -*- coding: utf-8 -*-
2 import gtk
3 import gtk.gdk as gdk
4 import gobject
5 import ibus
6 from lang import LANGUAGES
7 from ibus import interface
8 from languagebar import LanguageBar
9 from candidatepanel import CandidatePanel
11 class Panel (ibus.Object):
12 def __init__ (self, proxy, _ibus):
13 gobject.GObject.__init__ (self)
14 self._proxy = proxy
15 self._ibus = _ibus
16 self._language_bar = LanguageBar ()
17 self._language_bar.connect ("property-activate",
18 lambda widget, prop_name: self._proxy.PropertyActivate (prop_name))
19 self._language_bar.show_all ()
21 self._candidate_panel = CandidatePanel ()
22 self._candidate_panel.connect ("cursor-up",
23 lambda widget: self._proxy.CursorUp ())
24 self._candidate_panel.connect ("cursor-down",
25 lambda widget: self._proxy.CursorDown ())
27 self._status_icon = gtk.StatusIcon ()
28 self._status_icon.connect ("popup-menu", self._status_icon_popup_menu_cb)
29 self._status_icon.connect ("activate", self._status_icon_activate_cb)
30 self._status_icon.set_from_icon_name ("engine-default")
31 self._status_icon.set_tooltip ("ibus - running")
32 self._status_icon.set_visible (True)
34 def set_cursor_location (self, x, y, w, h):
35 self._candidate_panel.move (x + w, y + h)
37 def update_preedit (self, text, attrs, cursor_pos, show):
38 self._candidate_panel.update_preedit (text, attrs, cursor_pos, show)
40 def show_preedit_string (self):
41 self._candidate_panel.show_preedit_string ()
43 def hide_preedit_string (self):
44 self._candidate_panel.hide_preedit_string ()
46 def update_aux_string (self, text, attrs, show):
47 self._candidate_panel.update_aux_string (text, attrs, show)
49 def show_aux_string (self):
50 self._candidate_panel.show_aux_string ()
52 def hide_aux_string (self):
53 self._candidate_panel.hide_aux_string ()
55 def update_lookup_table (self, lookup_table, show):
56 self._candidate_panel.update_lookup_table (lookup_table, show)
58 def show_candidate_window (self):
59 self._candidate_panel.show ()
61 def hide_candidate_window (self):
62 self._candidate_panel.hide ()
64 def show_language_bar (self):
65 self._language_bar.show ()
67 def hide_language_bar (self):
68 self._language_bar.hide ()
70 def register_properties (self, props):
71 self._language_bar.register_properties (props)
73 def update_property (self, prop):
74 self._language_bar.update_property (self, prop)
76 def reset (self):
77 self._candidate_panel.reset ()
78 self._language_bar.reset ()
80 def do_destroy (self):
81 gtk.main_quit ()
83 def _popup_factory_menu (self, button, active_time):
84 menu = gtk.Menu ()
85 factories = self._ibus.GetFactories ()
86 if not factories:
87 item = gtk.MenuItem (label = "no im")
88 item.set_sensitive (False)
89 menu.add (item)
90 else:
91 for factory in factories:
92 name, lang, icon, authors, credits = self._ibus.GetFactoryInfo (factory)
93 item = gtk.ImageMenuItem ("%s - %s" % (LANGUAGES.get (lang, lang), name))
94 if not icon:
95 icon = "engine-default"
96 item.set_image (gtk.image_new_from_icon_name (icon, gtk.ICON_SIZE_MENU))
97 item.connect ("activate", self._menu_item_activate_cb, factory)
98 menu.add (item)
100 menu.show_all ()
101 menu.set_take_focus (False)
102 menu.popup (None, None, gtk.status_icon_position_menu, button, active_time, self._status_icon)
104 def _status_icon_activate_cb (self, status_icon):
105 self._popup_factory_menu (0, gtk.get_current_event_time ())
106 def _status_icon_popup_menu_cb (self, status_icon, button, active_time):
107 self._popup_factory_menu (button, active_time)
110 def _menu_item_activate_cb (self, item, factory):
111 self._ibus.SetFactory (factory)
113 gobject.type_register (Panel, "IBusPanel")
115 class PanelProxy (interface.IPanel):
116 def __init__ (self, dbusconn, object_path, _ibus):
117 interface.IPanel.__init__ (self, dbusconn, object_path)
118 self._dbusconn = dbusconn
119 self._panel = Panel (self, _ibus)
121 def SetCursorLocation (self, x, y, w, h):
122 self._panel.set_cursor_location (x, y, w, h)
124 def UpdatePreedit (self, text, attrs, cursor_pos, show):
125 attrs = ibus.attr_list_from_dbus_value (attrs)
126 self._panel.update_preedit (text, atrrs, cursor_pos, show)
128 def ShowPreeditString (self):
129 self._panel.show_preedit_string ()
131 def HidePreeditString (self):
132 self._panel.hide_preedit_string ()
134 def UpdateAuxString (self, text, attrs, show):
135 attrs = ibus.attr_list_from_dbus_value (attrs)
136 self._panel.update_aux_string (text, attrs, show)
138 def ShowAuxString (self):
139 self._panel.show_aux_string ()
141 def HideAuxString (self):
142 self._panel.hide_aux_string ()
144 def UpdateLookupTable (self, lookup_table, show):
145 lookup_table = ibus.lookup_table_from_dbus_value (lookup_table)
146 self._panel.update_lookup_table (lookup_table, show)
148 def ShowCandidateWindow (self):
149 self._panel.show_candidate_window ()
151 def HideCandidateWindow (self):
152 self._panel.hide_candidate_window ()
154 def ShowLanguageBar (self):
155 self._panel.show_language_bar ()
157 def HideLanguageBar (self):
158 self._panel.hide_language_bar ()
160 def RegisterProperties (self, props):
161 props = ibus.prop_list_from_dbus_value (props)
162 self._panel.register_properties (props)
164 def UpdateProperty (self, prop):
165 prop = ibus.property_from_dbus_value (props)
166 self._panel.update_property (prop)
168 def Reset (self):
169 self._panel.reset ()
171 def Destroy (self):
172 self._panel.destroy ()