diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index 35ea23497..20aca9c6a 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -259,7 +259,8 @@ def base_action(parent, name, category=None): action = QtGui.QAction(parent) action.setObjectName(name) if category is not None: - ActionList.add_action(action, category) + action_list = ActionList.get_instance() + action_list.add_action(action, category) return action def checkable_action(parent, name, checked=None, category=None): @@ -297,7 +298,8 @@ def shortcut_action(parent, name, shortcuts, function, icon=None, checked=None, action.setChecked(checked) action.setShortcuts(shortcuts) action.setShortcutContext(context) - ActionList.add_action(action, category) + action_list = ActionList.get_instance() + action_list.add_action(action, category) QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), function) return action @@ -335,7 +337,8 @@ def context_menu_action(base, icon, text, slot, shortcuts=None, category=None, if shortcuts is not None: action.setShortcuts(shortcuts) action.setShortcutContext(context) - ActionList.add_action(action) + action_list = ActionList.get_instance() + action_list.add_action(action) return action def context_menu(base, icon, text): diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 63c5aa777..2038e1972 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -39,7 +39,7 @@ from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \ ShortcutListForm, DisplayTagForm from openlp.core.utils import AppLocation, add_actions, LanguageManager, \ get_application_version -from openlp.core.utils.actions import ActionList +from openlp.core.utils.actions import ActionList, CategoryOrder log = logging.getLogger(__name__) @@ -162,7 +162,8 @@ class Ui_MainWindow(object): mainWindow.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.themeManagerDock) # Create the menu items - ActionList.add_category(UiStrings.File, 100) + action_list = ActionList.get_instance() + action_list.add_category(UiStrings.File, CategoryOrder.standardMenu) self.FileNewItem = shortcut_action(mainWindow, u'FileNewItem', [QtGui.QKeySequence(u'Ctrl+N')], self.ServiceManagerContents.onNewServiceClicked, @@ -185,17 +186,17 @@ class Ui_MainWindow(object): self.FileExitItem = shortcut_action(mainWindow, u'FileExitItem', [QtGui.QKeySequence(u'Alt+F4')], mainWindow.close, u':/system/system_exit.png', category=UiStrings.File) - ActionList.add_category(UiStrings.Import, 95) + action_list.add_category(UiStrings.Import, CategoryOrder.standardMenu) self.ImportThemeItem = base_action( mainWindow, u'ImportThemeItem', UiStrings.Import) self.ImportLanguageItem = base_action( mainWindow, u'ImportLanguageItem')#, UiStrings.Import) - ActionList.add_category(UiStrings.Export, 90) + action_list.add_category(UiStrings.Export, CategoryOrder.standardMenu) self.ExportThemeItem = base_action( mainWindow, u'ExportThemeItem', UiStrings.Export) self.ExportLanguageItem = base_action( mainWindow, u'ExportLanguageItem')#, UiStrings.Export) - ActionList.add_category(UiStrings.View, 85) + action_list.add_category(UiStrings.View, CategoryOrder.standardMenu) self.ViewMediaManagerItem = shortcut_action(mainWindow, u'ViewMediaManagerItem', [QtGui.QKeySequence(u'F8')], self.toggleMediaManager, u':/system/system_mediamanager.png', @@ -215,7 +216,7 @@ class Ui_MainWindow(object): self.ViewLivePanel = shortcut_action(mainWindow, u'ViewLivePanel', [QtGui.QKeySequence(u'F12')], self.setLivePanelVisibility, checked=liveVisible, category=UiStrings.View) - ActionList.add_category(UiStrings.ViewMode, 80) + action_list.add_category(UiStrings.ViewMode, CategoryOrder.standardMenu) self.ModeDefaultItem = checkable_action( mainWindow, u'ModeDefaultItem', category=UiStrings.ViewMode) self.ModeSetupItem = checkable_action( @@ -227,13 +228,13 @@ class Ui_MainWindow(object): self.ModeGroup.addAction(self.ModeSetupItem) self.ModeGroup.addAction(self.ModeLiveItem) self.ModeDefaultItem.setChecked(True) - ActionList.add_category(UiStrings.Tools, 75) + action_list.add_category(UiStrings.Tools, CategoryOrder.standardMenu) self.ToolsAddToolItem = icon_action(mainWindow, u'ToolsAddToolItem', u':/tools/tools_add.png', category=UiStrings.Tools) self.ToolsOpenDataFolder = icon_action(mainWindow, u'ToolsOpenDataFolder', u':/general/general_open.png', category=UiStrings.Tools) - ActionList.add_category(UiStrings.Settings, 70) + action_list.add_category(UiStrings.Settings, CategoryOrder.standardMenu) self.settingsPluginListItem = shortcut_action(mainWindow, u'settingsPluginListItem', [QtGui.QKeySequence(u'Alt+F7')], self.onPluginItemClicked, u':/system/settings_plugin_list.png', @@ -261,7 +262,7 @@ class Ui_MainWindow(object): self.SettingsConfigureItem = icon_action(mainWindow, u'SettingsConfigureItem', u':/system/system_settings.png', category=UiStrings.Settings) - ActionList.add_category(UiStrings.Help, 65) + action_list.add_category(UiStrings.Help, CategoryOrder.standardMenu) self.HelpDocumentationItem = icon_action(mainWindow, u'HelpDocumentationItem', u':/system/system_help_contents.png', category=None)#UiStrings.Help) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 528b642ce..864acc138 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -40,7 +40,7 @@ from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm from openlp.core.ui.printserviceform import PrintServiceForm from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \ split_filename -from openlp.core.utils.actions import ActionList +from openlp.core.utils.actions import ActionList, CategoryOrder class ServiceManagerList(QtGui.QTreeWidget): """ @@ -167,8 +167,9 @@ class ServiceManager(QtGui.QWidget): 'Move item to the top of the service.'), self.onServiceTop, shortcuts=[QtCore.Qt.Key_Home]) self.serviceManagerList.moveTop.setObjectName(u'moveTop') - ActionList.add_category(UiStrings.Service, 45) - ActionList.add_action( + action_list = ActionList.get_instance() + action_list.add_category(UiStrings.Service, CategoryOrder.standardToolbar) + action_list.add_action( self.serviceManagerList.moveTop, UiStrings.Service) self.serviceManagerList.moveUp = self.orderToolbar.addToolbarButton( translate('OpenLP.ServiceManager', 'Move &up'), @@ -177,7 +178,7 @@ class ServiceManager(QtGui.QWidget): 'Move item up one position in the service.'), self.onServiceUp, shortcuts=[QtCore.Qt.Key_PageUp]) self.serviceManagerList.moveUp.setObjectName(u'moveUp') - ActionList.add_action(self.serviceManagerList.moveUp, UiStrings.Service) + action_list.add_action(self.serviceManagerList.moveUp, UiStrings.Service) self.serviceManagerList.moveDown = self.orderToolbar.addToolbarButton( translate('OpenLP.ServiceManager', 'Move &down'), u':/services/service_down.png', @@ -185,7 +186,7 @@ class ServiceManager(QtGui.QWidget): 'Move item down one position in the service.'), self.onServiceDown, shortcuts=[QtCore.Qt.Key_PageDown]) self.serviceManagerList.moveDown.setObjectName(u'moveDown') - ActionList.add_action( + action_list.add_action( self.serviceManagerList.moveDown, UiStrings.Service) self.serviceManagerList.moveBottom = self.orderToolbar.addToolbarButton( translate('OpenLP.ServiceManager', 'Move to &bottom'), @@ -194,7 +195,7 @@ class ServiceManager(QtGui.QWidget): 'Move item to the end of the service.'), self.onServiceEnd, shortcuts=[QtCore.Qt.Key_End]) self.serviceManagerList.moveBottom.setObjectName(u'moveBottom') - ActionList.add_action( + action_list.add_action( self.serviceManagerList.moveBottom, UiStrings.Service) self.serviceManagerList.down = self.orderToolbar.addToolbarButton( translate('OpenLP.ServiceManager', 'Move &down'), @@ -203,7 +204,7 @@ class ServiceManager(QtGui.QWidget): 'Moves the selection down the window.'), self.onMoveSelectionDown, shortcuts=[QtCore.Qt.Key_Down]) self.serviceManagerList.down.setObjectName(u'down') - ActionList.add_action(self.serviceManagerList.down) + action_list.add_action(self.serviceManagerList.down) self.serviceManagerList.down.setVisible(False) self.serviceManagerList.up = self.orderToolbar.addToolbarButton( translate('OpenLP.ServiceManager', 'Move up'), @@ -212,7 +213,7 @@ class ServiceManager(QtGui.QWidget): 'Moves the selection up the window.'), self.onMoveSelectionUp, shortcuts=[QtCore.Qt.Key_Up]) self.serviceManagerList.up.setObjectName(u'up') - ActionList.add_action(self.serviceManagerList.up) + action_list.add_action(self.serviceManagerList.up) self.serviceManagerList.up.setVisible(False) self.orderToolbar.addSeparator() self.serviceManagerList.delete = self.orderToolbar.addToolbarButton( @@ -229,7 +230,7 @@ class ServiceManager(QtGui.QWidget): 'Expand all the service items.'), self.onExpandAll, shortcuts=[QtCore.Qt.Key_Plus]) self.serviceManagerList.expand.setObjectName(u'expand') - ActionList.add_action(self.serviceManagerList.expand, UiStrings.Service) + action_list.add_action(self.serviceManagerList.expand, UiStrings.Service) self.serviceManagerList.collapse = self.orderToolbar.addToolbarButton( translate('OpenLP.ServiceManager', '&Collapse all'), u':/services/service_collapse_all.png', @@ -237,7 +238,7 @@ class ServiceManager(QtGui.QWidget): 'Collapse all the service items.'), self.onCollapseAll, shortcuts=[QtCore.Qt.Key_Minus]) self.serviceManagerList.collapse.setObjectName(u'collapse') - ActionList.add_action( + action_list.add_action( self.serviceManagerList.collapse, UiStrings.Service) self.orderToolbar.addSeparator() self.serviceManagerList.makeLive = self.orderToolbar.addToolbarButton( @@ -247,7 +248,7 @@ class ServiceManager(QtGui.QWidget): 'Send the selected item to Live.'), self.makeLive, shortcuts=[QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return]) self.serviceManagerList.makeLive.setObjectName(u'orderToolbar') - ActionList.add_action( + action_list.add_action( self.serviceManagerList.makeLive, UiStrings.Service) self.layout.addWidget(self.orderToolbar) # Connect up our signals and slots diff --git a/openlp/core/ui/shortcutlistform.py b/openlp/core/ui/shortcutlistform.py index 336e160b1..ddf84fdd6 100644 --- a/openlp/core/ui/shortcutlistform.py +++ b/openlp/core/ui/shortcutlistform.py @@ -46,6 +46,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): QtGui.QDialog.__init__(self, parent) self.setupUi(self) self.changedActions = {} + self.action_list = ActionList.get_instance() QtCore.QObject.connect(self.primaryPushButton, QtCore.SIGNAL(u'toggled(bool)'), self.onPrimaryPushButtonClicked) QtCore.QObject.connect(self.alternatePushButton, @@ -96,7 +97,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): # The action we are attempting to change. changing_action = self._currentItemAction() shortcut_valid = True - for category in ActionList.categories: + for category in self.action_list.categories: for action in category.actions: shortcuts = self._actionShortcuts(action) if key_sequence not in shortcuts: @@ -149,7 +150,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): Reload the ``treeWidget`` list to add new and remove old actions. """ self.treeWidget.clear() - for category in ActionList.categories: + for category in self.action_list.categories: # Check if the category is for internal use only. if category.name is None: continue @@ -303,7 +304,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): return self._adjustButton(self.primaryPushButton, False, text=u'') self._adjustButton(self.alternatePushButton, False, text=u'') - for category in ActionList.categories: + for category in self.action_list.categories: for action in category.actions: self.changedActions[action] = action.defaultShortcuts self.refreshShortcutList() @@ -349,7 +350,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): """ settings = QtCore.QSettings() settings.beginGroup(u'shortcuts') - for category in ActionList.categories: + for category in self.action_list.categories: # Check if the category is for internal use only. if category.name is None: continue diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 204dada75..4f5ed1ea7 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -34,7 +34,7 @@ from openlp.core.lib import OpenLPToolbar, Receiver, resize_image, \ ItemCapabilities, translate from openlp.core.lib.ui import UiStrings, shortcut_action from openlp.core.ui import HideMode, MainDisplay -from openlp.core.utils.actions import ActionList +from openlp.core.utils.actions import ActionList, CategoryOrder log = logging.getLogger(__name__) @@ -367,16 +367,20 @@ class SlideController(QtGui.QWidget): def setPreviewHotkeys(self, parent=None): self.previousItem.setObjectName(u'previousItemPreview') self.nextItem.setObjectName(u'nextItemPreview') - ActionList.add_category(UiStrings.PreviewToolbar, 55) - ActionList.add_action(self.previousItem, UiStrings.PreviewToolbar) - ActionList.add_action(self.nextItem, UiStrings.PreviewToolbar) + action_list = ActionList.get_instance() + action_list.add_category( + UiStrings.PreviewToolbar, CategoryOrder.standardToolbar) + action_list.add_action(self.previousItem, UiStrings.PreviewToolbar) + action_list.add_action(self.nextItem, UiStrings.PreviewToolbar) def setLiveHotkeys(self, parent=None): self.previousItem.setObjectName(u'previousItemLive') self.nextItem.setObjectName(u'nextItemLive') - ActionList.add_category(UiStrings.LiveToolbar, 60) - ActionList.add_action(self.previousItem, UiStrings.LiveToolbar) - ActionList.add_action(self.nextItem, UiStrings.LiveToolbar) + action_list = ActionList.get_instance() + action_list.add_category( + UiStrings.LiveToolbar, CategoryOrder.standardToolbar) + action_list.add_action(self.previousItem, UiStrings.LiveToolbar) + action_list.add_action(self.nextItem, UiStrings.LiveToolbar) self.previousService = shortcut_action(parent, u'previousService', [QtCore.Qt.Key_Left], self.servicePrevious, UiStrings.LiveToolbar) self.previousService.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) diff --git a/openlp/core/utils/actions.py b/openlp/core/utils/actions.py index 214a42249..76b72c55c 100644 --- a/openlp/core/utils/actions.py +++ b/openlp/core/utils/actions.py @@ -183,10 +183,18 @@ class ActionList(object): has a weight by which it is sorted when iterating through the list of actions or categories. """ - categories = CategoryList() + instance = None + + def __init__(self): + self.categories = CategoryList() @staticmethod - def add_action(action, category=None, weight=None): + def get_instance(): + if ActionList.instance is None: + ActionList.instance = ActionList() + return ActionList.instance + + def add_action(self, action, category=None, weight=None): """ Add an action to the list of actions. @@ -206,13 +214,13 @@ class ActionList(object): """ if category is not None: category = unicode(category) - if category not in ActionList.categories: - ActionList.categories.append(category) + if category not in self.categories: + self.categories.append(category) action.defaultShortcuts = action.shortcuts() if weight is None: - ActionList.categories[category].actions.append(action) + self.categories[category].actions.append(action) else: - ActionList.categories[category].actions.add(action, weight) + self.categories[category].actions.add(action, weight) if category is None: # Stop here, as this action is not configurable. return @@ -225,8 +233,7 @@ class ActionList(object): [QtGui.QKeySequence(shortcut) for shortcut in shortcuts]) settings.endGroup() - @staticmethod - def remove_action(action, category=None): + def remove_action(self, action, category=None): """ This removes an action from its category. Empty categories are automatically removed. @@ -240,15 +247,14 @@ class ActionList(object): """ if category is not None: category = unicode(category) - if category not in ActionList.categories: + if category not in self.categories: return - ActionList.categories[category].actions.remove(action) + self.categories[category].actions.remove(action) # Remove empty categories. - if len(ActionList.categories[category].actions) == 0: - ActionList.categories.remove(category) + if len(self.categories[category].actions) == 0: + self.categories.remove(category) - @staticmethod - def add_category(name, weight): + def add_category(self, name, weight): """ Add an empty category to the list of categories. This is ony convenient for categories with a given weight. @@ -259,12 +265,20 @@ class ActionList(object): ``weight`` The category's weight (int). """ - if name in ActionList.categories: + if name in self.categories: # Only change the weight and resort the categories again. - for category in ActionList.categories: + for category in self.categories: if category.name == name: category.weight = weight - ActionList.categories.categories.sort( + self.categories.categories.sort( key=lambda cat: cat.weight, reverse=True) return - ActionList.categories.add(name, weight) + self.categories.add(name, weight) + + +class CategoryOrder(object): + """ + An enumeration class for category weights. + """ + standardMenu = 100 + standardToolbar = 90 diff --git a/openlp/plugins/alerts/alertsplugin.py b/openlp/plugins/alerts/alertsplugin.py index d564a9754..7d6eac6e2 100644 --- a/openlp/plugins/alerts/alertsplugin.py +++ b/openlp/plugins/alerts/alertsplugin.py @@ -75,7 +75,8 @@ class AlertsPlugin(Plugin): log.info(u'Alerts Initialising') Plugin.initialise(self) self.toolsAlertItem.setVisible(True) - ActionList.add_action(self.toolsAlertItem, UiStrings.Tools) + action_list = ActionList.get_instance() + action_list.add_action(self.toolsAlertItem, UiStrings.Tools) self.liveController.alertTab = self.settings_tab def finalise(self): @@ -86,7 +87,8 @@ class AlertsPlugin(Plugin): self.manager.finalise() Plugin.finalise(self) self.toolsAlertItem.setVisible(False) - ActionList.remove_action(self.toolsAlertItem, u'Tools') + action_list = ActionList.get_instance() + action_list.remove_action(self.toolsAlertItem, u'Tools') def toggleAlertsState(self): self.alertsActive = not self.alertsActive diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 60be388ba..aea732688 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -52,9 +52,10 @@ class BiblePlugin(Plugin): self.manager = BibleManager(self) Plugin.initialise(self) self.importBibleItem.setVisible(True) - ActionList.add_action(self.importBibleItem, UiStrings.Import) + action_list = ActionList.get_instance() + action_list.add_action(self.importBibleItem, UiStrings.Import) # Do not add the action to the list yet. - #ActionList.add_action(self.exportBibleItem, UiStrings.Export) + #action_list.add_action(self.exportBibleItem, UiStrings.Export) # Set to invisible until we can export bibles self.exportBibleItem.setVisible(False) @@ -65,9 +66,10 @@ class BiblePlugin(Plugin): log.info(u'Plugin Finalise') self.manager.finalise() Plugin.finalise(self) - ActionList.remove_action(self.importBibleItem, UiStrings.Import) + action_list = ActionList.get_instance() + action_list.remove_action(self.importBibleItem, UiStrings.Import) self.importBibleItem.setVisible(False) - #ActionList.remove_action(self.exportBibleItem, UiStrings.Export) + #action_list.remove_action(self.exportBibleItem, UiStrings.Export) self.exportBibleItem.setVisible(False) def addImportMenuItem(self, import_menu): diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index a3230ff7f..af50f3f94 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -66,9 +66,10 @@ class SongsPlugin(Plugin): log.info(u'Songs Initialising') Plugin.initialise(self) self.toolsReindexItem.setVisible(True) - ActionList.add_action(self.SongImportItem, UiStrings.Import) - ActionList.add_action(self.SongExportItem, UiStrings.Export) - ActionList.add_action(self.toolsReindexItem, UiStrings.Tools) + action_list = ActionList.get_instance() + action_list.add_action(self.SongImportItem, UiStrings.Import) + action_list.add_action(self.SongExportItem, UiStrings.Export) + action_list.add_action(self.toolsReindexItem, UiStrings.Tools) self.mediaItem.displayResultsSong( self.manager.get_all_objects(Song, order_by_ref=Song.search_title)) @@ -258,7 +259,8 @@ class SongsPlugin(Plugin): log.info(u'Songs Finalising') self.manager.finalise() self.toolsReindexItem.setVisible(False) - ActionList.remove_action(self.SongImportItem, UiStrings.Import) - ActionList.remove_action(self.SongExportItem, UiStrings.Export) - ActionList.remove_action(self.toolsReindexItem, UiStrings.Tools) + action_list = ActionList.get_instance() + action_list.remove_action(self.SongImportItem, UiStrings.Import) + action_list.remove_action(self.SongExportItem, UiStrings.Export) + action_list.remove_action(self.toolsReindexItem, UiStrings.Tools) Plugin.finalise(self) diff --git a/openlp/plugins/songusage/songusageplugin.py b/openlp/plugins/songusage/songusageplugin.py index b0a545ad8..5f21451b6 100644 --- a/openlp/plugins/songusage/songusageplugin.py +++ b/openlp/plugins/songusage/songusageplugin.py @@ -110,11 +110,12 @@ class SongUsagePlugin(Plugin): self.settingsSection + u'/active', QtCore.QVariant(False)).toBool() self.SongUsageStatus.setChecked(self.SongUsageActive) - ActionList.add_action(self.SongUsageDelete, + action_list = ActionList.get_instance() + action_list.add_action(self.SongUsageDelete, translate('SongUsagePlugin', 'Song Usage')) - ActionList.add_action(self.SongUsageReport, + action_list.add_action(self.SongUsageReport, translate('SongUsagePlugin', 'Song Usage')) - ActionList.add_action(self.SongUsageStatus, + action_list.add_action(self.SongUsageStatus, translate('SongUsagePlugin', 'Song Usage')) if self.manager is None: self.manager = Manager(u'songusage', init_schema) @@ -131,11 +132,12 @@ class SongUsagePlugin(Plugin): self.manager.finalise() Plugin.finalise(self) self.SongUsageMenu.menuAction().setVisible(False) - ActionList.remove_action(self.SongUsageDelete, + action_list = ActionList.get_instance() + action_list.remove_action(self.SongUsageDelete, translate('SongUsagePlugin', 'Song Usage')) - ActionList.remove_action(self.SongUsageReport, + action_list.remove_action(self.SongUsageReport, translate('SongUsagePlugin', 'Song Usage')) - ActionList.remove_action(self.SongUsageStatus, + action_list.remove_action(self.SongUsageStatus, translate('SongUsagePlugin', 'Song Usage')) #stop any events being processed self.SongUsageActive = False