2008-06-24 04:39:20 +04:00
|
|
|
# vim:set noet ts=4:
|
|
|
|
#
|
|
|
|
# ibus - The Input Bus
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this program; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
# Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
import gtk
|
2008-06-24 09:27:35 +04:00
|
|
|
import gtk.gdk as gdk
|
2008-06-24 04:39:20 +04:00
|
|
|
import gobject
|
|
|
|
import ibus
|
2008-06-24 06:32:48 +04:00
|
|
|
from menu import *
|
2008-06-24 04:39:20 +04:00
|
|
|
|
|
|
|
class ToolButton (gtk.ToolButton):
|
|
|
|
__gsignals__ = {
|
|
|
|
"property-activate" : (
|
|
|
|
gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_STRING, gobject.TYPE_INT)),
|
|
|
|
}
|
|
|
|
|
2008-06-24 10:21:03 +04:00
|
|
|
def __init__ (self, label = None, icon = None, tooltip = None, prop = None):
|
2008-06-24 04:39:20 +04:00
|
|
|
if prop == None:
|
2008-06-24 06:32:48 +04:00
|
|
|
prop = ibus.Property (name= "", type = ibus.PROP_TYPE_NORMAL,
|
2008-06-24 10:21:03 +04:00
|
|
|
label = label, icon = icon, tooltip = tooltip)
|
2008-06-24 04:39:20 +04:00
|
|
|
self._prop = prop
|
|
|
|
|
|
|
|
gtk.ToolButton.__init__ (self, label = prop._label)
|
|
|
|
self.set_icon_name (prop._icon)
|
2008-06-24 10:21:03 +04:00
|
|
|
self.set_tooltip_text (prop._tooltip)
|
|
|
|
self.set_sensitive (prop._sensitive)
|
|
|
|
if prop._visible:
|
|
|
|
self.set_no_show_all (False)
|
|
|
|
self.show_all ()
|
|
|
|
else:
|
|
|
|
self.set_no_show_all (True)
|
|
|
|
self.hide_all ()
|
|
|
|
|
2008-06-24 04:39:20 +04:00
|
|
|
|
|
|
|
def set_icon_name (self, icon_name):
|
|
|
|
if icon_name:
|
|
|
|
gtk.ToolButton.set_icon_name (self, icon_name)
|
|
|
|
self.set_is_important (False)
|
|
|
|
else:
|
|
|
|
gtk.ToolButton.set_icon_name (self, None)
|
|
|
|
self.set_is_important (True)
|
|
|
|
|
|
|
|
self._prop._icon = icon_name
|
|
|
|
|
2008-06-24 10:21:03 +04:00
|
|
|
def set_tooltip_text (self, text):
|
|
|
|
if text:
|
|
|
|
gtk.ToolButton.set_tooltip_text (self, text)
|
|
|
|
else:
|
|
|
|
gtk.ToolButton.set_tooltip_text (self, None)
|
|
|
|
|
|
|
|
self._prop._tooltip = text
|
|
|
|
|
2008-06-24 04:39:20 +04:00
|
|
|
def do_clicked (self):
|
|
|
|
self.emit ("property-activate", self._prop._name, self._prop._state)
|
|
|
|
|
|
|
|
|
|
|
|
class ToggleToolButton (gtk.ToggleToolButton):
|
|
|
|
__gsignals__ = {
|
|
|
|
"property-activate" : (
|
|
|
|
gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_STRING, gobject.TYPE_INT)),
|
|
|
|
}
|
|
|
|
|
2008-06-24 10:21:03 +04:00
|
|
|
def __init__ (self, label = None, icon = None, tooltip = None, state = ibus.PROP_STATE_UNCHECKED, prop = None):
|
2008-06-24 04:39:20 +04:00
|
|
|
if prop == None:
|
2008-06-24 06:32:48 +04:00
|
|
|
prop = ibus.Property (name = "", type = ibus.PROP_TYPE_TOGGLE,
|
2008-06-24 10:21:03 +04:00
|
|
|
label = label, icon = icon, tooltip = tooltip, state = state)
|
2008-06-24 04:39:20 +04:00
|
|
|
self._prop = prop
|
|
|
|
|
|
|
|
gtk.ToggleToolButton.__init__ (self)
|
|
|
|
self.set_label (prop._label)
|
|
|
|
self.set_icon_name (prop._icon)
|
2008-06-24 10:21:03 +04:00
|
|
|
self.set_tooltip_text (prop._tooltip)
|
2008-06-24 04:39:20 +04:00
|
|
|
self.set_state (prop._state)
|
2008-06-24 10:21:03 +04:00
|
|
|
self.set_sensitive (prop._sensitive)
|
|
|
|
if prop._visible:
|
|
|
|
self.set_no_show_all (False)
|
|
|
|
self.show_all ()
|
|
|
|
else:
|
|
|
|
self.set_no_show_all (True)
|
|
|
|
self.hide_all ()
|
2008-06-24 04:39:20 +04:00
|
|
|
|
|
|
|
def set_icon_name (self, icon_name):
|
|
|
|
if icon_name:
|
2008-06-24 10:21:03 +04:00
|
|
|
gtk.ToggleToolButton.set_icon_name (self, icon_name)
|
2008-06-24 04:39:20 +04:00
|
|
|
self.set_is_important (False)
|
|
|
|
else:
|
2008-06-24 10:21:03 +04:00
|
|
|
gtk.ToggleToolButton.set_icon_name (self, None)
|
2008-06-24 04:39:20 +04:00
|
|
|
self.set_is_important (True)
|
|
|
|
|
|
|
|
self._prop._icon = icon_name
|
|
|
|
|
2008-06-24 10:21:03 +04:00
|
|
|
def set_tooltip_text (self, text):
|
|
|
|
if text:
|
|
|
|
gtk.ToggleToolButton.set_tooltip_text (self, text)
|
|
|
|
else:
|
|
|
|
gtk.ToggleToolButton.set_tooltip_text (self, None)
|
|
|
|
|
|
|
|
self._prop._tooltip = text
|
|
|
|
|
2008-06-24 04:39:20 +04:00
|
|
|
def set_state (self, state):
|
|
|
|
self.set_active (state == ibus.PROP_STATE_CHECKED)
|
|
|
|
self._prop._state = state
|
|
|
|
|
|
|
|
def get_state (self):
|
|
|
|
return self._prop._state
|
|
|
|
|
|
|
|
def do_toggled (self):
|
|
|
|
if self.get_active ():
|
|
|
|
self._prop._state = ibus.PROP_STATE_CHECKED
|
|
|
|
else:
|
|
|
|
self._prop._state = ibus.PROP_STATE_UNCHECKED
|
|
|
|
self.emit ("property-activate", self._prop._name, self._prop._state)
|
|
|
|
|
|
|
|
|
2008-06-24 09:27:35 +04:00
|
|
|
class MenuToolButton (ToggleToolButton):
|
|
|
|
# __gsignals__ = {
|
|
|
|
# "property-activate" : (
|
|
|
|
# gobject.SIGNAL_RUN_FIRST,
|
|
|
|
# gobject.TYPE_NONE,
|
|
|
|
# (gobject.TYPE_STRING, gobject.TYPE_INT)),
|
|
|
|
# }
|
|
|
|
|
2008-06-24 10:21:03 +04:00
|
|
|
def __init__ (self, label = None, icon = None, toolip = None, prop = None):
|
|
|
|
ToggleToolButton.__init__ (self, label = label, icon = icon, tooltip = None, prop = prop)
|
2008-06-24 06:32:48 +04:00
|
|
|
self._menu = Menu (prop)
|
2008-06-24 09:27:35 +04:00
|
|
|
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))
|
2008-06-24 04:39:20 +04:00
|
|
|
|
2008-06-24 09:27:35 +04:00
|
|
|
def do_toggled (self):
|
|
|
|
if self.get_active ():
|
|
|
|
self._menu.popup (0, gtk.get_current_event_time (), self)
|
2008-06-24 04:39:20 +04:00
|
|
|
|
2008-06-24 09:27:35 +04:00
|
|
|
gobject.type_register (ToolButton, "ToolButton")
|
|
|
|
gobject.type_register (ToggleToolButton, "IBusToggleToolButton")
|
2008-06-24 04:39:20 +04:00
|
|
|
gobject.type_register (MenuToolButton, "MenuToolButton")
|
|
|
|
|