def addHotKey(self, name, key): if not KGlobalAccel.isGlobalShortcutAvailable(key): actions = KGlobalAccel.getGlobalShortcutsByKey(key) if KGlobalAccel.promptStealShortcutSystemwide(None, actions, key): KGlobalAccel.stealShortcutSystemwide(key) action = KAction(None) action.setObjectName(name) action.setText(name) action.setGlobalShortcut(KShortcut(key), \ KAction.ShortcutType(KAction.ActiveShortcut | KAction.DefaultShortcut), KAction.NoAutoloading) action.triggered.connect(self.catchGlobalKey) self.actions[self.nextId] = action self.nextId += 1 return self.nextId - 1
def create (parent, ac): """here be common actions for satyr skins""" actions= ( ('queue', Qt.CTRL+Qt.Key_Q, False, "Queue songs"), ('rename', Qt.CTRL+Qt.Key_R, False, "Arrange songs"), ('toggleVA', Qt.CTRL+Qt.Key_V, False, "Toggle 'Various Artists' flag"), ('delete', Qt.CTRL+Qt.Key_D, False, "Delete songs"), # globals ('player.prev', KShortcut (Qt.Key_MediaPrevious), True, "Previous song"), ('player.stop', KShortcut (Qt.Key_MediaStop), True, "Stop"), ('player.play', KShortcut (Qt.Key_MediaPlay), True, "Play"), ('player.pause', KShortcut (Qt.Key_Pause), True, "Toggle Pause"), ('player.play_pause', KShortcut (Qt.Key_MediaPlay), True, "Switch between Play and Pause"), ('player.next', KShortcut (Qt.Key_MediaNext), True, "Next song"), ('player.toggleStopAfter', KShortcut (Qt.Key_Eject), True, "Stop after playing current song"), # TODO: S-Play/Pause -> cycle random # TODO: S-|<</>>| -> beginning/prev album, next album ) for fqn, shortcut, globalSC, text in actions: try: obj, name= traverseObjects (parent, fqn) except AttributeError, e: logger.warning ("actions.create(): %s, shortcut for %s not set", e.args[0], fqn) else: fqn= "satyr."+fqn action= KAction (text, parent) action.setObjectName (fqn) if globalSC: action.setGlobalShortcut (shortcut) else: action.setShortcut (shortcut) ac.addAction (fqn, action) # the skin can decide to not implement an action! method= getattr (obj, name, None) if method is not None: action.triggered.connect (method) else: logger.warning ("actions.create(): no method %s, shortcut for %s not set", name, fqn)