Fix bugs when moving languagebar.
[ibus.git] / panel / handle.py
blobe674fd78599508d123c2b94faa55f2d980788f96
1 import gtk
2 import gtk.gdk as gdk
3 import gobject
5 class Handle (gtk.EventBox):
6 def __init__ (self):
7 gtk.EventBox.__init__ (self)
8 self.set_visible_window (False)
9 self.set_size_request (10, -1)
10 self.set_events (
11 gdk.EXPOSURE_MASK | \
12 gdk.BUTTON_PRESS_MASK | \
13 gdk.BUTTON_RELEASE_MASK | \
14 gdk.BUTTON1_MOTION_MASK)
16 self._move_begined = False
18 def do_button_press_event (self, event):
19 if event.button == 1:
20 self._move_begined = True
21 self._press_pos = event.x_root, event.y_root
22 self.window.set_cursor (gdk.Cursor (gdk.FLEUR))
23 return True
24 return False
26 def do_button_release_event (self, event):
27 if event.button == 1:
28 self._move_begined = False
29 del self._press_pos
30 self.window.set_cursor (gdk.Cursor (gdk.LEFT_PTR))
31 return True
33 return False
35 def do_motion_notify_event (self, event):
36 if not self._move_begined:
37 return
38 toplevel = self.get_toplevel ()
39 x, y = toplevel.get_position ()
40 x = int (x + event.x_root - self._press_pos[0])
41 y = int (y + event.y_root - self._press_pos[1])
42 toplevel.move (x, y)
43 self._press_pos = event.x_root, event.y_root
45 def do_expose_event (self, event):
46 self.style.paint_handle (
47 self.window,
48 gtk.STATE_NORMAL,
49 gtk.SHADOW_OUT,
50 event.area,
51 self,
52 "",
53 self.allocation.x, self.allocation.y,
54 10, self.allocation.height,
55 gtk.ORIENTATION_VERTICAL)
56 return True
58 gobject.type_register (Handle, "IBusHandle")