1 # -*- coding: utf-8 -*-
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
)
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
)
77 self
._candidate
_panel
.reset ()
78 self
._language
_bar
.reset ()
80 def do_destroy (self
):
83 def _popup_factory_menu (self
, button
, active_time
):
85 factories
= self
._ibus
.GetFactories ()
87 item
= gtk
.MenuItem (label
= "no im")
88 item
.set_sensitive (False)
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
))
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
)
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
)
172 self
._panel
.destroy ()