summaryrefslogtreecommitdiff
path: root/Shortcuts.py
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2008-12-26 12:27:25 +0100
committerAnton Khirnov <wyskas@gmail.com>2008-12-26 12:27:25 +0100
commitd423d9571091d5907ab07f1a7984a6df9d18fb78 (patch)
tree54166f94413c4795775e4d5e011ee83f74623de0 /Shortcuts.py
parent16d5dd604faad8c43a7f6fc6e9aa51459a3800ea (diff)
Disable shortcuts plugin for now.
It should be rewritten without KDE4 dependency later.
Diffstat (limited to 'Shortcuts.py')
-rw-r--r--Shortcuts.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/Shortcuts.py b/Shortcuts.py
new file mode 100644
index 0000000..e76078f
--- /dev/null
+++ b/Shortcuts.py
@@ -0,0 +1,86 @@
+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],
+ ['togglewin', QtCore.Qt.META+QtCore.Qt.Key_P, self.toggleWinMain],
+ ]
+ # 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()
+
+ def toggleWinMain(self, b):
+ w=self.getWinMain()
+ if w.isVisible():
+ w.setVisible(False)
+ else:
+ w.setVisible(True)
+
+ def _getSettings(self):
+ txt=QtGui.QTextEdit()
+ txt.setReadOnly(True)
+ txt.insertPlainText("Keybindings (read-only)\n")
+ for entry in self.keys:
+ name=entry[0]
+ key=entry[1]
+
+ txt.insertPlainText("%s\t%s\n"%(name, QtGui.QKeySequence(key).toString()))
+ return [
+ ['', 'Keybindings', 'Current keybindings', txt],
+ ]