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
):
61 assert self
.timeout
is None
65 if now
- self
.time
> 2:
70 self
.timeout
= gobject
.timeout_add(delay
, lambda: self
.show(parent
))
72 def tooltip_draw(self
, widget
, ev
):
73 widget
.window
.draw_rectangle(widget
.style
.fg_gc
[widget
.state
],
75 widget
.allocation
.width
- 1,
76 widget
.allocation
.height
- 1)
78 def tooltip_destroyed(self
, widget
):
85 def get_tooltip_text(self
, item
):
86 "Override in subclasses."