Added context menus to ServiceManager

Refactored Icon Construction to single method
This commit is contained in:
Tim Bentley 2009-05-13 20:47:25 +01:00
parent 8c7c71e0c0
commit 0ba52fbd66
7 changed files with 65 additions and 108 deletions

View File

@ -15,7 +15,24 @@ You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
__all__ = ['convertStringToBoolean']
import types
from PyQt4 import QtCore, QtGui
__all__ = ['convertStringToBoolean','buildIcon',]
def convertStringToBoolean(stringvalue):
return stringvalue.strip().lower() in (u'true', u'yes', u'y')
def buildIcon(icon):
ButtonIcon = None
if type(icon) is QtGui.QIcon:
ButtonIcon = icon
elif type(icon) is types.StringType or type(icon) is types.UnicodeType:
ButtonIcon = QtGui.QIcon()
if icon.startswith(u':/'):
ButtonIcon.addPixmap(QtGui.QPixmap(icon), QtGui.QIcon.Normal,
QtGui.QIcon.Off)
else:
ButtonIcon.addPixmap(QtGui.QPixmap.fromImage(QImage(icon)),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
return ButtonIcon

View File

@ -20,7 +20,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
import types
from PyQt4 import QtCore, QtGui
from openlp.core.resources import *
from openlp.core.lib.toolbar import *
class MediaManagerItem(QtGui.QWidget):

View File

@ -18,12 +18,12 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
import types
import time
from openlp import buildIcon
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class ServiceItem():
"""
The service item is a base class for the plugins to use to interact with
@ -50,18 +50,7 @@ class ServiceItem():
log.debug(u'Service item created for %s', self.shortname)
def addIcon(self, icon):
ButtonIcon = None
if type(icon) is QIcon:
ButtonIcon = icon
elif type(icon) is types.StringType or type(icon) is types.UnicodeType:
ButtonIcon = QIcon()
if icon.startswith(u':/'):
ButtonIcon.addPixmap(QPixmap(icon), QIcon.Normal,
QIcon.Off)
else:
ButtonIcon.addPixmap(QPixmap.fromImage(QImage(icon)),
QIcon.Normal, QIcon.Off)
self.iconic_representation = ButtonIcon
self.iconic_representation = buildIcon(icon)
def render(self):
"""

View File

@ -26,6 +26,7 @@ from openlp.core.lib import OpenLPToolbar
from openlp.core.lib import ServiceItem
from openlp.core.lib import RenderManager
from openlp.core import translate
from openlp import buildIcon
from openlp.core.lib import Event, EventType, EventManager
class ServiceManager(QtGui.QWidget):
@ -82,15 +83,39 @@ class ServiceManager(QtGui.QWidget):
self.ServiceManagerList .__class__.dragEnterEvent=self.dragEnterEvent
self.ServiceManagerList .__class__.dragMoveEvent=self.dragEnterEvent
self.ServiceManagerList .__class__.dropEvent =self.dropEvent
#endable drag
#self.ServiceManagerList.setDragEnabled(True)
#self.ServiceManagerList .__class__.mouseMoveEvent =self.onMouseMoveEvent
self.ServiceManagerList.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
self.ServiceManagerList.addAction(self.contextMenuAction(
self.ServiceManagerList, ':/system/system_preview.png',
translate(u'ServiceManager',u'&Preview Verse'), self.makeLive))
self.ServiceManagerList.addAction(self.contextMenuAction(
self.ServiceManagerList, ':/system/system_live.png',
translate(u'ServiceManager',u'&Show Live'), self.makePreview))
self.ServiceManagerList.addAction(self.contextMenuSeparator(self.ServiceManagerList))
self.ServiceManagerList.addAction(self.contextMenuAction(
self.ServiceManagerList, ':/services/service_delete',
translate(u'ServiceManager',u'&Remove from Service'), self.onDeleteFromService))
self.Layout.addWidget(self.ServiceManagerList)
QtCore.QObject.connect(self.ThemeComboBox,
QtCore.SIGNAL("activated(int)"), self.onThemeComboBoxSelected)
def contextMenuAction(self, base, icon, text, slot):
"""
Utility method to help build context menus for plugins
"""
action = QtGui.QAction(text, base)
action .setIcon(buildIcon(icon))
QtCore.QObject.connect(action, QtCore.SIGNAL("triggered()"), slot)
return action
def contextMenuSeparator(self, base):
action = QtGui.QAction("", base)
action.setSeparator(True)
return action
def onServiceTop(self):
pass
@ -130,6 +155,9 @@ class ServiceManager(QtGui.QWidget):
treewidgetitem1.setText(0,text[:30])
#treewidgetitem1.setIcon(0,frame[u'image'])
def makePreview(self):
print "make Preview"
def makeLive(self):
print "make live"
self.liveController.addServiceManagerItem(None, 1)
@ -178,35 +206,8 @@ class ServiceManager(QtGui.QWidget):
link=event.mimeData()
if link.hasText():
plugin = event.mimeData().text()
print plugin
self.eventManager.post_event(Event(EventType.LoadServiceItem, plugin))
# def onMouseMoveEvent(self, event):
# """
# Drag and drop eventDo not care what data is selected
# as the recepient will use events to request the data move
# just tell it what plugin to call
# """
# print "ServiceManager"
# if event.buttons() != QtCore.Qt.LeftButton:
# return
#
# items = self.ServiceManagerList.selectedIndexes()
# if items == []:
# return
#
# drag = QtGui.QDrag(self)
# mimeData = QtCore.QMimeData()
# drag.setMimeData(mimeData)
# for item in items:
# mimeData.setText(u'ServiceManager')
#
# dropAction = drag.start(QtCore.Qt.CopyAction)
#
# if dropAction == QtCore.Qt.CopyAction:
# self.close()
def oos_as_text(self):
text=[]
log.info( "oos as text")

View File

@ -26,66 +26,6 @@ from openlp.core.lib import OpenLPToolbar
from openlp.core import translate
from openlp.core.lib import Event, EventType, EventManager
#class PreviewList(QtGui.QListView):
#
# def __init__(self,parent=None):
# QtGui.QListView.__init__(self,parent)
# self.setAcceptDrops(True)
# self.setDropIndicatorShown(True)
# self.setDragEnabled(False)
# self.setDragDropMode(QtGui.QAbstractItemView.DropOnly)
#
# def dragEnterEvent(self, event):
# """
# Accept Drag events
# """
# event.accept()
#
# def dropEvent(self, event):
# """
# Handle the release of the event and trigger the plugin
# to add the data
# """
# print "preview drop event"
# link=event.mimeData()
# if link.hasText():
# plugin = event.mimeData().text()
# if plugin == u'ServiceManager':
# #Service Manager to Preview is not a sane
# self.serviceManager.makeLive()
# else:
# print "preview fired ", plugin
# self.eventManager.post_event(Event(EventType.PreviewShow, plugin))
#
#class LiveList(QtGui.QListView):
# def __init__(self,parent=None):
# QtGui.QListView.__init__(self,parent)
# self.setAcceptDrops(True)
# self.setDropIndicatorShown(True)
# self.setDragEnabled(False)
# self.setDragDropMode(QtGui.QAbstractItemView.DropOnly)
#
# def dragEnterEvent(self, event):
# """
# Accept Drag events
# """
# event.accept()
#
# def dropEvent(self, event):
# """
# Handle the release of the event and trigger the plugin
# to add the data
# """
# print "Live drop event"
# link=event.mimeData()
# if link.hasText():
# plugin = event.mimeData().text()
# if plugin == u'ServiceManager':
# self.serviceManager.makeLive()
# else:
# self.eventManager.post_event(Event(EventType.LiveShow, plugin))
class SlideData(QtCore.QAbstractListModel):
"""
Tree of items for an order of Theme.
@ -102,6 +42,10 @@ class SlideData(QtCore.QAbstractListModel):
self.maximagewidth=self.rowheight*16/9.0;
log.info(u'Starting')
def eventFilter(self, obj, event):
print obj, event
return false
def clear(self):
self.items=[]
@ -185,8 +129,6 @@ class SlideController(QtGui.QWidget):
self.gridLayout = QtGui.QGridLayout(self.scrollAreaWidgetContents)
self.gridLayout.setObjectName("gridLayout")
#load the correct class for drag and drop
self.PreviewListView = QtGui.QListView(self.scrollAreaWidgetContents)
self.PreviewListData = SlideData()
self.PreviewListView.isLive = self.isLive
@ -246,6 +188,13 @@ class SlideController(QtGui.QWidget):
QtCore.QObject.connect(self.PreviewListView,
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSlideSelected)
QtCore.QObject.connect(self.PreviewListView,
QtCore.SIGNAL(u'activated(QModelIndex)'), self.onSlideSelected)
QtCore.QObject.connect(self.PreviewListView,
QtCore.SIGNAL(u'keyPressEvent(QKeyEvent)'), self.onSlideSelecteda)
def onSlideSelecteda(self, index):
print "a", index
def onSlideSelectedFirst(self):
row = self.PreviewListData.createIndex(0, 0)

View File

@ -230,6 +230,7 @@ class BibleMediaItem(MediaManagerItem):
QtCore.SIGNAL("pressed()"), self.onQuickSearchButton)
# Context Menus
self.BibleListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
self.BibleListView.addAction(self.contextMenuAction(
self.BibleListView, ':/system/system_preview.png',
translate(u'BibleMediaItem',u'&Preview Verse'), self.onBiblePreviewClick))

View File

@ -101,6 +101,7 @@ class ImageMediaItem(MediaManagerItem):
self.ImageListView.setModel(self.ImageListData)
self.ImageListView.setGeometry(QtCore.QRect(10, 100, 256, 591))
self.ImageListView.setSpacing(1)
self.ImageListView.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
self.ImageListView.setAlternatingRowColors(True)
self.ImageListView.setDragEnabled(True)
self.ImageListView.setObjectName('ImageListView')