Attempt to detect silly user errors, like closing down PowerPoint/PPTViewer whilst halfway through a presentation.

This commit is contained in:
Jonathan Corwin 2009-10-11 22:31:27 +01:00
parent 855174ce3e
commit bb4ab294c1
5 changed files with 93 additions and 52 deletions

View File

@ -79,7 +79,11 @@ class ImpressController(PresentationController):
when required. when required.
""" """
log.debug(u'start Openoffice') log.debug(u'start Openoffice')
if os.name != u'nt': if os.name == u'nt':
self.manager = self.get_com_servicemanager()
self.manager._FlagAsMethod(u'Bridge_GetStruct')
self.manager._FlagAsMethod(u'Bridge_GetValueObject')
else:
# -headless # -headless
cmd = u'openoffice.org -nologo -norestore -minimized -invisible ' + u'"' + u'-accept=socket,host=localhost,port=2002;urp;'+ u'"' cmd = u'openoffice.org -nologo -norestore -minimized -invisible ' + u'"' + u'-accept=socket,host=localhost,port=2002;urp;'+ u'"'
self.process = QtCore.QProcess() self.process = QtCore.QProcess()
@ -108,6 +112,9 @@ class ImpressController(PresentationController):
self.store_filename(presentation) self.store_filename(presentation)
if os.name == u'nt': if os.name == u'nt':
desktop = self.get_com_desktop() desktop = self.get_com_desktop()
if desktop is None:
self.start_process()
desktop = self.get_com_desktop()
url = u'file:///' + presentation.replace(u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20') url = u'file:///' + presentation.replace(u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
else: else:
desktop = self.get_uno_desktop() desktop = self.get_uno_desktop()
@ -169,7 +176,7 @@ class ImpressController(PresentationController):
try: try:
ctx = resolver.resolve(u'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext') ctx = resolver.resolve(u'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
except: except:
self.startOpenoffice() self.start_process()
loop += 1 loop += 1
try: try:
self.manager = ctx.ServiceManager self.manager = ctx.ServiceManager
@ -183,14 +190,11 @@ class ImpressController(PresentationController):
def get_com_desktop(self): def get_com_desktop(self):
log.debug(u'getCOMDesktop') log.debug(u'getCOMDesktop')
try: try:
self.manager = self.get_com_servicemanager()
self.manager._FlagAsMethod(u'Bridge_GetStruct')
self.manager._FlagAsMethod(u'Bridge_GetValueObject')
desktop = self.manager.createInstance(u'com.sun.star.frame.Desktop') desktop = self.manager.createInstance(u'com.sun.star.frame.Desktop')
return desktop return desktop
except: except:
log.exception(u'Failed to get COM desktop') log.exception(u'Failed to get COM desktop')
return None return None
def get_com_servicemanager(self): def get_com_servicemanager(self):
log.debug(u'get_com_servicemanager') log.debug(u'get_com_servicemanager')

View File

@ -64,74 +64,74 @@ class MessageListener(object):
self.handler, file = self.decodeMessage(message) self.handler, file = self.decodeMessage(message)
self.controller = self.controllers[self.handler] self.controller = self.controllers[self.handler]
if self.controller.is_loaded(): if self.controller.is_loaded():
self.shutdown() self.shutdown(None)
self.controller.load_presentation(file) self.controller.load_presentation(file)
self.controller.slidenumber = 0
def activate(self):
if self.controller.is_active():
return
if not self.controller.is_loaded():
self.controller.load_presentation(self.controller.filepath)
else:
self.controller.start_presentation()
if self.controller.slidenumber > 1:
self.controller.goto_slide(self.controller.slidenumber)
def slide(self, message): def slide(self, message):
#if not self.controller.is_loaded(): self.activate()
# return if message is not None:
#if not self.controller.is_active(): self.controller.goto_slide(message[0])
# self.controller.start_presentation() self.controller.slidenumber = self.controller.get_slide_number()
self.controller.goto_slide(message[0])
def first(self, message): def first(self, message):
""" """
Based on the handler passed at startup triggers the first slide Based on the handler passed at startup triggers the first slide
""" """
#if not self.controller.is_loaded(): self.activate()
# return
self.controller.start_presentation() self.controller.start_presentation()
self.controller.slidenumber = self.controller.get_slide_number()
def last(self, message): def last(self, message):
""" """
Based on the handler passed at startup triggers the first slide Based on the handler passed at startup triggers the first slide
""" """
#if not self.controller.is_loaded(): self.activate()
# return
#if not self.controller.is_active():
# self.controller.start_presentation()
self.controller.goto_slide(self.controller.get_slide_count()) self.controller.goto_slide(self.controller.get_slide_count())
self.controller.slidenumber = self.controller.get_slide_number()
def next(self, message): def next(self, message):
""" """
Based on the handler passed at startup triggers the next slide event Based on the handler passed at startup triggers the next slide event
""" """
#if not self.controller.is_loaded(): self.activate()
# return
#if not self.controller.is_active():
# self.controller.start_presentation()
# self.controller.goto_slide(self.controller.current_slide)
self.controller.next_step() self.controller.next_step()
self.controller.slidenumber = self.controller.get_slide_number()
def previous(self, message): def previous(self, message):
""" """
Based on the handler passed at startup triggers the previous slide event Based on the handler passed at startup triggers the previous slide event
""" """
#if not self.controller.is_loaded(): self.activate()
# return
#if not self.controller.is_active():
# self.controller.start_presentation()
# self.controller.goto_slide(self.controller.current_slide)
self.controller.previous_step() self.controller.previous_step()
self.controller.slidenumber = self.controller.get_slide_number()
def shutdown(self, message): def shutdown(self, message):
""" """
Based on the handler passed at startup triggers slide show to shut down Based on the handler passed at startup triggers slide show to shut down
""" """
self.controller.close_presentation() self.controller.close_presentation()
self.controller.slidenumber = 0
def blank(self): def blank(self):
#if not self.controller.is_loaded(): if not self.controller.is_loaded():
# return return
#if not self.controller.is_active(): if not self.controller.is_active():
# self.controller.start_presentation() return
self.controller.blank_screen() self.controller.blank_screen()
def unblank(self): def unblank(self):
#if not self.controller.is_loaded(): self.activate()
# return
#if not self.controller.is_active():
# self.controller.start_presentation()
self.controller.unblank_screen() self.controller.unblank_screen()
def decodeMessage(self, message): def decodeMessage(self, message):

View File

@ -80,16 +80,27 @@ class PowerpointController(PresentationController):
""" """
Returns true if a presentation is loaded Returns true if a presentation is loaded
""" """
if self.process is None: try:
return False if not self.process.Visible:
if self.process.Windows.Count == 0: return False
if self.process.Windows.Count == 0:
return False
if self.process.Presentations.Count == 0:
return False
except:
return False return False
return True
def kill(self): def kill(self):
""" """
Called at system exit to clean up any running presentations Called at system exit to clean up any running presentations
""" """
self.process.Quit() if self.process is None:
return
try:
self.process.Quit()
except:
pass
self.process = None self.process = None
def load_presentation(self, presentation): def load_presentation(self, presentation):
@ -105,7 +116,15 @@ class PowerpointController(PresentationController):
""" """
log.debug(u'LoadPresentation') log.debug(u'LoadPresentation')
self.store_filename(presentation) self.store_filename(presentation)
self.process.Presentations.Open(presentation, False, False, True) try:
if not self.process.Visible:
self.start_process()
except:
self.start_process()
try:
self.process.Presentations.Open(presentation, False, False, True)
except:
return
self.presentation = self.process.Presentations(self.process.Presentations.Count) self.presentation = self.process.Presentations(self.process.Presentations.Count)
self.create_thumbnails() self.create_thumbnails()
self.start_presentation() self.start_presentation()
@ -124,15 +143,18 @@ class PowerpointController(PresentationController):
self.presentation.Export(os.path.join(self.thumbnailpath, '') self.presentation.Export(os.path.join(self.thumbnailpath, '')
, 'png', 600, 480) , 'png', 600, 480)
def close_presentation(self): def close_presentation(self):
""" """
Close presentation and clean up objects Close presentation and clean up objects
Triggerent by new object being added to SlideController orOpenLP Triggerent by new object being added to SlideController orOpenLP
being shut down being shut down
""" """
self.presentation.Close() if self.presentation == None:
return
try:
self.presentation.Close()
except:
pass
self.presentation = None self.presentation = None
def is_active(self): def is_active(self):
@ -141,9 +163,12 @@ class PowerpointController(PresentationController):
""" """
if not self.is_loaded(): if not self.is_loaded():
return False return False
if self.presentation.SlideShowWindow == None: try:
return False if self.presentation.SlideShowWindow == None:
if self.presentation.SlideShowWindow.View == None: return False
if self.presentation.SlideShowWindow.View == None:
return False
except:
return False return False
return True return True
@ -171,12 +196,18 @@ class PowerpointController(PresentationController):
""" """
Starts a presentation from the beginning Starts a presentation from the beginning
""" """
#SlideShowWindow measures its size/position by points, not pixels
try:
dpi = win32ui.GetActiveWindow().GetDC().GetDeviceCaps(88)
except:
try:
dpi = win32ui.GetForegroundWindow().GetDC().GetDeviceCaps(88)
except:
dpi = 96
self.presentation.SlideShowSettings.Run() self.presentation.SlideShowSettings.Run()
self.presentation.SlideShowWindow.View.GotoSlide(1) self.presentation.SlideShowWindow.View.GotoSlide(1)
rendermanager = self.plugin.render_manager rendermanager = self.plugin.render_manager
rect = rendermanager.screen_list[rendermanager.current_display][u'size'] rect = rendermanager.screen_list[rendermanager.current_display][u'size']
#SlideShowWindow measures its size/position by points, not pixels
dpi = win32ui.GetActiveWindow().GetDC().GetDeviceCaps(88)
self.presentation.SlideShowWindow.Top = rect.y() * 72 / dpi self.presentation.SlideShowWindow.Top = rect.y() * 72 / dpi
self.presentation.SlideShowWindow.Height = rect.height() * 72 / dpi self.presentation.SlideShowWindow.Height = rect.height() * 72 / dpi
self.presentation.SlideShowWindow.Left = rect.x() * 72 / dpi self.presentation.SlideShowWindow.Left = rect.x() * 72 / dpi
@ -221,3 +252,4 @@ class PowerpointController(PresentationController):
""" """
return os.path.join(self.thumbnailpath, return os.path.join(self.thumbnailpath,
self.thumbnailprefix + unicode(slide_no) + u'.png') self.thumbnailprefix + unicode(slide_no) + u'.png')
\

View File

@ -128,13 +128,17 @@ class PptviewController(PresentationController):
""" """
Returns true if a presentation is loaded Returns true if a presentation is loaded
""" """
return self.pptid >= 0 if self.pptid < 0:
return False
if self.get_slide_count() < 0:
return False
return True
def is_active(self): def is_active(self):
""" """
Returns true if a presentation is currently active Returns true if a presentation is currently active
""" """
return self.pptid >= 0 return self.is_loaded()
def blank_screen(self): def blank_screen(self):
""" """

View File

@ -132,6 +132,7 @@ class PresentationController(object):
self.plugin = plugin self.plugin = plugin
self.name = name self.name = name
self.available = self.check_available() self.available = self.check_available()
self.slidenumber = 0
if self.available: if self.available:
self.enabled = int(plugin.config.get_config( self.enabled = int(plugin.config.get_config(
name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked