Progress bar tooltip
The tooltip shows the time corresponding to the mouse location on the widget.
This commit is contained in:
parent
2685572e52
commit
1e2d27377f
|
@ -75,3 +75,15 @@ def get_time():
|
|||
time = time.rsplit('.', 1)[0]
|
||||
time = time.split(':', 1)[1]
|
||||
return time
|
||||
|
||||
|
||||
def get_time_at(prcnt):
|
||||
duration = audio.duration()
|
||||
if duration == 0:
|
||||
return "00:00"
|
||||
pos = duration * prcnt
|
||||
pos /= 1000
|
||||
time = str(tdelta(microseconds=pos))
|
||||
time = time.rsplit('.', 1)[0]
|
||||
time = time.split(':', 1)[1]
|
||||
return time
|
||||
|
|
|
@ -5,13 +5,16 @@ gtk = ocarina.gtk
|
|||
gobject = ocarina.gobject
|
||||
update = None
|
||||
seek = None
|
||||
time_at = None
|
||||
|
||||
def set_fns():
|
||||
global update
|
||||
global get_time
|
||||
global seek
|
||||
global time_at
|
||||
update = ocarina.libsaria.audio.get_progress
|
||||
seek = ocarina.libsaria.audio.seek
|
||||
time_at = ocarina.libsaria.audio.get_time_at
|
||||
ocarina.libsaria.event.invite("POSTSTART", set_fns)
|
||||
|
||||
|
||||
|
@ -25,6 +28,7 @@ class PBar(gtk.HScale):
|
|||
self.set_range(0, 101)
|
||||
self.set_update_policy(gtk.UPDATE_DISCONTINUOUS)
|
||||
self.connect("change-value", self.change_value)
|
||||
self.connect("motion-notify-event", self.mouse_motion)
|
||||
gobject.timeout_add(500, self.update)
|
||||
self.show()
|
||||
|
||||
|
@ -36,3 +40,9 @@ class PBar(gtk.HScale):
|
|||
def change_value(self, scale, type, value):
|
||||
global seek
|
||||
seek(value / 100.0)
|
||||
|
||||
def mouse_motion(self, widget, event):
|
||||
alloc = self.get_allocation()
|
||||
prcnt = event.x / float(alloc.width)
|
||||
self.set_tooltip_text(time_at(prcnt))
|
||||
print widget, event, alloc.width
|
||||
|
|
Loading…
Reference in New Issue