5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA 02111-1307 USA
26 from image
import Image
27 from handle
import Handle
28 from toolitem
import ToolButton
,\
32 ICON_SIZE
= gtk
.ICON_SIZE_MENU
34 class LanguageBar (gtk
.Toolbar
):
36 "property-activate" : (
37 gobject
.SIGNAL_RUN_FIRST
,
39 (gobject
.TYPE_STRING
, gobject
.TYPE_INT
)),
41 gobject
.SIGNAL_RUN_FIRST
,
43 (gobject
.TYPE_PYOBJECT
, )),
47 gtk
.Toolbar
.__init
__ (self
)
48 self
.set_property ("icon-size", ICON_SIZE
)
52 self
._toplevel
= gtk
.Window (gtk
.WINDOW_POPUP
)
53 self
._toplevel
.add (self
)
55 root
= gdk
.get_default_root_window ()
56 workarea
= root
.property_get ("_NET_WORKAREA")[2]
57 self
._toplevel
.move (workarea
[2] - 200, workarea
[3] - 40)
59 def _create_ui (self
):
61 self
._handle
= gtk
.ToolItem ()
62 self
._handle
.add (Handle ())
63 self
.insert (self
._handle
, -1)
65 # create input methods menu
66 self
._im
_menu
= ToolButton (icon
= "engine-default")
67 self
._im
_menu
.connect ("clicked", lambda w
: self
.emit ("im-menu-popup", self
._im
_menu
))
68 self
.insert (self
._im
_menu
, -1)
70 def _remove_properties (self
):
71 # reset all properties
72 for name
, props
in self
._properties
.items ():
73 for prop
, widget
in props
:
80 gtk
.Toolbar
.do_show (self
)
83 def do_check_resize (self
):
86 w
, h
= item
.size_request ()
88 self
.set_size_request (width
+ 4, -1)
90 def do_size_request (self
, requisition
):
91 gtk
.Toolbar
.do_size_request (self
, requisition
)
92 self
._toplevel
.resize (1, 1)
95 self
._remove
_properties
()
97 def register_properties (self
, props
):
98 self
._remove
_properties
()
99 # create new properties
101 if prop
._type
== ibus
.PROP_TYPE_NORMAL
:
102 widget
= ToolButton (prop
= prop
)
103 widget
.connect ("property-activate",
104 lambda w
, n
, s
: self
.emit ("property-activate", n
, s
))
105 elif prop
._type
== ibus
.PROP_TYPE_TOGGLE
:
106 widget
= ToggleToolButton (prop
= prop
)
107 widget
.connect ("property-activate",
108 lambda w
, n
, s
: self
.emit ("property-activate", n
, s
))
109 elif prop
._type
== ibus
.PROP_TYPE_MENU
:
110 widget
= MenuToolButton (prop
= prop
)
111 widget
.connect ("property-activate",
112 lambda w
, n
, s
: self
.emit ("property-activate", n
, s
))
113 elif prop
._type
== PROP_TYPE_SEPARATOR
:
114 widget
= gtk
.SeparatorToolItem ()
116 widget
= gtk
.ToolItem ()
118 widget
.set_sensitive (prop
._sensitive
)
120 widget
.set_no_show_all (True)
126 if not self
._properties
.has_key (prop
._name
):
127 self
._properties
[prop
._name
] = []
129 self
._properties
[prop
._name
].append ((prop
, widget
))
130 self
.insert (widget
, -1)
134 def update_properties (self
, props
):
138 self
._toplevel
.show_all ()
139 gtk
.Toolbar
.show_all (self
)
142 self
._toplevel
.hide_all ()
143 gtk
.Toolbar
.hide_all (self
)
145 gobject
.type_register (LanguageBar
, "IBusLanguageBar")