mirror of
https://gitlab.com/openlp/openlp.git
synced 2024-09-28 10:57:36 +00:00
staticmethod for adding/removing actions
This commit is contained in:
parent
bba2f2c604
commit
4ca738e9b3
@ -31,7 +31,7 @@ import logging
|
|||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
from openlp.core.lib import build_icon, Receiver, translate
|
from openlp.core.lib import build_icon, Receiver, translate
|
||||||
from openlp.core.utils.actions import actionList
|
from openlp.core.utils.actions import ActionList
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ def base_action(parent, name, category=None):
|
|||||||
action = QtGui.QAction(parent)
|
action = QtGui.QAction(parent)
|
||||||
action.setObjectName(name)
|
action.setObjectName(name)
|
||||||
if category is not None:
|
if category is not None:
|
||||||
actionList.add_action(action, category)
|
ActionList.add_action(action, category)
|
||||||
return action
|
return action
|
||||||
|
|
||||||
def checkable_action(parent, name, checked=None, category=None):
|
def checkable_action(parent, name, checked=None, category=None):
|
||||||
|
@ -40,7 +40,7 @@ from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm
|
|||||||
from openlp.core.ui.printserviceform import PrintServiceForm
|
from openlp.core.ui.printserviceform import PrintServiceForm
|
||||||
from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \
|
from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \
|
||||||
split_filename
|
split_filename
|
||||||
from openlp.core.utils.actions import actionList
|
from openlp.core.utils.actions import ActionList
|
||||||
|
|
||||||
class ServiceManagerList(QtGui.QTreeWidget):
|
class ServiceManagerList(QtGui.QTreeWidget):
|
||||||
"""
|
"""
|
||||||
@ -316,15 +316,15 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
self.configUpdated()
|
self.configUpdated()
|
||||||
|
|
||||||
def setServiceHotkeys(self):
|
def setServiceHotkeys(self):
|
||||||
actionList.add_action(self.serviceManagerList.moveDown, u'Service')
|
ActionList.add_action(self.serviceManagerList.moveDown, u'Service')
|
||||||
actionList.add_action(self.serviceManagerList.moveUp, u'Service')
|
ActionList.add_action(self.serviceManagerList.moveUp, u'Service')
|
||||||
actionList.add_action(self.serviceManagerList.moveTop, u'Service')
|
ActionList.add_action(self.serviceManagerList.moveTop, u'Service')
|
||||||
actionList.add_action(self.serviceManagerList.moveBottom, u'Service')
|
ActionList.add_action(self.serviceManagerList.moveBottom, u'Service')
|
||||||
actionList.add_action(self.serviceManagerList.makeLive, u'Service')
|
ActionList.add_action(self.serviceManagerList.makeLive, u'Service')
|
||||||
actionList.add_action(self.serviceManagerList.up, u'Service')
|
ActionList.add_action(self.serviceManagerList.up, u'Service')
|
||||||
actionList.add_action(self.serviceManagerList.down, u'Service')
|
ActionList.add_action(self.serviceManagerList.down, u'Service')
|
||||||
actionList.add_action(self.serviceManagerList.expand, u'Service')
|
ActionList.add_action(self.serviceManagerList.expand, u'Service')
|
||||||
actionList.add_action(self.serviceManagerList.collapse, u'Service')
|
ActionList.add_action(self.serviceManagerList.collapse, u'Service')
|
||||||
|
|
||||||
|
|
||||||
def setModified(self, modified=True):
|
def setModified(self, modified=True):
|
||||||
|
@ -30,7 +30,7 @@ import re
|
|||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
from openlp.core.utils import translate
|
from openlp.core.utils import translate
|
||||||
from openlp.core.utils.actions import actionList
|
from openlp.core.utils.actions import ActionList
|
||||||
from shortcutlistdialog import Ui_ShortcutListDialog
|
from shortcutlistdialog import Ui_ShortcutListDialog
|
||||||
|
|
||||||
REMOVE_AMPERSAND = re.compile(r'&{1}')
|
REMOVE_AMPERSAND = re.compile(r'&{1}')
|
||||||
@ -96,7 +96,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
"""
|
"""
|
||||||
self.assingedShortcuts = []
|
self.assingedShortcuts = []
|
||||||
self.treeWidget.clear()
|
self.treeWidget.clear()
|
||||||
for category in actionList.categories:
|
for category in ActionList.categories:
|
||||||
item = QtGui.QTreeWidgetItem([category.name])
|
item = QtGui.QTreeWidgetItem([category.name])
|
||||||
for action in category.actions:
|
for action in category.actions:
|
||||||
self.assingedShortcuts.extend(action.shortcuts())
|
self.assingedShortcuts.extend(action.shortcuts())
|
||||||
@ -172,7 +172,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
|
|||||||
"""
|
"""
|
||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings()
|
||||||
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:
|
||||||
settings.setValue(
|
settings.setValue(
|
||||||
action.objectName(), QtCore.QVariant(action.shortcuts()))
|
action.objectName(), QtCore.QVariant(action.shortcuts()))
|
||||||
|
@ -34,7 +34,7 @@ from openlp.core.lib import OpenLPToolbar, Receiver, resize_image, \
|
|||||||
ItemCapabilities, translate
|
ItemCapabilities, translate
|
||||||
from openlp.core.lib.ui import icon_action, UiStrings, shortcut_action
|
from openlp.core.lib.ui import icon_action, UiStrings, shortcut_action
|
||||||
from openlp.core.ui import HideMode, MainDisplay
|
from openlp.core.ui import HideMode, MainDisplay
|
||||||
from openlp.core.utils.actions import actionList
|
from openlp.core.utils.actions import ActionList
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -364,18 +364,18 @@ class SlideController(QtGui.QWidget):
|
|||||||
|
|
||||||
def setPreviewHotkeys(self, parent=None):
|
def setPreviewHotkeys(self, parent=None):
|
||||||
self.previousItem.setShortcuts([QtCore.Qt.Key_Up, 0])
|
self.previousItem.setShortcuts([QtCore.Qt.Key_Up, 0])
|
||||||
actionList.add_action(self.previousItem, u'Preview Toolbar')
|
ActionList.add_action(self.previousItem, u'Preview Toolbar')
|
||||||
self.nextItem.setShortcuts([QtCore.Qt.Key_Down, 0])
|
self.nextItem.setShortcuts([QtCore.Qt.Key_Down, 0])
|
||||||
actionList.add_action(self.nextItem, u'Preview Toolbar')
|
ActionList.add_action(self.nextItem, u'Preview Toolbar')
|
||||||
|
|
||||||
def setLiveHotkeys(self, parent=None):
|
def setLiveHotkeys(self, parent=None):
|
||||||
self.previousItem.setShortcuts([QtCore.Qt.Key_Up, QtCore.Qt.Key_PageUp])
|
self.previousItem.setShortcuts([QtCore.Qt.Key_Up, QtCore.Qt.Key_PageUp])
|
||||||
self.previousItem.setShortcutContext(
|
self.previousItem.setShortcutContext(
|
||||||
QtCore.Qt.WidgetWithChildrenShortcut)
|
QtCore.Qt.WidgetWithChildrenShortcut)
|
||||||
actionList.add_action(self.previousItem, u'Live Toolbar')
|
ActionList.add_action(self.previousItem, u'Live Toolbar')
|
||||||
self.nextItem.setShortcuts([QtCore.Qt.Key_Down, QtCore.Qt.Key_PageDown])
|
self.nextItem.setShortcuts([QtCore.Qt.Key_Down, QtCore.Qt.Key_PageDown])
|
||||||
self.nextItem.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
|
self.nextItem.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
|
||||||
actionList.add_action(self.nextItem, u'Live Toolbar')
|
ActionList.add_action(self.nextItem, u'Live Toolbar')
|
||||||
self.previousService = shortcut_action(parent,
|
self.previousService = shortcut_action(parent,
|
||||||
translate('OpenLP.SlideController', 'Previous Service'),
|
translate('OpenLP.SlideController', 'Previous Service'),
|
||||||
[QtCore.Qt.Key_Left, 0], self.servicePrevious, u'Live Toolbar')
|
[QtCore.Qt.Key_Left, 0], self.servicePrevious, u'Live Toolbar')
|
||||||
|
@ -183,17 +183,17 @@ class ActionList(object):
|
|||||||
has a weight by which it is sorted when iterating through the list of
|
has a weight by which it is sorted when iterating through the list of
|
||||||
actions or categories.
|
actions or categories.
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
categories = CategoryList()
|
||||||
self.categories = CategoryList()
|
|
||||||
|
|
||||||
def add_action(self, action, category, weight=None):
|
@staticmethod
|
||||||
if category not in self.categories:
|
def add_action(action, category, weight=None):
|
||||||
self.categories.append(category)
|
if category not in ActionList.categories:
|
||||||
|
ActionList.categories.append(category)
|
||||||
action.defaultShortcuts = action.shortcuts()
|
action.defaultShortcuts = action.shortcuts()
|
||||||
if weight is None:
|
if weight is None:
|
||||||
self.categories[category].actions.append(action)
|
ActionList.categories[category].actions.append(action)
|
||||||
else:
|
else:
|
||||||
self.categories[category].actions.add(action, weight)
|
ActionList.categories[category].actions.add(action, weight)
|
||||||
# Load the shortcut from the config.
|
# Load the shortcut from the config.
|
||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings()
|
||||||
settings.beginGroup(u'shortcuts')
|
settings.beginGroup(u'shortcuts')
|
||||||
@ -203,9 +203,8 @@ class ActionList(object):
|
|||||||
[QtGui.QKeySequence(shortcut) for shortcut in shortcuts])
|
[QtGui.QKeySequence(shortcut) for shortcut in shortcuts])
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
|
||||||
def remove_action(self, action, category):
|
@staticmethod
|
||||||
if category not in self.categories:
|
def remove_action(action, category):
|
||||||
|
if category not in ActionList.categories:
|
||||||
return
|
return
|
||||||
self.categories[category].actions.remove(action)
|
ActionList.categories[category].actions.remove(action)
|
||||||
|
|
||||||
actionList = ActionList()
|
|
||||||
|
@ -31,7 +31,7 @@ from PyQt4 import QtCore, QtGui
|
|||||||
from openlp.core.lib import Plugin, StringContent, build_icon, translate
|
from openlp.core.lib import Plugin, StringContent, build_icon, translate
|
||||||
from openlp.core.lib.db import Manager
|
from openlp.core.lib.db import Manager
|
||||||
from openlp.core.lib.ui import icon_action
|
from openlp.core.lib.ui import icon_action
|
||||||
from openlp.core.utils.actions import actionList
|
from openlp.core.utils.actions import ActionList
|
||||||
from openlp.plugins.alerts.lib import AlertsManager, AlertsTab
|
from openlp.plugins.alerts.lib import AlertsManager, AlertsTab
|
||||||
from openlp.plugins.alerts.lib.db import init_schema
|
from openlp.plugins.alerts.lib.db import init_schema
|
||||||
from openlp.plugins.alerts.forms import AlertForm
|
from openlp.plugins.alerts.forms import AlertForm
|
||||||
@ -75,7 +75,7 @@ class AlertsPlugin(Plugin):
|
|||||||
log.info(u'Alerts Initialising')
|
log.info(u'Alerts Initialising')
|
||||||
Plugin.initialise(self)
|
Plugin.initialise(self)
|
||||||
self.toolsAlertItem.setVisible(True)
|
self.toolsAlertItem.setVisible(True)
|
||||||
actionList.add_action(self.toolsAlertItem, u'Tools')
|
ActionList.add_action(self.toolsAlertItem, u'Tools')
|
||||||
self.liveController.alertTab = self.settings_tab
|
self.liveController.alertTab = self.settings_tab
|
||||||
|
|
||||||
def finalise(self):
|
def finalise(self):
|
||||||
@ -86,7 +86,7 @@ class AlertsPlugin(Plugin):
|
|||||||
self.manager.finalise()
|
self.manager.finalise()
|
||||||
Plugin.finalise(self)
|
Plugin.finalise(self)
|
||||||
self.toolsAlertItem.setVisible(False)
|
self.toolsAlertItem.setVisible(False)
|
||||||
actionList.remove_action(self.toolsAlertItem, u'Tools')
|
ActionList.remove_action(self.toolsAlertItem, u'Tools')
|
||||||
|
|
||||||
def toggleAlertsState(self):
|
def toggleAlertsState(self):
|
||||||
self.alertsActive = not self.alertsActive
|
self.alertsActive = not self.alertsActive
|
||||||
|
@ -30,7 +30,7 @@ from PyQt4 import QtCore, QtGui
|
|||||||
|
|
||||||
from openlp.core.lib import Plugin, StringContent, build_icon, translate
|
from openlp.core.lib import Plugin, StringContent, build_icon, translate
|
||||||
from openlp.core.lib.ui import base_action
|
from openlp.core.lib.ui import base_action
|
||||||
from openlp.core.utils.actions import actionList
|
from openlp.core.utils.actions import ActionList
|
||||||
from openlp.plugins.bibles.lib import BibleManager, BiblesTab, BibleMediaItem
|
from openlp.plugins.bibles.lib import BibleManager, BiblesTab, BibleMediaItem
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -52,9 +52,9 @@ class BiblePlugin(Plugin):
|
|||||||
self.manager = BibleManager(self)
|
self.manager = BibleManager(self)
|
||||||
Plugin.initialise(self)
|
Plugin.initialise(self)
|
||||||
self.importBibleItem.setVisible(True)
|
self.importBibleItem.setVisible(True)
|
||||||
actionList.add_action(self.importBibleItem, u'Import')
|
ActionList.add_action(self.importBibleItem, u'Import')
|
||||||
# Do not add the action to the list yet.
|
# Do not add the action to the list yet.
|
||||||
#actionList.add_action(self.exportBibleItem, u'Export')
|
#ActionList.add_action(self.exportBibleItem, u'Export')
|
||||||
# Set to invisible until we can export bibles
|
# Set to invisible until we can export bibles
|
||||||
self.exportBibleItem.setVisible(False)
|
self.exportBibleItem.setVisible(False)
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ from openlp.core.lib import Plugin, StringContent, build_icon, translate, \
|
|||||||
Receiver
|
Receiver
|
||||||
from openlp.core.lib.db import Manager
|
from openlp.core.lib.db import Manager
|
||||||
from openlp.core.lib.ui import UiStrings, base_action, icon_action
|
from openlp.core.lib.ui import UiStrings, base_action, icon_action
|
||||||
from openlp.core.utils.actions import actionList
|
from openlp.core.utils.actions import ActionList
|
||||||
from openlp.plugins.songs.lib import clean_song, SongMediaItem, SongsTab
|
from openlp.plugins.songs.lib import clean_song, SongMediaItem, SongsTab
|
||||||
from openlp.plugins.songs.lib.db import init_schema, Song
|
from openlp.plugins.songs.lib.db import init_schema, Song
|
||||||
from openlp.plugins.songs.lib.importer import SongFormat
|
from openlp.plugins.songs.lib.importer import SongFormat
|
||||||
@ -66,9 +66,9 @@ class SongsPlugin(Plugin):
|
|||||||
log.info(u'Songs Initialising')
|
log.info(u'Songs Initialising')
|
||||||
Plugin.initialise(self)
|
Plugin.initialise(self)
|
||||||
self.toolsReindexItem.setVisible(True)
|
self.toolsReindexItem.setVisible(True)
|
||||||
actionList.add_action(self.SongImportItem, u'Import')
|
ActionList.add_action(self.SongImportItem, u'Import')
|
||||||
actionList.add_action(self.SongExportItem, u'Export')
|
ActionList.add_action(self.SongExportItem, u'Export')
|
||||||
actionList.add_action(self.toolsReindexItem, u'Tools')
|
ActionList.add_action(self.toolsReindexItem, u'Tools')
|
||||||
self.mediaItem.displayResultsSong(
|
self.mediaItem.displayResultsSong(
|
||||||
self.manager.get_all_objects(Song, order_by_ref=Song.search_title))
|
self.manager.get_all_objects(Song, order_by_ref=Song.search_title))
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ class SongsPlugin(Plugin):
|
|||||||
log.info(u'Songs Finalising')
|
log.info(u'Songs Finalising')
|
||||||
self.manager.finalise()
|
self.manager.finalise()
|
||||||
self.toolsReindexItem.setVisible(False)
|
self.toolsReindexItem.setVisible(False)
|
||||||
actionList.remove_action(self.SongImportItem, u'Import')
|
ActionList.remove_action(self.SongImportItem, u'Import')
|
||||||
actionList.remove_action(self.SongExportItem, u'Export')
|
ActionList.remove_action(self.SongExportItem, u'Export')
|
||||||
actionList.remove_action(self.toolsReindexItem, u'Tools')
|
ActionList.remove_action(self.toolsReindexItem, u'Tools')
|
||||||
Plugin.finalise(self)
|
Plugin.finalise(self)
|
||||||
|
Loading…
Reference in New Issue
Block a user