From 1333c2ff4369bbe219aca6bf5fcde7fad5a7be0e Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Thu, 30 Apr 2015 14:38:55 +0200 Subject: [PATCH] Implement workaround for unblanking bug in powerpoint 2010 --- .../presentations/lib/messagelistener.py | 3 ++- .../presentations/lib/powerpointcontroller.py | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index a599e6f87..69a23cc7f 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -244,7 +244,8 @@ class Controller(object): """ log.debug('Live = %s, stop' % self.is_live) # Save the current slide number to be able to return to this slide if the presentation is activated again. - self.doc.slidenumber = self.doc.get_slide_number() + if self.doc.is_active(): + self.doc.slidenumber = self.doc.get_slide_number() self.hide_mode = HideMode.Screen if not self.doc: return diff --git a/openlp/plugins/presentations/lib/powerpointcontroller.py b/openlp/plugins/presentations/lib/powerpointcontroller.py index ed90dda9a..4a0f5a0d3 100644 --- a/openlp/plugins/presentations/lib/powerpointcontroller.py +++ b/openlp/plugins/presentations/lib/powerpointcontroller.py @@ -37,6 +37,8 @@ if is_win(): import winreg import win32ui import pywintypes + import win32con + import win32api from openlp.core.lib import ScreenList from openlp.core.lib.ui import UiStrings, critical_error_message_box, translate @@ -225,10 +227,24 @@ class PowerpointDocument(PresentationDocument): """ log.debug('unblank_screen') try: - self.presentation.SlideShowSettings.Run() - # ppSlideShowRunning = 1 - self.presentation.SlideShowWindow.View.State = 1 - self.presentation.SlideShowWindow.Activate() + # Powerpoint 2010 (14.0) has a bug that prevents unblanking from working, + # so we have to works around it by sending a keystroke to Powerpoint. + # The keystroke 'U' should not have any bindings in Powerpoint so we use that + if float(self.presentation.Application.Version) == 14.0: + loops = 0 + while self.presentation.SlideShowWindow.View.State == 3: + if loops >= 10: + log.warning('Tried to unblank 10 times, break to avoid hang, leaving presentation blanked.') + break + log.debug('Unblanking by sending "U"') + self.presentation.SlideShowWindow.Activate() + win32api.keybd_event(ord('U'), 0, 0, 0) + time.sleep(0.01) + win32api.keybd_event(ord('U'), 0, win32con.KEYEVENTF_KEYUP, 0) + loops += 1 + else: + # ppSlideShowRunning = 1 + self.presentation.SlideShowWindow.View.State = 1 except (AttributeError, pywintypes.com_error) as e: log.exception('Caught exception while in unblank_screen') log.exception(e)