1 from PyQt4
import QtGui
, QtCore
2 from PyKDE4
import kdeui
3 from clMonty
import monty
8 class pluginShortcuts(Plugin
):
12 def __init__(self
, winMain
):
13 Plugin
.__init
__(self
, winMain
, 'Shortcuts')
16 winMain
=self
.getWinMain()
17 # Note people wanting to implement global shortcuts in KDE4 (and sniffing through
18 # this code): one needs to have a KApplication running, else shortcuts will fail
19 self
.col
=kdeui
.KActionCollection(None)
20 self
.col
.addAssociatedWidget(winMain
)
22 ['toggleplay', QtCore
.Qt
.META
+QtCore
.Qt
.Key_Home
, self
.togglePlay
],
23 ['volumeup', QtCore
.Qt
.META
+QtCore
.Qt
.Key_PageDown
, lambda b
: monty
.setVolume(monty
.getVolume()-5)],
24 ['volumedown', QtCore
.Qt
.META
+QtCore
.Qt
.Key_PageUp
, lambda b
: monty
.setVolume(monty
.getVolume()+5)],
25 ['playnext', QtCore
.Qt
.META
+QtCore
.Qt
.Key_Right
, monty
.next
],
26 ['playprevious', QtCore
.Qt
.META
+QtCore
.Qt
.Key_Left
, monty
.previous
],
27 ['showosd', QtCore
.Qt
.META
+QtCore
.Qt
.Key_O
, self
.showOSD
],
28 ['togglewin', QtCore
.Qt
.META
+QtCore
.Qt
.Key_P
, self
.toggleWinMain
],
30 # Note: don't use any non-alphanumerics in the prefix, as else it won't work
31 self
.actionPrefix
="shortcuts"
33 for entry
in self
.keys
:
38 self
.debug("%s - %s"%(name
, QtGui
.QKeySequence(key
).toString()))
40 action
=kdeui
.KAction(winMain
) # winMain needed
42 action
.setObjectName(name
)
43 action
.setGlobalShortcut(kdeui
.KShortcut(key
))
44 QtCore
.QObject
.connect(action
, QtCore
.SIGNAL('triggered(bool)'), callback
)
45 self
.col
.addAction("%s%s"%(self
.actionPrefix
, action
.objectName()), action
)
47 actions
=self
.col
.actions()
48 for action
in actions
:
50 if action
.objectName()[0:len(self
.actionPrefix
)]==self
.actionPrefix
:
51 self
.debug("removing %s"%(action
.objectName()))
52 self
.col
.removeAction(action
)
54 self
.important(str(e
))
57 return "Shortcuts for mpd."
60 plugins
.getPlugin('notify').onSongChange(None)
62 def togglePlay(self
, btns
=None, mods
=None):
68 def toggleWinMain(self
, b
):
75 def _getSettings(self
):
78 txt
.insertPlainText("Keybindings (read-only)\n")
79 for entry
in self
.keys
:
83 txt
.insertPlainText("%s\t%s\n"%(name
, QtGui
.QKeySequence(key
).toString()))
85 ['', 'Keybindings', 'Current keybindings', txt
],