diff --git a/openlp/core/lib/searchedit.py b/openlp/core/lib/searchedit.py index 4841d76dc..41699256f 100644 --- a/openlp/core/lib/searchedit.py +++ b/openlp/core/lib/searchedit.py @@ -29,6 +29,7 @@ import logging from PyQt4 import QtCore, QtGui from openlp.core.lib import build_icon +from openlp.core.lib.ui import icon_action log = logging.getLogger(__name__) @@ -132,7 +133,7 @@ class SearchEdit(QtGui.QLineEdit): menu = QtGui.QMenu(self) first = None for identifier, icon, title in items: - action = QtGui.QAction(build_icon(icon), title, menu) + action = icon_action(menu, title, icon) action.setData(QtCore.QVariant(identifier)) menu.addAction(action) QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered(bool)'), diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index c6f7dd070..a02041cad 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -280,21 +280,17 @@ def shortcut_action(parent, name, shortcuts, function, icon=None, checked=None, """ Return a shortcut enabled action. """ - # We cannot use the base_action, icon_action and the like, as we must not - # add the action to the actionList before the shortcut has been set - # (when we add the action to the list, the default shortcut is saved, to be - # able restore the shortcut). - action = QtGui.QAction(parent) - action.setObjectName(name) if icon is not None: - action.setIcon(build_icon(icon)) - if checked is not None: - action.setCheckable(True) - action.setChecked(checked) + action = icon_action(parent, name, icon, checked, category) + elif checked is not None: + action = checkable_action(parent, name, checked, category) + else: + action = base_action(parent, name, category) action.setShortcuts(shortcuts) - action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) - if category is not None: - ActionList.add_action(action, category) + action.setShortcutContext(QtCore.Qt.WindowShortcut) + # We have to save the default shortcut again, as the action's shortcut was + # set after adding the shortcut to the action list. + action.defaultShortcuts = action.shortcuts() QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), function) return action diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 14bed4712..458e8814f 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -165,28 +165,23 @@ class Ui_MainWindow(object): [QtGui.QKeySequence(u'Ctrl+N')], self.ServiceManagerContents.onNewServiceClicked, u':/general/general_new.png', category=u'File') - self.FileNewItem.setShortcutContext(QtCore.Qt.WindowShortcut) self.FileOpenItem = shortcut_action(mainWindow, u'FileOpenItem', [QtGui.QKeySequence(u'Ctrl+O')], self.ServiceManagerContents.onLoadServiceClicked, u':/general/general_open.png', category=u'File') - self.FileOpenItem.setShortcutContext(QtCore.Qt.WindowShortcut) self.FileSaveItem = shortcut_action(mainWindow, u'FileSaveItem', [QtGui.QKeySequence(u'Ctrl+S')], self.ServiceManagerContents.saveFile, u':/general/general_save.png', category=u'File') - self.FileSaveItem.setShortcutContext(QtCore.Qt.WindowShortcut) self.FileSaveAsItem = shortcut_action(mainWindow, u'FileSaveAsItem', [QtGui.QKeySequence(u'Ctrl+Shift+S')], self.ServiceManagerContents.saveFileAs, category=u'File') - self.FileSaveAsItem.setShortcutContext(QtCore.Qt.WindowShortcut) self.printServiceOrderItem = shortcut_action(mainWindow, u'printServiceItem', [QtGui.QKeySequence(u'Ctrl+P')], self.ServiceManagerContents.printServiceOrder, category=u'File') self.FileExitItem = shortcut_action(mainWindow, u'FileExitItem', [QtGui.QKeySequence(u'Alt+F4')], mainWindow.close, u':/system/system_exit.png', category=u'File') - self.FileSaveAsItem.setShortcutContext(QtCore.Qt.WindowShortcut) self.ImportThemeItem = base_action( mainWindow, u'ImportThemeItem', u'Import') self.ImportLanguageItem = base_action( @@ -199,21 +194,20 @@ class Ui_MainWindow(object): u'ViewMediaManagerItem', [QtGui.QKeySequence(u'F8')], self.toggleMediaManager, u':/system/system_mediamanager.png', self.mediaManagerDock.isVisible(), u'View') - self.FileSaveAsItem.setShortcutContext(QtCore.Qt.WindowShortcut) self.ViewThemeManagerItem = shortcut_action(mainWindow, - u'ViewThemeManagerItem', [QtGui.QKeySequence(u'F9')], + u'ViewThemeManagerItem', [QtGui.QKeySequence(u'F10')], self.toggleThemeManager, u':/system/system_thememanager.png', self.themeManagerDock.isVisible(), u'View') - self.FileSaveAsItem.setShortcutContext(QtCore.Qt.WindowShortcut) self.ViewServiceManagerItem = shortcut_action(mainWindow, - u'ViewServiceManagerItem', [QtGui.QKeySequence(u'F10')], + u'ViewServiceManagerItem', [QtGui.QKeySequence(u'F9')], self.toggleServiceManager, u':/system/system_servicemanager.png', self.serviceManagerDock.isVisible(), u'View') - self.FileSaveAsItem.setShortcutContext(QtCore.Qt.WindowShortcut) - self.ViewPreviewPanel = checkable_action(mainWindow, - u'ViewPreviewPanel', previewVisible, u'View') - self.ViewLivePanel = checkable_action( - mainWindow, u'ViewLivePanel', liveVisible, u'View') + self.ViewPreviewPanel = shortcut_action(mainWindow, + u'ViewPreviewPanel', [QtGui.QKeySequence(u'F11')], + self.setPreviewPanelVisibility, checked=previewVisible, category=u'View') + self.ViewLivePanel = shortcut_action(mainWindow, u'ViewLivePanel', + [QtGui.QKeySequence(u'F12')], self.setLivePanelVisibility, + checked=liveVisible, category=u'View') self.ModeDefaultItem = checkable_action( mainWindow, u'ModeDefaultItem', category=u'View Mode') self.ModeSetupItem = checkable_action( @@ -229,8 +223,9 @@ class Ui_MainWindow(object): u':/tools/tools_add.png', category=u'Tools') self.ToolsOpenDataFolder = icon_action(mainWindow, u'ToolsOpenDataFolder', u':/general/general_open.png', category=u'Tools') - self.settingsPluginListItem = icon_action(mainWindow, - u'settingsPluginListItem', u':/system/settings_plugin_list.png', + self.settingsPluginListItem = shortcut_action(mainWindow, + u'settingsPluginListItem', [QtGui.QKeySequence(u'Alt+F7')], + self.onPluginItemClicked, u':/system/settings_plugin_list.png', category=u'Settings') # i18n Language Items self.AutoLanguageItem = checkable_action(mainWindow, @@ -257,7 +252,8 @@ class Ui_MainWindow(object): u'HelpDocumentationItem', u':/system/system_help_contents.png', category=None)#u'Help') self.HelpDocumentationItem.setEnabled(False) - self.HelpAboutItem = icon_action(mainWindow, u'HelpAboutItem', + self.HelpAboutItem = shortcut_action(mainWindow, u'HelpAboutItem', + [QtGui.QKeySequence(u'Ctrl+F1')], self.onHelpAboutItemClicked, u':/system/system_about.png', category=u'Help') self.HelpOnlineHelpItem = base_action( mainWindow, u'HelpOnlineHelpItem', category=u'Help') @@ -389,30 +385,21 @@ class Ui_MainWindow(object): translate('OpenLP.MainWindow', 'Toggle Preview Panel')) self.ViewPreviewPanel.setStatusTip(translate('OpenLP.MainWindow', 'Toggle the visibility of the preview panel.')) - self.ViewPreviewPanel.setShortcut( - translate('OpenLP.MainWindow', 'F11')) self.ViewLivePanel.setText( translate('OpenLP.MainWindow', '&Live Panel')) self.ViewLivePanel.setToolTip( translate('OpenLP.MainWindow', 'Toggle Live Panel')) self.ViewLivePanel.setStatusTip(translate('OpenLP.MainWindow', 'Toggle the visibility of the live panel.')) - self.ViewLivePanel.setShortcut( - translate('OpenLP.MainWindow', 'F12')) self.settingsPluginListItem.setText(translate('OpenLP.MainWindow', '&Plugin List')) self.settingsPluginListItem.setStatusTip( translate('OpenLP.MainWindow', 'List the Plugins')) - self.settingsPluginListItem.setShortcut( - translate('OpenLP.MainWindow', 'Alt+F7')) self.HelpDocumentationItem.setText( translate('OpenLP.MainWindow', '&User Guide')) self.HelpAboutItem.setText(translate('OpenLP.MainWindow', '&About')) self.HelpAboutItem.setStatusTip( translate('OpenLP.MainWindow', 'More information about OpenLP')) - self.HelpAboutItem.setShortcut( - translate('OpenLP.MainWindow', 'Ctrl+F1')) - print self.HelpAboutItem.shortcuts() self.HelpOnlineHelpItem.setText( translate('OpenLP.MainWindow', '&Online Help')) # Uncomment after 1.9.5 beta string freeze @@ -494,10 +481,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.QObject.connect(self.ExportThemeItem, QtCore.SIGNAL(u'triggered()'), self.themeManagerContents.onExportTheme) - QtCore.QObject.connect(self.ViewPreviewPanel, - QtCore.SIGNAL(u'toggled(bool)'), self.setPreviewPanelVisibility) - QtCore.QObject.connect(self.ViewLivePanel, - QtCore.SIGNAL(u'toggled(bool)'), self.setLivePanelVisibility) QtCore.QObject.connect(self.mediaManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'), self.ViewMediaManagerItem.setChecked) @@ -511,12 +494,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.SIGNAL(u'triggered()'), self.onHelpWebSiteClicked) QtCore.QObject.connect(self.HelpOnlineHelpItem, QtCore.SIGNAL(u'triggered()'), self.onHelpOnLineHelpClicked) - QtCore.QObject.connect(self.HelpAboutItem, - QtCore.SIGNAL(u'triggered()'), self.onHelpAboutItemClicked) QtCore.QObject.connect(self.ToolsOpenDataFolder, QtCore.SIGNAL(u'triggered()'), self.onToolsOpenDataFolderClicked) - QtCore.QObject.connect(self.settingsPluginListItem, - QtCore.SIGNAL(u'triggered()'), self.onPluginItemClicked) QtCore.QObject.connect(self.DisplayTagItem, QtCore.SIGNAL(u'triggered()'), self.onDisplayTagItemClicked) QtCore.QObject.connect(self.SettingsConfigureItem, @@ -902,7 +881,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): def toggleThemeManager(self): self.themeManagerDock.setVisible(not self.themeManagerDock.isVisible()) - def setPreviewPanelVisibility(self, visible): + def setPreviewPanelVisibility(self, visible=None): """ Sets the visibility of the preview panel including saving the setting and updating the menu. @@ -912,12 +891,14 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): True - Visible False - Hidden """ + if visible is None: + visible = self.ViewPreviewPanel.isVisible() self.previewController.panel.setVisible(visible) QtCore.QSettings().setValue(u'user interface/preview panel', QtCore.QVariant(visible)) self.ViewPreviewPanel.setChecked(visible) - def setLivePanelVisibility(self, visible): + def setLivePanelVisibility(self, visible=None): """ Sets the visibility of the live panel including saving the setting and updating the menu. @@ -927,6 +908,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): True - Visible False - Hidden """ + if visible is None: + visible = self.ViewLivePanel.isVisible() self.liveController.panel.setVisible(visible) QtCore.QSettings().setValue(u'user interface/live panel', QtCore.QVariant(visible)) @@ -984,8 +967,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.FileMenu.addSeparator() for fileId, filename in enumerate(recentFilesToDisplay): log.debug('Recent file name: %s', filename) - action = QtGui.QAction(u'&%d %s' % (fileId + 1, - QtCore.QFileInfo(filename).fileName()), self) + action = base_action(self, u'&%d %s' % (fileId + 1, + QtCore.QFileInfo(filename).fileName())) action.setData(QtCore.QVariant(filename)) self.connect(action, QtCore.SIGNAL(u'triggered()'), self.ServiceManagerContents.onRecentServiceClicked) diff --git a/openlp/core/ui/shortcutlistform.py b/openlp/core/ui/shortcutlistform.py index 4746ae3f7..e350009cd 100644 --- a/openlp/core/ui/shortcutlistform.py +++ b/openlp/core/ui/shortcutlistform.py @@ -42,13 +42,13 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): The shortcut list dialog """ #TODO: do not close on ESC -#TODO: Fix Preview/Live controller (have the same shortcut +#TODO: Fix Preview/Live controller (have the same shortcut) def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.setupUi(self) - self.assingedShortcuts = [] self.column = -1 self.shortcutButton.setText(u'') + self.shortcutButton.setEnabled(False) QtCore.QObject.connect(self.shortcutButton, QtCore.SIGNAL(u'toggled(bool)'), self.onShortcutButtonClicked) QtCore.QObject.connect(self.treeWidget, @@ -76,7 +76,27 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): if event.modifiers() & Qt.ShiftModifier == Qt.ShiftModifier: key_string = u'Shift+' + key_string key_sequence = QtGui.QKeySequence(key_string) - if key_sequence in self.assingedShortcuts: + # The item/action we are attempting to change. + changing_item = self.treeWidget.currentItem() + changing_action = changing_item.data(0, QtCore.Qt.UserRole).toPyObject() + shortcut_valid = True + for category in ActionList.categories: + for action in category.actions: + shortcuts = action.shortcuts() + if key_sequence not in shortcuts: + continue + if action is changing_action: + continue + # Have the same parentWidget, thus they cannot have the same + # shortcut. + #TODO: Does not fully work right now. + if action.parentWidget() is changing_action.parentWidget(): + shortcut_valid = False + if action.shortcutContext() == QtCore.Qt.WindowShortcut: + shortcut_valid = False + if changing_action.shortcutContext() == QtCore.Qt.WindowShortcut: + shortcut_valid = False + if not shortcut_valid: QtGui.QMessageBox.warning(self, translate('OpenLP.ShortcutListDialog', 'Duplicate Shortcut'), unicode(translate('OpenLP.ShortcutListDialog', 'The shortcut ' @@ -91,6 +111,9 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): def exec_(self): self.reloadShortcutList() + self.shortcutButton.setChecked(False) + self.shortcutButton.setEnabled(False) + self.shortcutButton.setText(u'') return QtGui.QDialog.exec_(self) def reloadShortcutList(self): @@ -116,7 +139,6 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): This refreshes the item's shortcuts shown in the list. Note, this neither adds new actions nor removes old actions. """ - self.assingedShortcuts = [] iterator = QtGui.QTreeWidgetItemIterator(self.treeWidget) while iterator.value(): item = iterator.value() @@ -124,7 +146,6 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): action = item.data(0, QtCore.Qt.UserRole).toPyObject() if action is None: continue - self.assingedShortcuts.extend(action.shortcuts()) if len(action.shortcuts()) == 0: item.setText(1, u'') item.setText(2, u'') @@ -142,6 +163,8 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): if toggled: return item = self.treeWidget.currentItem() + if item is None: + return action = item.data(0, QtCore.Qt.UserRole).toPyObject() if action is None: return @@ -163,12 +186,13 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): def onItemDoubleClicked(self, item, column): """ + A item has been double clicked. ``The shortcutButton`` will be checked + and the item's shortcut will be displayed. """ - item = self.treeWidget.currentItem() action = item.data(0, QtCore.Qt.UserRole).toPyObject() + if action is None: + return self.shortcutButton.setChecked(True) - if action is None or column not in [1, 2]: - self.shortcutButton.setChecked(False) self.onItemPressed(item, column) def onItemPressed(self, item, column): @@ -177,11 +201,11 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): shortcut which is encapsulate in the item. """ self.column = column - item = self.treeWidget.currentItem() action = item.data(0, QtCore.Qt.UserRole).toPyObject() self.shortcutButton.setEnabled(True) text = u'' if action is None or column not in [1, 2]: + self.shortcutButton.setChecked(False) self.shortcutButton.setEnabled(False) elif column == 1 and len(action.shortcuts()) != 0: text = action.shortcuts()[0].toString() @@ -194,16 +218,15 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): Restore the defaults of this """ item = self.treeWidget.currentItem() + self.shortcutButton.setChecked(False) if item is None: return action = item.data(0, QtCore.Qt.UserRole).toPyObject() if action is None: return - #FIXME: defaultShortcuts action.setShortcuts(action.defaultShortcuts) - self.shortcutButton.setChecked(False) - self.shortcutButton.setText(u'') self.refreshShortcutList() + self.onItemPressed(item, self.column) def save(self): """ diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index e9d748ad5..750ada7cd 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -157,16 +157,20 @@ class SlideController(QtGui.QWidget): self.toolbar.addToolbarWidget(u'Hide Menu', self.hideMenu) self.hideMenu.setMenu(QtGui.QMenu( translate('OpenLP.SlideController', 'Hide'), self.toolbar)) - self.blankScreen = icon_action(self.hideMenu, u'Blank Screen', + self.blankScreen = shortcut_action(self.hideMenu, u'blankScreen', + [QtCore.Qt.Key_Period], self.onBlankDisplay, u':/slides/slide_blank.png', False, u'Live Toolbar') self.blankScreen.setText( translate('OpenLP.SlideController', 'Blank Screen')) - self.themeScreen = icon_action(self.hideMenu, u'Blank Theme', + self.themeScreen = shortcut_action(self.hideMenu, u'themeScreen', + [QtGui.QKeySequence(u'T')], self.onThemeDisplay, u':/slides/slide_theme.png', False, u'Live Toolbar') self.themeScreen.setText( translate('OpenLP.SlideController', 'Blank to Theme')) - self.desktopScreen = icon_action(self.hideMenu, u'Desktop Screen', - u':/slides/slide_desktop.png', False, u'Live Toolbar') + self.desktopScreen = shortcut_action(self.hideMenu, + u'desktopScreen', [QtGui.QKeySequence(u'D')], + self.onHideDisplay, u':/slides/slide_desktop.png', False, + u'Live Toolbar') self.desktopScreen.setText( translate('OpenLP.SlideController', 'Show Desktop')) self.hideMenu.setDefaultAction(self.blankScreen) @@ -294,12 +298,6 @@ class SlideController(QtGui.QWidget): QtCore.QObject.connect(self.previewListWidget, QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSlideSelected) if self.isLive: - QtCore.QObject.connect(self.blankScreen, - QtCore.SIGNAL(u'triggered(bool)'), self.onBlankDisplay) - QtCore.QObject.connect(self.themeScreen, - QtCore.SIGNAL(u'triggered(bool)'), self.onThemeDisplay) - QtCore.QObject.connect(self.desktopScreen, - QtCore.SIGNAL(u'triggered(bool)'), self.onHideDisplay) QtCore.QObject.connect(self.volumeSlider, QtCore.SIGNAL(u'sliderReleased()'), self.mediaVolume) QtCore.QObject.connect(Receiver.get_receiver(), @@ -380,14 +378,17 @@ class SlideController(QtGui.QWidget): ActionList.add_action(self.nextItem, u'Live Toolbar') self.previousService = shortcut_action(parent, u'previousService', [QtCore.Qt.Key_Left], self.servicePrevious, u'Live Toolbar') + self.previousService.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) self.previousService.setText( translate('OpenLP.SlideController', 'Previous Service')) self.nextService = shortcut_action(parent, 'nextService', [QtCore.Qt.Key_Right], self.serviceNext, u'Live Toolbar') + self.nextService.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) self.nextService.setText( translate('OpenLP.SlideController', 'Next Service')) self.escapeItem = shortcut_action(parent, 'escapeItem', [QtCore.Qt.Key_Escape], self.liveEscape, u'Live Toolbar') + self.escapeItem.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) self.escapeItem.setText( translate('OpenLP.SlideController', 'Escape Item')) @@ -742,10 +743,12 @@ class SlideController(QtGui.QWidget): """ self.onBlankDisplay(False) - def onBlankDisplay(self, checked): + def onBlankDisplay(self, checked=None): """ Handle the blank screen button actions """ + if checked is None: + checked = self.blankScreen.isChecked() log.debug(u'onBlankDisplay %s' % checked) self.hideMenu.setDefaultAction(self.blankScreen) self.blankScreen.setChecked(checked) @@ -763,10 +766,12 @@ class SlideController(QtGui.QWidget): self.blankPlugin(checked) self.updatePreview() - def onThemeDisplay(self, checked): + def onThemeDisplay(self, checked=None): """ Handle the Theme screen button """ + if checked is None: + checked = self.themeScreen.isChecked() log.debug(u'onThemeDisplay %s' % checked) self.hideMenu.setDefaultAction(self.themeScreen) self.blankScreen.setChecked(False) @@ -784,10 +789,12 @@ class SlideController(QtGui.QWidget): self.blankPlugin(checked) self.updatePreview() - def onHideDisplay(self, checked): + def onHideDisplay(self, checked=None): """ Handle the Hide screen button """ + if checked is None: + checked = self.desktopScreen.isChecked() log.debug(u'onHideDisplay %s' % checked) self.hideMenu.setDefaultAction(self.desktopScreen) self.blankScreen.setChecked(False) @@ -1102,11 +1109,11 @@ class SlideController(QtGui.QWidget): screen hide attributes """ blank = None - if self.blankScreen.isChecked: + if self.blankScreen.isChecked(): blank = self.blankScreen - if self.themeScreen.isChecked: + if self.themeScreen.isChecked(): blank = self.themeScreen - if self.desktopScreen.isChecked: + if self.desktopScreen.isChecked(): blank = self.desktopScreen if blank: blank.setChecked(False) diff --git a/openlp/core/utils/actions.py b/openlp/core/utils/actions.py index 34bc72173..7421db30e 100644 --- a/openlp/core/utils/actions.py +++ b/openlp/core/utils/actions.py @@ -173,6 +173,11 @@ class CategoryList(object): self.categories.append(category) self.categories.sort(key=lambda cat: cat.weight) + def remove(self, name): + for category in self.categories: + if category.name == name: + self.categories.remove(category) + class ActionList(object): """ @@ -206,3 +211,6 @@ class ActionList(object): if category not in ActionList.categories: return ActionList.categories[category].actions.remove(action) + # Remove empty categories. + if len(ActionList.categories[category].actions) == 0: + ActionList.categories.remove(category) diff --git a/openlp/plugins/songusage/songusageplugin.py b/openlp/plugins/songusage/songusageplugin.py index 8ff40373a..2e55a23c0 100644 --- a/openlp/plugins/songusage/songusageplugin.py +++ b/openlp/plugins/songusage/songusageplugin.py @@ -32,6 +32,8 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import Plugin, StringContent, Receiver, build_icon, \ translate from openlp.core.lib.db import Manager +from openlp.core.lib.ui import base_action, shortcut_action +from openlp.core.utils.actions import ActionList from openlp.plugins.songusage.forms import SongUsageDetailForm, \ SongUsageDeleteForm from openlp.plugins.songusage.lib.db import init_schema, SongUsageItem @@ -63,30 +65,25 @@ class SongUsagePlugin(Plugin): self.SongUsageMenu.setObjectName(u'SongUsageMenu') self.SongUsageMenu.setTitle(translate( 'SongUsagePlugin', '&Song Usage Tracking')) - #SongUsage Delete - self.SongUsageDelete = QtGui.QAction(tools_menu) + # SongUsage Delete + self.SongUsageDelete = base_action(tools_menu, u'SongUsageDelete') self.SongUsageDelete.setText(translate('SongUsagePlugin', '&Delete Tracking Data')) self.SongUsageDelete.setStatusTip(translate('SongUsagePlugin', 'Delete song usage data up to a specified date.')) - self.SongUsageDelete.setObjectName(u'SongUsageDelete') - #SongUsage Report - self.SongUsageReport = QtGui.QAction(tools_menu) + # SongUsage Report + self.SongUsageReport = base_action(tools_menu, u'SongUsageReport') self.SongUsageReport.setText( translate('SongUsagePlugin', '&Extract Tracking Data')) self.SongUsageReport.setStatusTip( translate('SongUsagePlugin', 'Generate a report on song usage.')) - self.SongUsageReport.setObjectName(u'SongUsageReport') - #SongUsage activation - self.SongUsageStatus = QtGui.QAction(tools_menu) - self.SongUsageStatus.setCheckable(True) - self.SongUsageStatus.setChecked(False) + # SongUsage activation + self.SongUsageStatus = shortcut_action(tools_menu, u'SongUsageStatus', + [QtCore.Qt.Key_F4], self.toggleSongUsageState, checked=False) self.SongUsageStatus.setText(translate( 'SongUsagePlugin', 'Toggle Tracking')) self.SongUsageStatus.setStatusTip(translate('SongUsagePlugin', 'Toggle the tracking of song usage.')) - self.SongUsageStatus.setShortcut(u'F4') - self.SongUsageStatus.setObjectName(u'SongUsageStatus') #Add Menus together self.toolsMenu.addAction(self.SongUsageMenu.menuAction()) self.SongUsageMenu.addAction(self.SongUsageStatus) @@ -97,9 +94,6 @@ class SongUsagePlugin(Plugin): QtCore.QObject.connect(self.SongUsageStatus, QtCore.SIGNAL(u'visibilityChanged(bool)'), self.SongUsageStatus.setChecked) - QtCore.QObject.connect(self.SongUsageStatus, - QtCore.SIGNAL(u'triggered(bool)'), - self.toggleSongUsageState) QtCore.QObject.connect(self.SongUsageDelete, QtCore.SIGNAL(u'triggered()'), self.onSongUsageDelete) QtCore.QObject.connect(self.SongUsageReport, @@ -116,6 +110,9 @@ class SongUsagePlugin(Plugin): self.settingsSection + u'/active', QtCore.QVariant(False)).toBool() self.SongUsageStatus.setChecked(self.SongUsageActive) + ActionList.add_action(self.SongUsageDelete, u'Song Usage') + ActionList.add_action(self.SongUsageReport, u'Song Usage') + ActionList.add_action(self.SongUsageStatus, u'Song Usage') if self.manager is None: self.manager = Manager(u'songusage', init_schema) self.SongUsagedeleteform = SongUsageDeleteForm(self.manager, @@ -131,6 +128,9 @@ class SongUsagePlugin(Plugin): self.manager.finalise() Plugin.finalise(self) self.SongUsageMenu.menuAction().setVisible(False) + ActionList.remove_action(self.SongUsageDelete, u'Song Usage') + ActionList.remove_action(self.SongUsageReport, u'Song Usage') + ActionList.remove_action(self.SongUsageStatus, u'Song Usage') #stop any events being processed self.SongUsageActive = False