From 86115ec9646c89848e663db81eae9496d39f231e Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 2 Mar 2009 22:12:14 +0000 Subject: [PATCH] Plugins pass themselves as the parent to MediaManagerItem to facilitate easier communication between each plugin's set of objects. bzr-revno: 357 --- openlp/core/lib/mediamanageritem.py | 3 +- openlp/plugins/bibles/bibleplugin.py | 3 +- openlp/plugins/bibles/lib/biblemediaitem.py | 56 +++++++++++-------- openlp/plugins/images/imageplugin.py | 36 +++++++----- .../presentations/presentationplugin.py | 28 +++++----- openlp/plugins/songs/songsplugin.py | 4 +- openlp/plugins/videos/videoplugin.py | 4 +- 7 files changed, 76 insertions(+), 58 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 8e08dc8e5..c965854ad 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -27,11 +27,12 @@ class MediaManagerItem(QtGui.QWidget): """ MediaManagerItem is a helper widget for plugins. """ - def __init__(self, icon=None, title=None): + def __init__(self, parent=None, icon=None, title=None): """ Constructor to create the media manager item. """ QtGui.QWidget.__init__(self) + self.parent = parent if type(icon) is QtGui.QIcon: self.icon = icon elif type(icon) is types.StringType: diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 9d963b51a..00b4199d1 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -52,8 +52,7 @@ class BiblePlugin(Plugin, PluginUtils): def get_media_manager_item(self): # Create the MediaManagerItem object - self.media_item = BibleMediaItem(self.icon, 'Bible Verses', - self.biblemanager) + self.media_item = BibleMediaItem(self, self.icon, 'Bible Verses') return self.media_item def add_import_menu_item(self, import_menu): diff --git a/openlp/plugins/bibles/lib/biblemediaitem.py b/openlp/plugins/bibles/lib/biblemediaitem.py index 4776da987..821bf1932 100644 --- a/openlp/plugins/bibles/lib/biblemediaitem.py +++ b/openlp/plugins/bibles/lib/biblemediaitem.py @@ -35,12 +35,11 @@ class BibleMediaItem(MediaManagerItem): log=logging.getLogger("BibleMediaItem") log.info("Bible Media Item loaded") - def __init__(self, icon, title, biblemanager): - self.biblemanager = biblemanager + def __init__(self, parent, icon, title): + MediaManagerItem.__init__(self, parent, icon, title) self.search_results = {} # place to store the search results QtCore.QObject.connect(Receiver().get_receiver(), QtCore.SIGNAL("openlpreloadbibles"), self.reloadBibles) - MediaManagerItem.__init__(self, icon, title) def setupUi(self): # Add a toolbar @@ -183,14 +182,21 @@ class BibleMediaItem(MediaManagerItem): self.BibleListView.setAlternatingRowColors(True) self.PageLayout.addWidget(self.BibleListView) # Combo Boxes - QtCore.QObject.connect(self.AdvancedVersionComboBox, QtCore.SIGNAL("activated(int)"), self.onAdvancedVersionComboBox) - QtCore.QObject.connect(self.AdvancedBookComboBox, QtCore.SIGNAL("activated(int)"), self.onAdvancedBookComboBox) - QtCore.QObject.connect(self.AdvancedFromChapter, QtCore.SIGNAL("activated(int)"), self.onAdvancedFromChapter) - QtCore.QObject.connect(self.AdvancedFromVerse, QtCore.SIGNAL("activated(int)"), self.onAdvancedFromVerse) - QtCore.QObject.connect(self.AdvancedToChapter, QtCore.SIGNAL("activated(int)"), self.onAdvancedToChapter) + QtCore.QObject.connect(self.AdvancedVersionComboBox, + QtCore.SIGNAL("activated(int)"), self.onAdvancedVersionComboBox) + QtCore.QObject.connect(self.AdvancedBookComboBox, + QtCore.SIGNAL("activated(int)"), self.onAdvancedBookComboBox) + QtCore.QObject.connect(self.AdvancedFromChapter, + QtCore.SIGNAL("activated(int)"), self.onAdvancedFromChapter) + QtCore.QObject.connect(self.AdvancedFromVerse, + QtCore.SIGNAL("activated(int)"), self.onAdvancedFromVerse) + QtCore.QObject.connect(self.AdvancedToChapter, + QtCore.SIGNAL("activated(int)"), self.onAdvancedToChapter) # Buttons - QtCore.QObject.connect(self.AdvancedSearchButton, QtCore.SIGNAL("pressed()"), self.onAdvancedSearchButton) - QtCore.QObject.connect(self.QuickSearchButton, QtCore.SIGNAL("pressed()"), self.onQuickSearchButton) + QtCore.QObject.connect(self.AdvancedSearchButton, + QtCore.SIGNAL("pressed()"), self.onAdvancedSearchButton) + QtCore.QObject.connect(self.QuickSearchButton, + QtCore.SIGNAL("pressed()"), self.onQuickSearchButton) # Context Menus self.BibleListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) self.BibleListView.addAction(self.contextMenuAction( @@ -226,6 +232,8 @@ class BibleMediaItem(MediaManagerItem): def initialise(self): self.loadBibles() + + def initialiseForm(self): self.QuickSearchComboBox.clear() self.QuickVersionComboBox.clear() self.AdvancedVersionComboBox.clear() @@ -233,10 +241,10 @@ class BibleMediaItem(MediaManagerItem): self.ClearAdvancedSearchComboBox.clear() def loadBibles(self): - bibles = self.biblemanager.get_bibles('full') + bibles = self.parent.biblemanager.get_bibles('full') for bible in bibles: # load bibles into the combo boxes self.QuickVersionComboBox.addItem(bible) - bibles = self.biblemanager.get_bibles('partial') # Without HTTP + bibles = self.parent.biblemanager.get_bibles('partial') # Without HTTP first = True for bible in bibles: # load bibles into the combo boxes self.AdvancedVersionComboBox.addItem(bible) @@ -252,7 +260,7 @@ class BibleMediaItem(MediaManagerItem): self.initialiseBible(str(self.AdvancedVersionComboBox.currentText())) # restet the bible info def onBibleNewClick(self): - self.bibleimportform = BibleImportForm(self.config, self.biblemanager, self) + self.bibleimportform = BibleImportForm(self.config, self.parent.biblemanager, self) self.bibleimportform.exec_() pass @@ -278,7 +286,7 @@ class BibleMediaItem(MediaManagerItem): if t1 != t2: bible = str(self.AdvancedVersionComboBox.currentText()) book = str(self.AdvancedBookComboBox.currentText()) - vse = self.biblemanager.get_book_verse_count(bible, book, int(t2))[0] # get the verse count for new chapter + vse = self.parent.biblemanager.get_book_verse_count(bible, book, int(t2))[0] # get the verse count for new chapter self.adjustComboBox(1, vse, self.AdvancedToVerse) def onAdvancedSearchButton(self): @@ -288,7 +296,7 @@ class BibleMediaItem(MediaManagerItem): chapter_to = int(self.AdvancedToChapter.currentText()) verse_from = int(self.AdvancedFromVerse.currentText()) verse_to = int(self.AdvancedToVerse.currentText()) - self.search_results = self.biblemanager.get_verse_text(bible, book, + self.search_results = self.parent.biblemanager.get_verse_text(bible, book, chapter_from, chapter_to, verse_from, verse_to) if self.ClearAdvancedSearchComboBox.currentIndex() == 0: self.BibleListView.clear() # clear the results @@ -300,7 +308,7 @@ class BibleMediaItem(MediaManagerItem): book = str(self.AdvancedBookComboBox.currentText()) cf = self.AdvancedFromChapter.currentText() self._adjust_combobox(cf, self.chapters_from, self.AdvancedToChapter) - vse = self.biblemanager.get_book_verse_count(bible, book, int(cf))[0] # get the verse count for new chapter + vse = self.parent.biblemanager.get_book_verse_count(bible, book, int(cf))[0] # get the verse count for new chapter self._adjust_combobox(1, vse, self.AdvancedFromVerse) self._adjust_combobox(1, vse, self.AdvancedToVerse) @@ -312,7 +320,7 @@ class BibleMediaItem(MediaManagerItem): self.BibleListView.clear() # clear the results self.BibleListView.setRowCount(0) elif self.QuickSearchComboBox.currentIndex() == 1: - self.search_results = self.biblemanager.get_verse_from_text(bible, text) + self.search_results = self.parent.biblemanager.get_verse_from_text(bible, text) else: self.searchByReference(bible, text) if not self.search_results == None: @@ -354,19 +362,19 @@ class BibleMediaItem(MediaManagerItem): return loc def reloadBibles(self): - self.biblemanager.reload_bibles() - self._initialise_form() + self.parent.biblemanager.reload_bibles() + self.initialiseForm() def initialiseBible(self, bible): log.debug('initialiseBible %s', bible) current_book = str(self.AdvancedBookComboBox.currentText()) - chapter_count = self.biblemanager.get_book_chapter_count(bible, + chapter_count = self.parent.biblemanager.get_book_chapter_count(bible, current_book)[0] log.debug('Book change bible %s book %s ChapterCount %s', bible, current_book, chapter_count) if chapter_count == None: # Only change the search details if the book is missing from the new bible - books = self.biblemanager.get_bible_books(str( + books = self.parent.biblemanager.get_bible_books(str( self.AdvancedVersionComboBox.currentText())) self.AdvancedBookComboBox.clear() first = True @@ -378,8 +386,8 @@ class BibleMediaItem(MediaManagerItem): def initialiseChapterVerse(self, bible, book): log.debug("initialiseChapterVerse %s , %s", bible, book) - self.chapters_from = self.biblemanager.get_book_chapter_count(bible, book)[0] - self.verses = self.biblemanager.get_book_verse_count(bible, book, 1)[0] + self.chapters_from = self.parent.biblemanager.get_book_chapter_count(bible, book)[0] + self.verses = self.parent.biblemanager.get_book_verse_count(bible, book, 1)[0] self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter) self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter) self.adjustComboBox(1, self.verses, self.AdvancedFromVerse) @@ -475,7 +483,7 @@ class BibleMediaItem(MediaManagerItem): if message == None: self.search_results = None - self.search_results = self.biblemanager.get_verse_text(bible, book, + self.search_results = self.parent.biblemanager.get_verse_text(bible, book, int(start_chapter), int(end_chapter), int(start_verse), int(end_verse)) else: diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index b82560d8d..0f87b3adf 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -34,13 +34,16 @@ class ListWithPreviews(QtCore.QAbstractListModel): global log log=logging.getLogger("ListWithPreviews") log.info("started") + def __init__(self): QtCore.QAbstractListModel.__init__(self) self.items=[] # will be a list of (filename, QPixmap) tuples self.rowheight=50 self.maximagewidth=self.rowheight*16/9.0; + def rowCount(self, parent): return len(self.items) + def insertRow(self, row, filename): self.beginInsertRows(QModelIndex(),row,row) log.info("insert row %d:%s"%(row,filename)) @@ -60,18 +63,19 @@ class ListWithPreviews(QtCore.QAbstractListModel): # finally create the row self.items.insert(row, (filename, p, shortfilename)) self.endInsertRows() + def removeRow(self, row): self.beginRemoveRows(QModelIndex(), row,row) self.items.pop(row) self.endRemoveRows() + def addRow(self, filename): self.insertRow(len(self.items), filename) - + def data(self, index, role): row=index.row() if row > len(self.items): # if the last row is selected and deleted, we then get called with an empty row! return QVariant() - if role==Qt.DisplayRole: retval= self.items[row][2] elif role == Qt.DecorationRole: @@ -80,19 +84,21 @@ class ListWithPreviews(QtCore.QAbstractListModel): retval= self.items[row][0] else: retval= QVariant() - # log.info("Returning"+ str(retval)) if type(retval) is not type(QVariant): return QVariant(retval) else: return retval + def get_file_list(self): filelist=[i[0] for i in self.items]; return filelist + class ImagePlugin(Plugin, PluginUtils): global log log=logging.getLogger("ImagePlugin") log.info("Image Plugin loaded") + def __init__(self, preview_controller, live_controller): # Call the parent constructor Plugin.__init__(self, 'Images', '1.9.0', preview_controller, live_controller) @@ -104,9 +110,10 @@ class ImagePlugin(Plugin, PluginUtils): self.preview_service_item=ImageServiceItem(preview_controller) self.live_service_item=ImageServiceItem(live_controller) + def get_media_manager_item(self): # Create the MediaManagerItem object - self.MediaManagerItem = MediaManagerItem(self.icon, 'Images') + self.MediaManagerItem = MediaManagerItem(self, self.icon, 'Images') # Add a toolbar self.MediaManagerItem.addToolbar() # Create buttons for the toolbar @@ -133,29 +140,29 @@ class ImagePlugin(Plugin, PluginUtils): self.ImageListView.uniformItemSizes=True self.ImageListData=ListWithPreviews() self.ImageListView.setModel(self.ImageListData) - + self.ImageListView.setGeometry(QtCore.QRect(10, 100, 256, 591)) self.ImageListView.setObjectName("ImageListView") self.MediaManagerItem.PageLayout.addWidget(self.ImageListView) - + #define and add the context menu self.ImageListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) - self.ImageListView.addAction(self.add_to_context_menu(self.ImageListView, ':/system/system_preview.png', "&Preview Image", self.onImagePreviewClick)) - self.ImageListView.addAction(self.add_to_context_menu(self.ImageListView, ':/system/system_live.png', "&Show Live", self.onImageLiveClick)) + self.ImageListView.addAction(self.add_to_context_menu(self.ImageListView, ':/system/system_preview.png', "&Preview Image", self.onImagePreviewClick)) + self.ImageListView.addAction(self.add_to_context_menu(self.ImageListView, ':/system/system_live.png', "&Show Live", self.onImageLiveClick)) self.ImageListView.addAction(self.add_to_context_menu(self.ImageListView, ':/system/system_add.png', "&Add to Service", self.onImageAddClick)) self.ImageListPreview = QtGui.QWidget() self.MediaManagerItem.PageLayout.addWidget(self.ImageListPreview) self.ImageListView.setGeometry(QtCore.QRect(10, 100, 256, 591)) - + return self.MediaManagerItem def initialise(self): log.info("Plugin Initialising") list = self._load_display_list() - self._load_image_list(list) + self._load_image_list(list) log.info("Done") def onImagesNewClick(self): @@ -164,19 +171,19 @@ class ImagePlugin(Plugin, PluginUtils): if len(files) > 0: self._load_image_list(files) self._save_last_directory(files[0]) - self._save_display_list(self.ImageListData.get_file_list()) + self._save_display_list(self.ImageListData.get_file_list()) def _load_image_list(self, list): for f in list: self.ImageListData.addRow(f) - + def onImageDeleteClick(self): indexes=self.ImageListView.selectedIndexes() for i in indexes: cr = i.row() self.ImageListData.removeRow(int(cr)) - self._save_display_list(self.ImageListData.get_file_list()) + self._save_display_list(self.ImageListData.get_file_list()) def onImageClick(self, where): cr = self.ImageListView.currentRow() @@ -184,9 +191,10 @@ class ImagePlugin(Plugin, PluginUtils): log.info("Click %s:%s"%(str(where), filename)) where.add(filename) where.render() - + def onImagePreviewClick(self): self.onImageClick(self.preview_service_item) + def onImageLiveClick(self): self.onImageClick(self.live_service_item) diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index 7edeeff02..6c264ea3a 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -26,6 +26,7 @@ from openlp.core.resources import * from openlp.core.lib import Plugin, PluginUtils, MediaManagerItem class PresentationPlugin(Plugin, PluginUtils): + def __init__(self): # Call the parent constructor Plugin.__init__(self, 'Presentations', '1.9.0') @@ -35,10 +36,9 @@ class PresentationPlugin(Plugin, PluginUtils): self.icon.addPixmap(QtGui.QPixmap(':/media/media_presentation.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off) - def get_media_manager_item(self): # Create the MediaManagerItem object - self.MediaManagerItem = MediaManagerItem(self.icon, 'Presentations') + self.MediaManagerItem = MediaManagerItem(self, self.icon, 'Presentations') # Add a toolbar self.MediaManagerItem.addToolbar() # Create buttons for the toolbar @@ -66,50 +66,50 @@ class PresentationPlugin(Plugin, PluginUtils): self.PresentationListView.setColumnHidden(0, True) self.PresentationListView.setColumnWidth(1, 275) self.PresentationListView.setShowGrid(False) - self.PresentationListView.setSortingEnabled(False) + self.PresentationListView.setSortingEnabled(False) self.PresentationListView.setAlternatingRowColors(True) - self.PresentationListView.setHorizontalHeaderLabels(QtCore.QStringList(["","Name"])) + self.PresentationListView.setHorizontalHeaderLabels(QtCore.QStringList(["","Name"])) self.PresentationListView.setGeometry(QtCore.QRect(10, 100, 256, 591)) self.PresentationListView.setObjectName("PresentationListView") - self.PresentationListView.setAlternatingRowColors(True) + self.PresentationListView.setAlternatingRowColors(True) self.MediaManagerItem.PageLayout.addWidget(self.PresentationListView) - + #define and add the context menu self.PresentationListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) - self.PresentationListView.addAction(self.add_to_context_menu(self.PresentationListView, ':/system/system_preview.png', "&Preview Presentation", self.onPresentationPreviewClick)) - self.PresentationListView.addAction(self.add_to_context_menu(self.PresentationListView, ':/system/system_live.png', "&Show Live", self.onPresentationLiveClick)) - self.PresentationListView.addAction(self.add_to_context_menu(self.PresentationListView, ':/system/system_add.png', "&Add to Service", self.onPresentationAddClick)) + self.PresentationListView.addAction(self.add_to_context_menu(self.PresentationListView, ':/system/system_preview.png', "&Preview Presentation", self.onPresentationPreviewClick)) + self.PresentationListView.addAction(self.add_to_context_menu(self.PresentationListView, ':/system/system_live.png', "&Show Live", self.onPresentationLiveClick)) + self.PresentationListView.addAction(self.add_to_context_menu(self.PresentationListView, ':/system/system_add.png', "&Add to Service", self.onPresentationAddClick)) return self.MediaManagerItem def initialise(self): list = self._load_display_list() - self._load_presentation_list(list) + self._load_presentation_list(list) def onPresentationLoadClick(self): files = QtGui.QFileDialog.getOpenFileNames(None, "Select Presentation(s)", self._get_last_dir(), "Images (*.ppt *.pps *.odi)") if len(files) > 0: self._load_presentation_list(files) self._save_last_directory(files[0]) - self._save_display_list(self.PresentationListView) + self._save_display_list(self.PresentationListView) def _load_presentation_list(self, list): for f in list: - fl , nm = os.path.split(str(f)) + fl , nm = os.path.split(str(f)) c = self.PresentationListView.rowCount() self.PresentationListView.setRowCount(c+1) twi = QtGui.QTableWidgetItem(str(f)) self.PresentationListView.setItem(c , 0, twi) twi = QtGui.QTableWidgetItem(str(nm)) self.PresentationListView.setItem(c , 1, twi) - self.PresentationListView.setRowHeight(c, 20) + self.PresentationListView.setRowHeight(c, 20) def onPresentationDeleteClick(self): cr = self.PresentationListView.currentRow() self.PresentationListView.removeRow(int(cr)) - self._save_display_list(self.PresentationListView) + self._save_display_list(self.PresentationListView) def onPresentationPreviewClick(self): pass diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 94548019f..a513c88f9 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -28,9 +28,11 @@ from forms import EditSongForm, OpenLPImportForm, OpenSongImportForm, \ from openlp.plugins.songs.lib import SongManager, SongsTab class SongsPlugin(Plugin, PluginUtils): + global log log=logging.getLogger("SongsPlugin") log.info("Song Plugin loaded") + def __init__(self): # Call the parent constructor Plugin.__init__(self, 'Songs', '1.9.0') @@ -49,7 +51,7 @@ class SongsPlugin(Plugin, PluginUtils): def get_media_manager_item(self): # Create the MediaManagerItem object - self.MediaManagerItem = MediaManagerItem(self.icon, 'Songs') + self.MediaManagerItem = MediaManagerItem(self, self.icon, 'Songs') # Add a toolbar self.MediaManagerItem.addToolbar() # Create buttons for the toolbar diff --git a/openlp/plugins/videos/videoplugin.py b/openlp/plugins/videos/videoplugin.py index 45400ec5f..53f184494 100644 --- a/openlp/plugins/videos/videoplugin.py +++ b/openlp/plugins/videos/videoplugin.py @@ -25,6 +25,7 @@ from openlp.core.lib import Plugin, PluginUtils, MediaManagerItem, SettingsTab from openlp.plugins.videos.lib import VideoTab class VideoPlugin(Plugin, PluginUtils): + def __init__(self): # Call the parent constructor Plugin.__init__(self, 'Videos', '1.9.0') @@ -36,12 +37,11 @@ class VideoPlugin(Plugin, PluginUtils): def get_settings_tab(self): self.VideosTab = VideoTab() - return self.VideosTab def get_media_manager_item(self): # Create the MediaManagerItem object - self.MediaManagerItem = MediaManagerItem(self.icon, 'Videos') + self.MediaManagerItem = MediaManagerItem(self, self.icon, 'Videos') # Add a toolbar self.MediaManagerItem.addToolbar() # Create buttons for the toolbar