This commit is contained in:
Andreas Preikschat 2011-03-29 18:44:36 +02:00
parent 32240f7bbe
commit d9c2d92c8c
7 changed files with 90 additions and 87 deletions

View File

@ -239,41 +239,47 @@ def create_up_down_push_button_set(parent):
QtCore.SIGNAL(u'clicked()'), parent.onDownButtonClicked) QtCore.SIGNAL(u'clicked()'), parent.onDownButtonClicked)
return up_button, down_button return up_button, down_button
def base_action(parent, name): def base_action(parent, name, category=None):
""" """
Return the most basic action with the object name set. Return the most basic action with the object name set.
""" """
action = QtGui.QAction(parent) action = QtGui.QAction(parent)
action.setObjectName(name) action.setObjectName(name)
if category is not None:
actionList.add_action(action, category)
return action return action
def checkable_action(parent, name, checked=None): def checkable_action(parent, name, checked=None, category=None):
""" """
Return a standard action with the checkable attribute set. Return a standard action with the checkable attribute set.
""" """
action = base_action(parent, name) action = base_action(parent, name, category)
action.setCheckable(True) action.setCheckable(True)
if checked is not None: if checked is not None:
action.setChecked(checked) action.setChecked(checked)
return action return action
def icon_action(parent, name, icon, checked=None): def icon_action(parent, name, icon, checked=None, category=None):
""" """
Return a standard action with an icon. Return a standard action with an icon.
``category``
The category the action should be listed in the shortcut dialog. If you
not wish, that this action is added to the shortcut dialog, then do not
state any.
""" """
if checked is not None: if checked is not None:
action = checkable_action(parent, name, checked) action = checkable_action(parent, name, checked, category)
else: else:
action = base_action(parent, name) action = base_action(parent, name, category)
action.setIcon(build_icon(icon)) action.setIcon(build_icon(icon))
#actionList.add_action(action, name)
return action return action
def shortcut_action(parent, text, shortcuts, function): def shortcut_action(parent, text, shortcuts, function, category=None):
""" """
Return a shortcut enabled action. Return a shortcut enabled action.
""" """
action = QtGui.QAction(text, parent) action = base_action(parent, text, category)
action.setShortcuts(shortcuts) action.setShortcuts(shortcuts)
action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), function) QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), function)

View File

