From f8fdcf8fba6c23acf43a3605dbadd116f2fec815 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 1 May 2011 09:17:30 +0200 Subject: [PATCH 1/4] allow to empty shortcuts; allow 'space' to be used as shortcut --- openlp/core/ui/shortcutlistdialog.py | 25 +++++++++++++++++++++---- openlp/core/ui/shortcutlistform.py | 15 +++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) 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) From 6c1e66de994377f916d7c3aa8793fd0992f7f522 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 1 May 2011 17:50:48 +0200 Subject: [PATCH 2/4] do not check the button --- openlp/core/ui/shortcutlistdialog.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openlp/core/ui/shortcutlistdialog.py b/openlp/core/ui/shortcutlistdialog.py index 449f60509..55ac694f1 100644 --- a/openlp/core/ui/shortcutlistdialog.py +++ b/openlp/core/ui/shortcutlistdialog.py @@ -43,8 +43,6 @@ class CaptureShortcutButton(QtGui.QPushButton): """ if event.key() == QtCore.Qt.Key_Space and self.isChecked(): event.ignore() - else: - self.setChecked(True) class Ui_ShortcutListDialog(object): From 76bd8241143ecc0a3e46a750ef6a2f723fe66004 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 1 May 2011 17:54:05 +0200 Subject: [PATCH 3/4] added comment --- openlp/core/ui/shortcutlistdialog.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/ui/shortcutlistdialog.py b/openlp/core/ui/shortcutlistdialog.py index 55ac694f1..e22bf1241 100644 --- a/openlp/core/ui/shortcutlistdialog.py +++ b/openlp/core/ui/shortcutlistdialog.py @@ -42,6 +42,7 @@ class CaptureShortcutButton(QtGui.QPushButton): checked state. """ if event.key() == QtCore.Qt.Key_Space and self.isChecked(): + # Ignore the event, so that the parent can take care of this. event.ignore() From 9a997afd81d74b741d7ec3bb492b9d7c266be54c Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 1 May 2011 18:03:42 +0200 Subject: [PATCH 4/4] fixed wording --- openlp/core/ui/shortcutlistform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/shortcutlistform.py b/openlp/core/ui/shortcutlistform.py index 99b9e0f07..8e38ebff5 100644 --- a/openlp/core/ui/shortcutlistform.py +++ b/openlp/core/ui/shortcutlistform.py @@ -252,7 +252,7 @@ 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 + # When we are capturing a new shortcut, we do not want, the buttons to # display the current shortcut. if self.primaryPushButton.isChecked(): primary_text = u''