This commit is contained in:
Huang Peng 2008-06-23 18:30:12 +08:00
Родитель c380db468f
Коммит 39480c25c4
7 изменённых файлов: 123 добавлений и 37 удалений

Просмотреть файл

@ -1,4 +1,5 @@
# vim:set noet ts=4:
# -*- coding: utf-8 -*-
#
# ibus - The Input Bus
#
@ -39,11 +40,34 @@ class Engine (interface.IEngine):
self._context._set_encoding (anthy.ANTHY_UTF8_ENCODING)
self._lookup_table = ibus.LookupTable ()
self._prop_list = ibus.PropList ()
self._prop_list = self._init_props ()
# use reset to init values
self._reset ()
def _init_props (self):
props = ibus.PropList ()
mode_prop = ibus.Property (name = "InputMode", type = ibus.PROP_TYPE_MENU, label = u"")
props.append (mode_prop)
mode_props = ibus.PropList ()
mode_props.append (ibus.Property (name = "InputModeHiragana",
type = ibus.PROP_TYPE_RADIO,
label = u"Hiragana"))
mode_props.append (ibus.Property (name = "InputModeKatagana",
type = ibus.PROP_TYPE_RADIO,
label = u"Katagana"))
mode_props.append (ibus.Property (name = "InputModeHalfWidthHiragana",
type = ibus.PROP_TYPE_RADIO,
label = u"Half width hiragana"))
mode_props.append (ibus.Property (name = "InputModeHalfWidthKatagana",
type = ibus.PROP_TYPE_RADIO,
label = u"Half width katagana"))
mode_props.append (ibus.Property (name = "InputModeLatin",
type = ibus.PROP_TYPE_RADIO,
label = u"Direct input"))
mode_prop.set_sub_props (mode_props)
return props
# reset values of engine
def _reset (self):
self._input_chars = u""
@ -428,8 +452,8 @@ class Engine (interface.IEngine):
if self._enable:
self.RegisterProperties (self._prop_list.to_dbus_value ())
def PropertyActivate (self, prop_name):
print "PropertyActivate (%s)" % prop_name
def PropertyActivate (self, prop_name, prop_state):
print "PropertyActivate (%s, %d)" % (prop_name, prop_state)
def Destroy (self):
print "Destroy"

Просмотреть файл

@ -252,10 +252,10 @@ class IBus (ibus.Object):
if self._focused_context:
self._focused_context.cursor_down ()
def _panel_property_active_cb (self, panel, prop_name):
def _panel_property_active_cb (self, panel, prop_name, prop_state):
assert panel == self._panel
if self._focused_context:
self._focused_context.property_activate (prop_name)
self._focused_context.property_activate (prop_name, prop_state)
def _panel_destroy_cb (self, panel):
if panel == self._panel:

Просмотреть файл

@ -131,8 +131,8 @@ class Engine (ibus.Object):
def cursor_down (self):
self._engine.CursorDown (**ibus.DEFAULT_ASYNC_HANDLERS)
def property_activate (self, prop_name):
self._engine.PropertyActivate (prop_name,
def property_activate (self, prop_name, prop_state):
self._engine.PropertyActivate (prop_name, prop_state,
**ibus.DEFAULT_ASYNC_HANDLERS)
def destroy (self):

Просмотреть файл

@ -127,9 +127,9 @@ class InputContext (ibus.Object):
if self._engine:
self._engine.cursor_down ()
def property_activate (self, prop_name):
def property_activate (self, prop_name, prop_state):
if self._engine:
self._engine.property_activate (prop_name)
self._engine.property_activate (prop_name, prop_state)
def is_enabled (self):
return self._enable

Просмотреть файл

@ -44,7 +44,7 @@ class Panel (ibus.Object):
"property-activate" : (
gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
(gobject.TYPE_STRING, )),
(gobject.TYPE_STRING, gobject.TYPE_INT)),
}
def __init__ (self, ibusconn, object_path):
@ -113,7 +113,7 @@ class Panel (ibus.Object):
self.emit ("cursor-down")
elif message.is_signal (ibus.IBUS_PANEL_IFACE, "PropertyActivate"):
args = message.get_args_list ()
self.emit ("property-activate", args[0])
self.emit ("property-activate", args[0], args[1])
else:
return False
return True

Просмотреть файл