@ -39,7 +39,7 @@ from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \
ShortcutListForm, DisplayTagForm ShortcutListForm, DisplayTagForm
from openlp.core.utils import AppLocation, add_actions, LanguageManager, \ from openlp.core.utils import AppLocation, add_actions, LanguageManager, \
get_application_version get_application_version
from openlp.core.utils.actions import actionList #from openlp.core.utils.actions import actionList
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -163,72 +163,60 @@ class Ui_MainWindow(object):
self.themeManagerDock) self.themeManagerDock)
# Create the menu items # Create the menu items
self.FileNewItem = icon_action(mainWindow, u'FileNewItem', self.FileNewItem = icon_action(mainWindow, u'FileNewItem',
u':/general/general_new.png') u':/general/general_new.png', category=u'File')
actionList.add_action(self.FileNewItem, u'File')
self.FileOpenItem = icon_action(mainWindow, u'FileOpenItem', self.FileOpenItem = icon_action(mainWindow, u'FileOpenItem',
u':/general/general_open.png') u':/general/general_open.png', category=u'File')
actionList.add_action(self.FileOpenItem, u'File')
self.FileSaveItem = icon_action(mainWindow, u'FileSaveItem', self.FileSaveItem = icon_action(mainWindow, u'FileSaveItem',
u':/general/general_save.png') u':/general/general_save.png', category=u'File')
actionList.add_action(self.FileSaveItem, u'File') self.FileSaveAsItem = base_action(
self.FileSaveAsItem = base_action(mainWindow, u'FileSaveAsItem') mainWindow, u'FileSaveAsItem', u'File')
actionList.add_action(self.FileSaveAsItem, u'File')
self.printServiceOrderItem = base_action( self.printServiceOrderItem = base_action(
mainWindow, u'printServiceItem') mainWindow, u'printServiceItem', u'File')
actionList.add_action(self.printServiceOrderItem, u'File')
self.FileExitItem = icon_action(mainWindow, u'FileExitItem', self.FileExitItem = icon_action(mainWindow, u'FileExitItem',
u':/system/system_exit.png') u':/system/system_exit.png', category=u'File')
actionList.add_action(self.FileExitItem, u'File') self.ImportThemeItem = base_action(
self.ImportThemeItem = base_action(mainWindow, u'ImportThemeItem') mainWindow, u'ImportThemeItem', u'Import')
actionList.add_action(self.ImportThemeItem, u'Import') self.ImportLanguageItem = base_action(
self.ImportLanguageItem = base_action(mainWindow, u'ImportLanguageItem') mainWindow, u'ImportLanguageItem', u'Import')
actionList.add_action(self.ImportLanguageItem, u'Import') self.ExportThemeItem = base_action(
self.ExportThemeItem = base_action(mainWindow, u'ExportThemeItem') mainWindow, u'ExportThemeItem', u'Export')
actionList.add_action(self.ExportThemeItem, u'Export') self.ExportLanguageItem = base_action(
self.ExportLanguageItem = base_action(mainWindow, u'ExportLanguageItem') mainWindow, u'ExportLanguageItem', u'Export')
actionList.add_action(self.ExportLanguageItem, u'Export')
self.ViewMediaManagerItem = icon_action(mainWindow, self.ViewMediaManagerItem = icon_action(mainWindow,
u'ViewMediaManagerItem', u':/system/system_mediamanager.png', u'ViewMediaManagerItem', u':/system/system_mediamanager.png',
self.mediaManagerDock.isVisible()) self.mediaManagerDock.isVisible(), u'View')
self.ViewThemeManagerItem = icon_action(mainWindow, self.ViewThemeManagerItem = icon_action(mainWindow,
u'ViewThemeManagerItem', u':/system/system_thememanager.png', u'ViewThemeManagerItem', u':/system/system_thememanager.png',
self.themeManagerDock.isVisible()) self.themeManagerDock.isVisible(), u'View')
actionList.add_action(self.ViewMediaManagerItem, u'View')
self.ViewServiceManagerItem = icon_action(mainWindow, self.ViewServiceManagerItem = icon_action(mainWindow,
u'ViewServiceManagerItem', u':/system/system_servicemanager.png', u'ViewServiceManagerItem', u':/system/system_servicemanager.png',
self.serviceManagerDock.isVisible()) self.serviceManagerDock.isVisible(), u'View')
actionList.add_action(self.ViewServiceManagerItem, u'View')
self.ViewPreviewPanel = checkable_action(mainWindow, self.ViewPreviewPanel = checkable_action(mainWindow,
u'ViewPreviewPanel', previewVisible) u'ViewPreviewPanel', previewVisible, u'View')
actionList.add_action(self.ViewPreviewPanel, u'View') self.ViewLivePanel = checkable_action(
self.ViewLivePanel = checkable_action(mainWindow, u'ViewLivePanel', mainWindow, u'ViewLivePanel', liveVisible, u'View')
liveVisible) self.ModeDefaultItem = checkable_action(
actionList.add_action(self.ViewLivePanel, u'View') mainWindow, u'ModeDefaultItem', category=u'View Mode')
self.ModeDefaultItem = checkable_action(mainWindow, u'ModeDefaultItem') self.ModeSetupItem = checkable_action(
actionList.add_action(self.ModeDefaultItem, u'View Mode') mainWindow, u'ModeLiveItem', category=u'View Mode')
self.ModeSetupItem = checkable_action(mainWindow, u'ModeLiveItem') self.ModeLiveItem = checkable_action(
actionList.add_action(self.ModeSetupItem, u'View Mode') mainWindow, u'ModeLiveItem', True, u'View Mode')
self.ModeLiveItem = checkable_action(mainWindow, u'ModeLiveItem', True)
actionList.add_action(self.ModeLiveItem, u'View Mode')
self.ModeGroup = QtGui.QActionGroup(mainWindow) self.ModeGroup = QtGui.QActionGroup(mainWindow)
self.ModeGroup.addAction(self.ModeDefaultItem) self.ModeGroup.addAction(self.ModeDefaultItem)
self.ModeGroup.addAction(self.ModeSetupItem) self.ModeGroup.addAction(self.ModeSetupItem)
self.ModeGroup.addAction(self.ModeLiveItem) self.ModeGroup.addAction(self.ModeLiveItem)
self.ModeDefaultItem.setChecked(True) self.ModeDefaultItem.setChecked(True)
self.ToolsAddToolItem = icon_action(mainWindow, u'ToolsAddToolItem', self.ToolsAddToolItem = icon_action(mainWindow, u'ToolsAddToolItem',
u':/tools/tools_add.png') u':/tools/tools_add.png', category=u'Tools')
actionList.add_action(self.ToolsAddToolItem, u'Tools') self.ToolsOpenDataFolder = icon_action(mainWindow, u'ToolsOpenDataFolder',
self.ToolsOpenDataFolder = icon_action(mainWindow, u':/general/general_open.png', category=u'Tools')
u'ToolsOpenDataFolder', u':/general/general_open.png')
actionList.add_action(self.ToolsOpenDataFolder, u'Tools')
self.settingsPluginListItem = icon_action(mainWindow, self.settingsPluginListItem = icon_action(mainWindow,
u'settingsPluginListItem', u':/system/settings_plugin_list.png') u'settingsPluginListItem', u':/system/settings_plugin_list.png',
actionList.add_action(self.settingsPluginListItem, category=u'Settings')
u'Settings')
# i18n Language Items # i18n Language Items
self.AutoLanguageItem = checkable_action(mainWindow, self.AutoLanguageItem = checkable_action(mainWindow,
u'AutoLanguageItem', LanguageManager.auto_language) u'AutoLanguageItem', LanguageManager.auto_language)
actionList.add_action(self.AutoLanguageItem, u'Settings') #actionList.add_action(self.AutoLanguageItem, u'Settings')
self.LanguageGroup = QtGui.QActionGroup(mainWindow) self.LanguageGroup = QtGui.QActionGroup(mainWindow)
self.LanguageGroup.setExclusive(True) self.LanguageGroup.setExclusive(True)
self.LanguageGroup.setObjectName(u'LanguageGroup') self.LanguageGroup.setObjectName(u'LanguageGroup')
@ -241,24 +229,22 @@ class Ui_MainWindow(object):
add_actions(self.LanguageGroup, [languageItem]) add_actions(self.LanguageGroup, [languageItem])
self.SettingsShortcutsItem = icon_action(mainWindow, self.SettingsShortcutsItem = icon_action(mainWindow,
u'SettingsShortcutsItem', u'SettingsShortcutsItem',
u':/system/system_configure_shortcuts.png') u':/system/system_configure_shortcuts.png', category=u'Settings')
self.DisplayTagItem = icon_action(mainWindow, self.DisplayTagItem = icon_action(mainWindow,
u'DisplayTagItem', u':/system/tag_editor.png') u'DisplayTagItem', u':/system/tag_editor.png', category=u'Settings')
self.SettingsConfigureItem = icon_action(mainWindow, self.SettingsConfigureItem = icon_action(mainWindow,
u'SettingsConfigureItem', u':/system/system_settings.png') u'SettingsConfigureItem', u':/system/system_settings.png',
actionList.add_action(self.SettingsShortcutsItem, category=u'Settings')
u'Settings')
self.HelpDocumentationItem = icon_action(mainWindow, self.HelpDocumentationItem = icon_action(mainWindow,
u'HelpDocumentationItem', u':/system/system_help_contents.png') u'HelpDocumentationItem', u':/system/system_help_contents.png',
category=None)#u'Help')
self.HelpDocumentationItem.setEnabled(False) self.HelpDocumentationItem.setEnabled(False)
actionList.add_action(self.HelpDocumentationItem, u'Help')
self.HelpAboutItem = icon_action(mainWindow, u'HelpAboutItem', self.HelpAboutItem = icon_action(mainWindow, u'HelpAboutItem',
u':/system/system_about.png') u':/system/system_about.png', category=None)#u'Help')
actionList.add_action(self.HelpAboutItem, u'Help') self.HelpOnlineHelpItem = base_action(
self.HelpOnlineHelpItem = base_action(mainWindow, u'HelpOnlineHelpItem') mainWindow, u'HelpOnlineHelpItem', category=u'Help')
actionList.add_action(self.HelpOnlineHelpItem, u'Help') self.helpWebSiteItem = base_action(
self.helpWebSiteItem = base_action(mainWindow, u'helpWebSiteItem') mainWindow, u'helpWebSiteItem', category=u'Help')
actionList.add_action(self.helpWebSiteItem, u'Help')
add_actions(self.FileImportMenu, add_actions(self.FileImportMenu,
(self.ImportThemeItem, self.ImportLanguageItem)) (self.ImportThemeItem, self.ImportLanguageItem))
add_actions(self.FileExportMenu, add_actions(self.FileExportMenu,

View File

@ -45,6 +45,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
#TODO: ability to remove actions #TODO: ability to remove actions
#TODO: Save shortcuts #TODO: Save shortcuts
#TODO: doc #TODO: doc
#TODO: Fix Preview/Live controller (have the same shortcut)
def __init__(self, parent=None): def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent) QtGui.QDialog.__init__(self, parent)
self.setupUi(self) self.setupUi(self)
@ -89,7 +90,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
# The dialog is opened the first time # The dialog is opened the first time
if self.treeWidget.topLevelItemCount() == 0: if self.treeWidget.topLevelItemCount() == 0:
QtCore.QObject.connect(actionList.signal, QtCore.QObject.connect(actionList.signal,
QtCore.SIGNAL(u'addedAction()'), self.initialiseActionList) QtCore.SIGNAL(u'addedAction()'), self.asdf)
self.initialiseActionList() self.initialiseActionList()
self.refreshActionList() self.refreshActionList()
return QtGui.QDialog.exec_(self) return QtGui.QDialog.exec_(self)
@ -125,6 +126,18 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
item.setExpanded(True) item.setExpanded(True)
self.treeWidget.addTopLevelItem(item) self.treeWidget.addTopLevelItem(item)
def asdf(self, action, category):
print action
for category in actionList.categories:
item = QtGui.QTreeWidgetItem([category.name])
for action in category.actions:
actionItem = QtGui.QTreeWidgetItem()
actionItem.setIcon(0, action.icon())
actionItem.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(action))
item.addChild(actionItem)
item.setExpanded(True)
self.treeWidget.addTopLevelItem(item)
def onShortcutButtonClicked(self, toggled): def onShortcutButtonClicked(self, toggled):
if toggled: if toggled:
return return

