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 menu
import menu_position
29 from toolitem
import ToolButton
,\
34 ICON_SIZE
= gtk
.ICON_SIZE_MENU
36 class LanguageBar (gtk
.Toolbar
):
38 "property-activate" : (
39 gobject
.SIGNAL_RUN_FIRST
,
41 (gobject
.TYPE_STRING
, gobject
.TYPE_INT
)),
43 gobject
.SIGNAL_RUN_LAST
,
44 gobject
.TYPE_PYOBJECT
,
49 gtk
.Toolbar
.__init
__ (self
)
50 self
.set_property ("icon-size", ICON_SIZE
)
54 self
._toplevel
= gtk
.Window (gtk
.WINDOW_POPUP
)
55 self
._toplevel
.add (self
)
57 root
= gdk
.get_default_root_window ()
58 workarea
= root
.property_get ("_NET_WORKAREA")[2]
59 self
._toplevel
.move (workarea
[2] - 200, workarea
[3] - 40)
61 def _create_ui (self
):
63 self
._handle
= gtk
.ToolItem ()
64 self
._handle
.add (Handle ())
65 self
.insert (self
._handle
, -1)
67 # create input methods menu
68 self
._im
_menu
= ToggleToolButton (ibus
.Property (name
= "", type = ibus
.PROP_TYPE_TOGGLE
, icon
= "engine-default", tooltip
= "Swicth engine"))
69 self
._im
_menu
.connect ("toggled", self
._im
_menu
_toggled
_cb
)
70 self
.insert (self
._im
_menu
, -1)
72 def _im_menu_toggled_cb (self
, widget
):
73 if self
._im
_menu
.get_active ():
74 menu
= self
.emit ("get-im-menu")
75 menu
.connect ("deactivate", self
._im
_menu
_deactivate
_cb
)
76 menu
.popup (None, None,
79 gtk
.get_current_event_time (),
81 def _im_menu_deactivate_cb (self
, menu
):
82 self
._im
_menu
.set_active (False)
84 def _remove_properties (self
):
85 # reset all properties
87 map (lambda i
: i
.destroy (), self
._properties
)
92 gtk
.Toolbar
.do_show (self
)
95 def do_check_resize (self
):
98 w
, h
= item
.size_request ()
100 self
.set_size_request (width
+ 4, -1)
102 def do_size_request (self
, requisition
):
103 gtk
.Toolbar
.do_size_request (self
, requisition
)
104 self
._toplevel
.resize (1, 1)
106 def set_im_icon (self
, icon_name
):
107 self
._im
_menu
.set_icon_name (icon_name
)
110 self
._remove
_properties
()
112 def register_properties (self
, props
):
113 self
._remove
_properties
()
114 # create new properties
116 if prop
._type
== ibus
.PROP_TYPE_NORMAL
:
117 item
= ToolButton (prop
= prop
)
118 elif prop
._type
== ibus
.PROP_TYPE_TOGGLE
:
119 item
= ToggleToolButton (prop
= prop
)
120 elif prop
._type
== ibus
.PROP_TYPE_MENU
:
121 item
= MenuToolButton (prop
= prop
)
122 elif prop
._type
== PROP_TYPE_SEPARATOR
:
123 item
= SeparatorToolItem ()
125 raise IBusException ("Unknown property type = %d" % prop
._type
)
127 item
.connect ("property-activate",
128 lambda w
, n
, s
: self
.emit ("property-activate", n
, s
))
130 item
.set_sensitive (prop
._sensitive
)
132 item
.set_no_show_all (True)
139 self
._properties
.append (item
)
140 self
.insert (item
, -1)
144 def update_property (self
, prop
):
145 map (lambda x
: x
.update_property (prop
), self
._properties
)
148 self
._toplevel
.show_all ()
149 gtk
.Toolbar
.show_all (self
)
152 self
._toplevel
.hide_all ()
153 gtk
.Toolbar
.hide_all (self
)
156 self
._im
_menu
.set_sensitive (True)
158 def focus_out (self
):
159 self
._im
_menu
.set_sensitive (False)
161 gobject
.type_register (LanguageBar
, "IBusLanguageBar")