UI library - shortcut_action

This commit is contained in:
Jon Tibble 2011-02-04 02:56:59 +00:00
parent 8fd9111f99
commit 70e7b549d5
2 changed files with 21 additions and 21 deletions

View File

@ -172,3 +172,13 @@ def icon_action(parent, name, icon, checked=None):
action = base_action(parent, name) action = base_action(parent, name)
action.setIcon(build_icon(icon)) action.setIcon(build_icon(icon))
return action return action
def shortcut_action(parent, text, shortcuts, function):
"""
Return a shortcut enabled action.
"""
action = QtGui.QAction(text, parent)
action.setShortcuts(shortcuts)
action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), function)
return action

View File

@ -30,9 +30,10 @@ import os
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from PyQt4.phonon import Phonon from PyQt4.phonon import Phonon
from openlp.core.ui import HideMode, MainDisplay
from openlp.core.lib import OpenLPToolbar, Receiver, resize_image, \ from openlp.core.lib import OpenLPToolbar, Receiver, resize_image, \
ItemCapabilities, translate ItemCapabilities, translate
from openlp.core.lib.ui import shortcut_action
from openlp.core.ui import HideMode, MainDisplay
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -390,28 +391,17 @@ class SlideController(QtGui.QWidget):
self.nextItem.setShortcuts([QtCore.Qt.Key_Down, QtCore.Qt.Key_PageDown]) self.nextItem.setShortcuts([QtCore.Qt.Key_Down, QtCore.Qt.Key_PageDown])
self.nextItem.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) self.nextItem.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
actionList.add_action(self.nextItem, u'Live') actionList.add_action(self.nextItem, u'Live')
self.previousService = QtGui.QAction(translate( self.previousService = shortcut_action(parent,
'OpenLP.SlideController', 'Previous Service'), parent) translate('OpenLP.SlideController', 'Previous Service'),
self.previousService.setShortcuts([QtCore.Qt.Key_Left, 0]) [QtCore.Qt.Key_Left, 0], self.servicePrevious)
self.previousService.setShortcutContext(
QtCore.Qt.WidgetWithChildrenShortcut)
QtCore.QObject.connect(self.previousService,
QtCore.SIGNAL(u'triggered()'), self.servicePrevious)
actionList.add_action(self.previousService, u'Live') actionList.add_action(self.previousService, u'Live')
self.nextService = QtGui.QAction(translate( self.nextService = shortcut_action(parent,
'OpenLP.SlideController', 'Next Service'), parent) translate('OpenLP.SlideController', 'Next Service'),
self.nextService.setShortcuts([QtCore.Qt.Key_Right, 0]) [QtCore.Qt.Key_Right, 0], self.serviceNext)
self.nextService.setShortcutContext(
QtCore.Qt.WidgetWithChildrenShortcut)
QtCore.QObject.connect(self.nextService,
QtCore.SIGNAL(u'triggered()'), self.serviceNext)
actionList.add_action(self.nextService, u'Live') actionList.add_action(self.nextService, u'Live')
self.escapeItem = QtGui.QAction(translate( self.escapeItem = shortcut_action(parent,
'OpenLP.SlideController', 'Escape Item'), parent) translate('OpenLP.SlideController', 'Escape Item'),
self.escapeItem.setShortcuts([QtCore.Qt.Key_Escape, 0]) [QtCore.Qt.Key_Escape, 0], self.liveEscape)
self.escapeItem.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
QtCore.QObject.connect(self.escapeItem,
QtCore.SIGNAL(u'triggered()'), self.liveEscape)
actionList.add_action(self.escapeItem, u'Live') actionList.add_action(self.escapeItem, u'Live')
def liveEscape(self): def liveEscape(self):