Try to catch more powerpoint COM exceptions

This commit is contained in:
Tomas Groth 2014-06-16 22:50:39 +02:00
parent a045ae3533
commit 90adc1acca

View File

@ -100,7 +100,7 @@ class PowerpointController(PresentationController):
if self.process.Presentations.Count > 0: if self.process.Presentations.Count > 0:
return return
self.process.Quit() self.process.Quit()
except pywintypes.com_error: except (AttributeError, pywintypes.com_error):
pass pass
self.process = None self.process = None
@ -124,9 +124,9 @@ class PowerpointDocument(PresentationDocument):
Opens the PowerPoint file using the process created earlier. Opens the PowerPoint file using the process created earlier.
""" """
log.debug(u'load_presentation') log.debug(u'load_presentation')
if not self.controller.process or not self.controller.process.Visible:
self.controller.start_process()
try: try:
if not self.controller.process or not self.controller.process.Visible:
self.controller.start_process()
self.controller.process.Presentations.Open(self.filepath, False, self.controller.process.Presentations.Open(self.filepath, False,
False, True) False, True)
except pywintypes.com_error: except pywintypes.com_error:
@ -275,28 +275,44 @@ class PowerpointDocument(PresentationDocument):
Returns the current slide number. Returns the current slide number.
""" """
log.debug(u'get_slide_number') log.debug(u'get_slide_number')
return self.presentation.SlideShowWindow.View.CurrentShowPosition try:
ret = self.presentation.SlideShowWindow.View.CurrentShowPosition
except pywintypes.com_error:
ret = 0
log.error('COM error while in get_slide_number')
return ret
def get_slide_count(self): def get_slide_count(self):
""" """
Returns total number of slides. Returns total number of slides.
""" """
log.debug(u'get_slide_count') log.debug(u'get_slide_count')
return self.presentation.Slides.Count try:
ret = self.presentation.Slides.Count
except pywintypes.com_error:
ret = 0
log.error('COM error while in get_slide_count')
return ret
def goto_slide(self, slideno): def goto_slide(self, slideno):
""" """
Moves to a specific slide in the presentation. Moves to a specific slide in the presentation.
""" """
log.debug(u'goto_slide') log.debug(u'goto_slide')
self.presentation.SlideShowWindow.View.GotoSlide(slideno) try:
self.presentation.SlideShowWindow.View.GotoSlide(slideno)
except pywintypes.com_error:
log.error('COM error while in goto_slide')
def next_step(self): def next_step(self):
""" """
Triggers the next effect of slide on the running presentation. Triggers the next effect of slide on the running presentation.
""" """
log.debug(u'next_step') log.debug(u'next_step')
self.presentation.SlideShowWindow.View.Next() try:
self.presentation.SlideShowWindow.View.Next()
except pywintypes.com_error:
log.error('COM error while in next_step')
if self.get_slide_number() > self.get_slide_count(): if self.get_slide_number() > self.get_slide_count():
self.previous_step() self.previous_step()
@ -305,7 +321,10 @@ class PowerpointDocument(PresentationDocument):
Triggers the previous slide on the running presentation. Triggers the previous slide on the running presentation.
""" """
log.debug(u'previous_step') log.debug(u'previous_step')
self.presentation.SlideShowWindow.View.Previous() try:
self.presentation.SlideShowWindow.View.Previous()
except pywintypes.com_error:
log.error('COM error while in previous_step')
def get_slide_text(self, slide_no): def get_slide_text(self, slide_no):
""" """