diff options
author | jerous <jerous@gmail.com> | 2008-11-15 23:23:33 +0100 |
---|---|---|
committer | jerous <jerous@gmail.com> | 2008-11-15 23:23:33 +0100 |
commit | 1abac81ba802be21e40b93fe8b9b408c1d281d5d (patch) | |
tree | 99defabf86ad62f3bf1d66660197752c9f485618 /plugins | |
parent | 751270f0a6e47781c03db95df1e331def1cf0bfb (diff) |
allrighty - a shortcuts plugin!
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Shortcuts.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/plugins/Shortcuts.py b/plugins/Shortcuts.py new file mode 100644 index 0000000..79c43f6 --- /dev/null +++ b/plugins/Shortcuts.py @@ -0,0 +1,67 @@ +from PyQt4 import QtGui, QtCore +from PyKDE4 import kdeui +from clMonty import monty +from clPlugin import * +from misc import * +import format + +class pluginShortcuts(Plugin): + keys=None + col=None + actionPrefix=None + def __init__(self, winMain): + Plugin.__init__(self, winMain, 'Shortcuts') + + def _load(self): + winMain=self.getWinMain() + # Note people wanting to implement global shortcuts in KDE4 (and sniffing through + # this code): one needs to have a KApplication running, else shortcuts will fail + self.col=kdeui.KActionCollection(None) + self.col.addAssociatedWidget(winMain) + self.keys=[ + ['toggleplay', QtCore.Qt.META+QtCore.Qt.Key_Home, self.togglePlay], + ['volumeup', QtCore.Qt.META+QtCore.Qt.Key_PageDown, lambda b: monty.setVolume(monty.getVolume()-5)], + ['volumedown', QtCore.Qt.META+QtCore.Qt.Key_PageUp, lambda b: monty.setVolume(monty.getVolume()+5)], + ['playnext', QtCore.Qt.META+QtCore.Qt.Key_Right, monty.next], + ['playprevious', QtCore.Qt.META+QtCore.Qt.Key_Left, monty.previous], + ['showosd', QtCore.Qt.META+QtCore.Qt.Key_O, self.showOSD], + ] + # Note: don't use any non-alphanumerics in the prefix, as else it won't work + self.actionPrefix="shortcuts" + + for entry in self.keys: + name=entry[0] + key=entry[1] + callback=entry[2] + + self.debug("%s - %s"%(name, QtGui.QKeySequence(key).toString())) + + action=kdeui.KAction(winMain) # winMain needed + action.setText(name) + action.setObjectName(name) + action.setGlobalShortcut(kdeui.KShortcut(key)) + QtCore.QObject.connect(action, QtCore.SIGNAL('triggered(bool)'), callback) + self.col.addAction("%s%s"%(self.actionPrefix, action.objectName()), action) + def _unload(self): + actions=self.col.actions() + for action in actions: + try: + if action.objectName()[0:len(self.actionPrefix)]==self.actionPrefix: + self.debug("removing %s"%(action.objectName())) + self.col.removeAction(action) + except Exception, e: + self.important(str(e)) + + def getInfo(self): + return "Shortcuts for mpd." + + def showOSD(self, b): + plugins.getPlugin('notify').onSongChange(None) + + def togglePlay(self, btns=None, mods=None): + if monty.isPlaying(): + monty.pause() + else: + monty.resume() + + |