forked from openlp/openlp
Add Key Actions to Shortcut Dialogs
bzr-revno: 1235
This commit is contained in:
commit
ee51a98ab9
@ -28,8 +28,6 @@ Provide common toolbar handling for OpenLP
|
||||
"""
|
||||
import logging
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
from openlp.core.lib import build_icon
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -51,7 +49,8 @@ class OpenLPToolbar(QtGui.QToolBar):
|
||||
log.debug(u'Init done')
|
||||
|
||||
def addToolbarButton(self, title, icon, tooltip=None, slot=None,
|
||||
checkable=False):
|
||||
checkable=False, shortcut=0, alternate=0,
|
||||
context=QtCore.Qt.WidgetShortcut):
|
||||
"""
|
||||
A method to help developers easily add a button to the toolbar.
|
||||
|
||||
@ -72,6 +71,15 @@ class OpenLPToolbar(QtGui.QToolBar):
|
||||
``checkable``
|
||||
If *True* the button has two, *off* and *on*, states. Default is
|
||||
*False*, which means the buttons has only one state.
|
||||
|
||||
``shortcut``
|
||||
The primary shortcut for this action
|
||||
|
||||
``alternate``
|
||||
The alternate shortcut for this action
|
||||
|
||||
``context``
|
||||
Specify the context in which this shortcut is valid
|
||||
"""
|
||||
newAction = None
|
||||
if icon:
|
||||
@ -93,6 +101,8 @@ class OpenLPToolbar(QtGui.QToolBar):
|
||||
QtCore.QObject.connect(newAction,
|
||||
QtCore.SIGNAL(u'toggled(bool)'), slot)
|
||||
self.actions[title] = newAction
|
||||
newAction.setShortcuts([shortcut, alternate])
|
||||
newAction.setShortcutContext(context)
|
||||
return newAction
|
||||
|
||||
def addToolbarSeparator(self, handle):
|
||||
|
@ -54,45 +54,6 @@ class DisplayWidget(QtGui.QGraphicsView):
|
||||
QtGui.QGraphicsView.__init__(self)
|
||||
self.parent = parent
|
||||
self.live = live
|
||||
self.hotkey_map = {
|
||||
QtCore.Qt.Key_Return: 'servicemanager_next_item',
|
||||
QtCore.Qt.Key_Space: 'slidecontroller_live_next_noloop',
|
||||
QtCore.Qt.Key_Enter: 'slidecontroller_live_next_noloop',
|
||||
QtCore.Qt.Key_0: 'servicemanager_next_item',
|
||||
QtCore.Qt.Key_Backspace: 'slidecontroller_live_previous_noloop'}
|
||||
self.setStyleSheet(u'border: none;')
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
"""
|
||||
Handle key events from display screen
|
||||
"""
|
||||
# Key events only needed for live
|
||||
if not self.live:
|
||||
return
|
||||
if isinstance(event, QtGui.QKeyEvent):
|
||||
# Here accept the event and do something
|
||||
if event.key() == QtCore.Qt.Key_Up:
|
||||
Receiver.send_message(u'slidecontroller_live_previous')
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_Down:
|
||||
Receiver.send_message(u'slidecontroller_live_next')
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_PageUp:
|
||||
Receiver.send_message(u'slidecontroller_live_first')
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_PageDown:
|
||||
Receiver.send_message(u'slidecontroller_live_last')
|
||||
event.accept()
|
||||
elif event.key() in self.hotkey_map:
|
||||
Receiver.send_message(self.hotkey_map[event.key()])
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_Escape:
|
||||
self.setVisible(False)
|
||||
self.videoStop()
|
||||
event.accept()
|
||||
event.ignore()
|
||||
else:
|
||||
event.ignore()
|
||||
|
||||
|
||||
class MainDisplay(DisplayWidget):
|
||||
|
@ -49,34 +49,6 @@ class ServiceManagerList(QtGui.QTreeWidget):
|
||||
QtGui.QTreeWidget.__init__(self, parent)
|
||||
self.mainwindow = mainwindow
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if isinstance(event, QtGui.QKeyEvent):
|
||||
#here accept the event and do something
|
||||
if event.key() == QtCore.Qt.Key_Enter:
|
||||
self.mainwindow.makeLive()
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_Home:
|
||||
self.mainwindow.onServiceTop()
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_End:
|
||||
self.mainwindow.onServiceEnd()
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_PageUp:
|
||||
self.mainwindow.onServiceUp()
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_PageDown:
|
||||
self.mainwindow.onServiceDown()
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_Up:
|
||||
self.mainwindow.onMoveSelectionUp()
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_Down:
|
||||
self.mainwindow.onMoveSelectionDown()
|
||||
event.accept()
|
||||
event.ignore()
|
||||
else:
|
||||
event.ignore()
|
||||
|
||||
def mouseMoveEvent(self, event):
|
||||
"""
|
||||
Drag and drop event does not care what data is selected
|
||||
@ -178,50 +150,72 @@ class ServiceManager(QtGui.QWidget):
|
||||
self.layout.addWidget(self.serviceManagerList)
|
||||
# Add the bottom toolbar
|
||||
self.orderToolbar = OpenLPToolbar(self)
|
||||
self.orderToolbar.addToolbarButton(
|
||||
self.serviceManagerList.moveTop = self.orderToolbar.addToolbarButton(
|
||||
translate('OpenLP.ServiceManager', 'Move to &top'),
|
||||
u':/services/service_top.png',
|
||||
translate('OpenLP.ServiceManager',
|
||||
'Move item to the top of the service.'),
|
||||
self.onServiceTop)
|
||||
self.orderToolbar.addToolbarButton(
|
||||
self.onServiceTop, shortcut=QtCore.Qt.Key_Home)
|
||||
self.serviceManagerList.moveUp = self.orderToolbar.addToolbarButton(
|
||||
translate('OpenLP.ServiceManager', 'Move &up'),
|
||||
u':/services/service_up.png',
|
||||
translate('OpenLP.ServiceManager',
|
||||
'Move item up one position in the service.'),
|
||||
self.onServiceUp)
|
||||
self.orderToolbar.addToolbarButton(
|
||||
self.onServiceUp, shortcut=QtCore.Qt.Key_PageUp)
|
||||
self.serviceManagerList.moveDown = self.orderToolbar.addToolbarButton(
|
||||
translate('OpenLP.ServiceManager', 'Move &down'),
|
||||
u':/services/service_down.png',
|
||||
translate('OpenLP.ServiceManager',
|
||||
'Move item down one position in the service.'),
|
||||
self.onServiceDown)
|
||||
self.orderToolbar.addToolbarButton(
|
||||
self.onServiceDown, shortcut=QtCore.Qt.Key_PageDown)
|
||||
self.serviceManagerList.moveBottom = self.orderToolbar.addToolbarButton(
|
||||
translate('OpenLP.ServiceManager', 'Move to &bottom'),
|
||||
u':/services/service_bottom.png',
|
||||
translate('OpenLP.ServiceManager',
|
||||
'Move item to the end of the service.'),
|
||||
self.onServiceEnd)
|
||||
self.onServiceEnd, shortcut=QtCore.Qt.Key_End)
|
||||
self.serviceManagerList.down = self.orderToolbar.addToolbarButton(
|
||||
translate('OpenLP.ServiceManager', 'Move &down'),
|
||||
None,
|
||||
translate('OpenLP.ServiceManager',
|
||||
'Moves the selection up the window.'),
|
||||
self.onMoveSelectionDown, shortcut=QtCore.Qt.Key_Up)
|
||||
self.serviceManagerList.down.setVisible(False)
|
||||
self.serviceManagerList.up = self.orderToolbar.addToolbarButton(
|
||||
translate('OpenLP.ServiceManager', 'Move up'),
|
||||
None,
|
||||
translate('OpenLP.ServiceManager',
|
||||
'Moves the selection up the window.'),
|
||||
self.onMoveSelectionUp, shortcut=QtCore.Qt.Key_Up)
|
||||
self.serviceManagerList.up.setVisible(False)
|
||||
self.orderToolbar.addSeparator()
|
||||
self.orderToolbar.addToolbarButton(
|
||||
self.serviceManagerList.delete = self.orderToolbar.addToolbarButton(
|
||||
translate('OpenLP.ServiceManager', '&Delete From Service'),
|
||||
u':/general/general_delete.png',
|
||||
translate('OpenLP.ServiceManager',
|
||||
'Delete the selected item from the service.'),
|
||||
self.onDeleteFromService)
|
||||
self.orderToolbar.addSeparator()
|
||||
self.orderToolbar.addToolbarButton(
|
||||
self.serviceManagerList.expand = self.orderToolbar.addToolbarButton(
|
||||
translate('OpenLP.ServiceManager', '&Expand all'),
|
||||
u':/services/service_expand_all.png',
|
||||
translate('OpenLP.ServiceManager',
|
||||
'Expand all the service items.'),
|
||||
self.onExpandAll)
|
||||
self.orderToolbar.addToolbarButton(
|
||||
self.serviceManagerList.collapse = self.orderToolbar.addToolbarButton(
|
||||
translate('OpenLP.ServiceManager', '&Collapse all'),
|
||||
u':/services/service_collapse_all.png',
|
||||
translate('OpenLP.ServiceManager',
|
||||
'Collapse all the service items.'),
|
||||
self.onCollapseAll)
|
||||
self.orderToolbar.addSeparator()
|
||||
self.serviceManagerList.makeLive = self.orderToolbar.addToolbarButton(
|
||||
translate('OpenLP.ServiceManager', 'Go Live'),
|
||||
u':/general/general_live.png',
|
||||
translate('OpenLP.ServiceManager',
|
||||
'Send the selected item to Live.'),
|
||||
self.makeLive, shortcut=QtCore.Qt.Key_Enter,
|
||||
alternate=QtCore.Qt.Key_Return)
|
||||
self.orderToolbar.setObjectName(u'orderToolbar')
|
||||
self.layout.addWidget(self.orderToolbar)
|
||||
# Connect up our signals and slots
|
||||
@ -292,8 +286,28 @@ class ServiceManager(QtGui.QWidget):
|
||||
self.themeMenu = QtGui.QMenu(
|
||||
translate('OpenLP.ServiceManager', '&Change Item Theme'))
|
||||
self.menu.addMenu(self.themeMenu)
|
||||
self.setServiceHotkeys()
|
||||
self.serviceManagerList.addActions(
|
||||
[self.serviceManagerList.moveDown,
|
||||
self.serviceManagerList.moveUp,
|
||||
self.serviceManagerList.makeLive,
|
||||
self.serviceManagerList.moveTop,
|
||||
self.serviceManagerList.moveBottom,
|
||||
self.serviceManagerList.up,
|
||||
self.serviceManagerList.down
|
||||
])
|
||||
self.configUpdated()
|
||||
|
||||
def setServiceHotkeys(self):
|
||||
actionList = self.mainwindow.actionList
|
||||
actionList.add_action(self.serviceManagerList.moveDown, u'Service')
|
||||
actionList.add_action(self.serviceManagerList.moveUp, u'Service')
|
||||
actionList.add_action(self.serviceManagerList.moveTop, u'Service')
|
||||
actionList.add_action(self.serviceManagerList.moveBottom, u'Service')
|
||||
actionList.add_action(self.serviceManagerList.makeLive, u'Service')
|
||||
actionList.add_action(self.serviceManagerList.up, u'Service')
|
||||
actionList.add_action(self.serviceManagerList.down, u'Service')
|
||||
|
||||
def setModified(self, modified=True):
|
||||
"""
|
||||
Setter for property "modified". Sets whether or not the current service
|
||||
|
@ -33,6 +33,7 @@ from PyQt4.phonon import Phonon
|
||||
from openlp.core.ui import HideMode, MainDisplay
|
||||
from openlp.core.lib import OpenLPToolbar, Receiver, resize_image, \
|
||||
ItemCapabilities, translate
|
||||
from openlp.core.utils import ActionList
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -44,34 +45,6 @@ class SlideList(QtGui.QTableWidget):
|
||||
def __init__(self, parent=None, name=None):
|
||||
QtGui.QTableWidget.__init__(self, parent.Controller)
|
||||
self.parent = parent
|
||||
self.hotkeyMap = {
|
||||
QtCore.Qt.Key_Return: 'servicemanager_next_item',
|
||||
QtCore.Qt.Key_Space: 'slidecontroller_live_next_noloop',
|
||||
QtCore.Qt.Key_Enter: 'slidecontroller_live_next_noloop',
|
||||
QtCore.Qt.Key_0: 'servicemanager_next_item',
|
||||
QtCore.Qt.Key_Backspace: 'slidecontroller_live_previous_noloop'}
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if isinstance(event, QtGui.QKeyEvent):
|
||||
#here accept the event and do something
|
||||
if event.key() == QtCore.Qt.Key_Up:
|
||||
self.parent.onSlideSelectedPrevious()
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_Down:
|
||||
self.parent.onSlideSelectedNext()
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_PageUp:
|
||||
self.parent.onSlideSelectedFirst()
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_PageDown:
|
||||
self.parent.onSlideSelectedLast()
|
||||
event.accept()
|
||||
elif event.key() in self.hotkeyMap and self.parent.isLive:
|
||||
Receiver.send_message(self.hotkeyMap[event.key()])
|
||||
event.accept()
|
||||
event.ignore()
|
||||
else:
|
||||
event.ignore()
|
||||
|
||||
|
||||
class SlideController(QtGui.QWidget):
|
||||
@ -162,12 +135,14 @@ class SlideController(QtGui.QWidget):
|
||||
sizeToolbarPolicy.setHeightForWidth(
|
||||
self.Toolbar.sizePolicy().hasHeightForWidth())
|
||||
self.Toolbar.setSizePolicy(sizeToolbarPolicy)
|
||||
self.Toolbar.addToolbarButton(
|
||||
u'Previous Slide', u':/slides/slide_previous.png',
|
||||
self.previousItem = self.Toolbar.addToolbarButton(
|
||||
translate('OpenLP.SlideController', 'Previous Slide'),
|
||||
u':/slides/slide_previous.png',
|
||||
translate('OpenLP.SlideController', 'Move to previous'),
|
||||
self.onSlideSelectedPrevious)
|
||||
self.Toolbar.addToolbarButton(
|
||||
u'Next Slide', u':/slides/slide_next.png',
|
||||
self.nextItem = self.Toolbar.addToolbarButton(
|
||||
translate('OpenLP.SlideController', 'Next Slide'),
|
||||
u':/slides/slide_next.png',
|
||||
translate('OpenLP.SlideController', 'Move to next'),
|
||||
self.onSlideSelectedNext)
|
||||
if self.isLive:
|
||||
@ -339,6 +314,25 @@ class SlideController(QtGui.QWidget):
|
||||
self.onGoLiveClick)
|
||||
self.Toolbar.makeWidgetsInvisible(self.songEditList)
|
||||
self.Mediabar.setVisible(False)
|
||||
if self.isLive:
|
||||
self.setLiveHotkeys(self)
|
||||
self.PreviewListWidget.addActions(
|
||||
[self.previousItem,
|
||||
self.nextItem,
|
||||
self.previousService,
|
||||
self.nextService,
|
||||
self.escapeItem])
|
||||
self.display.addActions(
|
||||
[self.previousItem,
|
||||
self.nextItem,
|
||||
self.previousService,
|
||||
self.nextService,
|
||||
self.escapeItem])
|
||||
else:
|
||||
self.setPreviewHotkeys()
|
||||
self.PreviewListWidget.addActions(
|
||||
[self.nextItem,
|
||||
self.previousItem])
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'slidecontroller_%s_stop_loop' % self.typePrefix),
|
||||
self.onStopLoop)
|
||||
@ -379,6 +373,55 @@ class SlideController(QtGui.QWidget):
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'config_screen_changed'), self.screenSizeChanged)
|
||||
|
||||
def setPreviewHotkeys(self, parent=None):
|
||||
actionList = self.parent.actionList
|
||||
self.previousItem.setShortcuts([QtCore.Qt.Key_Up, 0])
|
||||
actionList.add_action(self.previousItem, u'Preview')
|
||||
self.nextItem.setShortcuts([QtCore.Qt.Key_Down, 0])
|
||||
actionList.add_action(self.nextItem, u'Preview')
|
||||
|
||||
def setLiveHotkeys(self, parent=None):
|
||||
actionList = self.parent.actionList
|
||||
self.previousItem.setShortcuts([QtCore.Qt.Key_Up, QtCore.Qt.Key_PageUp])
|
||||
self.previousItem.setShortcutContext(
|
||||
QtCore.Qt.WidgetWithChildrenShortcut)
|
||||
actionList.add_action(self.nextItem, u'Live')
|
||||
self.nextItem.setShortcuts([QtCore.Qt.Key_Down, QtCore.Qt.Key_PageDown])
|
||||
self.nextItem.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
|
||||
actionList.add_action(self.nextItem, u'Live')
|
||||
self.previousService = QtGui.QAction(translate(
|
||||
'OpenLP.SlideController', 'Previous Service'), parent)
|
||||
self.previousService.setShortcuts([QtCore.Qt.Key_Left, 0])
|
||||
self.previousService.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
|
||||
QtCore.QObject.connect(self.previousService,
|
||||
QtCore.SIGNAL(u'triggered()'), self.servicePrevious)
|
||||
actionList.add_action(self.previousService, u'Live')
|
||||
self.nextService = QtGui.QAction(translate(
|
||||
'OpenLP.SlideController', 'Next Service'), parent)
|
||||
self.nextService.setShortcuts([QtCore.Qt.Key_Right, 0])
|
||||
self.nextService.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
|
||||
QtCore.QObject.connect(self.nextService,
|
||||
QtCore.SIGNAL(u'triggered()'), self.serviceNext)
|
||||
actionList.add_action(self.nextService, u'Live')
|
||||
self.escapeItem = QtGui.QAction(translate(
|
||||
'OpenLP.SlideController', 'Escape Item'), parent)
|
||||
self.escapeItem.setShortcuts([QtCore.Qt.Key_Escape, 0])
|
||||
self.escapeItem.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
|
||||
QtCore.QObject.connect(self.escapeItem,
|
||||
QtCore.SIGNAL(u'triggered()'), self.liveEscape)
|
||||
actionList.add_action(self.escapeItem, u'Live')
|
||||
|
||||
def liveEscape(self):
|
||||
self.display.setVisible(False)
|
||||
self.display.videoStop()
|
||||
|
||||
def servicePrevious(self):
|
||||
Receiver.send_message('servicemanager_previous_item')
|
||||
|
||||
def serviceNext(self):
|
||||
Receiver.send_message('servicemanager_next_item')
|
||||
|
||||
|
||||
def screenSizeChanged(self):
|
||||
"""
|
||||
Settings dialog has changed the screen size of adjust output and
|
||||
@ -389,6 +432,13 @@ class SlideController(QtGui.QWidget):
|
||||
self.display.imageManager = self.parent.renderManager.image_manager
|
||||
self.display.alertTab = self.alertTab
|
||||
self.display.setup()
|
||||
if self.isLive:
|
||||
self.display.addActions(
|
||||
[self.previousItem,
|
||||
self.nextItem,
|
||||
self.previousService,
|
||||
self.nextService,
|
||||
self.escapeItem])
|
||||
# The SlidePreview's ratio.
|
||||
self.ratio = float(self.screens.current[u'size'].width()) / \
|
||||
float(self.screens.current[u'size'].height())
|
||||
@ -1071,4 +1121,3 @@ class SlideController(QtGui.QWidget):
|
||||
if self.DesktopScreen.isChecked:
|
||||
self.DesktopScreen.setChecked(False)
|
||||
self.HideMenu.setDefaultAction(self.DesktopScreen)
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
The :mod:`~openlp.core.utils.actions` module provides action list classes used
|
||||
by the shortcuts system.
|
||||
"""
|
||||
from PyQt4 import QtCore
|
||||
|
||||
class ActionCategory(object):
|
||||
"""
|
||||
@ -181,4 +182,4 @@ class ActionList(object):
|
||||
if weight is None:
|
||||
self.categories[category].actions.append(action)
|
||||
else:
|
||||
self.categories[category].actions.add(action, weight)
|
||||
self.categories[category].actions.add(action, weight)
|
||||
|
Loading…
Reference in New Issue
Block a user