forked from openlp/openlp
This commit is contained in:
parent
28b83aadae
commit
0a5b3b2c2d
@ -295,7 +295,6 @@ def shortcut_action(parent, name, shortcuts, function, icon=None, checked=None,
|
|||||||
if checked is not None:
|
if checked is not None:
|
||||||
action.setCheckable(True)
|
action.setCheckable(True)
|
||||||
action.setChecked(checked)
|
action.setChecked(checked)
|
||||||
action.setCheckable(True)
|
|
||||||
action.setShortcuts(shortcuts)
|
action.setShortcuts(shortcuts)
|
||||||
action.setShortcutContext(QtCore.Qt.WindowShortcut)
|
action.setShortcutContext(QtCore.Qt.WindowShortcut)
|
||||||
if category is not None:
|
if category is not None:
|
||||||
|
@ -34,6 +34,9 @@ class Ui_ShortcutListDialog(object):
|
|||||||
shortcutListDialog.setObjectName(u'shortcutListDialog')
|
shortcutListDialog.setObjectName(u'shortcutListDialog')
|
||||||
self.dialogLayout = QtGui.QVBoxLayout(shortcutListDialog)
|
self.dialogLayout = QtGui.QVBoxLayout(shortcutListDialog)
|
||||||
self.dialogLayout.setObjectName(u'dialogLayout')
|
self.dialogLayout.setObjectName(u'dialogLayout')
|
||||||
|
self.descriptionLabel = QtGui.QLabel(shortcutListDialog);
|
||||||
|
self.descriptionLabel.setObjectName(u'descriptionLabel')
|
||||||
|
self.dialogLayout.addWidget(self.descriptionLabel)
|
||||||
self.treeWidget = QtGui.QTreeWidget(shortcutListDialog)
|
self.treeWidget = QtGui.QTreeWidget(shortcutListDialog)
|
||||||
self.treeWidget.setAlternatingRowColors(True)
|
self.treeWidget.setAlternatingRowColors(True)
|
||||||
self.treeWidget.setObjectName(u'treeWidget')
|
self.treeWidget.setObjectName(u'treeWidget')
|
||||||
@ -57,8 +60,8 @@ class Ui_ShortcutListDialog(object):
|
|||||||
self.customLayout.addStretch()
|
self.customLayout.addStretch()
|
||||||
self.dialogLayout.addLayout(self.customLayout)
|
self.dialogLayout.addLayout(self.customLayout)
|
||||||
self.buttonBox = QtGui.QDialogButtonBox(shortcutListDialog)
|
self.buttonBox = QtGui.QDialogButtonBox(shortcutListDialog)
|
||||||
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok |
|
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel |
|
||||||
QtGui.QDialogButtonBox.RestoreDefaults)
|
QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.RestoreDefaults)
|
||||||
self.buttonBox.setObjectName(u'buttonBox')
|
self.buttonBox.setObjectName(u'buttonBox')
|
||||||
self.dialogLayout.addWidget(self.buttonBox)
|
self.dialogLayout.addWidget(self.buttonBox)
|
||||||
self.retranslateUi(shortcutListDialog)
|
self.retranslateUi(shortcutListDialog)
|
||||||
@ -71,9 +74,15 @@ class Ui_ShortcutListDialog(object):
|
|||||||
def retranslateUi(self, shortcutListDialog):
|
def retranslateUi(self, shortcutListDialog):
|
||||||
shortcutListDialog.setWindowTitle(
|
shortcutListDialog.setWindowTitle(
|
||||||
translate('OpenLP.ShortcutListDialog', 'Customize Shortcuts'))
|
translate('OpenLP.ShortcutListDialog', 'Customize Shortcuts'))
|
||||||
|
self.descriptionLabel.setText(translate('OpenLP.ShortcutListDialog',
|
||||||
|
'Select an action and click the button below to start capturing '
|
||||||
|
'a new shortcut.'))
|
||||||
self.treeWidget.setHeaderLabels([
|
self.treeWidget.setHeaderLabels([
|
||||||
translate('OpenLP.ShortcutListDialog', 'Action'),
|
translate('OpenLP.ShortcutListDialog', 'Action'),
|
||||||
translate('OpenLP.ShortcutListDialog', 'Shortcut'),
|
translate('OpenLP.ShortcutListDialog', 'Shortcut'),
|
||||||
translate('OpenLP.ShortcutListDialog', 'Alternate')])
|
translate('OpenLP.ShortcutListDialog', 'Alternate')])
|
||||||
self.shortcutButton.setText(
|
self.shortcutButton.setToolTip(
|
||||||
translate('OpenLP.ShortcutListDialog', 'None'))
|
translate('OpenLP.ShortcutListDialog', 'Capture shortcut.'))
|
||||||
|
self.clearShortcutButton.setToolTip(
|
||||||
|
translate('OpenLP.ShortcutListDialog',
|
||||||
|
'Restore the default shortcut(s) of this action.'))
|
||||||
|
@ -46,6 +46,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
QtGui.QDialog.__init__(self, parent)
|
QtGui.QDialog.__init__(self, parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.column = -1
|
self.column = -1
|
||||||
|
self.changedActions = {}
|
||||||
self.shortcutButton.setText(u'')
|
self.shortcutButton.setText(u'')
|
||||||
self.shortcutButton.setEnabled(False)
|
self.shortcutButton.setEnabled(False)
|
||||||
QtCore.QObject.connect(self.shortcutButton,
|
QtCore.QObject.connect(self.shortcutButton,
|
||||||
@ -63,7 +64,11 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
self.onRestoreDefaultsClicked)
|
self.onRestoreDefaultsClicked)
|
||||||
|
|
||||||
def keyPressEvent(self, event):
|
def keyPressEvent(self, event):
|
||||||
event.ignore()
|
if self.shortcutButton.isChecked():
|
||||||
|
event.ignore()
|
||||||
|
elif event.key() == QtCore.Qt.Key_Escape:
|
||||||
|
event.accept()
|
||||||
|
self.close()
|
||||||
|
|
||||||
def keyReleaseEvent(self, event):
|
def keyReleaseEvent(self, event):
|
||||||
Qt = QtCore.Qt
|
Qt = QtCore.Qt
|
||||||
@ -87,7 +92,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
shortcut_valid = True
|
shortcut_valid = True
|
||||||
for category in ActionList.categories:
|
for category in ActionList.categories:
|
||||||
for action in category.actions:
|
for action in category.actions:
|
||||||
shortcuts = action.shortcuts()
|
shortcuts = self._actionShortcuts(action)
|
||||||
if key_sequence not in shortcuts:
|
if key_sequence not in shortcuts:
|
||||||
continue
|
continue
|
||||||
if action is changing_action:
|
if action is changing_action:
|
||||||
@ -116,6 +121,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
self.shortcutButton.setChecked(False)
|
self.shortcutButton.setChecked(False)
|
||||||
|
|
||||||
def exec_(self):
|
def exec_(self):
|
||||||
|
self.changedActions = {}
|
||||||
self.reloadShortcutList()
|
self.reloadShortcutList()
|
||||||
self.shortcutButton.setChecked(False)
|
self.shortcutButton.setChecked(False)
|
||||||
self.shortcutButton.setEnabled(False)
|
self.shortcutButton.setEnabled(False)
|
||||||
@ -152,15 +158,16 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
||||||
if action is None:
|
if action is None:
|
||||||
continue
|
continue
|
||||||
if len(action.shortcuts()) == 0:
|
shortcuts = self._actionShortcuts(action)
|
||||||
|
if len(shortcuts) == 0:
|
||||||
item.setText(1, u'')
|
item.setText(1, u'')
|
||||||
item.setText(2, u'')
|
item.setText(2, u'')
|
||||||
elif len(action.shortcuts()) == 1:
|
elif len(shortcuts) == 1:
|
||||||
item.setText(1, action.shortcuts()[0].toString())
|
item.setText(1, shortcuts[0].toString())
|
||||||
item.setText(2, u'')
|
item.setText(2, u'')
|
||||||
else:
|
else:
|
||||||
item.setText(1, action.shortcuts()[0].toString())
|
item.setText(1, shortcuts[0].toString())
|
||||||
item.setText(2, action.shortcuts()[1].toString())
|
item.setText(2, shortcuts[1].toString())
|
||||||
|
|
||||||
def onShortcutButtonClicked(self, toggled):
|
def onShortcutButtonClicked(self, toggled):
|
||||||
"""
|
"""
|
||||||
@ -174,20 +181,21 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
||||||
if action is None:
|
if action is None:
|
||||||
return
|
return
|
||||||
shortcuts = []
|
shortcuts = self._actionShortcuts(action)
|
||||||
|
new_shortcuts = []
|
||||||
# We are changing the primary shortcut.
|
# We are changing the primary shortcut.
|
||||||
if self.column == 1:
|
if self.column in [0, 1]:
|
||||||
shortcuts.append(QtGui.QKeySequence(self.shortcutButton.text()))
|
new_shortcuts.append(QtGui.QKeySequence(self.shortcutButton.text()))
|
||||||
if len(action.shortcuts()) == 2:
|
if len(shortcuts) == 2:
|
||||||
shortcuts.append(action.shortcuts()[1])
|
new_shortcuts.append(shortcuts[1])
|
||||||
# We are changing the secondary shortcut.
|
# We are changing the secondary shortcut.
|
||||||
elif self.column == 2:
|
elif self.column == 2:
|
||||||
if len(action.shortcuts()) != 0:
|
if len(shortcuts) != 0:
|
||||||
shortcuts.append(action.shortcuts()[0])
|
new_shortcuts.append(shortcuts[0])
|
||||||
shortcuts.append(QtGui.QKeySequence(self.shortcutButton.text()))
|
new_shortcuts.append(QtGui.QKeySequence(self.shortcutButton.text()))
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
action.setShortcuts(shortcuts)
|
self.changedActions[action] = new_shortcuts
|
||||||
self.refreshShortcutList()
|
self.refreshShortcutList()
|
||||||
|
|
||||||
def onItemDoubleClicked(self, item, column):
|
def onItemDoubleClicked(self, item, column):
|
||||||
@ -209,15 +217,17 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
"""
|
"""
|
||||||
self.column = column
|
self.column = column
|
||||||
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
||||||
self.shortcutButton.setEnabled(True)
|
|
||||||
text = u''
|
text = u''
|
||||||
if action is None or column not in [1, 2]:
|
if action is None:# or column not in [1, 2]:
|
||||||
self.shortcutButton.setChecked(False)
|
self.shortcutButton.setChecked(False)
|
||||||
self.shortcutButton.setEnabled(False)
|
self.shortcutButton.setEnabled(False)
|
||||||
elif column == 1 and len(action.shortcuts()) != 0:
|
else:
|
||||||
text = action.shortcuts()[0].toString()
|
self.shortcutButton.setEnabled(True)
|
||||||
elif len(action.shortcuts()) == 2 and len(action.shortcuts()) != 0:
|
shortcuts = self._actionShortcuts(action)
|
||||||
text = action.shortcuts()[1].toString()
|
if column != 2 and len(shortcuts) != 0:
|
||||||
|
text = shortcuts[0].toString()
|
||||||
|
elif len(shortcuts) == 2:
|
||||||
|
text = shortcuts[1].toString()
|
||||||
self.shortcutButton.setText(text)
|
self.shortcutButton.setText(text)
|
||||||
|
|
||||||
def onClearShortcutButtonClicked(self, toggled):
|
def onClearShortcutButtonClicked(self, toggled):
|
||||||
@ -231,7 +241,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
||||||
if action is None:
|
if action is None:
|
||||||
return
|
return
|
||||||
action.setShortcuts(action.defaultShortcuts)
|
self.changedActions[action] = action.defaultShortcuts
|
||||||
self.refreshShortcutList()
|
self.refreshShortcutList()
|
||||||
self.onItemPressed(item, self.column)
|
self.onItemPressed(item, self.column)
|
||||||
|
|
||||||
@ -252,7 +262,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
self.shortcutButton.setText(u'')
|
self.shortcutButton.setText(u'')
|
||||||
for category in ActionList.categories:
|
for category in ActionList.categories:
|
||||||
for action in category.actions:
|
for action in category.actions:
|
||||||
action.setShortcuts(action.defaultShortcuts)
|
self.changedActions[action] = action.defaultShortcuts
|
||||||
self.refreshShortcutList()
|
self.refreshShortcutList()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
@ -264,6 +274,18 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
settings.beginGroup(u'shortcuts')
|
settings.beginGroup(u'shortcuts')
|
||||||
for category in ActionList.categories:
|
for category in ActionList.categories:
|
||||||
for action in category.actions:
|
for action in category.actions:
|
||||||
|
if self.changedActions .has_key(action):
|
||||||
|
action.setShortcuts(self.changedActions[action])
|
||||||
settings.setValue(
|
settings.setValue(
|
||||||
action.objectName(), QtCore.QVariant(action.shortcuts()))
|
action.objectName(), QtCore.QVariant(action.shortcuts()))
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
|
||||||
|
def _actionShortcuts(self, action):
|
||||||
|
"""
|
||||||
|
This returns the shortcuts for the given ``action``, which also includes
|
||||||
|
those shortcuts which are not yet assigned to an action (as changes are
|
||||||
|
applied when closing the dialog).
|
||||||
|
"""
|
||||||
|
if self.changedActions.has_key(action):
|
||||||
|
return self.changedActions[action]
|
||||||
|
return action.shortcuts()
|
||||||
|
Loading…
Reference in New Issue
Block a user