forked from openlp/openlp
This commit is contained in:
parent
dab699371c
commit
ea5e0d65cc
@ -119,7 +119,7 @@ class Ui_ShortcutListDialog(object):
|
|||||||
translate('OpenLP.ShortcutListDialog', 'Capture shortcut.'))
|
translate('OpenLP.ShortcutListDialog', 'Capture shortcut.'))
|
||||||
self.clearPrimaryButton.setToolTip(
|
self.clearPrimaryButton.setToolTip(
|
||||||
translate('OpenLP.ShortcutListDialog',
|
translate('OpenLP.ShortcutListDialog',
|
||||||
'Restore the default shortcut(s) of this action.'))
|
'Restore the default shortcut of this action.'))
|
||||||
self.clearAlternateButton.setToolTip(
|
self.clearAlternateButton.setToolTip(
|
||||||
translate('OpenLP.ShortcutListDialog',
|
translate('OpenLP.ShortcutListDialog',
|
||||||
'Restore the default shortcut(s) of this action.'))
|
'Restore the default shortcut of this action.'))
|
||||||
|
@ -127,21 +127,17 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if self.primaryPushButton.isChecked():
|
if self.primaryPushButton.isChecked():
|
||||||
self.primaryPushButton.setText(key_sequence.toString())
|
self._adjustButton(self.primaryPushButton,
|
||||||
self.primaryPushButton.setChecked(False)
|
checked=False, text=key_sequence.toString())
|
||||||
elif self.alternatePushButton.isChecked():
|
elif self.alternatePushButton.isChecked():
|
||||||
self.alternatePushButton.setText(key_sequence.toString())
|
self._adjustButton(self.alternatePushButton,
|
||||||
self.alternatePushButton.setChecked(False)
|
checked=False, text=key_sequence.toString())
|
||||||
|
|
||||||
def exec_(self):
|
def exec_(self):
|
||||||
self.changedActions = {}
|
self.changedActions = {}
|
||||||
self.reloadShortcutList()
|
self.reloadShortcutList()
|
||||||
self.primaryPushButton.setChecked(False)
|
self._adjustButton(self.primaryPushButton, False, False, u'')
|
||||||
self.primaryPushButton.setEnabled(False)
|
self._adjustButton(self.alternatePushButton, False, False, u'')
|
||||||
self.primaryPushButton.setText(u'')
|
|
||||||
self.alternatePushButton.setChecked(False)
|
|
||||||
self.alternatePushButton.setEnabled(False)
|
|
||||||
self.alternatePushButton.setText(u'')
|
|
||||||
return QtGui.QDialog.exec_(self)
|
return QtGui.QDialog.exec_(self)
|
||||||
|
|
||||||
def reloadShortcutList(self):
|
def reloadShortcutList(self):
|
||||||
@ -227,7 +223,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
|
|
||||||
def onItemDoubleClicked(self, item, column):
|
def onItemDoubleClicked(self, item, column):
|
||||||
"""
|
"""
|
||||||
A item has been double clicked. ``The primaryPushButton`` will be
|
A item has been double clicked. The ``primaryPushButton`` will be
|
||||||
checked and the item's shortcut will be displayed.
|
checked and the item's shortcut will be displayed.
|
||||||
"""
|
"""
|
||||||
action = self._currentItemAction(item)
|
action = self._currentItemAction(item)
|
||||||
@ -251,18 +247,30 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
self.alternatePushButton.setEnabled(action is not None)
|
self.alternatePushButton.setEnabled(action is not None)
|
||||||
primary_text = u''
|
primary_text = u''
|
||||||
alternate_text = u''
|
alternate_text = u''
|
||||||
|
primary_label_text = u''
|
||||||
|
alternate_label_text = u''
|
||||||
if action is None:
|
if action is None:
|
||||||
self.primaryPushButton.setChecked(False)
|
self.primaryPushButton.setChecked(False)
|
||||||
self.alternatePushButton.setChecked(False)
|
self.alternatePushButton.setChecked(False)
|
||||||
else:
|
else:
|
||||||
|
if len(action.defaultShortcuts) != 0:
|
||||||
|
primary_label_text = action.defaultShortcuts[0].toString()
|
||||||
|
if len(action.defaultShortcuts) == 2:
|
||||||
|
alternate_label_text = action.defaultShortcuts[1].toString()
|
||||||
shortcuts = self._actionShortcuts(action)
|
shortcuts = self._actionShortcuts(action)
|
||||||
if len(shortcuts) == 1:
|
if shortcuts != action.defaultShortcuts:
|
||||||
primary_text = shortcuts[0].toString()
|
self.customRadioButton.setChecked(True)
|
||||||
elif len(shortcuts) == 2:
|
if len(shortcuts) == 1:
|
||||||
primary_text = shortcuts[0].toString()
|
primary_text = shortcuts[0].toString()
|
||||||
alternate_text = shortcuts[1].toString()
|
elif len(shortcuts) == 2:
|
||||||
|
primary_text = shortcuts[0].toString()
|
||||||
|
alternate_text = shortcuts[1].toString()
|
||||||
|
else:
|
||||||
|
self.defaultRadioButton.setChecked(True)
|
||||||
self.primaryPushButton.setText(primary_text)
|
self.primaryPushButton.setText(primary_text)
|
||||||
self.alternatePushButton.setText(alternate_text)
|
self.alternatePushButton.setText(alternate_text)
|
||||||
|
self.primaryLabel.setText(primary_label_text)
|
||||||
|
self.alternateLabel.setText(alternate_label_text)
|
||||||
|
|
||||||
def onRestoreDefaultsClicked(self, button):
|
def onRestoreDefaultsClicked(self, button):
|
||||||
"""
|
"""
|
||||||
@ -277,10 +285,8 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
QtGui.QMessageBox.Yes |
|
QtGui.QMessageBox.Yes |
|
||||||
QtGui.QMessageBox.No)) == QtGui.QMessageBox.No:
|
QtGui.QMessageBox.No)) == QtGui.QMessageBox.No:
|
||||||
return
|
return
|
||||||
self.primaryPushButton.setChecked(False)
|
self._adjustButton(self.primaryPushButton, False, text=u'')
|
||||||
self.primaryPushButton.setText(u'')
|
self._adjustButton(self.alternatePushButton, False, text=u'')
|
||||||
self.alternatePushButton.setChecked(False)
|
|
||||||
self.alternatePushButton.setText(u'')
|
|
||||||
for category in ActionList.categories:
|
for category in ActionList.categories:
|
||||||
for action in category.actions:
|
for action in category.actions:
|
||||||
self.changedActions[action] = action.defaultShortcuts
|
self.changedActions[action] = action.defaultShortcuts
|
||||||
@ -318,7 +324,8 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
|
|
||||||
def _clearButtonClicked(self, button):
|
def _clearButtonClicked(self, button):
|
||||||
"""
|
"""
|
||||||
Restore the defaults of this action. The given button will be unchecked.
|
Restore the defaults of this action. The given ``button`` will be
|
||||||
|
unchecked.
|
||||||
"""
|
"""
|
||||||
button.setChecked(False)
|
button.setChecked(False)
|
||||||
action = self._currentItemAction()
|
action = self._currentItemAction()
|
||||||
@ -331,8 +338,8 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
def _actionShortcuts(self, action):
|
def _actionShortcuts(self, action):
|
||||||
"""
|
"""
|
||||||
This returns the shortcuts for the given ``action``, which also includes
|
This returns the shortcuts for the given ``action``, which also includes
|
||||||
those shortcuts which are not yet assigned to an action (as changes are
|
those shortcuts which are not saved yet but already assigned (as changes
|
||||||
applied when closing the dialog).
|
are applied when closing the dialog).
|
||||||
"""
|
"""
|
||||||
if self.changedActions.has_key(action):
|
if self.changedActions.has_key(action):
|
||||||
return self.changedActions[action]
|
return self.changedActions[action]
|
||||||
@ -340,11 +347,22 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
|
|
||||||
def _currentItemAction(self, item=None):
|
def _currentItemAction(self, item=None):
|
||||||
"""
|
"""
|
||||||
Returns the action of the current item if no item is given, otherwise
|
Returns the action of the given ``item``. If no item is given, we return
|
||||||
we return the action of the given item.
|
the action of the current item of the ``treeWidget``.
|
||||||
"""
|
"""
|
||||||
if item is None:
|
if item is None:
|
||||||
item = self.treeWidget.currentItem()
|
item = self.treeWidget.currentItem()
|
||||||
if item is None:
|
if item is None:
|
||||||
return
|
return
|
||||||
return item.data(0, QtCore.Qt.UserRole).toPyObject()
|
return item.data(0, QtCore.Qt.UserRole).toPyObject()
|
||||||
|
|
||||||
|
def _adjustButton(self, button, checked=None, enabled=None, text=None):
|
||||||
|
"""
|
||||||
|
Can be called to adjust more properties of the given ``button`` at once.
|
||||||
|
"""
|
||||||
|
if checked is not None:
|
||||||
|
button.setChecked(checked)
|
||||||
|
if enabled is not None:
|
||||||
|
button.setEnabled(enabled)
|
||||||
|
if text is not None:
|
||||||
|
button.setText(text)
|
||||||
|
Loading…
Reference in New Issue
Block a user