1 # vim:set et sts=4 sw=4:
5 # Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com>
6 # Copyright (c) 2007-2010 Red Hat, Inc.
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this program; if not, write to the
20 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 # Boston, MA 02111-1307 USA
27 from propitem import PropItem
31 class ToolButton(gtk.ToolButton, PropItem):
32 __gtype_name__ = "IBusToolButton"
34 "property-activate" : (
35 gobject.SIGNAL_RUN_FIRST,
37 (gobject.TYPE_STRING, gobject.TYPE_INT)),
40 def __init__(self, prop):
41 gtk.ToolButton.__init__(self, label = prop.label.text)
42 self.set_homogeneous(False)
43 PropItem.__init__(self, prop)
44 self.property_changed()
46 def set_icon_name(self, icon_name):
48 widget = icon.IconWidget(icon_name, 18)
49 gtk.ToolButton.set_icon_widget(self, widget)
50 self.set_is_important(False)
51 elif self._prop.label.text:
52 gtk.ToolButton.set_icon_widget(self, None)
53 self.set_is_important(True)
55 widget = icon.IconWidget("ibus", 18)
56 gtk.ToolButton.set_icon_widget(self, widget)
57 self.set_is_important(False)
59 self._prop.icon = icon_name
61 def set_tooltip_text(self, text):
63 gtk.ToolButton.set_tooltip_text(self, text.text)
65 gtk.ToolButton.set_tooltip_text(self, None)
67 self._prop.tooltip = text
69 def property_changed(self):
70 self.set_label(self._prop.label.text)
71 self.set_tooltip_text(self._prop.tooltip)
72 self.set_sensitive(self._prop.sensitive)
73 self.set_icon_name(self._prop.icon)
75 if self._prop.visible:
76 self.set_no_show_all(False)
79 self.set_no_show_all(True)
83 self.emit("property-activate", self._prop.key, self._prop.state)
86 class ToggleToolButton(gtk.ToggleToolButton, PropItem):
87 __gtype_name__ = "IBusToggleToolButton"
89 "property-activate" : (
90 gobject.SIGNAL_RUN_FIRST,
92 (gobject.TYPE_STRING, gobject.TYPE_INT)),
95 def __init__(self, prop):
96 gtk.ToggleToolButton.__init__(self)
97 self.set_homogeneous(False)
98 PropItem.__init__(self, prop)
99 self.property_changed()
101 def set_icon_name(self, icon_name):
103 widget = icon.IconWidget(icon_name, 18)
104 gtk.ToggleToolButton.set_icon_widget(self, widget)
105 self.set_is_important(False)
106 elif self._prop.label:
107 gtk.ToggleToolButton.set_icon_widget(self, None)
108 self.set_is_important(True)
110 widget = icon.IconWidget("ibus", 18)
111 gtk.ToggleToolButton.set_icon_widget(self, widget)
112 self.set_is_important(False)
114 self._prop.icon = icon_name
116 def set_tooltip_text(self, text):
118 gtk.ToggleToolButton.set_tooltip_text(self, text.text)
120 gtk.ToggleToolButton.set_tooltip_text(self, None)
122 self._prop.tooltip = text
124 def property_changed(self):
125 self.set_tooltip_text(self._prop.tooltip)
126 self.set_label(self._prop.label.text)
127 self.set_icon_name(self._prop.icon)
128 self.set_active(self._prop.state == ibus.PROP_STATE_CHECKED)
129 self.set_sensitive(self._prop.sensitive)
130 if self._prop.visible:
131 self.set_no_show_all(False)
134 self.set_no_show_all(True)
137 def do_toggled(self):
138 if self.get_active():
139 self._prop.state = ibus.PROP_STATE_CHECKED
141 self._prop.state = ibus.PROP_STATE_UNCHECKED
142 self.emit("property-activate", self._prop.key, self._prop.state)
144 class SeparatorToolItem(gtk.SeparatorToolItem, PropItem):
145 __gtype_name__ = "IBusSeparatorToolItem"
146 def __init__ (self, prop):
147 gtk.SeparatorToolItem.__init__(self)
148 self.set_homogeneous(False)
149 PropItem.__init__(self, prop)
151 class MenuToolButton(ToggleToolButton):
152 __gtype_name__ = "IBusMenuToolButton"
154 # "property-activate" : (
155 # gobject.SIGNAL_RUN_FIRST,
157 # (gobject.TYPE_STRING, gobject.TYPE_INT)),
160 def __init__(self, prop):
161 super(MenuToolButton, self).__init__(prop)
162 self._menu = Menu(prop)
163 self._menu.connect("deactivate", lambda m: self.set_active(False))
164 self._menu.connect("property-activate", lambda w,n,s: self.emit("property-activate", n, s))
166 def update_property(self, prop):
167 PropItem.update_property(self, prop)
168 self._menu.update_property(prop)
170 def do_toggled(self):
171 if self.get_active():
172 self._menu.popup(0, gtk.get_current_event_time(), self)
177 super(MenuToolButton, self).destroy()