fixed wrong context of shortcuts; moved functions

This commit is contained in:
Andreas Preikschat 2011-04-04 16:38:17 +02:00
parent 3f32ff42a1
commit 84605fb430
4 changed files with 85 additions and 71 deletions

View File

@ -166,59 +166,6 @@ def build_icon(icon):
QtGui.QIcon.Normal, QtGui.QIcon.Off) QtGui.QIcon.Normal, QtGui.QIcon.Off)
return button_icon return button_icon
def context_menu_action(base, icon, text, slot, shortcuts=None):
"""
Utility method to help build context menus for plugins
``base``
The parent menu to add this menu item to
``icon``
An icon for this action
``text``
The text to display for this action
``slot``
The code to run when this action is triggered
"""
action = QtGui.QAction(text, base)
if icon:
action.setIcon(build_icon(icon))
QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), slot)
if shortcuts is not None:
action.setShortcuts(shortcuts)
ActionList.add_action(action)
return action
def context_menu(base, icon, text):
"""
Utility method to help build context menus for plugins
``base``
The parent object to add this menu to
``icon``
An icon for this menu
``text``
The text to display for this menu
"""
action = QtGui.QMenu(text, base)
action.setIcon(build_icon(icon))
return action
def context_menu_separator(base):
"""
Add a separator to a context menu
``base``
The menu object to add the separator to
"""
action = QtGui.QAction(u'', base)
action.setSeparator(True)
return action
def image_to_byte(image): def image_to_byte(image):
""" """
Resize an image to fit on the current screen for the web and returns Resize an image to fit on the current screen for the web and returns

View File

@ -31,10 +31,10 @@ import os
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import context_menu_action, context_menu_separator, \ from openlp.core.lib import SettingsManager, OpenLPToolbar, ServiceItem, \
SettingsManager, OpenLPToolbar, ServiceItem, StringContent, build_icon, \ StringContent, build_icon, translate, Receiver, ListWidgetWithDnD
translate, Receiver, ListWidgetWithDnD from openlp.core.lib.ui import UiStrings, context_menu_action, \
from openlp.core.lib.ui import UiStrings context_menu_separator
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -260,39 +260,42 @@ class MediaManagerItem(QtGui.QWidget):
context_menu_action( context_menu_action(
self.listView, u':/general/general_edit.png', self.listView, u':/general/general_edit.png',
self.plugin.getString(StringContent.Edit)[u'title'], self.plugin.getString(StringContent.Edit)[u'title'],
self.onEditClick)) self.onEditClick, context=QtCore.Qt.WidgetShortcut))
self.listView.addAction(context_menu_separator(self.listView)) self.listView.addAction(context_menu_separator(self.listView))
if self.hasDeleteIcon: if self.hasDeleteIcon:
self.listView.addAction( self.listView.addAction(
context_menu_action( context_menu_action(
self.listView, u':/general/general_delete.png', self.listView, u':/general/general_delete.png',
self.plugin.getString(StringContent.Delete)[u'title'], self.plugin.getString(StringContent.Delete)[u'title'],
self.onDeleteClick, [QtCore.Qt.Key_Delete])) self.onDeleteClick, [QtCore.Qt.Key_Delete],
context=QtCore.Qt.WidgetShortcut))
self.listView.addAction(context_menu_separator(self.listView)) self.listView.addAction(context_menu_separator(self.listView))
self.listView.addAction( self.listView.addAction(
context_menu_action( context_menu_action(
self.listView, u':/general/general_preview.png', self.listView, u':/general/general_preview.png',
self.plugin.getString(StringContent.Preview)[u'title'], self.plugin.getString(StringContent.Preview)[u'title'],
self.onPreviewClick, [QtCore.Qt.Key_Enter])) self.onPreviewClick, [QtCore.Qt.Key_Enter],
context=QtCore.Qt.WidgetShortcut))
self.listView.addAction( self.listView.addAction(
context_menu_action( context_menu_action(
self.listView, u':/general/general_live.png', self.listView, u':/general/general_live.png',
self.plugin.getString(StringContent.Live)[u'title'], self.plugin.getString(StringContent.Live)[u'title'],
self.onLiveClick, [QtCore.Qt.ShiftModifier + \ self.onLiveClick, [QtCore.Qt.ShiftModifier + \
QtCore.Qt.Key_Enter, QtCore.Qt.ShiftModifier + \ QtCore.Qt.Key_Enter, QtCore.Qt.ShiftModifier + \
QtCore.Qt.Key_Return])) QtCore.Qt.Key_Return], context=QtCore.Qt.WidgetShortcut))
self.listView.addAction( self.listView.addAction(
context_menu_action( context_menu_action(
self.listView, u':/general/general_add.png', self.listView, u':/general/general_add.png',
self.plugin.getString(StringContent.Service)[u'title'], self.plugin.getString(StringContent.Service)[u'title'],
self.onAddClick, [QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal])) self.onAddClick, [QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal],
context=QtCore.Qt.WidgetShortcut))
if self.addToServiceItem: if self.addToServiceItem:
self.listView.addAction( self.listView.addAction(
context_menu_action( context_menu_action(
self.listView, u':/general/general_add.png', self.listView, u':/general/general_add.png',
translate('OpenLP.MediaManagerItem', translate('OpenLP.MediaManagerItem',
'&Add to selected Service Item'), '&Add to selected Service Item'),
self.onAddEditClick)) self.onAddEditClick, context=QtCore.Qt.WidgetShortcut))
QtCore.QObject.connect(self.listView, QtCore.QObject.connect(self.listView,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.onClickPressed) self.onClickPressed)

