diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index ab712a57d..63c5aa777 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -39,6 +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 log = logging.getLogger(__name__) @@ -161,6 +162,7 @@ class Ui_MainWindow(object): mainWindow.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.themeManagerDock) # Create the menu items + ActionList.add_category(UiStrings.File, 100) self.FileNewItem = shortcut_action(mainWindow, u'FileNewItem', [QtGui.QKeySequence(u'Ctrl+N')], self.ServiceManagerContents.onNewServiceClicked, @@ -183,14 +185,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) self.ImportThemeItem = base_action( mainWindow, u'ImportThemeItem', UiStrings.Import) self.ImportLanguageItem = base_action( mainWindow, u'ImportLanguageItem')#, UiStrings.Import) + ActionList.add_category(UiStrings.Export, 90) self.ExportThemeItem = base_action( mainWindow, u'ExportThemeItem', UiStrings.Export) self.ExportLanguageItem = base_action( mainWindow, u'ExportLanguageItem')#, UiStrings.Export) + ActionList.add_category(UiStrings.View, 85) self.ViewMediaManagerItem = shortcut_action(mainWindow, u'ViewMediaManagerItem', [QtGui.QKeySequence(u'F8')], self.toggleMediaManager, u':/system/system_mediamanager.png', @@ -210,6 +215,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) self.ModeDefaultItem = checkable_action( mainWindow, u'ModeDefaultItem', category=UiStrings.ViewMode) self.ModeSetupItem = checkable_action( @@ -221,11 +227,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) 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) self.settingsPluginListItem = shortcut_action(mainWindow, u'settingsPluginListItem', [QtGui.QKeySequence(u'Alt+F7')], self.onPluginItemClicked, u':/system/settings_plugin_list.png', @@ -253,6 +261,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) 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 caecaca50..528b642ce 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -167,6 +167,7 @@ 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( self.serviceManagerList.moveTop, UiStrings.Service) self.serviceManagerList.moveUp = self.orderToolbar.addToolbarButton( diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 66c26da3b..204dada75 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -367,12 +367,14 @@ 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) 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) self.previousService = shortcut_action(parent, u'previousService', diff --git a/openlp/core/utils/actions.py b/openlp/core/utils/actions.py index efac7b1bd..214a42249 100644 --- a/openlp/core/utils/actions.py +++ b/openlp/core/utils/actions.py @@ -154,13 +154,10 @@ class CategoryList(object): return False def append(self, name, actions=None): - weight = 0 - if len(self.categories) > 0: - weight = self.categories[-1].weight + 1 if actions: - self.add(name, weight, actions) + self.add(name, actions=actions) else: - self.add(name, weight) + self.add(name) def add(self, name, weight=0, actions=None): category = ActionCategory(name, weight) @@ -171,7 +168,7 @@ class CategoryList(object): else: category.actions.append(action) self.categories.append(category) - self.categories.sort(key=lambda cat: cat.weight) + self.categories.sort(key=lambda cat: cat.weight, reverse=True) def remove(self, name): for category in self.categories: @@ -230,6 +227,17 @@ class ActionList(object): @staticmethod def remove_action(action, category=None): + """ + This removes an action from its category. Empty categories are + automatically removed. + + ``action`` + The QAction object to be removed. + + ``category`` + The name (unicode string) of the category, which contains the + action. Defaults to None. + """ if category is not None: category = unicode(category) if category not in ActionList.categories: @@ -238,3 +246,25 @@ class ActionList(object): # Remove empty categories. if len(ActionList.categories[category].actions) == 0: ActionList.categories.remove(category) + + @staticmethod + def add_category(name, weight): + """ + Add an empty category to the list of categories. This is ony convenient + for categories with a given weight. + + ``name`` + The category's name. + + ``weight`` + The category's weight (int). + """ + if name in ActionList.categories: + # Only change the weight and resort the categories again. + for category in ActionList.categories: + if category.name == name: + category.weight = weight + ActionList.categories.categories.sort( + key=lambda cat: cat.weight, reverse=True) + return + ActionList.categories.add(name, weight)