diff --git a/openlp/core/ui/shortcutlistdialog.py b/openlp/core/ui/shortcutlistdialog.py index 288086cba..449f60509 100644 --- a/openlp/core/ui/shortcutlistdialog.py +++ b/openlp/core/ui/shortcutlistdialog.py @@ -28,6 +28,25 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import translate, build_icon +class CaptureShortcutButton(QtGui.QPushButton): + """ + A class to encapsulate a ``QPushButton``. + """ + def __init__(self, *args): + QtGui.QPushButton.__init__(self, *args) + self.setCheckable(True) + + def keyPressEvent(self, event): + """ + Block the ``Key_Space`` key, so that the button will not change the + checked state. + """ + if event.key() == QtCore.Qt.Key_Space and self.isChecked(): + event.ignore() + else: + self.setChecked(True) + + class Ui_ShortcutListDialog(object): def setupUi(self, shortcutListDialog): shortcutListDialog.setObjectName(u'shortcutListDialog') @@ -56,12 +75,11 @@ class Ui_ShortcutListDialog(object): self.detailsLayout.addWidget(self.customRadioButton, 1, 0, 1, 1) self.primaryLayout = QtGui.QHBoxLayout() self.primaryLayout.setObjectName(u'primaryLayout') - self.primaryPushButton = QtGui.QPushButton(shortcutListDialog) + self.primaryPushButton = CaptureShortcutButton(shortcutListDialog) self.primaryPushButton.setObjectName(u'primaryPushButton') self.primaryPushButton.setMinimumSize(QtCore.QSize(84, 0)) self.primaryPushButton.setIcon( build_icon(u':/system/system_configure_shortcuts.png')) - self.primaryPushButton.setCheckable(True) self.primaryLayout.addWidget(self.primaryPushButton) self.clearPrimaryButton = QtGui.QToolButton(shortcutListDialog) self.clearPrimaryButton.setObjectName(u'clearPrimaryButton') @@ -72,9 +90,8 @@ class Ui_ShortcutListDialog(object): self.detailsLayout.addLayout(self.primaryLayout, 1, 1, 1, 1) self.alternateLayout = QtGui.QHBoxLayout() self.alternateLayout.setObjectName(u'alternateLayout') - self.alternatePushButton = QtGui.QPushButton(shortcutListDialog) + self.alternatePushButton = CaptureShortcutButton(shortcutListDialog) self.alternatePushButton.setObjectName(u'alternatePushButton') - self.alternatePushButton.setCheckable(True) self.alternatePushButton.setIcon( build_icon(u':/system/system_configure_shortcuts.png')) self.alternateLayout.addWidget(self.alternatePushButton) diff --git a/openlp/core/ui/shortcutlistform.py b/openlp/core/ui/shortcutlistform.py index 3136c9b1f..99b9e0f07 100644 --- a/openlp/core/ui/shortcutlistform.py +++ b/openlp/core/ui/shortcutlistform.py @@ -71,7 +71,9 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): QtCore.SIGNAL(u'clicked(bool)'), self.onCustomRadioButtonClicked) def keyPressEvent(self, event): - if self.primaryPushButton.isChecked() or \ + if event.key() == QtCore.Qt.Key_Space: + self.keyReleaseEvent(event) + elif self.primaryPushButton.isChecked() or \ self.alternatePushButton.isChecked(): event.ignore() elif event.key() == QtCore.Qt.Key_Escape: @@ -163,6 +165,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): self.customRadioButton.setChecked(True) if toggled: self.alternatePushButton.setChecked(False) + self.primaryPushButton.setText(u'') return action = self._currentItemAction() if action is None: @@ -181,6 +184,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): self.customRadioButton.setChecked(True) if toggled: self.primaryPushButton.setChecked(False) + self.alternatePushButton.setText(u'') return action = self._currentItemAction() if action is None: @@ -211,10 +215,11 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): self.primaryPushButton.setChecked(column in [0, 1]) self.alternatePushButton.setChecked(column not in [0, 1]) if column in [0, 1]: + self.primaryPushButton.setText(u'') self.primaryPushButton.setFocus(QtCore.Qt.OtherFocusReason) else: + self.alternatePushButton.setText(u'') self.alternatePushButton.setFocus(QtCore.Qt.OtherFocusReason) - self.onCurrentItemChanged(item) def onCurrentItemChanged(self, item=None, previousItem=None): """ @@ -247,6 +252,12 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): elif len(shortcuts) == 2: primary_text = shortcuts[0].toString() alternate_text = shortcuts[1].toString() + # When we are capturing a new shortcut, we do not want, that the buttons + # display the current shortcut. + if self.primaryPushButton.isChecked(): + primary_text = u'' + if self.alternatePushButton.isChecked(): + alternate_text = u'' self.primaryPushButton.setText(primary_text) self.alternatePushButton.setText(alternate_text) self.primaryLabel.setText(primary_label_text)