openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #08814
[Merge] lp:~googol-hush/openlp/gui into lp:openlp
Andreas Preikschat has proposed merging lp:~googol-hush/openlp/gui into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~googol-hush/openlp/gui/+merge/60928
Hello,
- only show the context menu if we are over an item
- ServiceManager clean ups
--
https://code.launchpad.net/~googol-hush/openlp/gui/+merge/60928
Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/gui into lp:openlp.
=== modified file 'openlp/core/lib/mediamanageritem.py'
--- openlp/core/lib/mediamanageritem.py 2011-04-30 17:36:13 +0000
+++ openlp/core/lib/mediamanageritem.py 2011-05-13 14:43:24 +0000
@@ -244,7 +244,7 @@
"""
# Add the List widget
self.listView = ListWidgetWithDnD(self, self.plugin.name)
- self.listView.uniformItemSizes = True
+ self.listView.setUniformItemSizes(True)
self.listView.setSpacing(1)
self.listView.setSelectionMode(
QtGui.QAbstractItemView.ExtendedSelection)
@@ -254,54 +254,49 @@
# Add to pageLayout
self.pageLayout.addWidget(self.listView)
# define and add the context menu
- self.listView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
+ self.listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
if self.hasEditIcon:
- self.listView.addAction(
- context_menu_action(
- self.listView, u':/general/general_edit.png',
- self.plugin.getString(StringContent.Edit)[u'title'],
- self.onEditClick, context=QtCore.Qt.WidgetShortcut))
- self.listView.addAction(context_menu_separator(self.listView))
+ context_menu_action(
+ self.listView, u':/general/general_edit.png',
+ self.plugin.getString(StringContent.Edit)[u'title'],
+ self.onEditClick)
+ context_menu_separator(self.listView)
if self.hasDeleteIcon:
- self.listView.addAction(
- context_menu_action(
- self.listView, u':/general/general_delete.png',
- self.plugin.getString(StringContent.Delete)[u'title'],
- self.onDeleteClick, [QtCore.Qt.Key_Delete],
- context=QtCore.Qt.WidgetShortcut))
- self.listView.addAction(context_menu_separator(self.listView))
- self.listView.addAction(
- context_menu_action(
- self.listView, u':/general/general_preview.png',
- self.plugin.getString(StringContent.Preview)[u'title'],
- self.onPreviewClick, [QtCore.Qt.Key_Enter,
- QtCore.Qt.Key_Return], context=QtCore.Qt.WidgetShortcut))
- self.listView.addAction(
- context_menu_action(
- self.listView, u':/general/general_live.png',
- self.plugin.getString(StringContent.Live)[u'title'],
- self.onLiveClick, [QtCore.Qt.ShiftModifier + \
- QtCore.Qt.Key_Enter, QtCore.Qt.ShiftModifier + \
- QtCore.Qt.Key_Return], context=QtCore.Qt.WidgetShortcut))
- self.listView.addAction(
+ context_menu_action(
+ self.listView, u':/general/general_delete.png',
+ self.plugin.getString(StringContent.Delete)[u'title'],
+ self.onDeleteClick, [QtCore.Qt.Key_Delete])
+ context_menu_separator(self.listView)
+ context_menu_action(
+ self.listView, u':/general/general_preview.png',
+ self.plugin.getString(StringContent.Preview)[u'title'],
+ self.onPreviewClick, [QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return])
+ context_menu_action(
+ self.listView, u':/general/general_live.png',
+ self.plugin.getString(StringContent.Live)[u'title'],
+ self.onLiveClick, [QtCore.Qt.ShiftModifier + QtCore.Qt.Key_Enter,
+ QtCore.Qt.ShiftModifier + QtCore.Qt.Key_Return])
+ context_menu_action(
+ self.listView, u':/general/general_add.png',
+ self.plugin.getString(StringContent.Service)[u'title'],
+ self.onAddClick, [QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal])
+ if self.addToServiceItem:
context_menu_action(
self.listView, u':/general/general_add.png',
- self.plugin.getString(StringContent.Service)[u'title'],
- self.onAddClick, [QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal],
- context=QtCore.Qt.WidgetShortcut))
- if self.addToServiceItem:
- self.listView.addAction(
- context_menu_action(
- self.listView, u':/general/general_add.png',
- translate('OpenLP.MediaManagerItem',
- '&Add to selected Service Item'),
- self.onAddEditClick, context=QtCore.Qt.WidgetShortcut))
+ translate('OpenLP.MediaManagerItem',
+ '&Add to selected Service Item'), self.onAddEditClick)
+ # Create the context menu and add all actions from the listView.
+ self.menu = QtGui.QMenu()
+ self.menu.addActions(self.listView.actions())
QtCore.QObject.connect(self.listView,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.onClickPressed)
QtCore.QObject.connect(self.listView,
QtCore.SIGNAL(u'itemSelectionChanged()'),
self.onSelectionChange)
+ QtCore.QObject.connect(self.listView,
+ QtCore.SIGNAL('customContextMenuRequested(QPoint)'),
+ self.contextMenu)
def initialise(self):
"""
@@ -354,6 +349,15 @@
self.settingsSection, self.getFileList())
Receiver.send_message(u'cursor_normal')
+ def contextMenu(self, point):
+ item = self.listView.itemAt(point)
+ # Decide if we have to show the context menu or not.
+ if item is None:
+ return
+ if not item.flags() & QtCore.Qt.ItemIsSelectable:
+ return
+ self.menu.exec_(self.listView.mapToGlobal(point))
+
def getFileList(self):
"""
Return the current list of files
=== modified file 'openlp/core/lib/ui.py'
--- openlp/core/lib/ui.py 2011-05-07 18:40:48 +0000
+++ openlp/core/lib/ui.py 2011-05-13 14:43:24 +0000
@@ -329,9 +329,9 @@
return action
def context_menu_action(base, icon, text, slot, shortcuts=None, category=None,
- context=QtCore.Qt.WindowShortcut):
+ context=QtCore.Qt.WidgetShortcut):
"""
- Utility method to help build context menus for plugins
+ Utility method to help build context menus.
``base``
The parent menu to add this menu item to
@@ -350,7 +350,7 @@
``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.
+ left to ``None``, then the action will be hidden in the shortcut dialog.
``context``
The context the shortcut is valid.
@@ -364,11 +364,12 @@
action.setShortcutContext(context)
action_list = ActionList.get_instance()
action_list.add_action(action)
+ base.addAction(action)
return action
def context_menu(base, icon, text):
"""
- Utility method to help build context menus for plugins
+ Utility method to help build context menus.
``base``
The parent object to add this menu to
@@ -392,6 +393,7 @@
"""
action = QtGui.QAction(u'', base)
action.setSeparator(True)
+ base.addAction(action)
return action
def add_widget_completer(cache, widget):
=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py 2011-05-12 15:50:20 +0000
+++ openlp/core/ui/servicemanager.py 2011-05-13 14:43:24 +0000
@@ -36,7 +36,7 @@
ItemCapabilities, SettingsManager, translate
from openlp.core.lib.theme import ThemeLevel
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
- context_menu_action, find_and_set_in_combo_box
+ context_menu_action, context_menu_separator, find_and_set_in_combo_box
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, \
@@ -301,31 +301,34 @@
self.addToAction.setIcon(build_icon(u':/general/general_edit.png'))
# build the context menu
self.menu = QtGui.QMenu()
- self.editAction = self.menu.addAction(
- translate('OpenLP.ServiceManager', '&Edit Item'))
- self.editAction.setIcon(build_icon(u':/general/general_edit.png'))
- self.maintainAction = self.menu.addAction(
- translate('OpenLP.ServiceManager', '&Reorder Item'))
- self.maintainAction.setIcon(build_icon(u':/general/general_edit.png'))
- self.notesAction = self.menu.addAction(
- translate('OpenLP.ServiceManager', '&Notes'))
- self.notesAction.setIcon(build_icon(u':/services/service_notes.png'))
- self.timeAction = self.menu.addAction(
- translate('OpenLP.ServiceManager', '&Start Time'))
- self.timeAction.setIcon(build_icon(u':/media/media_time.png'))
- self.deleteAction = self.menu.addAction(
- translate('OpenLP.ServiceManager', '&Delete From Service'))
- self.deleteAction.setIcon(build_icon(u':/general/general_delete.png'))
- self.sep1 = self.menu.addAction(u'')
- self.sep1.setSeparator(True)
- self.previewAction = self.menu.addAction(
- translate('OpenLP.ServiceManager', 'Show &Preview'))
- self.previewAction.setIcon(build_icon(u':/general/general_preview.png'))
- self.liveAction = self.menu.addAction(
- translate('OpenLP.ServiceManager', 'Show &Live'))
- self.liveAction.setIcon(build_icon(u':/general/general_live.png'))
- self.sep2 = self.menu.addAction(u'')
- self.sep2.setSeparator(True)
+ self.editAction = context_menu_action(
+ self.menu, u':/general/general_edit.png',
+ translate('OpenLP.ServiceManager', '&Edit Item'), self.remoteEdit)
+ self.maintainAction = context_menu_action(
+ self.menu, u':/general/general_edit.png',
+ translate('OpenLP.ServiceManager', '&Reorder Item'),
+ self.onServiceItemEditForm)
+ self.notesAction = context_menu_action(
+ self.menu, u':/services/service_notes.png',
+ translate('OpenLP.ServiceManager', '&Notes'),
+ self.onServiceItemNoteForm)
+ self.timeAction = context_menu_action(
+ self.menu, u':/media/media_time.png',
+ translate('OpenLP.ServiceManager', '&Start Time'),
+ self.onStartTimeForm)
+ self.deleteAction = context_menu_action(
+ self.menu, u':/general/general_delete.png',
+ translate('OpenLP.ServiceManager', '&Delete From Service'),
+ self.onDeleteFromService)
+ context_menu_separator(self.menu)
+ self.previewAction = context_menu_action(
+ self.menu, u':/general/general_preview.png',
+ translate('OpenLP.ServiceManager', 'Show &Preview'),
+ self.makePreview)
+ self.liveAction = context_menu_action(
+ self.menu, u':/general/general_live.png',
+ translate('OpenLP.ServiceManager', 'Show &Live'), self.makeLive)
+ context_menu_separator(self.menu)
self.themeMenu = QtGui.QMenu(
translate('OpenLP.ServiceManager', '&Change Item Theme'))
self.menu.addMenu(self.themeMenu)
@@ -675,20 +678,6 @@
if serviceItem[u'service_item'].is_text():
self.themeMenu.menuAction().setVisible(True)
action = self.menu.exec_(self.serviceManagerList.mapToGlobal(point))
- if action == self.editAction:
- self.remoteEdit()
- elif action == self.maintainAction:
- self.onServiceItemEditForm()
- elif action == self.deleteAction:
- self.onDeleteFromService()
- elif action == self.notesAction:
- self.onServiceItemNoteForm()
- elif action == self.timeAction:
- self.onStartTimeForm()
- elif action == self.previewAction:
- self.makePreview()
- elif action == self.liveAction:
- self.makeLive()
def onServiceItemNoteForm(self):
item = self.findServiceItem()[0]
@@ -840,7 +829,7 @@
correct state.
"""
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0]
- self.serviceItems[pos -1 ][u'expanded'] = False
+ self.serviceItems[pos - 1][u'expanded'] = False
def onExpandAll(self):
"""
@@ -1288,9 +1277,8 @@
self.themeComboBox.addItem(u'')
for theme in theme_list:
self.themeComboBox.addItem(theme)
- action = context_menu_action(self.serviceManagerList, None, theme,
- self.onThemeChangeAction, context=QtCore.Qt.WidgetShortcut)
- self.themeMenu.addAction(action)
+ context_menu_action(self.themeMenu, None, theme,
+ self.onThemeChangeAction)
find_and_set_in_combo_box(self.themeComboBox, self.service_theme)
self.mainwindow.renderer.set_service_theme(self.service_theme)
self.regenerateServiceItems()
Follow ups