View File

@ -156,15 +156,15 @@ class SlideController(QtGui.QWidget):
self.hideMenu.setMenu(QtGui.QMenu( self.hideMenu.setMenu(QtGui.QMenu(
translate('OpenLP.SlideController', 'Hide'), self.toolbar)) translate('OpenLP.SlideController', 'Hide'), self.toolbar))
self.blankScreen = icon_action(self.hideMenu, u'Blank Screen', self.blankScreen = icon_action(self.hideMenu, u'Blank Screen',
u':/slides/slide_blank.png', False) u':/slides/slide_blank.png', False, u'Live Toolbar')
self.blankScreen.setText( self.blankScreen.setText(
translate('OpenLP.SlideController', 'Blank Screen')) translate('OpenLP.SlideController', 'Blank Screen'))
self.themeScreen = icon_action(self.hideMenu, u'Blank Theme', self.themeScreen = icon_action(self.hideMenu, u'Blank Theme',
u':/slides/slide_theme.png', False) u':/slides/slide_theme.png', False, u'Live Toolbar')
self.themeScreen.setText( self.themeScreen.setText(
translate('OpenLP.SlideController', 'Blank to Theme')) translate('OpenLP.SlideController', 'Blank to Theme'))
self.desktopScreen = icon_action(self.hideMenu, u'Desktop Screen', self.desktopScreen = icon_action(self.hideMenu, u'Desktop Screen',
u':/slides/slide_desktop.png', False) u':/slides/slide_desktop.png', False, u'Live Toolbar')
self.desktopScreen.setText( self.desktopScreen.setText(
translate('OpenLP.SlideController', 'Show Desktop')) translate('OpenLP.SlideController', 'Show Desktop'))
self.hideMenu.setDefaultAction(self.blankScreen) self.hideMenu.setDefaultAction(self.blankScreen)
@ -364,30 +364,27 @@ 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') 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') 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') 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') 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) [QtCore.Qt.Key_Left, 0], self.servicePrevious, u'Live Toolbar')
actionList.add_action(self.previousService, u'Live')
self.nextService = shortcut_action(parent, self.nextService = shortcut_action(parent,
translate('OpenLP.SlideController', 'Next Service'), translate('OpenLP.SlideController', 'Next Service'),
[QtCore.Qt.Key_Right, 0], self.serviceNext) [QtCore.Qt.Key_Right, 0], self.serviceNext, u'Live Toolbar')
actionList.add_action(self.nextService, u'Live')
self.escapeItem = shortcut_action(parent, self.escapeItem = shortcut_action(parent,
translate('OpenLP.SlideController', 'Escape Item'), translate('OpenLP.SlideController', 'Escape Item'),
[QtCore.Qt.Key_Escape, 0], self.liveEscape) [QtCore.Qt.Key_Escape, 0], self.liveEscape, u'Live Toolbar')
actionList.add_action(self.escapeItem, u'Live')
def liveEscape(self): def liveEscape(self):
self.display.setVisible(False) self.display.setVisible(False)

