From: Huang Peng Date: Tue, 24 Jun 2008 05:27:35 +0000 (+0800) Subject: WIP panel. X-Git-Tag: 0.1.0.20080810~314 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5963367438651a3ad2bf9420b05fea9ecc331324;p=platform%2Fupstream%2Fibus.git WIP panel. --- diff --git a/panel/languagebar.py b/panel/languagebar.py index 814cdcd..ef3e0f6 100644 --- a/panel/languagebar.py +++ b/panel/languagebar.py @@ -25,6 +25,7 @@ import gobject import ibus from image import Image from handle import Handle +from menu import menu_position from toolitem import ToolButton,\ ToggleToolButton, \ MenuToolButton @@ -37,10 +38,10 @@ class LanguageBar (gtk.Toolbar): gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_INT)), - "im-menu-popup" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, )), + "get-im-menu" : ( + gobject.SIGNAL_RUN_LAST, + gobject.TYPE_PYOBJECT, + ()), } def __init__ (self): @@ -63,10 +64,22 @@ class LanguageBar (gtk.Toolbar): self.insert (self._handle, -1) # create input methods menu - self._im_menu = ToolButton (icon = "engine-default") - self._im_menu.connect ("clicked", lambda w: self.emit ("im-menu-popup", self._im_menu)) + self._im_menu = ToggleToolButton (icon = "engine-default") + self._im_menu.connect ("toggled", self._im_menu_toggled_cb) self.insert (self._im_menu, -1) + def _im_menu_toggled_cb (self, widget): + if self._im_menu.get_active (): + menu = self.emit ("get-im-menu") + menu.connect ("deactivate", self._im_menu_deactivate_cb) + menu.popup (None, None, + menu_position, + 0, + gtk.get_current_event_time (), + widget) + def _im_menu_deactivate_cb (self, menu): + self._im_menu.set_active (False) + def _remove_properties (self): # reset all properties for name, props in self._properties.items (): diff --git a/panel/panel.py b/panel/panel.py index 8f187e8..3e5b76f 100644 --- a/panel/panel.py +++ b/panel/panel.py @@ -28,7 +28,6 @@ from lang import LANGUAGES from ibus import interface from languagebar import LanguageBar from candidatepanel import CandidatePanel -from menu import menu_position class Panel (ibus.Object): def __init__ (self, proxy, _ibus): @@ -45,8 +44,8 @@ class Panel (ibus.Object): self._language_bar = LanguageBar () self._language_bar.connect ("property-activate", 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.connect ("get-im-menu", + self._get_im_menu_cb) self._language_bar.show_all () self._candidate_panel = CandidatePanel () @@ -132,13 +131,9 @@ class Panel (ibus.Object): menu.set_take_focus (False) return menu - def _im_menu_popup_cb (self, languagebar, button): + def _get_im_menu_cb (self, languagebar): menu = self._create_im_menu () - menu.popup (None, None, - menu_position, - 0, - gtk.get_current_event_time (), - button) + return menu def _status_icon_activate_cb (self, status_icon): menu = self._create_im_menu () diff --git a/panel/toolitem.py b/panel/toolitem.py index 869654b..04d2b25 100644 --- a/panel/toolitem.py +++ b/panel/toolitem.py @@ -20,6 +20,7 @@ # Boston, MA 02111-1307 USA import gtk +import gtk.gdk as gdk import gobject import ibus from menu import * @@ -54,7 +55,6 @@ class ToolButton (gtk.ToolButton): def do_clicked (self): self.emit ("property-activate", self._prop._name, self._prop._state) -gobject.type_register (ToolButton, "ToolButton") class ToggleToolButton (gtk.ToggleToolButton): __gsignals__ = { @@ -99,16 +99,26 @@ class ToggleToolButton (gtk.ToggleToolButton): self._prop._state = ibus.PROP_STATE_UNCHECKED self.emit ("property-activate", self._prop._name, self._prop._state) -gobject.type_register (ToggleToolButton, "IBusToggleToolButton") -class MenuToolButton (ToolButton): +class MenuToolButton (ToggleToolButton): + # __gsignals__ = { + # "property-activate" : ( + # gobject.SIGNAL_RUN_FIRST, + # gobject.TYPE_NONE, + # (gobject.TYPE_STRING, gobject.TYPE_INT)), + # } + def __init__ (self, label = None, icon = None, prop = None): - ToolButton.__init__ (self, label, icon, prop) + ToggleToolButton.__init__ (self, label = label, icon = icon, prop = prop) self._menu = Menu (prop) - self._menu.connect ("property-activate", lambda w,n,s:self.emit ("property-activate", n, s)) + self._menu.connect ("deactivate", lambda m: self.set_active (False)) + self._menu.connect ("property-activate", lambda w,n,s: self.emit ("property-activate", n, s)) - def do_clicked (self): - self._menu.popup (0, gtk.get_current_event_time (), self) + def do_toggled (self): + if self.get_active (): + self._menu.popup (0, gtk.get_current_event_time (), self) +gobject.type_register (ToolButton, "ToolButton") +gobject.type_register (ToggleToolButton, "IBusToggleToolButton") gobject.type_register (MenuToolButton, "MenuToolButton")