-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathalttoolbar_widget.py
84 lines (68 loc) · 2.85 KB
/
alttoolbar_widget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- Mode: python; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*-
#
# alttoolbar_widget.py - custom widgets
# Copyright (C) 2015 - 2020 David Mohammed <[email protected]>
# Copyright (C) 2018 Nguyễn Gia Phong <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
from gi.repository import Gtk
class Slider(Gtk.Scale):
"""Wrapper around Gtk.Scale to handle signals from user and
Rhythmbox itself.
"""
def __init__(self, shell_player):
super().__init__()
self.set_orientation(Gtk.Orientation.HORIZONTAL)
self.adjustment = Gtk.Adjustment(0, 0, 10, 1, 10, 0)
self.set_adjustment(self.adjustment)
self.set_hexpand(True)
self.set_draw_value(False)
self.set_sensitive(False)
self.shell_player = shell_player
self.dragging = self.drag_moved = False
self.connect('button-press-event', slider_press_callback)
self.connect('motion-notify-event', slider_moved_callback)
self.connect('button-release-event', slider_release_callback)
self.connect('focus-out-event', slider_release_callback)
self.changed_callback_id = self.connect('value-changed',
slider_changed_callback)
self.set_size_request(150, -1)
self.show_all()
def apply_position(self):
"""Sync slider elapsed time with Rhythmbox."""
self.shell_player.set_playing_time(self.adjustment.get_value())
def slider_press_callback(slider, event):
"""Handle 'button-press-event' signals."""
slider.dragging = True
slider.drag_moved = False
return False
def slider_moved_callback(slider, event):
"""Handle 'motion-notify-event' signals."""
if not slider.dragging:
return False
slider.drag_moved = True
slider.apply_position()
return False
def slider_release_callback(slider, event):
"""Handle 'button-release-event' and 'focus-out-event' signals."""
if not slider.dragging:
return False
if slider.drag_moved:
slider.apply_position()
slider.dragging = slider.drag_moved = False
return False
def slider_changed_callback(slider):
"""Handle 'value-changed-event' signals."""
slider.apply_position()