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.
"""
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
cmd = u'openoffice.org -nologo -norestore -minimized -invisible ' + u'"' + u'-accept=socket,host=localhost,port=2002;urp;'+ u'"'
self.process = QtCore.QProcess()
@ -108,6 +112,9 @@ class ImpressController(PresentationController):
self.store_filename(presentation)
if os.name == u'nt':
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')
else:
desktop = self.get_uno_desktop()
@ -169,7 +176,7 @@ class ImpressController(PresentationController):
try:
ctx = resolver.resolve(u'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
except:
self.startOpenoffice()
self.start_process()
loop += 1
try:
self.manager = ctx.ServiceManager
@ -183,9 +190,6 @@ class ImpressController(PresentationController):
def get_com_desktop(self):
log.debug(u'getCOMDesktop')
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')
return desktop
except:

View File

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

View File

@ -80,16 +80,27 @@ class PowerpointController(PresentationController):
"""
Returns true if a presentation is loaded
"""
if self.process is None:
try:
if not self.process.Visible:
return False
if self.process.Windows.Count == 0:
return False
if self.process.Presentations.Count == 0:
return False
except:
return False
return True
def kill(self):
"""
Called at system exit to clean up any running presentations
"""
if self.process is None:
return
try:
self.process.Quit()
except:
pass
self.process = None
def load_presentation(self, presentation):
@ -105,7 +116,15 @@ class PowerpointController(PresentationController):
"""
log.debug(u'LoadPresentation')
self.store_filename(presentation)
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.create_thumbnails()
self.start_presentation()
@ -124,15 +143,18 @@ class PowerpointController(PresentationController):
self.presentation.Export(os.path.join(self.thumbnailpath, '')
, 'png', 600, 480)
def close_presentation(self):
"""
Close presentation and clean up objects
Triggerent by new object being added to SlideController orOpenLP
being shut down
"""
if self.presentation == None:
return
try:
self.presentation.Close()
except:
pass
self.presentation = None
def is_active(self):
@ -141,10 +163,13 @@ class PowerpointController(PresentationController):
"""
if not self.is_loaded():
return False
try:
if self.presentation.SlideShowWindow == None:
return False
if self.presentation.SlideShowWindow.View == None:
return False
except:
return False
return True
def unblank_screen(self):
@ -171,12 +196,18 @@ class PowerpointController(PresentationController):
"""
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.SlideShowWindow.View.GotoSlide(1)
rendermanager = self.plugin.render_manager
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.Height = rect.height() * 72 / dpi
self.presentation.SlideShowWindow.Left = rect.x() * 72 / dpi
@ -221,3 +252,4 @@ class PowerpointController(PresentationController):
"""
return os.path.join(self.thumbnailpath,
self.thumbnailprefix + unicode(slide_no) + u'.png')
\

View File

@ -128,13 +128,17 @@ class PptviewController(PresentationController):
"""
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):
"""
Returns true if a presentation is currently active
"""
return self.pptid >= 0
return self.is_loaded()
def blank_screen(self):
"""

View File

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