@ -33,7 +33,7 @@ class LanguageBar (gtk.Toolbar):
"property-activate" : (
gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
(gobject.TYPE_STRING, )),
(gobject.TYPE_STRING, gobject.TYPE_INT)),
"im-menu-popup" : (
gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
@ -53,24 +53,6 @@ class LanguageBar (gtk.Toolbar):
workarea = root.property_get ("_NET_WORKAREA")[2]
self._toplevel.move (workarea[2] - 200, workarea[3] - 40)
def _add_items (self):
img = gtk.image_new_from_icon_name ("engine-default", ICON_SIZE)
btn = gtk.ToolButton (img, "engine")
btn.connect ("clicked", lambda x: self._add_items ())
self.insert (btn, -1)
img = gtk.image_new_from_icon_name ("ibus-keyboard", ICON_SIZE)
btn = gtk.ToolButton (img, "keyboard")
self.insert (btn, -1)
img = gtk.image_new_from_icon_name ("ibus-zh", ICON_SIZE)
btn = gtk.ToolButton (img, "keyboard")
self.insert (btn, -1)
self.insert (gtk.SeparatorToolItem (), -1)
self.show_all ()
self.check_resize ()
def _create_ui (self):
# create move handle
self._handle = gtk.ToolItem ()
@ -115,26 +97,48 @@ class LanguageBar (gtk.Toolbar):
# create new properties
for prop in props:
if prop._type == ibus.PROP_TYPE_NORMAL:
widget = gtk.ToolButton ()
widget = gtk.ToolButton (label = prop._label)
if prop._icon:
widget.set_icon_name (prop._icon)
else:
widget.set_is_important (True)
widget.connect ("clicked",
self._property_clicked, prop)
elif prop._type == ibus.PROP_TYPE_TOGGLE:
widget = gtk.ToggleToolButton ()
widget.set_icon_name (prop._icon)
widget.set_label (prop._label)
widget.set_active (prop._state == ibus.PROP_STATE_CHECKED)
widget.connect ("clicked",
lambda widget, prop: self.emit ("property-activate", prop._name),
prop)
self._property_clicked, prop)
elif prop._type == ibus.PROP_TYPE_MENU:
widget = gtk.ToolButton (label = prop._label)
if prop._icon:
widget.set_icon_name (prop._icon)
else:
widget.set_is_important (True)
menu = self._create_prop_menu (prop.get_sub_props ())
widget.connect ("clicked",
self._property_menu_clicked, prop, menu)
elif prop._type == PROP_TYPE_SEPARATOR:
widget = gtk.SeparatorToolItem ()
else:
widget = gtk.ToolItem ()
widget.set_sensitive (prop._sensitive)
widget.set_no_show_all (True)
if prop._visible:
widget.set_no_show_all (False)
widget.show ()
else:
widget.set_no_show_all (True)
widget.hide ()
if not self._properties.has_key (prop._name):
self._properties [prop._name] = []
self._properties [prop._name].append ((prop, widget))
self.insert (widget, -1)
self.check_resize ()
def update_properties (self, props):
@ -148,5 +152,63 @@ class LanguageBar (gtk.Toolbar):
self._toplevel.hide_all ()
gtk.Toolbar.hide_all (self)
def _create_prop_menu (self, props):
menu = gtk.Menu ()
menu.set_take_focus (False)
radio_group = None
for prop in props:
if prop._type == ibus.PROP_TYPE_NORMAL:
item = gtk.ImageMenuItem (prop._label)
if prop._icon:
item.set_image (gtk.image_new_from_icon_name (prop._icon, gtk.ICON_SIZE_MENU))
item.connect ("activate", self._property_clicked, prop)
elif prop._type == ibus.PROP_TYPE_TOGGLE:
item = gtk.CheckMenuItem (label = prop._label)
item.set_active (prop._state == ibus.PROP_STATE_CHECKED)
item.connect ("toggled", self._property_clicked, prop)
elif prop._type == ibus.PROP_TYPE_RADIO:
item = gtk.RadioMenuItem (group = radio_group, label = prop._label)
item.set_active (prop._state == ibus.PROP_STATE_CHECKED)
if radio_group == None:
radio_group = item
item.connect ("toggled", self._property_clicked, prop)
elif prop._type == ibus.PROP_TYPE_SEPARATOR:
item = gtk.SeparatorMenuItem ()
radio_group = None
elif prop._type == ibus.PROP_TYPE_MENU:
item = gtk.ImageMenuItem (prop._label)
if prop._icon:
item.set_image (gtk.image_new_from_icon_name (prop._icon, gtk.ICON_SIZE_MENU))
item.set_submenu (self._create_prop_menu (prop.get_sub_props ()))
else:
assert Fasle
item.set_sensitive (prop._sensitive)
item.set_no_show_all (True)
if prop._visible:
item.show ()
else:
item.hide ()
menu.append (item)
menu.show_all ()
return menu
def _property_clicked (self, widget, prop):
if prop._type in (ibus.PROP_TYPE_TOGGLE, ibus.PROP_TYPE_RADIO):
if widget.get_active ():
prop._state = ibus.PROP_STATE_CHECKED
else:
prop._state = ibus.PROP_STATE_UNCHECKED
self.emit ("property-activate", prop._name, prop._state)
def _property_menu_clicked (self, widget, prop, menu):
menu.popup (None, None, None, 0, 0)
gobject.type_register (LanguageBar, "IBusLanguageBar")

Просмотреть файл

@ -43,7 +43,7 @@ class Panel (ibus.Object):
self._language_bar = LanguageBar ()
self._language_bar.connect ("property-activate",
lambda widget, prop_name: self._proxy.PropertyActivate (prop_name))
lambda widget, prop_name, prop_state: self._proxy.PropertyActivate (prop_name, prop_state))
self._language_bar.connect ("im-menu-popup",
self._im_menu_popup_cb)
self._language_bar.show_all ()
@ -114,7 +114,7 @@ class Panel (ibus.Object):
menu = gtk.Menu ()
factories = self._ibus.GetFactories ()
if not factories:
item = gtk.MenuItem (label = "no im")
item = gtk.MenuItem (label = "no engine")
item.set_sensitive (False)
menu.add (item)
else: