← Back to team overview

openlp-core team mailing list archive

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

 

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

Requested reviews:
  Jon Tibble (meths)
  Raoul Snyman (raoul-snyman): needs fixing


Presentation changes:
Coding standards
Specific Exception catching in PptViewer and Powerpoint (Impress still to do)
Fix Show Screen for PptViewer and Impress
Small change to assist in PowerPoint viewer 2010 support in the future
Better detection of PptViewer not being able to open requested file

Will be a separate merge request for the pptviewlib.dll. (Might be worth considering trying to incorporate building of this in Windows nightly build after Alpha 2, but would require MS Visual C++ Express installed)

-- 
https://code.launchpad.net/~j-corwin/openlp/present/+merge/28450
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/presentations/lib/impresscontroller.py'
--- openlp/plugins/presentations/lib/impresscontroller.py	2010-06-14 22:01:04 +0000
+++ openlp/plugins/presentations/lib/impresscontroller.py	2010-06-24 19:49:24 +0000
@@ -331,7 +331,10 @@
 
     def stop_presentation(self):
         log.debug(u'stop presentation OpenOffice')
-        self.control.deactivate()
+        # deactivate should hide the screen according to docs, but doesn't
+        #self.control.deactivate()
+        self.presentation.end()
+        self.control = None
 
     def start_presentation(self):
         log.debug(u'start presentation OpenOffice')

=== modified file 'openlp/plugins/presentations/lib/messagelistener.py'
--- openlp/plugins/presentations/lib/messagelistener.py	2010-06-16 21:22:02 +0000
+++ openlp/plugins/presentations/lib/messagelistener.py	2010-06-24 19:49:24 +0000
@@ -41,31 +41,31 @@
     log.info(u'Controller loaded')
 
     def __init__(self, live):
-        self.isLive = live
+        self.is_live = live
         self.doc = None
         log.info(u'%s controller loaded' % live)
 
-    def addHandler(self, controller, file, isBlank):
-        log.debug(u'Live = %s, addHandler %s' % (self.isLive, file))
+    def add_handler(self, controller, file, is_blank):
+        log.debug(u'Live = %s, add_handler %s' % (self.is_live, file))
         self.controller = controller
         if self.doc is not None:
             self.shutdown()
         self.doc = self.controller.add_doc(file)
         self.doc.load_presentation()
-        if self.isLive:
+        if self.is_live:
             self.doc.start_presentation()
-            if isBlank:
+            if is_blank:
                 self.blank()
             Receiver.send_message(u'maindisplay_hide', HideMode.Screen)
         self.doc.slidenumber = 0
 
     def activate(self):
-        log.debug(u'Live = %s, activate' % self.isLive)
+        log.debug(u'Live = %s, activate' % self.is_live)
         if self.doc.is_active():
             return
         if not self.doc.is_loaded():
             self.doc.load_presentation()
-        if self.isLive:
+        if self.is_live:
             self.doc.start_presentation()
             if self.doc.slidenumber > 1:
                 self.doc.goto_slide(self.doc.slidenumber)
@@ -85,36 +85,36 @@
         """
         Based on the handler passed at startup triggers the first slide
         """
-        log.debug(u'Live = %s, first' % self.isLive)
-        if not self.isLive:
+        log.debug(u'Live = %s, first' % self.is_live)
+        if not self.is_live:
             return
         if self.doc.is_blank():
             self.doc.slidenumber = 1
             return
         self.activate()
         self.doc.start_presentation()
-        self.doc.poll_slidenumber(self.isLive)
+        self.doc.poll_slidenumber(self.is_live)
 
     def last(self):
         """
         Based on the handler passed at startup triggers the first slide
         """
-        log.debug(u'Live = %s, last' % self.isLive)
-        if not self.isLive:
+        log.debug(u'Live = %s, last' % self.is_live)
+        if not self.is_live:
             return
         if self.doc.is_blank():
             self.doc.slidenumber = self.doc.get_slide_count()
             return
         self.activate()
         self.doc.goto_slide(self.doc.get_slide_count())
-        self.doc.poll_slidenumber(self.isLive)
+        self.doc.poll_slidenumber(self.is_live)
 
     def next(self):
         """
         Based on the handler passed at startup triggers the next slide event
         """
-        log.debug(u'Live = %s, next' % self.isLive)
-        if not self.isLive:
+        log.debug(u'Live = %s, next' % self.is_live)
+        if not self.is_live:
             return
         if self.doc.is_blank():
             if self.doc.slidenumber < self.doc.get_slide_count():
@@ -122,14 +122,14 @@
             return
         self.activate()
         self.doc.next_step()
-        self.doc.poll_slidenumber(self.isLive)
+        self.doc.poll_slidenumber(self.is_live)
 
     def previous(self):
         """
         Based on the handler passed at startup triggers the previous slide event
         """
-        log.debug(u'Live = %s, previous' % self.isLive)
-        if not self.isLive:
+        log.debug(u'Live = %s, previous' % self.is_live)
+        if not self.is_live:
             return
         if self.doc.is_blank():
             if self.doc.slidenumber > 1:
@@ -137,14 +137,14 @@
             return
         self.activate()
         self.doc.previous_step()
-        self.doc.poll_slidenumber(self.isLive)
+        self.doc.poll_slidenumber(self.is_live)
 
     def shutdown(self):
         """
         Based on the handler passed at startup triggers slide show to shut down
         """
-        log.debug(u'Live = %s, shutdown' % self.isLive)
-        if self.isLive:
+        log.debug(u'Live = %s, shutdown' % self.is_live)
+        if self.is_live:
             Receiver.send_message(u'maindisplay_show')
         self.doc.close_presentation()
         self.doc = None
@@ -152,8 +152,8 @@
         #self.timer.stop()
 
     def blank(self):
-        log.debug(u'Live = %s, blank' % self.isLive)
-        if not self.isLive:
+        log.debug(u'Live = %s, blank' % self.is_live)
+        if not self.is_live:
             return
         if not self.doc.is_loaded():
             return
@@ -162,8 +162,8 @@
         self.doc.blank_screen()
 
     def stop(self):
-        log.debug(u'Live = %s, stop' % self.isLive)
-        if not self.isLive:
+        log.debug(u'Live = %s, stop' % self.is_live)
+        if not self.is_live:
             return
         if not self.doc.is_loaded():
             return
@@ -172,8 +172,8 @@
         self.doc.stop_presentation()
 
     def unblank(self):
-        log.debug(u'Live = %s, unblank' % self.isLive)
-        if not self.isLive:
+        log.debug(u'Live = %s, unblank' % self.is_live)
+        if not self.is_live:
             return
         self.activate()
         if self.doc.slidenumber and \
@@ -183,7 +183,7 @@
         Receiver.send_message(u'maindisplay_hide', HideMode.Screen)
 
     def poll(self):
-        self.doc.poll_slidenumber(self.isLive)
+        self.doc.poll_slidenumber(self.is_live)
 
 class MessageListener(object):
     """
@@ -195,8 +195,8 @@
     def __init__(self, mediaitem):
         self.controllers = mediaitem.controllers
         self.mediaitem = mediaitem
-        self.previewHandler = Controller(False)
-        self.liveHandler = Controller(True)
+        self.preview_handler = Controller(False)
+        self.live_handler = Controller(True)
         # messages are sent from core.ui.slidecontroller
         QtCore.QObject.connect(Receiver.get_receiver(),
             QtCore.SIGNAL(u'presentations_start'), self.startup)
@@ -228,9 +228,10 @@
         Start of new presentation
         Save the handler as any new presentations start here
         """
-        isLive, item = self.decode_message(message)
+        is_live = message[1]
+        item = message[0]
         log.debug(u'Startup called with message %s' % message)
-        isBlank = message[2]
+        is_blank = message[2]
         file = os.path.join(item.get_frame_path(),
             item.get_frame_title())
         self.handler = item.title
@@ -238,75 +239,71 @@
             self.handler = self.mediaitem.findControllerByType(file)
             if not self.handler:
                 return
-        if isLive:
-            controller = self.liveHandler
-        else:
-            controller = self.previewHandler
-        controller.addHandler(self.controllers[self.handler], file, isBlank)
-
-    def decode_message(self, message):
-        if len(message) == 3:
-            return message[1], message[0], message[2]
-        else:
-            return message[1], message[0]
+        if is_live:
+            controller = self.live_handler
+        else:
+            controller = self.preview_handler
+        controller.add_handler(self.controllers[self.handler], file, is_blank)
 
     def slide(self, message):
-        isLive, item, slide = self.decode_message(message)
-        if isLive:
-            self.liveHandler.slide(slide, isLive)
+        is_live = message[1]
+        slide = message[2]
+        item = message[0]
+        if is_live:
+            self.live_handler.slide(slide, item)
         else:
-            self.previewHandler.slide(slide, isLive)
+            self.preview_handler.slide(slide, item)
 
     def first(self, message):
-        isLive = self.decode_message(message)[0]
-        if isLive:
-            self.liveHandler.first()
+        is_live = message[1]
+        if is_live:
+            self.live_handler.first()
         else:
-            self.previewHandler.first()
+            self.preview_handler.first()
 
     def last(self, message):
