Update new plugin infrastructure

This commit is contained in:
Tim Bentley 2009-06-27 06:46:05 +01:00
parent b36b78afdc
commit 23f49bfee7
3 changed files with 82 additions and 101 deletions

View File

@ -50,7 +50,6 @@ class MediaManagerItem(QtGui.QWidget):
if title is not None:
self.title = title
self.Toolbar = None
#self.ConfigSection = None
self.PageLayout = QtGui.QVBoxLayout(self)
self.PageLayout.setSpacing(0)
self.PageLayout.setMargin(0)
@ -118,13 +117,17 @@ class MediaManagerItem(QtGui.QWidget):
# self.PluginTextShort # eg "Image" for the image plugin
# self.ConfigSection - where the items in the media manager are stored
# this could potentially be self.PluginTextShort.lower()
# self.IconPath=u'images/images' - allows specific icons to be used
# self.hasFileIcon - Is the file Icon required
# self.hasEditIcon - Is the edit Icon required
# self.hasNewIcon - Is the new Icon required
#
# self.OnNewPrompt=u'Select Image(s)'
# self.OnNewFileMasks=u'Images (*.jpg *jpeg *.gif *.png *.bmp)'
# assumes that the new action is to load a file. If not, override onnew
# self.ListViewWithDnD_class - there is a base list class with DnD assigned to it (openlp.core.lib.BaseListWithDnD())
# each plugin needs to inherit a class from this and pass that *class* (not an instance) to here
# via the ListViewWithDnD_class member
# each plugin needs to inherit a class from this and pass that *class* (not an instance) to here
# via the ListViewWithDnD_class member
# The assumption is that given that at least two plugins are of the form
# "text with an icon" then all this will help
# even for plugins of another sort, the setup of the right-click menu, common toolbar
@ -139,16 +142,29 @@ class MediaManagerItem(QtGui.QWidget):
# Add a toolbar
self.addToolbar()
# Create buttons for the toolbar
## New Song Button ##
self.addToolbarButton(
translate(self.TranslationContext, u'Load '+self.PluginTextShort),
translate(self.TranslationContext, u'Load item into openlp.org'),
u':/images/image_load.png', self.onNewClick, u'ImageNewItem')
## Delete Song Button ##
## File Button ##
if self.hasFileIcon:
self.addToolbarButton(
translate(self.TranslationContext, u'Load '+self.PluginTextShort),
translate(self.TranslationContext, u'Load a new '+self.PluginTextShort),
u':'+self.IconPath+ u'_load.png', self.onFileClick, self.PluginTextShort+u'FileItem')
## New Button ##
if self.hasNewIcon:
self.addToolbarButton(
translate(self.TranslationContext, u'New '+self.PluginTextShort),
translate(self.TranslationContext, u'Add a new '+self.PluginTextShort),
u':'+self.IconPath+ u'_load.png', self.onNewClick, self.PluginTextShort+u'NewItem')
## Edit Button ##
if self.hasEditIcon:
self.addToolbarButton(
translate(self.TranslationContext, u'Edit '+self.PluginTextShort),
translate(self.TranslationContext, u'Edit the selected '+self.PluginTextShort),
u':'+self.IconPath+ u'_load.png', self.onEditClick, self.PluginTextShort+u'EditItem')
## Delete Button ##
self.addToolbarButton(
translate(self.TranslationContext, u'Delete '+self.PluginTextShort),
translate(self.TranslationContext, u'Delete the selected item'),
u':/images/image_delete.png', self.onDeleteClick, u'DeleteItem')
u':'+self.IconPath+ u'_delete.png', self.onDeleteClick, self.PluginTextShort+u'DeleteItem')
## Separator Line ##
self.addToolbarSeparator()
## Preview Button ##
@ -166,20 +182,27 @@ class MediaManagerItem(QtGui.QWidget):
translate(self.TranslationContext, u'Add '+self.PluginTextShort+u' To Service'),
translate(self.TranslationContext, u'Add the selected item(s) to the service'),
u':/system/system_add.png', self.onAddClick, self.PluginTextShort+u'AddItem')
#Allow the plugin to define it's own header
self.addHeaderBar()
#Add the List widget
self.ListView = self.ListViewWithDnD_class()
self.ListView.uniformItemSizes = True
self.ListData = ListWithPreviews()
self.ListView.setModel(self.ListData)
self.ListView.setGeometry(QtCore.QRect(10, 100, 256, 591))
self.ListView.setSpacing(1)
self.ListView.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self.ListView.setAlternatingRowColors(True)
self.ListView.setDragEnabled(True)
self.ListView.setObjectName(self.PluginTextShort+u'ListView')
#Add tp PageLayout
self.PageLayout.addWidget(self.ListView)
#define and add the context menu
self.ListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
if self.hasEditIcon:
self.ListView.addAction(self.contextMenuAction(self.ListView,
':' +self.IconPath+u'_new.png',
translate(self.TranslationContext, u'&Edit '+self.PluginTextShort),
self.onEditClick))
self.ListView.addAction(self.contextMenuSeparator(self.SongListWidget))
self.ListView.addAction(self.contextMenuAction(
self.ListView, ':/system/system_preview.png',
translate(self.TranslationContext, u'&Preview '+self.PluginTextShort),
@ -195,10 +218,10 @@ class MediaManagerItem(QtGui.QWidget):
QtCore.QObject.connect(self.ListView,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onPreviewClick)
def initialise(self):
self.loadList(self.parent.config.load_list(self.ConfigSection))
def addHeaderBar(self):
pass
def onNewClick(self):
def onFileClick(self):
files = QtGui.QFileDialog.getOpenFileNames(None,
translate(self.TranslationContext, self.OnNewPrompt),
self.parent.config.get_last_dir(),
@ -214,6 +237,12 @@ class MediaManagerItem(QtGui.QWidget):
for file in list:
self.ListData.addRow(file)
def onNewClick(self):
raise NotImplementedError(u'MediaManagerItem.onNewClick needs to be defined by the plugin')
def onEditClick(self):
raise NotImplementedError(u'MediaManagerItem.onEditClick needs to be defined by the plugin')
def onDeleteClick(self):
indexes = self.ListView.selectedIndexes()
for index in indexes:

View File

@ -45,6 +45,10 @@ class ImageMediaItem(MediaManagerItem):
self.TranslationContext = u'ImagePlugin'
self.PluginTextShort = u'Image'
self.ConfigSection = u'images'
self.IconPath = u'images/image'
self.hasFileIcon = True
self.hasNewIcon = False
self.hasEditIcon = False
self.OnNewPrompt = u'Select Image(s)'
self.OnNewFileMasks = u'Images (*.jpg *jpeg *.gif *.png *.bmp)'
# this next is a class, not an instance of a class - it will
@ -52,6 +56,12 @@ class ImageMediaItem(MediaManagerItem):
self.ListViewWithDnD_class = ImageListView
MediaManagerItem.__init__(self, parent, icon, title)
def initialise(self):
self.ListData = ListWithPreviews()
self.ListView.setModel(self.ListData)
self.loadList(self.parent.config.load_list(self.ConfigSection))
def generateSlideData(self, service_item):
indexes = self.ListView.selectedIndexes()
service_item.title = u'Image(s)'

View File

@ -43,104 +43,46 @@ class PresentationMediaItem(MediaManagerItem):
self.TranslationContext = u'PresentationPlugin'
self.PluginTextShort = u'Presentation'
self.ConfigSection = u'presentation'
self.OnNewPrompt = u'Select Image(s)'
self.OnNewFileMasks = u'Images (*.ppt *.pps *.odp)'
self.hasFileIcon = True
self.hasNewIcon = False
self.hasEditIcon = False
self.IconPath = u'presentations/presentation'
self.OnNewPrompt = u'Select Presentation(s)'
self.OnNewFileMasks = u'Presentations (*.ppt *.pps *.odp)'
# this next is a class, not an instance of a class - it will
# be instanced by the base MediaManagerItem
self.ListViewWithDnD_class = PresentationListView
MediaManagerItem.__init__(self, parent, icon, title)
# def setupUi(self):
# # Add a toolbar
# self.addToolbar()
# # Create buttons for the toolbar
# ## New Presentation Button ##
# self.addToolbarButton(
# translate(u'PresentationsMediaItem',u'New presentations'),
# translate(u'PresentationsMediaItem',u'Load presentations into openlp.org'),
# ':/presentations/presentation_load.png', self.onPresentationNewClick, 'PresentationNewItem')
# ## Delete Presentation Button ##
# self.addToolbarButton(
# translate(u'PresentationsMediaItem',u'Delete Presentation'),
# translate(u'PresentationsMediaItem',u'Delete the selected presentation'),
# ':/presentations/presentation_delete.png', self.onPresentationDeleteClick, 'PresentationDeleteItem')
# ## Separator Line ##
# self.addToolbarSeparator()
# ## Preview Presentation Button ##
# self.addToolbarButton(
# translate(u'PresentationsMediaItem',u'Preview Presentation'),
# translate(u'PresentationsMediaItem',u'Preview the selected Presentation'),
# ':/system/system_preview.png', self.onPresentationPreviewClick, 'PresentationPreviewItem')
# ## Live Presentation Button ##
# self.addToolbarButton(
# translate(u'PresentationsMediaItem',u'Go Live'),
# translate(u'PresentationsMediaItem',u'Send the selected presentation live'),
# ':/system/system_live.png', self.onPresentationLiveClick, 'PresentationLiveItem')
# ## Add Presentation Button ##
# self.addToolbarButton(
# translate(u'PresentationsMediaItem',u'Add Presentation To Service'),
# translate(u'PresentationsMediaItem',u'Add the selected Presentations(s) to the service'),
# ':/system/system_add.png',self.onPresentationAddClick, 'PresentationsAddItem')
# ## Add the Presentationlist widget ##
#
# self.PresentationWidget = QtGui.QWidget(self)
# sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
# sizePolicy.setHorizontalStretch(0)
# sizePolicy.setVerticalStretch(0)
# sizePolicy.setHeightForWidth(self.PresentationWidget.sizePolicy().hasHeightForWidth())
# self.PresentationWidget.setSizePolicy(sizePolicy)
# self.PresentationWidget.setObjectName(u'PresentationWidget')
# self.DisplayLayout = QtGui.QGridLayout(self.PresentationWidget)
# self.DisplayLayout.setObjectName(u'DisplayLayout')
# self.DisplayTypeComboBox = QtGui.QComboBox(self.PresentationWidget)
# self.DisplayTypeComboBox.setObjectName(u'DisplayTypeComboBox')
# self.DisplayLayout.addWidget(self.DisplayTypeComboBox, 0, 1, 1, 2)
# self.DisplayTypeLabel = QtGui.QLabel(self.PresentationWidget)
# self.DisplayTypeLabel.setObjectName(u'SearchTypeLabel')
# self.DisplayLayout.addWidget(self.DisplayTypeLabel, 0, 0, 1, 1)
#
# self.DisplayTypeLabel.setText(translate(u'PresentationMediaItem', u'Present using:'))
#
# # Add the song widget to the page layout
# self.PageLayout.addWidget(self.PresentationWidget)
#
# self.PresentationsListView = QtGui.QListView()
# self.PresentationsListView.setAlternatingRowColors(True)
# self.PresentationsListData = FileListData()
# self.PresentationsListView.setModel(self.PresentationsListData)
#
# self.PageLayout.addWidget(self.PresentationsListView)
#
# #define and add the context menu
# self.PresentationsListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
#
# self.PresentationsListView.addAction(self.contextMenuAction(
# self.PresentationsListView, ':/system/system_preview.png',
# translate(u'PresentationsMediaItem',u'&Preview presentations'), self.onPresentationPreviewClick))
# self.PresentationsListView.addAction(self.contextMenuAction(
# self.PresentationsListView, ':/system/system_live.png',
# translate(u'PresentationsMediaItem',u'&Show Live'), self.onPresentationLiveClick))
# self.PresentationsListView.addAction(self.contextMenuAction(
# self.PresentationsListView, ':/system/system_add.png',
# translate(u'PresentationsMediaItem',u'&Add to Service'), self.onPresentationAddClick))
def addHeaderBar(self):
self.PresentationWidget = QtGui.QWidget(self)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.PresentationWidget.sizePolicy().hasHeightForWidth())
self.PresentationWidget.setSizePolicy(sizePolicy)
self.PresentationWidget.setObjectName(u'PresentationWidget')
self.DisplayLayout = QtGui.QGridLayout(self.PresentationWidget)
self.DisplayLayout.setObjectName(u'DisplayLayout')
self.DisplayTypeComboBox = QtGui.QComboBox(self.PresentationWidget)
self.DisplayTypeComboBox.setObjectName(u'DisplayTypeComboBox')
self.DisplayLayout.addWidget(self.DisplayTypeComboBox, 0, 1, 1, 2)
self.DisplayTypeLabel = QtGui.QLabel(self.PresentationWidget)
self.DisplayTypeLabel.setObjectName(u'SearchTypeLabel')
self.DisplayLayout.addWidget(self.DisplayTypeLabel, 0, 0, 1, 1)
self.DisplayTypeLabel.setText(translate(u'PresentationMediaItem', u'Present using:'))
# Add the Presentation widget to the page layout
self.PageLayout.addWidget(self.PresentationWidget)
def initialise(self):
list = self.parent.config.load_list(u'presentations')
self.loadPresentationList(list)
# self.DisplayTypeComboBox.addItem(u'Impress')
self.DisplayTypeComboBox.addItem(u'Impress')
# self.DisplayTypeComboBox.addItem(u'Powerpoint')
# self.DisplayTypeComboBox.addItem(u'Keynote')
def onPresentationNewClick(self):
files = QtGui.QFileDialog.getOpenFileNames(None,
translate(u'PresentationsMediaItem', u'Select presentations(s)'),
self.parent.config.get_last_dir(), u'Presentations (*.ppt *.pps *.odp)')
if len(files) > 0:
self.loadPresentationList(files)
dir, filename = os.path.split(unicode(files[0]))
self.parent.config.set_last_dir(dir)
self.parent.config.set_list(u'Presentations', self.PresentationsListData.getFileList())
def getFileList(self):
filelist = [item[0] for item in self.PresentationsListView];
return filelist