1 import time
, gobject
, gtk
9 def show(self
, parent
):
11 gobject
.source_remove(self
.timeout
)
21 text
= self
.get_tooltip_text(self
.item
)
25 self
.widget
= gtk
.Window(gtk
.WINDOW_POPUP
)
26 self
.widget
.set_app_paintable(True)
27 self
.widget
.set_name('gtk-tooltips')
29 self
.widget
.connect('expose-event', self
.tooltip_draw
)
31 label
= gtk
.Label(text
)
32 label
.set_line_wrap(True)
33 label
.set_padding(4, 2)
34 self
.widget
.add(label
)
37 w
, h
= self
.widget
.size_request()
38 if hasattr(parent
, 'get_screen'):
39 screen
= parent
.get_screen()
40 root
= screen
.get_root_window()
42 root
= gtk
.gdk
.get_default_root_window()
43 px
, py
, mask
= gtk
.gdk
.Window
.get_pointer(root
)
45 #m = gtk.gdk.screen_get_default().get_monitor_at_point(px, py)
50 # Test if pointer is over the tooltip window
51 if py
>= y
and py
<= y
+ h
:
53 self
.widget
.move(x
, y
)
56 self
.widget
.connect('destroy', self
.tooltip_destroyed
)
57 self
.time
= time
.time()
59 def prime(self
, parent
, item
):
64 assert self
.timeout
is None
68 if now
- self
.time
> 2:
73 self
.timeout
= gobject
.timeout_add(delay
, lambda: self
.show(parent
))
75 def tooltip_draw(self
, widget
, ev
):
76 widget
.window
.draw_rectangle(widget
.style
.fg_gc
[widget
.state
],
78 widget
.allocation
.width
- 1,
79 widget
.allocation
.height
- 1)
81 def tooltip_destroyed(self
, widget
):