summaryrefslogtreecommitdiff
path: root/plugins/Systray.py
diff options
context:
space:
mode:
authorjerous <jerous@gmail.com>2008-10-30 19:50:51 +0100
committerjerous <jerous@gmail.com>2008-10-30 19:50:51 +0100
commit581ba6116c5b9ff887fc252b7eea03715a4ea7c1 (patch)
treeb11481efd033574cad1a54a26dad3a747224bcf0 /plugins/Systray.py
parentae87697f23971d7297452b2cf6971c97b01d2c64 (diff)
Systray: playing information in tooltip
Diffstat (limited to 'plugins/Systray.py')
-rw-r--r--plugins/Systray.py42
1 files changed, 37 insertions, 5 deletions
diff --git a/plugins/Systray.py b/plugins/Systray.py
index 1eeee8a..911eea0 100644
--- a/plugins/Systray.py
+++ b/plugins/Systray.py
@@ -2,17 +2,27 @@ from PyQt4 import QtGui
from clMonty import monty
from clPlugin import *
from misc import *
+import format
+
+SYSTRAY_FORMAT="$if($title,$title)$if($artist, by $artist) - [$album # $track] ($time/$length)"
class pluginSystray(Plugin):
o=None
+ format=None
+ eventObj=None
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'Systray')
+ self.addMontyListener('onSongChange', self.update)
+ self.addMontyListener('onReady', self.update)
+ self.addMontyListener('onConnect', self.update)
+ self.addMontyListener('onDisconnect', self.update)
+
def _load(self):
- class TrayIcon(QtGui.QSystemTrayIcon):
- def __init__(self, winMain):
- QtGui.QSystemTrayIcon.__init__(self, appIcon, winMain)
- def event(self, event):
+ self.format=format.compile(SYSTRAY_FORMAT)
+ 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
@@ -20,17 +30,39 @@ class pluginSystray(Plugin):
event.accept()
return True
return False
- self.o=TrayIcon(self.winMain)
+
+ self.o=QtGui.QSystemTrayIcon(appIcon, self.winMain)
+ self.eventObj=SystrayWheelEventObject()
+ self.o.installEventFilter(self.eventObj)
self.winMain.connect(self.o, QtCore.SIGNAL('activated (QSystemTrayIcon::ActivationReason)')
, self.onSysTrayClick)
self.o.show()
+ self.update(None)
def _unload(self):
self.o.hide()
self.o=None
self.winMain._wheelEvent=None
def getInfo(self):
return "Display the montypc icon in the systray."
+
+ def update(self, params):
+ status=monty.getStatus()
+ song=monty.getCurrentSong()
+ values={'state':''}
+ try:
+ values['state']={'play':'playing', 'stop':'stopped', 'pause':'paused'}[status['state']]
+ if 'time' in status:
+ values['length']=sec2min(status['length'])
+ values['time']=sec2min(status['time'])
+ except:
+ pass
+
+ if song:
+ self.o.setToolTip(self.format(format.params(song, values)))
+ else:
+ self.o.setToolTip("montypc not playing")
+
def onSysTrayClick(self, reason):
if reason==QtGui.QSystemTrayIcon.Trigger \
or reason==QtGui.QSystemTrayIcon.Context: