forked from openlp/openlp
basic saving and loading of shortcuts
This commit is contained in:
parent
5ef0cc12c0
commit
772bd8eb66
@ -762,7 +762,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
Show the shortcuts dialog
|
Show the shortcuts dialog
|
||||||
"""
|
"""
|
||||||
if self.shortcutForm.exec_():
|
if self.shortcutForm.exec_():
|
||||||
self.shortcutForm.saveShortcuts()
|
self.shortcutForm.save()
|
||||||
|
|
||||||
def onModeDefaultItemClicked(self):
|
def onModeDefaultItemClicked(self):
|
||||||
"""
|
"""
|
||||||
|
@ -87,10 +87,10 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
self.shortcutButton.setChecked(False)
|
self.shortcutButton.setChecked(False)
|
||||||
|
|
||||||
def exec_(self):
|
def exec_(self):
|
||||||
self.refreshActionList()
|
self.reloadActionList()
|
||||||
return QtGui.QDialog.exec_(self)
|
return QtGui.QDialog.exec_(self)
|
||||||
|
|
||||||
def refreshActionList(self):
|
def reloadActionList(self):
|
||||||
self.assingedShortcuts = []
|
self.assingedShortcuts = []
|
||||||
self.treeWidget.clear()
|
self.treeWidget.clear()
|
||||||
for category in actionList.categories:
|
for category in actionList.categories:
|
||||||
@ -147,36 +147,23 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
||||||
self.shortcutButton.setEnabled(True)
|
self.shortcutButton.setEnabled(True)
|
||||||
text = u''
|
text = u''
|
||||||
if action is None or column not in [1, 2] or \
|
if action is None or column not in [1, 2]:
|
||||||
len(action.shortcuts()) == 0:
|
|
||||||
self.shortcutButton.setEnabled(False)
|
self.shortcutButton.setEnabled(False)
|
||||||
elif column == 1:
|
elif column == 1 and len(action.shortcuts()) != 0:
|
||||||
text = action.shortcuts()[0].toString()
|
text = action.shortcuts()[0].toString()
|
||||||
elif len(action.shortcuts()) == 2:
|
elif len(action.shortcuts()) == 2 and len(action.shortcuts()) != 0:
|
||||||
text = action.shortcuts()[1].toString()
|
text = action.shortcuts()[1].toString()
|
||||||
self.shortcutButton.setText(text)
|
self.shortcutButton.setText(text)
|
||||||
|
|
||||||
def saveShortcuts(self):
|
def save(self):
|
||||||
"""
|
"""
|
||||||
Save the shortcuts.
|
Save the shortcuts. **Note**, that we do not have to load the shortcuts,
|
||||||
|
as they are loaded in :class:`~openlp.core.utils.ActionList`.
|
||||||
"""
|
"""
|
||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings()
|
||||||
settings.beginGroup(u'shortcuts')
|
settings.beginGroup(u'shortcuts')
|
||||||
for category in actionList.categories:
|
for category in actionList.categories:
|
||||||
break
|
|
||||||
for action in category.actions:
|
for action in category.actions:
|
||||||
if action.defaultShortcuts != action.shortcuts():
|
settings.setValue(
|
||||||
settings.setValue(action.text(),
|
action.objectName(), QtCore.QVariant(action.shortcuts()))
|
||||||
QtCore.QVariant(action.shortcuts()))
|
|
||||||
settings.endGroup()
|
|
||||||
|
|
||||||
def loadShortcuts(self):
|
|
||||||
"""
|
|
||||||
Load the shortcuts.
|
|
||||||
"""
|
|
||||||
settings = QtCore.QSettings()
|
|
||||||
settings.beginGroup(u'shortcuts')
|
|
||||||
for shortcut in settings.allKeys():
|
|
||||||
pass
|
|
||||||
# TODO: Load shortcuts
|
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
@ -27,6 +27,10 @@
|
|||||||
The :mod:`~openlp.core.utils.actions` module provides action list classes used
|
The :mod:`~openlp.core.utils.actions` module provides action list classes used
|
||||||
by the shortcuts system.
|
by the shortcuts system.
|
||||||
"""
|
"""
|
||||||
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
|
from openlp.core.lib import translate
|
||||||
|
|
||||||
class ActionCategory(object):
|
class ActionCategory(object):
|
||||||
"""
|
"""
|
||||||
The :class:`~openlp.core.utils.ActionCategory` class encapsulates a
|
The :class:`~openlp.core.utils.ActionCategory` class encapsulates a
|
||||||
@ -190,6 +194,14 @@ class ActionList(object):
|
|||||||
self.categories[category].actions.append(action)
|
self.categories[category].actions.append(action)
|
||||||
else:
|
else:
|
||||||
self.categories[category].actions.add(action, weight)
|
self.categories[category].actions.add(action, weight)
|
||||||
|
# Load the shortcut from the config.
|
||||||
|
settings = QtCore.QSettings()
|
||||||
|
settings.beginGroup(u'shortcuts')
|
||||||
|
shortcuts = settings.value(action.objectName(),
|
||||||
|
QtCore.QVariant(action.shortcuts())).toStringList()
|
||||||
|
action.setShortcuts(
|
||||||
|
[QtGui.QKeySequence(shortcut) for shortcut in shortcuts])
|
||||||
|
settings.endGroup()
|
||||||
|
|
||||||
def remove_action(self, action, category):
|
def remove_action(self, action, category):
|
||||||
if category not in self.categories:
|
if category not in self.categories:
|
||||||
|
Loading…
Reference in New Issue
Block a user