openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #00483
[Merge] lp:~j-corwin/openlp/present into lp:openlp
Jonathan Corwin has proposed merging lp:~j-corwin/openlp/present into lp:openlp.
Requested reviews:
Raoul Snyman (raoul-snyman)
--
https://code.launchpad.net/~j-corwin/openlp/present/+merge/12683
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/presentations/lib/__init__.py'
--- openlp/plugins/presentations/lib/__init__.py 2009-09-26 20:51:05 +0000
+++ openlp/plugins/presentations/lib/__init__.py 2009-09-30 19:45:21 +0000
@@ -23,9 +23,6 @@
###############################################################################
from presentationcontroller import PresentationController
-from impresscontroller import ImpressController
-from powerpointcontroller import PowerpointController
-from pptviewcontroller import PptviewController
from messagelistener import MessageListener
from mediaitem import PresentationMediaItem
from presentationtab import PresentationTab
=== modified file 'openlp/plugins/presentations/lib/impresscontroller.py'
--- openlp/plugins/presentations/lib/impresscontroller.py 2009-09-27 12:44:11 +0000
+++ openlp/plugins/presentations/lib/impresscontroller.py 2009-09-30 19:45:21 +0000
@@ -38,7 +38,6 @@
from presentationcontroller import PresentationController
-
class ImpressController(PresentationController):
"""
Class to control interactions with Impress presentations.
@@ -47,6 +46,7 @@
"""
global log
log = logging.getLogger(u'ImpressController')
+ log.info(u'loaded')
def __init__(self, plugin):
"""
@@ -59,16 +59,17 @@
self.presentation = None
self.controller = None
- def is_available(self):
- """
- PPT Viewer is able to run on this machine
- """
- log.debug(u'is_available')
- try:
- self.start_process()
+ def check_available(self):
+ """
+ Impress is able to run on this machine
+ """
+ log.debug(u'check_available')
+ if os.name == u'nt':
+ return self.get_com_servicemanager() is not None
+ else:
+ # If not windows, and we've got this far then probably
+ # installed else the import uno would likely have failed
return True
- except:
- return False
def start_process(self):
"""
@@ -148,13 +149,21 @@
def get_com_desktop(self):
log.debug(u'getCOMDesktop')
try:
- smgr = Dispatch("com.sun.star.ServiceManager")
+ smgr = self.get_com_servicemanager()
desktop = smgr.createInstance( "com.sun.star.frame.Desktop")
return desktop
except:
log.exception(u'Failed to get COM desktop')
return None
+ def get_com_servicemanager(self):
+ log.debug(u'get_com_servicemanager')
+ try:
+ return Dispatch("com.sun.star.ServiceManager")
+ except:
+ log.exception(u'Failed to get COM service manager')
+ return None
+
def close_presentation(self):
"""
Close presentation and clean up objects
=== modified file 'openlp/plugins/presentations/lib/mediaitem.py'
--- openlp/plugins/presentations/lib/mediaitem.py 2009-09-28 20:45:04 +0000
+++ openlp/plugins/presentations/lib/mediaitem.py 2009-09-30 19:45:21 +0000
@@ -94,7 +94,8 @@
self.loadList(list)
for item in self.controllers:
#load the drop down selection
- self.DisplayTypeComboBox.addItem(item)
+ if self.controllers[item].enabled:
+ self.DisplayTypeComboBox.addItem(item)
def loadList(self, list):
for file in list:
=== modified file 'openlp/plugins/presentations/lib/powerpointcontroller.py'
--- openlp/plugins/presentations/lib/powerpointcontroller.py 2009-09-27 21:49:00 +0000
+++ openlp/plugins/presentations/lib/powerpointcontroller.py 2009-09-30 19:45:21 +0000
@@ -27,6 +27,7 @@
if os.name == u'nt':
from win32com.client import Dispatch
+ import _winreg
from presentationcontroller import PresentationController
@@ -41,7 +42,8 @@
"""
global log
log = logging.getLogger(u'PowerpointController')
-
+ log.info(u'loaded')
+
def __init__(self, plugin):
"""
Initialise the class
@@ -51,18 +53,18 @@
self.process = None
self.presentation = None
- def is_available(self):
+ def check_available(self):
"""
PowerPoint is able to run on this machine
"""
- log.debug(u'is_available')
- if os.name != u'nt':
- return False
- try:
- self.start_process()
- return True
- except:
- return False
+ log.debug(u'check_available')
+ if os.name == u'nt':
+ try:
+ _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, u'PowerPoint.Application').Close()
+ return True
+ except:
+ pass
+ return False
if os.name == u'nt':
def start_process(self):
@@ -83,6 +85,9 @@
return False
def kill(self):
+ """
+ Called at system exit to clean up any running presentations
+ """
self.process.Quit()
self.process = None
=== modified file 'openlp/plugins/presentations/lib/pptviewcontroller.py'
--- openlp/plugins/presentations/lib/pptviewcontroller.py 2009-09-26 20:51:05 +0000
+++ openlp/plugins/presentations/lib/pptviewcontroller.py 2009-09-30 19:45:21 +0000
@@ -39,37 +39,50 @@
"""
global log
log = logging.getLogger(u'PptviewController')
+ log.info(u'loaded')
def __init__(self, plugin):
"""
Initialise the class
"""
log.debug(u'Initialising')
+ self.process = None
PresentationController.__init__(self, plugin, u'Powerpoint Viewer')
- self.process = None
self.pptid = None
self.thumbnailpath = os.path.join(plugin.config.get_data_path(),
u'pptview', u'thumbnails')
self.thumbprefix = u'slide'
- def is_available(self):
+ def check_available(self):
"""
PPT Viewer is able to run on this machine
"""
- log.debug(u'is_available')
+ log.debug(u'check_available')
if os.name != u'nt':
return False
try:
- self.start_process()
- return True
+ return self.check_installed()
except:
return False
if os.name == u'nt':
+ def check_installed(self):
+ """
+ Check the viewer is installed
+ """
+ log.debug(u'Check installed')
+ try:
+ self.start_process()
+ return self.process.CheckInstalled()
+ except:
+ return False
+
def start_process(self):
"""
Loads the PPTVIEWLIB library
"""
+ if self.process is not None:
+ return
log.debug(u'start PPTView')
self.process = cdll.LoadLibrary(r'openlp\plugins\presentations\lib\pptviewlib\pptviewlib.dll')
=== modified file 'openlp/plugins/presentations/lib/pptviewlib/README.TXT'
--- openlp/plugins/presentations/lib/pptviewlib/README.TXT 2009-09-13 15:14:45 +0000
+++ openlp/plugins/presentations/lib/pptviewlib/README.TXT 2009-09-30 19:45:21 +0000
@@ -25,6 +25,9 @@
USAGE
-----
+BOOL CheckInstalled(void);
+ Returns TRUE if PowerPointViewer is installed. FALSE if not.
+
int OpenPPT(char *filename, HWND hParentWnd, RECT rect, char *previewpath);
Opens the PowerPoint file, counts the number of slides, sizes and positions accordingly
=== modified file 'openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp'
--- openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp 2009-09-23 20:40:19 +0000
+++ openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp 2009-09-30 19:45:21 +0000
@@ -82,6 +82,14 @@
DEBUG("enabled\n");
}
+DllExport BOOL CheckInstalled()
+{
+ DEBUG("CheckInstalled\n");
+ char cmdline[MAX_PATH * 2];
+
+ return GetPPTViewerPath(cmdline, sizeof(cmdline));
+}
+
// Open the PointPoint, count the slides and take a snapshot of each slide
// for use in previews
// previewpath is a prefix for the location to put preview images of each slide.
=== modified file 'openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h'
--- openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h 2009-09-23 20:40:19 +0000
+++ openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h 2009-09-30 19:45:21 +0000
@@ -4,6 +4,7 @@
enum PPTVIEWSTATE { PPT_CLOSED, PPT_STARTED, PPT_OPENED, PPT_LOADED, PPT_CLOSING};
DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, char *previewpath);
+DllExport BOOL CheckInstalled();
DllExport void ClosePPT(int id);
DllExport int GetCurrentSlide(int id);
DllExport int GetSlideCount(int id);
=== modified file 'openlp/plugins/presentations/lib/presentationcontroller.py'
--- openlp/plugins/presentations/lib/presentationcontroller.py 2009-09-28 19:34:55 +0000
+++ openlp/plugins/presentations/lib/presentationcontroller.py 2009-09-30 19:45:21 +0000
@@ -20,6 +20,8 @@
import logging
+from PyQt4 import QtCore
+
class PresentationController(object):
"""
Base class for presentation controllers to inherit from
@@ -32,6 +34,13 @@
``name``
The name that appears in the options and the media manager
+ ``enabled``
+ The controller is enabled
+
+ ``available``
+ The controller is available on this machine. Set by init via
+ call to check_available
+
``plugin``
The presentationplugin object
@@ -40,7 +49,7 @@
``kill()``
Called at system exit to clean up any running presentations
- ``is_available()``
+ ``check_available()``
Returns True if presentation application is installed/can run on this machine
``load_presentation(presentation)``
@@ -108,8 +117,14 @@
"""
self.plugin = plugin
self.name = name
+ self.available = self.check_available()
+ if self.available:
+ self.enabled = int(plugin.config.get_config(
+ name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked
+ else:
+ self.enabled = False
- def is_available(self):
+ def check_available(self):
"""
Presentation app is able to run on this machine
"""
=== modified file 'openlp/plugins/presentations/lib/presentationtab.py'
--- openlp/plugins/presentations/lib/presentationtab.py 2009-09-26 20:51:05 +0000
+++ openlp/plugins/presentations/lib/presentationtab.py 2009-09-30 19:45:21 +0000
@@ -60,24 +60,17 @@
self.VerseTypeLayout.setSpacing(8)
self.VerseTypeLayout.setMargin(0)
self.VerseTypeLayout.setObjectName(u'VerseTypeLayout')
- self.PowerpointCheckBox = QtGui.QCheckBox(self.VerseDisplayGroupBox)
- self.PowerpointCheckBox.setTristate(False)
- if os.name != u'nt':
- self.PowerpointCheckBox.setEnabled(False)
- self.PowerpointCheckBox.setObjectName(u'PowerpointCheckBox')
- self.VerseDisplayLayout.addWidget(self.PowerpointCheckBox, 0, 0, 1, 1)
- self.PowerpointViewerCheckBox = QtGui.QCheckBox(
- self.VerseDisplayGroupBox)
- self.PowerpointViewerCheckBox.setTristate(False)
- if os.name != u'nt':
- self.PowerpointViewerCheckBox.setEnabled(False)
- self.PowerpointViewerCheckBox.setObjectName(u'PowerpointViewerCheckBox')
- self.VerseDisplayLayout.addWidget(
- self.PowerpointViewerCheckBox, 1, 0, 1, 1)
- self.ImpressCheckBox = QtGui.QCheckBox(self.VerseDisplayGroupBox)
- self.ImpressCheckBox.setTristate(False)
- self.ImpressCheckBox.setObjectName(u'ImpressCheckBox')
- self.VerseDisplayLayout.addWidget(self.ImpressCheckBox, 2, 0, 1, 1)
+ self.PresenterCheckboxes = {}
+ index = 0
+ for key in self.controllers:
+ controller = self.controllers[key]
+ checkbox = QtGui.QCheckBox(self.VerseDisplayGroupBox)
+ checkbox.setTristate(False)
+ checkbox.setEnabled(controller.available)
+ checkbox.setObjectName(controller.name + u'CheckBox')
+ self.PresenterCheckboxes[controller.name] = checkbox
+ index = index + 1
+ self.VerseDisplayLayout.addWidget(checkbox, index, 0, 1, 1)
self.PresentationThemeWidget = QtGui.QWidget(self.VerseDisplayGroupBox)
self.PresentationThemeWidget.setObjectName(u'PresentationThemeWidget')
self.PresentationThemeLayout = QtGui.QHBoxLayout(
@@ -103,26 +96,23 @@
self.PresentationLayout.addWidget(self.PresentationRightWidget)
def retranslateUi(self):
- self.PowerpointCheckBox.setText(
- translate(u'PresentationTab', 'Powerpoint available:'))
- self.PowerpointViewerCheckBox.setText(
- translate(u'PresentationTab', 'PowerpointViewer available:'))
- self.ImpressCheckBox.setText(
- translate(u'PresentationTab', 'Impress available:'))
+ for key in self.controllers:
+ controller = self.controllers[key]
+ checkbox = self.PresenterCheckboxes[controller.name]
+ checkbox.setText(translate(u'PresentationTab',
+ controller.name + u' available:'))
def load(self):
- self.PowerpointCheckBox.setChecked(
- int(self.config.get_config(u'Powerpoint', 0)))
- self.PowerpointViewerCheckBox.setChecked(
- int(self.config.get_config(u'Powerpoint Viewer', 0)))
- self.ImpressCheckBox.setChecked(
- int(self.config.get_config(u'Impress', 0)))
+ for key in self.controllers:
+ controller = self.controllers[key]
+ if controller.available:
+ checkbox = self.PresenterCheckboxes[controller.name]
+ checkbox.setChecked(
+ int(self.config.get_config(controller.name, 0)))
def save(self):
- self.config.set_config(
- u'Powerpoint', unicode(self.PowerpointCheckBox.checkState()))
- self.config.set_config(
- u'Powerpoint Viewer',
- unicode(self.PowerpointViewerCheckBox.checkState()))
- self.config.set_config(
- u'Impress', unicode(self.ImpressCheckBox.checkState()))
+ for key in self.controllers:
+ controller = self.controllers[key]
+ checkbox = self.PresenterCheckboxes[controller.name]
+ self.config.set_config(
+ controller.name, unicode(checkbox.checkState()))
=== modified file 'openlp/plugins/presentations/presentationplugin.py'
--- openlp/plugins/presentations/presentationplugin.py 2009-09-29 17:05:34 +0000
+++ openlp/plugins/presentations/presentationplugin.py 2009-09-30 19:45:21 +0000
@@ -22,11 +22,12 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
+import os
import logging
-from PyQt4 import QtCore
+from PyQt4 import QtGui
-from openlp.core.lib import Plugin, buildIcon
+from openlp.core.lib import Plugin
from openlp.plugins.presentations.lib import *
class PresentationPlugin(Plugin):
@@ -41,7 +42,9 @@
Plugin.__init__(self, u'Presentations', u'1.9.0', plugin_helpers)
self.weight = -8
# Create the plugin icon
- self.icon = buildIcon(u':/media/media_presentation.png')
+ self.icon = QtGui.QIcon()
+ self.icon.addPixmap(QtGui.QPixmap(u':/media/media_presentation.png'),
+ QtGui.QIcon.Normal, QtGui.QIcon.Off)
def get_settings_tab(self):
"""
@@ -67,25 +70,25 @@
If Not do not install the plugin.
"""
log.debug(u'check_pre_conditions')
- #Lets see if Powerpoint is required (Default is Not wanted)
- controller = PowerpointController(self)
- if int(self.config.get_config(
- controller.name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked:
- if controller.is_available():
- self.registerControllers(controller)
- #Lets see if Impress is required (Default is Not wanted)
- controller = ImpressController(self)
- if int(self.config.get_config(
- controller.name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked:
- if controller.is_available():
- self.registerControllers(controller)
- #Lets see if Powerpoint Viewer is required (Default is Not wanted)
- controller = PptviewController(self)
- if int(self.config.get_config(
- controller.name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked:
- if controller.is_available():
- self.registerControllers(controller)
- #If we have no available controllers disable plugin
+ dir = os.path.join(os.path.dirname(__file__), u'lib')
+ for filename in os.listdir(dir):
+ if filename.endswith(u'controller.py') and \
+ not filename == 'presentationcontroller.py':
+ path = os.path.join(dir, filename)
+ if os.path.isfile(path):
+ modulename = u'openlp.plugins.presentations.lib.' + \
+ os.path.splitext(filename)[0]
+ log.debug(u'Importing controller %s', modulename)
+ try:
+ __import__(modulename, globals(), locals(), [])
+ except ImportError, e:
+ log.error(u'Failed to import %s on path %s for reason %s', modulename, path, e.args[0])
+ controller_classes = PresentationController.__subclasses__()
+ for controller_class in controller_classes:
+ controller = controller_class(self)
+ self.registerControllers(controller)
+ if controller.enabled:
+ controller.start_process()
if len(self.controllers) > 0:
return True
else:
@@ -94,5 +97,7 @@
def finalise(self):
log.debug(u'Finalise')
#Ask each controller to tidy up
- for controller in self.controllers:
- self.controllers[controller].kill()
+ for key in self.controllers:
+ controller = self.controllers[key]
+ if controller.enabled:
+ controller.kill()
References