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
|
#
# Copyright (C) 2008 jerous <jerous@gmail.com>
# Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
#
# Nephilim 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 of the License, or
# (at your option) any later version.
#
# Nephilim 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 Nephilim. If not, see <http://www.gnu.org/licenses/>.
#
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QVariant
from ..plugin import Plugin
from ..misc import sec2min, APPNAME, appIcon, expand_tags
class Systray(Plugin):
o = None
format = None
eventObj = None
DEFAULTS = {'format': '$track - $title by $artist on $album ($length)'}
def _load(self):
self.format = self.settings().value(self.name() + '/format').toString()
class SystrayWheelEventObject(QtCore.QObject):
"""This class listens for systray-wheel events"""
def eventFilter(self, object, event):
if type(event)==QtGui.QWheelEvent:
numDegrees=event.delta() / 8
numSteps=5*numDegrees/15
self.plugin.mpclient().set_volume(self.plugin.mpclient().volume() + numSteps)
event.accept()
return True
return False
self.o = QtGui.QSystemTrayIcon(QtGui.QIcon(appIcon), self.parent())
self.eventObj=SystrayWheelEventObject()
self.eventObj.plugin = self
self.o.installEventFilter(self.eventObj)
self.parent().connect(self.o, QtCore.SIGNAL('activated (QSystemTrayIcon::ActivationReason)')
, self.onSysTrayClick)
self.connect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.update)
self.o.show()
def _unload(self):
self.disconnect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.update)
self.disconnect(self.mpclient(), QtCore.SIGNAL('disconnected'), self.update)
self.disconnect(self.mpclient(), QtCore.SIGNAL('time_changed'), self.update)
self.o.hide()
self.o.setIcon(QtGui.QIcon(None))
self.o = None
self.parent()._wheelEvent = None
def getInfo(self):
return "Display the mpclientpc icon in the systray."
def update(self):
status = self.mpclient().status()
if not status:
return
values = {'state':''}
values['state']={'play':'playing', 'stop':'stopped', 'pause':'paused'}[status['state']]
if 'time' in status:
values['length'] = sec2min(status['length'])
values['time'] = sec2min(status['time'])
song = self.mpclient().current_song()
if song:
self.o.setToolTip(expand_tags(self.format, (song,)))
else:
self.o.setToolTip('%s not playing'%APPNAME)
def onSysTrayClick(self, reason):
if reason == QtGui.QSystemTrayIcon.Trigger or\
reason == QtGui.QSystemTrayIcon.Context:
w = self.parent()
if w.isVisible():
w.setVisible(False)
else:
w.setVisible(True)
elif reason == QtGui.QSystemTrayIcon.MiddleClick:
if self.mpclient().is_playing():
self.mpclient().pause()
else:
self.mpclient().resume()
class SettingsWidgetSystray(Plugin.SettingsWidget):
format = None
def __init__(self, plugin):
Plugin.SettingsWidget.__init__(self, plugin)
self.format = QtGui.QLineEdit(self.settings().value(self.plugin.name() + '/format').toString())
self.setLayout(QtGui.QVBoxLayout())
self._add_widget(self.format, 'Tooltip format')
def save_settings(self):
self.settings().beginGroup(self.plugin.name())
self.settings().setValue('format', QVariant(self.format.text()))
self.settings().endGroup()
def get_settings_widget(self):
return self.SettingsWidgetSystray(self)
|