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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QVariant
import logging
from ..misc import ORGNAME, APPNAME, Button
from ..plugin import Plugin
class wgPlayControl(QtGui.QToolBar):
"""Displays controls for interacting with playing, like play, volume ..."""
" control buttons"
btnPlayPause = None
btnStop = None
btnPrevious = None
btnNext = None
slrVolume=None
repeat = None
random = None
p = None
" queued songs: int*"
queuedSongs=[]
# what mode where we in before the queue started?
beforeQueuedMode=None
class VolumeSlider(QtGui.QSlider):
def __init__(self, parent):
QtGui.QSlider.__init__(self, parent)
self.setOrientation(parent.orientation())
self.setMaximum(100)
self.setToolTip('Volume control')
def paintEvent(self, event):
painter = QtGui.QPainter(self)
painter.eraseRect(self.rect())
grad = QtGui.QLinearGradient(0, 0, self.width(), self.height())
grad.setColorAt(0, self.palette().color(QtGui.QPalette.Window))
grad.setColorAt(1, self.palette().color(QtGui.QPalette.Highlight))
if self.orientation() == QtCore.Qt.Horizontal:
rect = QtCore.QRect(0, 0, self.width() * self.value() / self.maximum(), self.height())
else:
rect = QtCore.QRect(0, self.height() * (1 - float(self.value()) / self.maximum()), self.width(), self.height())
painter.fillRect(rect, QtGui.QBrush(grad))
def __init__(self, p, parent = None):
QtGui.QToolBar.__init__(self, p.name(), parent)
self.setMovable(True)
self.p = p
self.slrVolume = self.VolumeSlider(self)
self.connect(self.slrVolume, QtCore.SIGNAL('valueChanged(int)'),self.onVolumeSliderChange)
self.btnPlayPause=Button("play", self.onBtnPlayPauseClick, 'gfx/media-playback-start.svg', True)
self.btnStop=Button("stop", self.onBtnStopClick, 'gfx/media-playback-stop.svg', True)
self.btnPrevious=Button("prev", self.onBtnPreviousClick, 'gfx/media-skip-backward.svg', True)
self.btnNext=Button("next", self.onBtnNextClick, 'gfx/media-skip-forward.svg', True)
self.random = QtGui.QPushButton(QtGui.QIcon('gfx/random.png'), '', self)
self.random.setToolTip('Random')
self.random.setCheckable(True)
self.connect(self.random, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient().random)
self.repeat = QtGui.QPushButton(QtGui.QIcon('gfx/repeat.png'), '', self)
self.repeat.setToolTip('Repeat')
self.repeat.setCheckable(True)
self.connect(self.repeat, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient().repeat)
self.addWidget(self.btnPlayPause)
self.addWidget(self.btnStop)
self.addWidget(self.btnPrevious)
self.addWidget(self.btnNext)
self.addSeparator()
self.addWidget(self.slrVolume)
self.addSeparator()
self.addWidget(self.random)
self.addWidget(self.repeat)
self.connect(self, QtCore.SIGNAL('orientationChanged(Qt::Orientation)'), self.slrVolume.setOrientation)
# queue gets loaded in _load of pluginPlayControl
self.queuedSongs=[]
self.connect(self.p.mpclient(), QtCore.SIGNAL('state_changed'), self.onStateChange)
self.connect(self.p.mpclient(), QtCore.SIGNAL('volume_changed'), self.onVolumeChange)
def addSongsToQueue(self, songs):
self.queuedSongs.extend(songs)
def onStateChange(self, new_state):
status = self.p.mpclient().status()
if new_state == 'play':
self.btnPlayPause.changeIcon('gfx/media-playback-pause.svg')
self.btnPlayPause.setToolTip('pauze')
elif new_state == 'pause' or new_state == 'stop':
self.btnPlayPause.changeIcon('gfx/media-playback-start.svg')
self.btnPlayPause.setToolTip('play')
def onVolumeChange(self, new_vol):
self.slrVolume.setValue(new_vol)
def onBtnPlayPauseClick(self):
status=self.p.mpclient().status()
if status['state']=='play':
self.p.mpclient().pause()
logging.info("Toggling playback")
elif status['state']=='stop':
self.p.mpclient().play(None)
logging.info("Pausing playback")
else:
self.p.mpclient().resume()
def onBtnStopClick(self):
self.p.mpclient().stop()
logging.info("Stopping playback")
def onBtnPreviousClick(self):
self.p.mpclient().previous()
logging.info("Playing previous")
def onBtnNextClick(self):
self.p.mpclient().next()
logging.info("Playing next")
def onVolumeSliderChange(self):
v=self.slrVolume.value()
self.p.mpclient().set_volume(v)
if v<=1:
mode='mute'
else:
mode=('0', 'min', 'med', 'max')[int(3*v/100)]
# save and load the queue
def saveQueue(self):
# save the ids as a list of space-separated numbers
logging.info("saving queue")
self.p.settings().setValue(self.p.name() + '/queue', QVariant(str(self.queuedSongs)[1:-1].replace(',', '')))
def loadQueue(self):
# just read all the numbers!
logging.info("loading queue")
self.queuedSongs=[]
i=0
ids=self.p.settings().value(self.p.name() + '/queue').toString().split(' ')
for id in ids:
try:
self.queuedSongs.append(int(id))
except:
pass
class PlayControl(Plugin):
o=None
DEFAULTS = {'queue' : ''}
def _load(self):
self.o = wgPlayControl(self, None)
self.o.loadQueue()
self.parent().addToolBar(QtCore.Qt.TopToolBarArea, self.o)
def _unload(self):
self.o.saveQueue()
self.parent().removeToolBar(self.o)
self.o = None
def getInfo(self):
return "Have total control over the playing!"
def addSongsToQueue(self, songs):
return self.o.addSongsToQueue(songs)
|