View File

@ -495,7 +495,7 @@ def get_uno_instance(resolver):
from languagemanager import LanguageManager from languagemanager import LanguageManager
from actions import ActionList from actions import ActionList
__all__ = [u'AppLocation', u'check_latest_version', u'add_actions', __all__ = [u'AppLocation', u'get_application_version', u'check_latest_version',
u'get_filesystem_encoding', u'LanguageManager', u'ActionList', u'add_actions', u'get_filesystem_encoding', u'LanguageManager',
u'get_web_page', u'file_is_unicode', u'string_is_unicode', u'ActionList', u'get_web_page', u'file_is_unicode', u'string_is_unicode',
u'get_uno_command', u'get_uno_instance', u'delete_file'] u'get_uno_command', u'get_uno_instance', u'delete_file']

View File

@ -184,7 +184,7 @@ class ActionList(object):
self.categories[category].actions.append(action) self.categories[category].actions.append(action)
else: else:
self.categories[category].actions.add(action, weight) self.categories[category].actions.add(action, weight)
self.signal.emit(QtCore.SIGNAL(u'addedAction()')) self.signal.emit(QtCore.SIGNAL(u'addedAction(QtGui.QAction, QString)'), action, QtCore.QString(category))
class Emit(QtCore.QObject): class Emit(QtCore.QObject):

View File

@ -62,7 +62,6 @@ class AlertsPlugin(Plugin):
log.info(u'add tools menu') log.info(u'add tools menu')
self.toolsAlertItem = icon_action(tools_menu, u'toolsAlertItem', self.toolsAlertItem = icon_action(tools_menu, u'toolsAlertItem',
u':/plugins/plugin_alerts.png') u':/plugins/plugin_alerts.png')
actionList.add_action(self.toolsAlertItem, u'Extra')
self.toolsAlertItem.setText(translate('AlertsPlugin', '&Alert')) self.toolsAlertItem.setText(translate('AlertsPlugin', '&Alert'))
self.toolsAlertItem.setStatusTip( self.toolsAlertItem.setStatusTip(
translate('AlertsPlugin', 'Show an alert message.')) translate('AlertsPlugin', 'Show an alert message.'))
@ -76,6 +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')
self.liveController.alertTab = self.settings_tab self.liveController.alertTab = self.settings_tab
def finalise(self): def finalise(self):
@ -86,6 +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)
#TODO: remove the action from the actionList
def toggleAlertsState(self): def toggleAlertsState(self):
self.alertsActive = not self.alertsActive self.alertsActive = not self.alertsActive