-        isLive = self.decode_message(message)[0]
-        if isLive:
-            self.liveHandler.last()
+        is_live = message[1]
+        if is_live:
+            self.live_handler.last()
         else:
-            self.previewHandler.last()
+            self.preview_handler.last()
 
     def next(self, message):
-        isLive = self.decode_message(message)[0]
-        if isLive:
-            self.liveHandler.next()
+        is_live = message[1]
+        if is_live:
+            self.live_handler.next()
         else:
-            self.previewHandler.next()
+            self.preview_handler.next()
 
     def previous(self, message):
-        isLive = self.decode_message(message)[0]
-        if isLive:
-            self.liveHandler.previous()
+        is_live = message[1]
+        if is_live:
+            self.live_handler.previous()
         else:
-            self.previewHandler.previous()
+            self.preview_handler.previous()
 
     def shutdown(self, message):
-        isLive = self.decode_message(message)[0]
-        if isLive:
+        is_live = message[1]
+        if is_live:
             Receiver.send_message(u'maindisplay_show')
-            self.liveHandler.shutdown()
+            self.live_handler.shutdown()
         else:
-            self.previewHandler.shutdown()
+            self.preview_handler.shutdown()
 
     def hide(self, message):
-        isLive = self.decode_message(message)[0]
-        if isLive:
-            self.liveHandler.stop()
+        is_live = message[1]
+        if is_live:
+            self.live_handler.stop()
 
     def blank(self, message):
-        isLive = self.decode_message(message)[0]
-        if isLive:
-            self.liveHandler.blank()
+        is_live = message[1]
+        if is_live:
+            self.live_handler.blank()
 
     def unblank(self, message):
-        isLive = self.decode_message(message)[0]
-        if isLive:
-            self.liveHandler.unblank()
+        is_live = message[1]
+        if is_live:
+            self.live_handler.unblank()
 
     def timeout(self):
-        self.liveHandler.poll()
+        self.live_handler.poll()

=== modified file 'openlp/plugins/presentations/lib/powerpointcontroller.py'
--- openlp/plugins/presentations/lib/powerpointcontroller.py	2010-06-14 22:01:04 +0000
+++ openlp/plugins/presentations/lib/powerpointcontroller.py	2010-06-24 19:49:24 +0000
@@ -30,6 +30,7 @@
     from win32com.client import Dispatch
     import _winreg
     import win32ui
+    import pywintypes
 
 from presentationcontroller import PresentationController, PresentationDocument
 
@@ -65,7 +66,7 @@
                 _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT,
                     u'PowerPoint.Application').Close()
                 return True
-            except:
+            except WindowsError:
                 pass
         return False
 
@@ -91,7 +92,7 @@
                 return
             try:
                 self.process.Quit()
-            except:
+            except pywintypes.com_error:
                 pass
             self.process = None
 
@@ -121,11 +122,8 @@
         log.debug(u'LoadPresentation')
         if not self.controller.process.Visible:
             self.controller.start_process()
-        #try:
         self.controller.process.Presentations.Open(self.filepath, False, False,
             True)
-        #except:
-        #    return
         self.presentation = self.controller.process.Presentations(
             self.controller.process.Presentations.Count)
         self.create_thumbnails()
@@ -154,7 +152,7 @@
         if self.presentation:
             try:
                 self.presentation.Close()
-            except:
+            except pywintypes.com_error:
                 pass
         self.presentation = None
         self.controller.remove_doc(self)
@@ -170,7 +168,9 @@
                 return False
             if self.controller.process.Presentations.Count == 0:
                 return False
-        except:
+        except AttributeError:
+            return False
+        except pywintypes.com_error:
             return False
         return True
 
@@ -186,7 +186,7 @@
                 return False
             if self.presentation.SlideShowWindow.View is None:
                 return False
-        except:
+        except (AttributeError, pywintypes.com_error):
             return False
         return True
 
@@ -208,7 +208,10 @@
         """
         Returns true if screen is blank
         """
