self._is_invalidate = False
self._preedit_string = ""
self._lookup_table = ibus.LookupTable ()
+ self._prop_list = ibus.PropList ()
+ self._prop_list.append (ibus.Property ("test", icon = "ibus-locale"))
- # methods for dbus rpc
- def ProcessKeyEvent (self, keyval, is_press, state):
- try:
- return self._process_key_event (keyval, is_press, state)
- except Exception, e:
- print e
- return False
def _process_key_event (self, keyval, is_press, state):
# ignore key release events
if not is_press:
self._update_lookup_table ()
return True
return False
-
+
def _cursor_down (self):
if self._lookup_table.cursor_down ():
self._update_lookup_table ()
self.UpdateLookupTable (self._lookup_table.to_dbus_value (), show)
+ # methods for dbus rpc
+ def ProcessKeyEvent (self, keyval, is_press, state):
+ try:
+ return self._process_key_event (keyval, is_press, state)
+ except Exception, e:
+ print e
+ return False
+
def FocusIn (self):
+ self.RegisterProperties (self._prop_list.to_dbus_value ())
print "FocusIn"
def FocusOut (self):
print "FocusOut"
+ def SetCursorLocation (self, x, y, w, h):
+ pass
+
def Reset (self):
print "Reset"
def PageDown (self):
print "PageDown"
-
+
def CursorUp (self):
- print "CursorUp"
self._cursor_up ()
-
+
def CursorDown (self):
self._cursor_down ()
- print "CursorDown"
-
+
def SetEnable (self, enable):
self._enable = enable
+ if self._enable:
+ self.RegisterProperties (self._prop_list.to_dbus_value ())
+
+
+ def PropertyActivate (self, prop_name):
+ print "PropertyActivate (%s)" % prop_name
def Destroy (self):
print "Destroy"
- def SetCursorLocation (self, x, y, w, h):
- pass
-
class DemoEngine (Engine):
pass
def _panel_property_active_cb (self, panel, prop_name):
assert panel == self._panel
if self._focused_client:
- self._focused_client.property_activate (self, prop_name)
+ self._focused_client.property_activate (prop_name)
def _panel_destroy_cb (self, panel):
if panel == self._panel:
self._lookup_table = lookup_table
self.emit ("update-lookup-table", lookup_table, visible)
- def _register_properties_cb (self, props):
+ def _register_properties_cb (self, engine, props):
self.emit ("register-properties", props)
- def _update_property_cb (self, prop):
+ def _update_property_cb (self, engine, prop):
self.emit ("update-property", prop)
def _remove_engine_handlers (self):
import gtk
import gtk.gdk as gdk
import gobject
+import ibus
from image import Image
from handle import Handle
ICON_SIZE = gtk.ICON_SIZE_MENU
class LanguageBar (gtk.Toolbar):
+ __gsignals__ = {
+ "property-activate" : (
+ gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_STRING, )),
+ }
def __init__ (self):
gtk.Toolbar.__init__ (self)
self.set_property ("icon-size", ICON_SIZE)
pass
def register_properties (self, props):
- pass
+ # reset all properties
+ for name, prop in self._properties.items ():
+ prop[1].destroy ()
+ self._properties = {}
+
+ # create new properties
+ for prop in props:
+ if prop._type == ibus.PROP_TYPE_NORMAL:
+ widget = gtk.ToolButton ()
+ widget.set_icon_name (prop._icon)
+ widget.set_label (prop._label)
+ widget.connect ("clicked",
+ lambda widget, prop: self.emit ("property-activate", prop._name),
+ prop)
+ else:
+ widget = gtk.ToolItem ()
+
+ widget.set_sensitive (prop._sensitive)
+ if prop._visible:
+ widget.set_no_show_all (False)
+ widget.show ()
+ else:
+ widget.set_no_show_all (True)
+ widget.hide ()
+
+ self._properties [prop._name] = (prop, widget)
+ self.insert (widget, -1)
+ self.check_resize ()
def update_properties (self, props):
pass
gobject.type_register (LanguageBar, "IBusLanguageBar")
class LanguageBarWindow (gtk.Window):
+ __gsignals__ = {
+ "property-activate" : (
+ gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_STRING, )),
+ }
def __init__ (self):
gtk.Window.__init__ (self, gtk.WINDOW_POPUP)
self._language_bar = LanguageBar ()
+ self._language_bar.connect ("property-activate",
+ lambda widget, prop_name: self.emit ("property-activate", prop_name))
self.add (self._language_bar)
self.show_all ()
gobject.GObject.__init__ (self)
self._proxy = proxy
self._language_bar = LanguageBarWindow ()
+ self._language_bar.connect ("property-activate",
+ lambda widget, prop_name: self._proxy.PropertyActivate (prop_name))
self._candidate_panel = CandidateWindow ()
- self._candidate_panel.connect ("cursor-up", lambda x: self._proxy.CursorUp ())
- self._candidate_panel.connect ("cursor-down", lambda x: self._proxy.CursorDown ())
+ self._candidate_panel.connect ("cursor-up",
+ lambda widget: self._proxy.CursorUp ())
+ self._candidate_panel.connect ("cursor-down",
+ lambda widget: self._proxy.CursorDown ())
def set_cursor_location (self, x, y, w, h):
self._candidate_panel.move (x + w, y + h)
self._language_bar.hide ()
def register_properties (self, props):
- self._language_bar.register_properties (self, props)
+ self._language_bar.register_properties (props)
def update_property (self, prop):
self._language_bar.update_property (self, prop)