View File

@ -284,7 +284,7 @@ def icon_action(parent, name, icon, checked=None, category=None):
return action return action
def shortcut_action(parent, name, shortcuts, function, icon=None, checked=None, def shortcut_action(parent, name, shortcuts, function, icon=None, checked=None,
category=None): category=None, context=QtCore.Qt.WindowShortcut):
""" """
Return a shortcut enabled action. Return a shortcut enabled action.
""" """
@ -296,12 +296,76 @@ def shortcut_action(parent, name, shortcuts, function, icon=None, checked=None,
action.setCheckable(True) action.setCheckable(True)
action.setChecked(checked) action.setChecked(checked)
action.setShortcuts(shortcuts) action.setShortcuts(shortcuts)
action.setShortcutContext(QtCore.Qt.WindowShortcut) action.setShortcutContext(context)
if category is not None: ActionList.add_action(action, category)
ActionList.add_action(action, category)
QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), function) QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), function)
return action return action
def context_menu_action(base, icon, text, slot, shortcuts=None, category=None,
context=QtCore.Qt.WindowShortcut):
"""
Utility method to help build context menus for plugins
``base``
The parent menu to add this menu item to
``icon``
An icon for this action
``text``
The text to display for this action
``slot``
The code to run when this action is triggered
``shortcuts``
The action's shortcuts.
``category``
The category the shortcut should be listed in the shortcut dialog. If
left to None, then the action will be hidden in the shortcut dialog.
``context``
The context the shortcut is valid.
"""
action = QtGui.QAction(text, base)
if icon:
action.setIcon(build_icon(icon))
QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), slot)
if shortcuts is not None:
action.setShortcuts(shortcuts)
action.setShortcutContext(context)
ActionList.add_action(action)
return action
def context_menu(base, icon, text):
"""
Utility method to help build context menus for plugins
``base``
The parent object to add this menu to
``icon``
An icon for this menu
``text``
The text to display for this menu
"""
action = QtGui.QMenu(text, base)
action.setIcon(build_icon(icon))
return action
def context_menu_separator(base):
"""
Add a separator to a context menu
``base``
The menu object to add the separator to
"""
action = QtGui.QAction(u'', base)
action.setSeparator(True)
return action
def add_widget_completer(cache, widget): def add_widget_completer(cache, widget):
""" """
Adds a text autocompleter to a widget. Adds a text autocompleter to a widget.

View File

@ -32,10 +32,10 @@ log = logging.getLogger(__name__)
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import OpenLPToolbar, ServiceItem, context_menu_action, \ from openlp.core.lib import OpenLPToolbar, ServiceItem, Receiver, build_icon, \
Receiver, build_icon, ItemCapabilities, SettingsManager, translate ItemCapabilities, SettingsManager, translate
from openlp.core.lib.theme import ThemeLevel from openlp.core.lib.theme import ThemeLevel
from openlp.core.lib.ui import UiStrings, critical_error_message_box from openlp.core.lib.ui import UiStrings, critical_error_message_box, context_menu_action
from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm 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, \
@ -1267,7 +1267,7 @@ class ServiceManager(QtGui.QWidget):
for theme in theme_list: for theme in theme_list:
self.themeComboBox.addItem(theme) self.themeComboBox.addItem(theme)
action = context_menu_action(self.serviceManagerList, None, theme, action = context_menu_action(self.serviceManagerList, None, theme,
self.onThemeChangeAction) self.onThemeChangeAction, context=QtCore.Qt.WidgetShortcut)
self.themeMenu.addAction(action) self.themeMenu.addAction(action)
index = self.themeComboBox.findText(self.service_theme, index = self.themeComboBox.findText(self.service_theme,
QtCore.Qt.MatchExactly) QtCore.Qt.MatchExactly)