-        return self.presentation.SlideShowWindow.View.State == 3
+        if self.is_active():
+            return self.presentation.SlideShowWindow.View.State == 3
+        else:
+            return False
 
     def stop_presentation(self):
         """
@@ -224,11 +227,11 @@
             #SlideShowWindow measures its size/position by points, not pixels
             try:
                 dpi = win32ui.GetActiveWindow().GetDC().GetDeviceCaps(88)
-            except:
+            except win32ui.error:
                 try:
                     dpi = \
                         win32ui.GetForegroundWindow().GetDC().GetDeviceCaps(88)
-                except:
+                except win32ui.error:
                     dpi = 96
             self.presentation.SlideShowSettings.Run()
             self.presentation.SlideShowWindow.View.GotoSlide(1)

=== modified file 'openlp/plugins/presentations/lib/pptviewcontroller.py'
--- openlp/plugins/presentations/lib/pptviewcontroller.py	2010-06-14 22:01:04 +0000
+++ openlp/plugins/presentations/lib/pptviewcontroller.py	2010-06-24 19:49:24 +0000
@@ -58,10 +58,7 @@
         log.debug(u'check_available')
         if os.name != u'nt':
             return False
-        try:
-            return self.check_installed()
-        except:
-            return False
+        return self.check_installed()
 
     if os.name == u'nt':
         def check_installed(self):
@@ -72,7 +69,7 @@
             try:
                 self.start_process()
                 return self.process.CheckInstalled()
-            except:
+            except WindowsError:
                 return False
 
         def start_process(self):
@@ -84,6 +81,7 @@
             log.debug(u'start PPTView')
             self.process = cdll.LoadLibrary(
                 r'openlp\plugins\presentations\lib\pptviewlib\pptviewlib.dll')
+            #self.process.SetDebug(1)
 
         def kill(self):
             """
@@ -106,6 +104,7 @@
         self.presentation = None
         self.pptid = None
         self.blanked = False
+        self.hidden = False
 
     def load_presentation(self):
         """
@@ -123,13 +122,11 @@
         rect = rendermanager.screens.current[u'size']
         rect = RECT(rect.x(), rect.y(), rect.right(), rect.bottom())
         filepath = str(self.filepath.replace(u'/', u'\\'))
-        try:
-            self.pptid = self.controller.process.OpenPPT(filepath, None, rect,
-                str(os.path.join(self.thumbnailpath,
-                self.controller.thumbnailprefix)))
+        self.pptid = self.controller.process.OpenPPT(filepath, None, rect,
+            str(os.path.join(self.thumbnailpath,
+            self.controller.thumbnailprefix)))
+        if self.pptid:
             self.stop_presentation()
-        except:
-            log.exception(u'Failed to load presentation')
 
     def close_presentation(self):
         """
@@ -156,7 +153,7 @@
         """
         Returns true if a presentation is currently active
         """
-        return self.is_loaded()
+        return self.is_loaded() and not self.hidden
 
     def blank_screen(self):
         """
@@ -183,13 +180,18 @@
         """
         Stops the current presentation and hides the output
         """
+        self.hidden = True
         self.controller.process.Stop(self.pptid)
 
     def start_presentation(self):
         """
         Starts a presentation from the beginning
         """
-        self.controller.process.RestartShow(self.pptid)
+        if self.hidden:
+            self.hidden = False
+            self.controller.process.Resume(self.pptid)
+        else:
+            self.controller.process.RestartShow(self.pptid)
 
     def get_slide_number(self):
         """

=== modified file 'openlp/plugins/presentations/lib/pptviewlib/README.TXT'
--- openlp/plugins/presentations/lib/pptviewlib/README.TXT	2009-09-30 19:26:51 +0000
+++ openlp/plugins/presentations/lib/pptviewlib/README.TXT	2010-06-24 19:49:24 +0000
@@ -23,6 +23,8 @@
 
 This library has a limit of 50 PowerPoints which can be opened simultaneously.
 
+This project can be built with the free Microsoft Visual C++ 2008 Express Edition.
+
 USAGE
 -----
 BOOL CheckInstalled(void);

=== modified file 'openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp'
--- openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp	2009-09-30 19:26:51 +0000
+++ openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp	2010-06-24 19:49:24 +0000
@@ -150,7 +150,7 @@
 		pptviewobj[id].rect.bottom = rect.bottom;
 		pptviewobj[id].rect.right = rect.right;
 	}
-	strcat_s(cmdline, MAX_PATH * 2, "/S \"");
+	strcat_s(cmdline, MAX_PATH * 2, "/F /S \"");
 	strcat_s(cmdline, MAX_PATH * 2, filename);
 	strcat_s(cmdline, MAX_PATH * 2, "\"");
 	memset(&si, 0, sizeof(si));
@@ -211,7 +211,7 @@
 		}
 		DEBUG("OpenPPT: Steps %d, first slide steps %d\n",pptviewobj[id].steps,pptviewobj[id].firstSlideSteps);
 		SavePPTInfo(id);
-	    if(pptviewobj[id].state==PPT_CLOSING){
+	    if(pptviewobj[id].state==PPT_CLOSING||pptviewobj[id].slideCount<=0){
 	        ClosePPT(id);
 	        id=-1;
 	    }


Follow ups