forked from openlp/openlp
started working on saving/loading shortcuts
This commit is contained in:
parent
fe92842c6b
commit
5ef0cc12c0
|
@ -761,7 +761,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||||
"""
|
"""
|
||||||
Show the shortcuts dialog
|
Show the shortcuts dialog
|
||||||
"""
|
"""
|
||||||
self.shortcutForm.exec_()
|
if self.shortcutForm.exec_():
|
||||||
|
self.shortcutForm.saveShortcuts()
|
||||||
|
|
||||||
def onModeDefaultItemClicked(self):
|
def onModeDefaultItemClicked(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -39,15 +39,8 @@ class Ui_ShortcutListDialog(object):
|
||||||
self.treeWidget.setObjectName(u'treeWidget')
|
self.treeWidget.setObjectName(u'treeWidget')
|
||||||
self.treeWidget.setColumnCount(3)
|
self.treeWidget.setColumnCount(3)
|
||||||
self.dialogLayout.addWidget(self.treeWidget)
|
self.dialogLayout.addWidget(self.treeWidget)
|
||||||
self.defaultButton = QtGui.QRadioButton(shortcutListDialog)
|
|
||||||
self.defaultButton.setChecked(True)
|
|
||||||
self.defaultButton.setObjectName(u'defaultButton')
|
|
||||||
self.dialogLayout.addWidget(self.defaultButton)
|
|
||||||
self.customLayout = QtGui.QHBoxLayout()
|
self.customLayout = QtGui.QHBoxLayout()
|
||||||
self.customLayout.setObjectName(u'customLayout')
|
self.customLayout.setObjectName(u'customLayout')
|
||||||
self.customButton = QtGui.QRadioButton(shortcutListDialog)
|
|
||||||
self.customButton.setObjectName(u'customButton')
|
|
||||||
self.customLayout.addWidget(self.customButton)
|
|
||||||
self.shortcutButton = QtGui.QPushButton(shortcutListDialog)
|
self.shortcutButton = QtGui.QPushButton(shortcutListDialog)
|
||||||
self.shortcutButton.setIcon(
|
self.shortcutButton.setIcon(
|
||||||
build_icon(u':/system/system_configure_shortcuts.png'))
|
build_icon(u':/system/system_configure_shortcuts.png'))
|
||||||
|
@ -82,9 +75,5 @@ class Ui_ShortcutListDialog(object):
|
||||||
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.defaultButton.setText(
|
|
||||||
translate('OpenLP.ShortcutListDialog', 'Default: %s'))
|
|
||||||
self.customButton.setText(
|
|
||||||
translate('OpenLP.ShortcutListDialog', 'Custom:'))
|
|
||||||
self.shortcutButton.setText(
|
self.shortcutButton.setText(
|
||||||
translate('OpenLP.ShortcutListDialog', 'None'))
|
translate('OpenLP.ShortcutListDialog', 'None'))
|
||||||
|
|
|
@ -49,6 +49,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
||||||
QtGui.QDialog.__init__(self, parent)
|
QtGui.QDialog.__init__(self, parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.assingedShortcuts = []
|
self.assingedShortcuts = []
|
||||||
|
self.column = -1
|
||||||
self.shortcutButton.setText(u'')
|
self.shortcutButton.setText(u'')
|
||||||
QtCore.QObject.connect(self.shortcutButton,
|
QtCore.QObject.connect(self.shortcutButton,
|
||||||
QtCore.SIGNAL(u'toggled(bool)'), self.onShortcutButtonClicked)
|
QtCore.SIGNAL(u'toggled(bool)'), self.onShortcutButtonClicked)
|
||||||
|
@ -119,25 +120,40 @@ 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
|
||||||
# TODO: Sort out which shortcuts should be kept.
|
shortcuts = []
|
||||||
action.setShortcuts(QtGui.QKeySequence(self.shortcutButton.text()))
|
if self.column == 1:
|
||||||
|
# We are changing the primary shortcut.
|
||||||
|
shortcuts.append(QtGui.QKeySequence(self.shortcutButton.text()))
|
||||||
|
if len(action.shortcuts()) == 2:
|
||||||
|
shortcuts.append(action.shortcuts()[1])
|
||||||
|
else:
|
||||||
|
shortcuts.append(0)
|
||||||
item.setText(1, self.shortcutButton.text())
|
item.setText(1, self.shortcutButton.text())
|
||||||
self.refreshActionList()
|
elif self.column == 2:
|
||||||
|
# We are changing the secondary shortcut.
|
||||||
|
if len(action.shortcuts()) == 1:
|
||||||
|
shortcuts.append(action.shortcuts()[0])
|
||||||
|
else:
|
||||||
|
shortcuts.append(0)
|
||||||
|
shortcuts.append(QtGui.QKeySequence(self.shortcutButton.text()))
|
||||||
|
item.setText(2, self.shortcutButton.text())
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
action.setShortcuts(shortcuts)
|
||||||
|
|
||||||
def onItemPressed(self, item, column):
|
def onItemPressed(self, item, column):
|
||||||
|
self.column = column
|
||||||
item = self.treeWidget.currentItem()
|
item = self.treeWidget.currentItem()
|
||||||
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
action = item.data(0, QtCore.Qt.UserRole).toPyObject()
|
||||||
self.shortcutButton.setEnabled(action is not None)
|
self.shortcutButton.setEnabled(True)
|
||||||
if action is None:
|
|
||||||
text = u''
|
text = u''
|
||||||
self.shortcutButton.setChecked(False)
|
if action is None or column not in [1, 2] or \
|
||||||
else:
|
len(action.shortcuts()) == 0:
|
||||||
if len(action.shortcuts()) == 0:
|
self.shortcutButton.setEnabled(False)
|
||||||
text = u''
|
elif column == 1:
|
||||||
elif len(action.shortcuts()) == 2 and column == 2:
|
|
||||||
text = action.shortcuts()[1].toString()
|
|
||||||
else:
|
|
||||||
text = action.shortcuts()[0].toString()
|
text = action.shortcuts()[0].toString()
|
||||||
|
elif len(action.shortcuts()) == 2:
|
||||||
|
text = action.shortcuts()[1].toString()
|
||||||
self.shortcutButton.setText(text)
|
self.shortcutButton.setText(text)
|
||||||
|
|
||||||
def saveShortcuts(self):
|
def saveShortcuts(self):
|
||||||
|
@ -146,7 +162,12 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
||||||
"""
|
"""
|
||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings()
|
||||||
settings.beginGroup(u'shortcuts')
|
settings.beginGroup(u'shortcuts')
|
||||||
# TODO: Save shortcuts
|
for category in actionList.categories:
|
||||||
|
break
|
||||||
|
for action in category.actions:
|
||||||
|
if action.defaultShortcuts != action.shortcuts():
|
||||||
|
settings.setValue(action.text(),
|
||||||
|
QtCore.QVariant(action.shortcuts()))
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
|
||||||
def loadShortcuts(self):
|
def loadShortcuts(self):
|
||||||
|
@ -155,5 +176,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
||||||
"""
|
"""
|
||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings()
|
||||||
settings.beginGroup(u'shortcuts')
|
settings.beginGroup(u'shortcuts')
|
||||||
|
for shortcut in settings.allKeys():
|
||||||
|
pass
|
||||||
# TODO: Load shortcuts
|
# TODO: Load shortcuts
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
|
|
@ -27,9 +27,9 @@
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
class Category(object):
|
class ActionCategory(object):
|
||||||
"""
|
"""
|
||||||
The :class:`~openlp.core.utils.Category` class encapsulates a
|
The :class:`~openlp.core.utils.ActionCategory` class encapsulates a
|
||||||
category for the :class:`~openlp.core.utils.CategoryList` class.
|
category for the :class:`~openlp.core.utils.CategoryList` class.
|
||||||
"""
|
"""
|
||||||
def __init__(self, name, weight=0):
|
def __init__(self, name, weight=0):
|
||||||
|
@ -161,7 +161,7 @@ class CategoryList(object):
|
||||||
self.add(name, weight)
|
self.add(name, weight)
|
||||||
|
|
||||||
def add(self, name, weight=0, actions=None):
|
def add(self, name, weight=0, actions=None):
|
||||||
category = Category(name, weight)
|
category = ActionCategory(name, weight)
|
||||||
if actions:
|
if actions:
|
||||||
for action in actions:
|
for action in actions:
|
||||||
if isinstance(action, tuple):
|
if isinstance(action, tuple):
|
||||||
|
@ -185,6 +185,7 @@ class ActionList(object):
|
||||||
def add_action(self, action, category, weight=None):
|
def add_action(self, action, category, weight=None):
|
||||||
if category not in self.categories:
|
if category not in self.categories:
|
||||||
self.categories.append(category)
|
self.categories.append(category)
|
||||||
|
action.defaultShortcuts = action.shortcuts()
|
||||||
if weight is None:
|
if weight is None:
|
||||||
self.categories[category].actions.append(action)
|
self.categories[category].actions.append(action)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue