Remove clSettings. Didn't i do this already?
[nephilim.git] / plugins / Notify.py
blob40767fa8fd71bbac8d759509d1c36ebbc72afb13
1 from PyQt4 import QtGui, QtCore
2 from PyQt4.QtCore import QVariant
3 from traceback import print_exc
5 from misc import *
6 from clPlugin import Plugin
7 import plugins
9 NOTIFY_PRIORITY_SONG = 1
10 NOTIFY_PRIORITY_VOLUME = 2
12 class winNotify(QtGui.QWidget):
13 _timerID=None
14 winMain=None
15 p=None
17 _current_priority = 0
19 timer=None
21 cover_label = None
22 text_label = None
24 def __init__(self, p, winMain, parent=None):
25 QtGui.QWidget.__init__(self, parent)
26 self.p=p
27 self.winMain=winMain
29 layout = QtGui.QHBoxLayout()
30 self.cover_label = QtGui.QLabel()
31 self.text_label = QtGui.QLabel()
32 self.text_label.setWordWrap(True)
33 layout.addWidget(self.cover_label)
34 layout.addWidget(self.text_label)
35 self.setLayout(layout)
37 self.setWindowFlags(QtCore.Qt.ToolTip | QtCore.Qt.WindowStaysOnTopHint)
38 self.setWindowOpacity(0.7)
40 font = QtGui.QFont()
41 font.setPixelSize(20)
42 self.setFont(font)
44 def mousePressEvent(self, event):
45 self.hide()
47 def show(self, text, time = 3, priority = 0):
48 if not priority >= self._current_priority:
49 return
50 self._current_priority = priority
52 cover = plugins.getPlugin('albumcover').getWidget().get_cover()
53 if cover:
54 self.cover_label.setPixmap(cover.scaledToHeight(self.fontInfo().pixelSize()*4))
55 else:
56 self.cover_label.clear()
58 self.text_label.setText(text)
59 if self._timerID:
60 self.killTimer(self._timerID)
61 self._timerID=self.startTimer(500)
62 self.timer = time*2
63 self.resize(self.layout().sizeHint())
64 self.centerH()
65 self.setVisible(True)
66 self.timerEvent(None)
68 def hide(self):
69 if self._timerID:
70 self.killTimer(self._timerID)
71 self._timerID=None
72 self.setHidden(True)
73 self._current_priority = -1
75 def centerH(self):
76 screen = QtGui.QDesktopWidget().screenGeometry()
77 size = self.geometry()
78 self.move((screen.width()-size.width())/2, 100)
80 def timerEvent(self, event):
81 self.timer-=1
82 if self.timer<=0:
83 self.hide()
84 self.update()
86 class pluginNotify(Plugin):
87 o=None
88 DEFAULTS = {'songformat' : '$track - $artist - $title ($album) [$length]',
89 'timer' : 3}
90 def __init__(self, winMain):
91 Plugin.__init__(self, winMain, 'Notify')
92 self.addListener('onSongChange', self.onSongChange)
93 self.addListener('onReady', self.onReady)
94 self.addListener('onDisconnect', self.onDisconnect)
95 self.addListener('onStateChange', self.onStateChange)
96 self.addListener('onVolumeChange', self.onVolumeChange)
98 def _load(self):
99 self.o = winNotify(self, self.winMain)
100 def _unload(self):
101 self.o=None
102 def getInfo(self):
103 return "Show interesting events in a popup window."
105 def onSongChange(self, params):
106 song = self.mpclient.getCurrentSong()
107 if not song:
108 return
109 self.settings.beginGroup(self.name)
110 self.o.show(song.expand_tags(self.settings.value('songformat').toString()), self.settings.value('timer').toInt()[0],
111 NOTIFY_PRIORITY_SONG)
112 self.settings.endGroup()
114 def onReady(self, params):
115 self.o.show('mpclientpc loaded!', self.settings.value(self.name + '/timer').toInt()[0])
117 def onDisconnect(self, params):
118 self.o.show('Disconnected!', self.settings.value(self.name + '/timer').toInt()[0])
120 def onStateChange(self, params):
121 self.o.show(params['newState'], self.settings.value(self.name + '/timer').toInt()[0])
123 def onVolumeChange(self, params):
124 self.o.show('Volume: %i%%'%(params['newVolume']), self.settings.value(self.name + '/timer').toInt()[0], priority = NOTIFY_PRIORITY_VOLUME)
126 class SettingsWidgetNotify(Plugin.SettingsWidget):
127 format = None
128 timer = None
130 def __init__(self, plugin):
131 Plugin.SettingsWidget.__init__(self, plugin)
132 self.settings.beginGroup(self.plugin.getName())
134 self.format = QtGui.QLineEdit(self.settings.value('songformat').toString())
136 self.timer = QtGui.QLineEdit(self.settings.value('timer').toString())
137 self.timer.setValidator(QtGui.QIntValidator(self.timer))
139 self.setLayout(QtGui.QVBoxLayout())
140 self.layout().addWidget(self.format)
141 self.layout().addWidget(self.timer)
142 self.settings.endGroup()
144 def save_settings(self):
145 self.settings.beginGroup(self.plugin.getName())
146 self.settings.setValue('songformat', QVariant(self.format.text()))
147 self.settings.setValue('timer', QVariant(self.timer.text().toInt()[0]))
148 self.settings.endGroup()
149 self.plugin.onSongChange(None)
151 def get_settings_widget(self):
152 return self.SettingsWidgetNotify(self)