Added the ability to capture a shortcut.

This commit is contained in:
Raoul Snyman 2010-10-08 18:07:52 +02:00
parent cff333ddc2
commit a988db8e08
2 changed files with 43 additions and 3 deletions

View File

@ -113,4 +113,5 @@ class Ui_ShortcutListDialog(object):
translate('OpenLP.ShortcutListDialog', 'Default: %s'))
self.customRadioButton.setText(
translate('OpenLP.ShortcutListDialog', 'Custom:'))
self.shortcutPushButton.setText('')
self.shortcutPushButton.setText(
translate('OpenLP.ShortcutListDialog', 'None'))

View File

@ -26,6 +26,7 @@
from PyQt4 import QtCore, QtGui
from openlp.core.utils import translate
from shortcutlistdialog import Ui_ShortcutListDialog
class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
@ -39,5 +40,43 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
#QtCore.QObject.connect(self.contributeButton,
# QtCore.SIGNAL(u'clicked()'), self.onContributeButtonClicked)
QtCore.QObject.connect(
self.shortcutPushButton,
QtCore.SIGNAL(u'toggled(bool)'),
self.onShortcutPushButtonClicked
)
def keyReleaseEvent(self, event):
Qt = QtCore.Qt
if not self.captureShortcut:
return
key = event.key()
if key == Qt.Key_Shift or key == Qt.Key_Control or \
key == Qt.Key_Meta or key == Qt.Key_Alt:
return
key_string = QtGui.QKeySequence(key).toString()
if event.modifiers() & Qt.ControlModifier == Qt.ControlModifier:
key_string = u'Ctrl+' + key_string
if event.modifiers() & Qt.AltModifier == Qt.AltModifier:
key_string = u'Alt+' + key_string
if event.modifiers() & Qt.ShiftModifier == Qt.ShiftModifier:
key_string = u'Shift+' + key_string;
key_sequence = QtGui.QKeySequence(key_string)
existing_key = QtGui.QKeySequence("Ctrl+Shift+F8")
if key_sequence == existing_key:
QtGui.QMessageBox.warning(
self,
translate('OpenLP.ShortcutListDialog', 'Duplicate Shortcut'),
unicode(translate('OpenLP.ShortcutListDialog', 'The shortcut '
'"%s" is already assigned to another action, please '
'use a different shortcut.')) % key_sequence.toString(),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok),
QtGui.QMessageBox.Ok
)
else:
self.shortcutPushButton.setText(key_sequence.toString())
self.shortcutPushButton.setChecked(False)
self.captureShortcut = False
def onShortcutPushButtonClicked(self, toggled):
self.captureShortcut = toggled