From ad48e1f4e6b87646aa930480d91db072d04357a8 Mon Sep 17 00:00:00 2001 From: Martin Thompson Date: Fri, 20 Feb 2009 21:13:04 +0000 Subject: [PATCH] Allowed slide contrllers to be passed to the plugins. It's broken at the moment though! bzr-revno: 331 --- openlp/core/lib/imageserviceitem.py | 28 +++++++++++++++++++++++++--- openlp/core/lib/plugin.py | 5 +++-- openlp/core/pluginmanager.py | 17 ++++++++++++----- openlp/core/ui/mainwindow.py | 6 ++++++ openlp/core/ui/slidecontroller.py | 3 ++- openlp/plugins/images/imageplugin.py | 8 ++++---- 6 files changed, 52 insertions(+), 15 deletions(-) diff --git a/openlp/core/lib/imageserviceitem.py b/openlp/core/lib/imageserviceitem.py index 659bbddd8..51818b866 100644 --- a/openlp/core/lib/imageserviceitem.py +++ b/openlp/core/lib/imageserviceitem.py @@ -17,6 +17,7 @@ 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 """ +from PyQt4 import QtCore, QtGui class ImageServiceItem(): """ @@ -24,11 +25,23 @@ class ImageServiceItem(): the service manager, the slide controller, and the renderer. """ - def __init__(self): + def __init__(self, controller): """ Init Method """ self.imgs=[] + self.slide_controller=controller + self.slide_controller.ControllerContents=QtGui.QTableWidget() + c=self.slide_controller.ControllerContents + c.setColumnCount(2) + c.setColumnHidden(0, True) + c.setColumnWidth(1, 275) + c.setShowGrid(False) + c.setSortingEnabled(False) + c.setAlternatingRowColors(True) + c.setHorizontalHeaderLabels(QtCore.QStringList(["","Name"])) + c.setAlternatingRowColors(True) + c.setGeometry(QtCore.QRect(10, 100, 256, 591)) pass def render(self): @@ -36,7 +49,16 @@ class ImageServiceItem(): The render method is what the plugin uses to render its meda to the screen. """ - pass + # render the "image chooser first" + for f in self.imgs: + fl , nm = os.path.split(str(f)) + c = self.slide_controller.rowCount() + self.slide_controller.setRowCount(c+1) + twi = QtGui.QTableWidgetItem(str(f)) + self.slide_controller.setItem(c , 0, twi) + twi = QtGui.QTableWidgetItem(str(nm)) + self.slide_controller.setItem(c , 1, twi) + self.slide_controller.setRowHeight(c, 20) def get_parent_node(self): """ @@ -61,4 +83,4 @@ class ImageServiceItem(): get text from the OOS file and setup the internal structure """ self.imgs=eval(text) - + diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 0acb1bc4a..e68adde67 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -67,7 +67,7 @@ class Plugin(object): and screen number. """ - def __init__(self, name=None, version=None): + def __init__(self, name=None, version=None, preview_controller=None, live_controller=None): """ This is the constructor for the plugin object. This provides an easy way for descendent plugins to populate common data. This method *must* @@ -89,7 +89,8 @@ class Plugin(object): # Set up logging self.log = logging.getLogger(self.name) self.repaint_main_window = None - + self.preview_controller=preview_controller + self.live_controller=live_controller def check_pre_conditions(self): """ Provides the Plugin with a handle to check if it can be loaded. diff --git a/openlp/core/pluginmanager.py b/openlp/core/pluginmanager.py index da2a0e618..6881909bb 100644 --- a/openlp/core/pluginmanager.py +++ b/openlp/core/pluginmanager.py @@ -35,7 +35,8 @@ class PluginManager(object): def __init__(self, dir): """ - The constructor for the plugin manager. This does a, b and c. + The constructor for the plugin manager. + Passes the controllers on to the plugins for them to interact with via their ServiceItems """ log.info("Plugin manager initing") if not dir in sys.path: @@ -44,13 +45,14 @@ class PluginManager(object): self.basepath = os.path.abspath(dir) log.debug("Base path %s ", self.basepath) self.plugins = [] - self.find_plugins(dir) + # this has to happen after the UI is sroted self.find_plugins(dir) log.info("Plugin manager done init") - - def find_plugins(self, dir): + def find_plugins(self, dir, preview_controller, live_controller): # xxx shouldn't dir come from self.basepath """ Scan the directory dir for objects inheriting from openlp.plugin """ + self.preview_controller=preview_controller + self.live_controller=live_controller startdepth=len(os.path.abspath(dir).split(os.sep)) log.debug("find plugins %s at depth %d" %( str(dir), startdepth)) @@ -76,7 +78,12 @@ class PluginManager(object): self.plugins = [] plugin_objects = [] for p in self.plugin_classes: - plugin = p() + try: + plugin = p(self.preview_controller, self.live_controller) + log.debug('loaded plugin' + str(p) + ' with controllers'+str(self.preview_controller)+str(self.live_controller)) + except TypeError: # xxx need to get rid of this once all plugins are up to date + plugin = p() + log.debug('loaded plugin' + str(p) + ' with no controllers') if plugin.check_pre_conditions(): plugin_objects.append(plugin) self.plugins = sorted(plugin_objects, self.order_by_weight) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index d6b7eb923..4972557e0 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -40,6 +40,12 @@ class MainWindow(object): pluginpath = os.path.abspath(os.path.join(pluginpath, '..', '..','plugins')) self.plugin_manager = PluginManager(pluginpath) self.setupUi() + self.plugin_manager.find_plugins(pluginpath, self.PreviewController, self.LiveController) + self.receiver = Receiver() + QtCore.QObject.connect(self.receiver.get_receiver(),QtCore.SIGNAL("openlprepaint"),self.repaint) + + def repaint(self): + self.main_window.repaint() def setupUi(self): self.main_window.setObjectName("main_window") diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 8cf226717..1f11dcf08 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -21,8 +21,9 @@ import os from time import sleep from PyQt4 import QtCore, QtGui -class SlideController(QtCore.QObject): +class SlideController(QtGui.QWidget): def __init__(self, control_splitter): + QtGui.QWidget.__init__(self) self.Pane = QtGui.QWidget(control_splitter) self.Splitter = QtGui.QSplitter(self.Pane) self.Splitter.setOrientation(QtCore.Qt.Vertical) diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index 703be3aa8..9e2e26f5b 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -24,17 +24,17 @@ from openlp.core.lib import Plugin, PluginUtils, MediaManagerItem, ImageServiceI #from forms import EditSongForm class ImagePlugin(Plugin, PluginUtils): - def __init__(self): + def __init__(self, preview_controller, live_controller): # Call the parent constructor - Plugin.__init__(self, 'Images', '1.9.0') + Plugin.__init__(self, 'Images', '1.9.0', preview_controller, live_controller) self.weight = -7 # Create the plugin icon self.icon = QtGui.QIcon() self.icon.addPixmap(QtGui.QPixmap(':/media/media_image.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.preview_service_item=ImageServiceItem() - self.live_service_item=ImageServiceItem() + self.preview_service_item=ImageServiceItem(preview_controller) + self.live_service_item=ImageServiceItem(live_controller) def get_media_manager_item(self): # Create the MediaManagerItem object