← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~j-corwin/openlp/presentations into lp:openlp

 

Jonathan Corwin has proposed merging lp:~j-corwin/openlp/presentations into lp:openlp.

Requested reviews:
    openlp.org Core (openlp-core)

If on Windows, use COM rather than PyUNO for controlling Impress. 
-- 
https://code.launchpad.net/~j-corwin/openlp/presentations/+merge/12005
Your team openlp.org Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/presentations/lib/impresscontroller.py'
--- openlp/plugins/presentations/lib/impresscontroller.py	2009-09-11 19:29:57 +0000
+++ openlp/plugins/presentations/lib/impresscontroller.py	2009-09-17 07:28:47 +0000
@@ -29,9 +29,14 @@
 import logging
 import os ,  subprocess
 import time
-import uno
 import sys
 
+if os.name == u'nt':
+    from win32com.client import Dispatch
+else:
+    import uno
+
+
 from PyQt4 import QtCore
 
 class ImpressController(object):
@@ -57,11 +62,12 @@
         when required.
         """
         log.debug(u'start Openoffice')
-        # -headless
-        cmd = u'openoffice.org -nologo -norestore -minimized -invisible ' + u'"' + u'-accept=socket,host=localhost,port=2002;urp;'+ u'"'
-        self.process = QtCore.QProcess()
-        self.process.startDetached(cmd)
-        self.process.waitForStarted()
+        if os.name != u'nt':
+            # -headless
+            cmd = u'openoffice.org -nologo -norestore -minimized -invisible ' + u'"' + u'-accept=socket,host=localhost,port=2002;urp;'+ u'"'
+            self.process = QtCore.QProcess()
+            self.process.startDetached(cmd)
+            self.process.waitForStarted()
 
     def kill(self):
         """
@@ -81,6 +87,26 @@
         The file name of the presentatios to the run.
         """
         log.debug(u'LoadPresentation')
+        if os.name == u'nt':
+            desktop = self.getCOMDesktop()
+            url = u'file:///' + presentation.replace(u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')            
+        else:
+            desktop = self.getUNODesktop()
+            url = uno.systemPathToFileUrl(presentation)
+        if(desktop==None):
+            return            
+        try:
+            properties = []
+            properties = tuple(properties)
+            self.document = desktop.loadComponentFromURL(url, "_blank", 0, properties)
+            self.presentation = self.document.getPresentation()
+            self.presentation.start()
+            self.xSlideShowController =  desktop.getCurrentComponent().Presentation.getController()
+        except:
+            log.error(u'Failed reason %s' % sys.exc_info())
+
+    def getUNODesktop(self):
+        log.debug(u'getUNODesktop')
         ctx = None
         loop = 0
         context = uno.getComponentContext()
@@ -94,15 +120,20 @@
         try:
             smgr = ctx.ServiceManager
             desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop", ctx )
-            url = uno.systemPathToFileUrl(presentation)
-            properties = []
-            properties = tuple(properties)
-            self.document = desktop.loadComponentFromURL(url, "_blank", 0, properties)
-            self.presentation = self.document.getPresentation()
-            self.presentation.start()
-            self.xSlideShowController =  desktop.getCurrentComponent().Presentation.getController()
-        except:
-            log.error(u'Failed reason %s' % sys.exc_info())
+            return desktop
+        except:
+            log.error(u'Failed reason %s' % sys.exc_info())
+            return None
+
+    def getCOMDesktop(self):
+        log.debug(u'getCOMDesktop')
+        try:
+            smgr = Dispatch("com.sun.star.ServiceManager")
+            desktop = smgr.createInstance( "com.sun.star.frame.Desktop")
+            return desktop
+        except:
+            log.error(u'Failed reason %s' % sys.exc_info())
+            return None
 
     def closePresentation(self):
         """

=== modified file 'openlp/plugins/presentations/presentationplugin.py'
--- openlp/plugins/presentations/presentationplugin.py	2009-09-13 07:39:48 +0000
+++ openlp/plugins/presentations/presentationplugin.py	2009-09-17 07:28:47 +0000
@@ -79,8 +79,12 @@
         #Lets see if Impress is required (Default is Not wanted)
         if int(self.config.get_config(u'Impress', QtCore.Qt.Unchecked)) == QtCore.Qt.Checked:
             try:
-                #Check to see if we have uno installed
-                import uno
+                if os.name == u'nt':
+                    #Check to see if we are Win32
+                    from win32com.client import Dispatch
+                else:
+                    #Check to see if we have uno installed
+                    import uno
                 openoffice = ImpressController()
                 self.registerControllers(u'Impress', openoffice)
             except:


Follow ups