pptview/impress fixes to thumbnails on Windows

This commit is contained in:
Jonathan Corwin 2010-07-11 21:22:53 +01:00
parent fb4faf0dbb
commit fe5b3e6771
3 changed files with 505 additions and 493 deletions

View File

@ -1,463 +1,468 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
############################################################################### ###############################################################################
# OpenLP - Open Source Lyrics Projection # # OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman # # Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael # # Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin # # Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
# Thompson, Jon Tibble, Carsten Tinggaard # # Thompson, Jon Tibble, Carsten Tinggaard #
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it # # This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free # # under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. # # Software Foundation; version 2 of the License. #
# # # #
# This program is distributed in the hope that it will be useful, but WITHOUT # # This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. # # more details. #
# # # #
# You should have received a copy of the GNU General Public License along # # You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 # # with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
# OOo API documentation: # OOo API documentation:
# http://api.openoffice.org/docs/common/ref/com/sun/star/presentation/XSlideShowController.html # http://api.openoffice.org/docs/common/ref/com/sun/star/presentation/XSlideShowController.html
# http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Basic/Getting_Information_about_UNO_Objects#Inspecting_interfaces_during_debugging # http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Basic/Getting_Information_about_UNO_Objects#Inspecting_interfaces_during_debugging
# http://docs.go-oo.org/sd/html/classsd_1_1SlideShow.html # http://docs.go-oo.org/sd/html/classsd_1_1SlideShow.html
# http://www.oooforum.org/forum/viewtopic.phtml?t=5252 # http://www.oooforum.org/forum/viewtopic.phtml?t=5252
# http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Working_with_Presentations # http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Working_with_Presentations
# http://mail.python.org/pipermail/python-win32/2008-January/006676.html # http://mail.python.org/pipermail/python-win32/2008-January/006676.html
# http://www.linuxjournal.com/content/starting-stopping-and-connecting-openoffice-python # http://www.linuxjournal.com/content/starting-stopping-and-connecting-openoffice-python
# http://nxsy.org/comparing-documents-with-openoffice-and-python # http://nxsy.org/comparing-documents-with-openoffice-and-python
import logging import logging
import os import os
import time import time
from openlp.core.lib import resize_image from openlp.core.lib import resize_image
if os.name == u'nt': if os.name == u'nt':
from win32com.client import Dispatch from win32com.client import Dispatch
import pywintypes import pywintypes
else: else:
try: try:
import uno import uno
from com.sun.star.beans import PropertyValue from com.sun.star.beans import PropertyValue
uno_available = True uno_available = True
except ImportError: except ImportError:
uno_available = False uno_available = False
from PyQt4 import QtCore from PyQt4 import QtCore
from presentationcontroller import PresentationController, PresentationDocument from presentationcontroller import PresentationController, PresentationDocument
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class ImpressController(PresentationController): class ImpressController(PresentationController):
""" """
Class to control interactions with Impress presentations. Class to control interactions with Impress presentations.
It creates the runtime environment, loads and closes the presentation as It creates the runtime environment, loads and closes the presentation as
well as triggering the correct activities based on the users input well as triggering the correct activities based on the users input
""" """
log.info(u'ImpressController loaded') log.info(u'ImpressController loaded')
def __init__(self, plugin): def __init__(self, plugin):
""" """
Initialise the class Initialise the class
""" """
log.debug(u'Initialising') log.debug(u'Initialising')
PresentationController.__init__(self, plugin, u'Impress') PresentationController.__init__(self, plugin, u'Impress')
self.supports = [u'.odp'] self.supports = [u'.odp']
self.alsosupports = [u'.ppt', u'.pps', u'.pptx', u'.ppsx'] self.alsosupports = [u'.ppt', u'.pps', u'.pptx', u'.ppsx']
self.process = None self.process = None
self.desktop = None self.desktop = None
self.manager = None
def check_available(self):
""" def check_available(self):
Impress is able to run on this machine """
""" Impress is able to run on this machine
log.debug(u'check_available') """
if os.name == u'nt': log.debug(u'check_available')
return self.get_com_servicemanager() is not None if os.name == u'nt':
else: return self.get_com_servicemanager() is not None
return uno_available else:
return uno_available
def start_process(self):
""" def start_process(self):
Loads a running version of OpenOffice in the background. """
It is not displayed to the user but is available to the UNO interface Loads a running version of OpenOffice in the background.
when required. It is not displayed to the user but is available to the UNO interface
""" when required.
log.debug(u'start process Openoffice') """
if os.name == u'nt': log.debug(u'start process Openoffice')
self.manager = self.get_com_servicemanager() if os.name == u'nt':
self.manager._FlagAsMethod(u'Bridge_GetStruct') self.manager = self.get_com_servicemanager()
self.manager._FlagAsMethod(u'Bridge_GetValueObject') self.manager._FlagAsMethod(u'Bridge_GetStruct')
else: self.manager._FlagAsMethod(u'Bridge_GetValueObject')
# -headless else:
cmd = u'openoffice.org -nologo -norestore -minimized -invisible -nofirststartwizard -accept="socket,host=localhost,port=2002;urp;"' # -headless
self.process = QtCore.QProcess() cmd = u'openoffice.org -nologo -norestore -minimized -invisible -nofirststartwizard -accept="socket,host=localhost,port=2002;urp;"'
self.process.startDetached(cmd) self.process = QtCore.QProcess()
self.process.waitForStarted() self.process.startDetached(cmd)
self.process.waitForStarted()
def get_uno_desktop(self):
""" def get_uno_desktop(self):
On non-Windows platforms, use Uno. Get the OpenOffice desktop """
which will be used to manage impress On non-Windows platforms, use Uno. Get the OpenOffice desktop
""" which will be used to manage impress
log.debug(u'get UNO Desktop Openoffice') """
ctx = None log.debug(u'get UNO Desktop Openoffice')
loop = 0 ctx = None
log.debug(u'get UNO Desktop Openoffice - getComponentContext') loop = 0
context = uno.getComponentContext() log.debug(u'get UNO Desktop Openoffice - getComponentContext')
log.debug(u'get UNO Desktop Openoffice - createInstaneWithContext - ' context = uno.getComponentContext()
u'UnoUrlResolver') log.debug(u'get UNO Desktop Openoffice - createInstaneWithContext - '
resolver = context.ServiceManager.createInstanceWithContext( u'UnoUrlResolver')
u'com.sun.star.bridge.UnoUrlResolver', context) resolver = context.ServiceManager.createInstanceWithContext(
while ctx is None and loop < 3: u'com.sun.star.bridge.UnoUrlResolver', context)
try: while ctx is None and loop < 3:
log.debug(u'get UNO Desktop Openoffice - resolve') try:
ctx = resolver.resolve(u'uno:socket,host=localhost,port=2002;' log.debug(u'get UNO Desktop Openoffice - resolve')
u'urp;StarOffice.ComponentContext') ctx = resolver.resolve(u'uno:socket,host=localhost,port=2002;'
except: u'urp;StarOffice.ComponentContext')
log.exception(u'Unable to find running instance ') except:
self.start_process() log.exception(u'Unable to find running instance ')
loop += 1 self.start_process()
try: loop += 1
self.manager = ctx.ServiceManager try:
log.debug(u'get UNO Desktop Openoffice - createInstanceWithContext' self.manager = ctx.ServiceManager
u' - Desktop') log.debug(u'get UNO Desktop Openoffice - createInstanceWithContext'
desktop = self.manager.createInstanceWithContext( u' - Desktop')
"com.sun.star.frame.Desktop", ctx ) desktop = self.manager.createInstanceWithContext(
return desktop "com.sun.star.frame.Desktop", ctx )
except: return desktop
log.exception(u'Failed to get UNO desktop') except:
return None log.exception(u'Failed to get UNO desktop')
return None
def get_com_desktop(self):
""" def get_com_desktop(self):
On Windows platforms, use COM. Return the desktop object which """
will be used to manage Impress On Windows platforms, use COM. Return the desktop object which
""" will be used to manage Impress
log.debug(u'get COM Desktop OpenOffice') """
return self.manager.createInstance(u'com.sun.star.frame.Desktop') log.debug(u'get COM Desktop OpenOffice')
if not self.manager:
def get_com_servicemanager(self): return None
""" return self.manager.createInstance(u'com.sun.star.frame.Desktop')
Return the OOo service manager for windows
""" def get_com_servicemanager(self):
log.debug(u'get_com_servicemanager openoffice') """
try: Return the OOo service manager for windows
return Dispatch(u'com.sun.star.ServiceManager') """
except pywintypes.com_error: log.debug(u'get_com_servicemanager openoffice')
log.exception(u'Failed to get COM service manager') try:
return None return Dispatch(u'com.sun.star.ServiceManager')
except pywintypes.com_error:
def kill(self): log.exception(u'Failed to get COM service manager')
""" return None
Called at system exit to clean up any running presentations
""" def kill(self):
log.debug(u'Kill OpenOffice') """
while self.docs: Called at system exit to clean up any running presentations
self.docs[0].close_presentation() """
if os.name != u'nt': log.debug(u'Kill OpenOffice')
desktop = self.get_uno_desktop() while self.docs:
else: self.docs[0].close_presentation()
desktop = self.get_com_desktop() if os.name != u'nt':
#Sometimes we get a failure and desktop is None desktop = self.get_uno_desktop()
if not desktop: else:
log.exception(u'Failed to terminate OpenOffice') desktop = self.get_com_desktop()
return #Sometimes we get a failure and desktop is None
docs = desktop.getComponents() if not desktop:
if docs.hasElements(): log.exception(u'Failed to terminate OpenOffice')
log.debug(u'OpenOffice not terminated') return
else: docs = desktop.getComponents()
try: if docs.hasElements():
desktop.terminate() log.debug(u'OpenOffice not terminated')
log.debug(u'OpenOffice killed') else:
except: try:
log.exception(u'Failed to terminate OpenOffice') desktop.terminate()
log.debug(u'OpenOffice killed')
def add_doc(self, name): except:
""" log.exception(u'Failed to terminate OpenOffice')
Called when a new Impress document is opened
""" def add_doc(self, name):
log.debug(u'Add Doc OpenOffice') """
doc = ImpressDocument(self, name) Called when a new Impress document is opened
self.docs.append(doc) """
return doc log.debug(u'Add Doc OpenOffice')
doc = ImpressDocument(self, name)
class ImpressDocument(PresentationDocument): self.docs.append(doc)
""" return doc
Class which holds information and controls a single presentation
""" class ImpressDocument(PresentationDocument):
"""
def __init__(self, controller, presentation): Class which holds information and controls a single presentation
""" """
Constructor, store information about the file and initialise
""" def __init__(self, controller, presentation):
log.debug(u'Init Presentation OpenOffice') """
PresentationDocument.__init__(self, controller, presentation) Constructor, store information about the file and initialise
self.document = None """
self.presentation = None log.debug(u'Init Presentation OpenOffice')
self.control = None PresentationDocument.__init__(self, controller, presentation)
self.document = None
def load_presentation(self): self.presentation = None
""" self.control = None
Called when a presentation is added to the SlideController.
It builds the environment, starts communcations with the background def load_presentation(self):
OpenOffice task started earlier. If OpenOffice is not present is is """
started. Once the environment is available the presentation is loaded Called when a presentation is added to the SlideController.
and started. It builds the environment, starts communcations with the background
OpenOffice task started earlier. If OpenOffice is not present is is
``presentation`` started. Once the environment is available the presentation is loaded
The file name of the presentatios to the run. and started.
"""
log.debug(u'Load Presentation OpenOffice') ``presentation``
#print "s.dsk1 ", self.desktop The file name of the presentatios to the run.
if os.name == u'nt': """
desktop = self.controller.get_com_desktop() log.debug(u'Load Presentation OpenOffice')
if desktop is None: #print "s.dsk1 ", self.desktop
self.controller.start_process() if os.name == u'nt':
desktop = self.controller.get_com_desktop() desktop = self.controller.get_com_desktop()
url = u'file:///' + self.filepath.replace(u'\\', u'/').replace( if desktop is None:
u':', u'|').replace(u' ', u'%20') self.controller.start_process()
else: desktop = self.controller.get_com_desktop()
desktop = self.controller.get_uno_desktop() url = u'file:///' + self.filepath.replace(u'\\', u'/').replace(
url = uno.systemPathToFileUrl(self.filepath) u':', u'|').replace(u' ', u'%20')
if desktop is None: else:
return False desktop = self.controller.get_uno_desktop()
self.desktop = desktop url = uno.systemPathToFileUrl(self.filepath)
properties = [] if desktop is None:
properties.append(self.create_property(u'Minimized', True)) return False
properties = tuple(properties) self.desktop = desktop
try: properties = []
self.document = desktop.loadComponentFromURL(url, u'_blank', properties.append(self.create_property(u'Minimized', True))
0, properties) properties = tuple(properties)
except: try:
log.exception(u'Failed to load presentation') self.document = desktop.loadComponentFromURL(url, u'_blank',
return False 0, properties)
self.presentation = self.document.getPresentation() except:
self.presentation.Display = \ log.exception(u'Failed to load presentation')
self.controller.plugin.renderManager.screens.current_display + 1 return False
self.control = None self.presentation = self.document.getPresentation()
self.create_thumbnails() self.presentation.Display = \
return True self.controller.plugin.renderManager.screens.current_display + 1
self.control = None
def create_thumbnails(self): self.create_thumbnails()
""" return True
Create thumbnail images for presentation
""" def create_thumbnails(self):
log.debug(u'create thumbnails OpenOffice') """
if self.check_thumbnails(): Create thumbnail images for presentation
return """
if os.name == u'nt': log.debug(u'create thumbnails OpenOffice')
thumbdirurl = u'file:///' + self.get_temp_folder().replace( if self.check_thumbnails():
u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20') return
else: if os.name == u'nt':
thumbdirurl = uno.systemPathToFileUrl(self.get_temp_folder()) thumbdirurl = u'file:///' + self.get_temp_folder().replace(
props = [] u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
props.append(self.create_property(u'FilterName', u'impress_png_Export')) else:
props = tuple(props) thumbdirurl = uno.systemPathToFileUrl(self.get_temp_folder())
doc = self.document props = []
pages = doc.getDrawPages() props.append(self.create_property(u'FilterName', u'impress_png_Export'))
for idx in range(pages.getCount()): props = tuple(props)
page = pages.getByIndex(idx) doc = self.document
doc.getCurrentController().setCurrentPage(page) pages = doc.getDrawPages()
urlpath = u'%s/%s.png' % (thumbdirurl, unicode(idx + 1)) if not os.path.isdir(self.get_temp_folder()):
path = os.path.join(self.get_temp_folder(), os.makedirs(self.get_temp_folder())
unicode(idx + 1) + u'.png') for idx in range(pages.getCount()):
try: page = pages.getByIndex(idx)
doc.storeToURL(urlpath, props) doc.getCurrentController().setCurrentPage(page)
self.convert_thumbnail(path, idx) urlpath = u'%s/%s.png' % (thumbdirurl, unicode(idx + 1))
if os.path.exists(path): path = os.path.join(self.get_temp_folder(),
os.remove(path) unicode(idx + 1) + u'.png')
except: try:
log.exception(u'%s - Unable to store openoffice preview' % path) doc.storeToURL(urlpath, props)
self.convert_thumbnail(path, idx + 1)
def create_property(self, name, value): if os.path.exists(path):
""" os.remove(path)
Create an OOo style property object which are passed into some except:
Uno methods log.exception(u'%s - Unable to store openoffice preview' % path)
"""
log.debug(u'create property OpenOffice') def create_property(self, name, value):
if os.name == u'nt': """
prop = self.controller.manager.\ Create an OOo style property object which are passed into some
Bridge_GetStruct(u'com.sun.star.beans.PropertyValue') Uno methods
else: """
prop = PropertyValue() log.debug(u'create property OpenOffice')
prop.Name = name if os.name == u'nt':
prop.Value = value prop = self.controller.manager.\
return prop Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')
else:
def close_presentation(self): prop = PropertyValue()
""" prop.Name = name
Close presentation and clean up objects prop.Value = value
Triggered by new object being added to SlideController or OpenLP return prop
being shutdown
""" def close_presentation(self):
log.debug(u'close Presentation OpenOffice') """
if self.document: Close presentation and clean up objects
if self.presentation: Triggered by new object being added to SlideController or OpenLP
try: being shutdown
self.presentation.end() """
self.presentation = None log.debug(u'close Presentation OpenOffice')
self.document.dispose() if self.document:
except: if self.presentation:
#We tried! try:
pass self.presentation.end()
self.document = None self.presentation = None
self.controller.remove_doc(self) self.document.dispose()
except:
def is_loaded(self): #We tried!
""" pass
Returns true if a presentation is loaded self.document = None
""" self.controller.remove_doc(self)
log.debug(u'is loaded OpenOffice')
#print "is_loaded " def is_loaded(self):
if self.presentation is None or self.document is None: """
#print "no present or document" Returns true if a presentation is loaded
return False """
try: log.debug(u'is loaded OpenOffice')
if self.document.getPresentation() is None: #print "is_loaded "
#print "no getPresentation" if self.presentation is None or self.document is None:
return False #print "no present or document"
except: return False
return False try:
return True if self.document.getPresentation() is None:
#print "no getPresentation"
def is_active(self): return False
""" except:
Returns true if a presentation is active and running return False
""" return True
log.debug(u'is active OpenOffice')
#print "is_active " def is_active(self):
if not self.is_loaded(): """
#print "False " Returns true if a presentation is active and running
return False """
#print "self.con ", self.control log.debug(u'is active OpenOffice')
if self.control is None: #print "is_active "
return False if not self.is_loaded():
return True #print "False "
return False
def unblank_screen(self): #print "self.con ", self.control
""" if self.control is None:
Unblanks the screen return False
""" return True
log.debug(u'unblank screen OpenOffice')
return self.control.resume() def unblank_screen(self):
"""
def blank_screen(self): Unblanks the screen
""" """
Blanks the screen log.debug(u'unblank screen OpenOffice')
""" return self.control.resume()
log.debug(u'blank screen OpenOffice')
self.control.blankScreen(0) def blank_screen(self):
"""
def is_blank(self): Blanks the screen
""" """
Returns true if screen is blank log.debug(u'blank screen OpenOffice')
""" self.control.blankScreen(0)
log.debug(u'is blank OpenOffice')
if self.control: def is_blank(self):
return self.control.isPaused() """
else: Returns true if screen is blank
return False """
log.debug(u'is blank OpenOffice')
def stop_presentation(self): if self.control:
""" return self.control.isPaused()
Stop the presentation, remove from screen else:
""" return False
log.debug(u'stop presentation OpenOffice')
# deactivate should hide the screen according to docs, but doesn't def stop_presentation(self):
#self.control.deactivate() """
self.presentation.end() Stop the presentation, remove from screen
self.control = None """
log.debug(u'stop presentation OpenOffice')
def start_presentation(self): # deactivate should hide the screen according to docs, but doesn't
""" #self.control.deactivate()
Start the presentation from the beginning self.presentation.end()
""" self.control = None
log.debug(u'start presentation OpenOffice')
if self.control is None or not self.control.isRunning(): def start_presentation(self):
self.presentation.start() """
# start() returns before the getCurrentComponent is ready. Start the presentation from the beginning
# Try for 5 seconds """
i = 1 log.debug(u'start presentation OpenOffice')
while self.desktop.getCurrentComponent() is None and i < 50: if self.control is None or not self.control.isRunning():
time.sleep(0.1) self.presentation.start()
i = i + 1 # start() returns before the getCurrentComponent is ready.
self.control = \ # Try for 5 seconds
self.desktop.getCurrentComponent().Presentation.getController() i = 1
else: while self.desktop.getCurrentComponent() is None and i < 50:
self.control.activate() time.sleep(0.1)
self.goto_slide(1) i = i + 1
self.control = \
def get_slide_number(self): self.desktop.getCurrentComponent().Presentation.getController()
""" else:
Return the current slide number on the screen, from 1 self.control.activate()
""" self.goto_slide(1)
return self.control.getCurrentSlideIndex() + 1
def get_slide_number(self):
def get_slide_count(self): """
""" Return the current slide number on the screen, from 1
Return the total number of slides """
""" return self.control.getCurrentSlideIndex() + 1
return self.document.getDrawPages().getCount()
def get_slide_count(self):
def goto_slide(self, slideno): """
""" Return the total number of slides
Go to a specific slide (from 1) """
""" return self.document.getDrawPages().getCount()
self.control.gotoSlideIndex(slideno-1)
def goto_slide(self, slideno):
def next_step(self): """
""" Go to a specific slide (from 1)
Triggers the next effect of slide on the running presentation """
""" self.control.gotoSlideIndex(slideno-1)
self.control.gotoNextEffect()
def next_step(self):
def previous_step(self): """
""" Triggers the next effect of slide on the running presentation
Triggers the previous slide on the running presentation """
""" self.control.gotoNextEffect()
self.control.gotoPreviousSlide()
def previous_step(self):
def get_slide_text(self, slide_no): """
""" Triggers the previous slide on the running presentation
Returns the text on the slide """
self.control.gotoPreviousSlide()
``slide_no``
The slide the text is required for, starting at 1 def get_slide_text(self, slide_no):
""" """
doc = self.document Returns the text on the slide
pages = doc.getDrawPages()
text = '' ``slide_no``
page = pages.getByIndex(slide_no - 1) The slide the text is required for, starting at 1
for idx in range(page.getCount()): """
shape = page.getByIndex(idx) doc = self.document
if shape.supportsService("com.sun.star.drawing.Text"): pages = doc.getDrawPages()
text += shape.getString() + '\n' text = ''
return text page = pages.getByIndex(slide_no - 1)
for idx in range(page.getCount()):
def get_slide_notes(self, slide_no): shape = page.getByIndex(idx)
""" if shape.supportsService("com.sun.star.drawing.Text"):
Returns the text on the slide text += shape.getString() + '\n'
return text
``slide_no``
The slide the notes are required for, starting at 1 def get_slide_notes(self, slide_no):
""" """
doc = self.document Returns the text on the slide
pages = doc.getDrawPages()
text = '' ``slide_no``
page = pages.getByIndex(slide_no - 1) The slide the notes are required for, starting at 1
notes = page.getNotesPage() """
for idx in range(notes.getCount()): doc = self.document
shape = notes.getByIndex(idx) pages = doc.getDrawPages()
if shape.supportsService("com.sun.star.drawing.Text"): text = ''
text += shape.getString() + '\n' page = pages.getByIndex(slide_no - 1)
return text notes = page.getNotesPage()
for idx in range(notes.getCount()):
shape = notes.getByIndex(idx)
if shape.supportsService("com.sun.star.drawing.Text"):
text += shape.getString() + '\n'
return text

View File

@ -131,7 +131,7 @@ class PresentationMediaItem(MediaManagerItem):
self.listView.setIconSize(QtCore.QSize(88, 50)) self.listView.setIconSize(QtCore.QSize(88, 50))
list = SettingsManager.load_list( list = SettingsManager.load_list(
self.settingsSection, u'presentations') self.settingsSection, u'presentations')
self.loadList(list) self.loadList(list, True)
for item in self.controllers: for item in self.controllers:
#load the drop down selection #load the drop down selection
if self.controllers[item].enabled: if self.controllers[item].enabled:
@ -140,7 +140,7 @@ class PresentationMediaItem(MediaManagerItem):
self.DisplayTypeComboBox.insertItem(0, self.Automatic) self.DisplayTypeComboBox.insertItem(0, self.Automatic)
self.DisplayTypeComboBox.setCurrentIndex(0) self.DisplayTypeComboBox.setCurrentIndex(0)
def loadList(self, list): def loadList(self, list, initialLoad=False):
""" """
Add presentations into the media manager Add presentations into the media manager
This is called both on initial load of the plugin to populate with This is called both on initial load of the plugin to populate with
@ -155,34 +155,39 @@ class PresentationMediaItem(MediaManagerItem):
continue continue
filename = os.path.split(unicode(file))[1] filename = os.path.split(unicode(file))[1]
if titles.count(filename) > 0: if titles.count(filename) > 0:
QtGui.QMessageBox.critical( if not initialLoad:
self, translate('PresentationPlugin.MediaItem', QtGui.QMessageBox.critical(
'File exists'), self, translate('PresentationPlugin.MediaItem',
translate('PresentationPlugin.MediaItem', 'File exists'),
'A presentation with that filename already exists.'), translate('PresentationPlugin.MediaItem',
QtGui.QMessageBox.Ok) 'A presentation with that filename already exists.'),
QtGui.QMessageBox.Ok)
continue continue
controller_name = self.findControllerByType(filename) controller_name = self.findControllerByType(filename)
if not controller_name: if controller_name:
QtGui.QMessageBox.critical( controller = self.controllers[controller_name]
self, translate('PresentationPlugin.MediaItem', doc = controller.add_doc(unicode(file))
'Unsupported file'), thumb = os.path.join(doc.get_thumbnail_folder(), u'icon.png')
translate('PresentationPlugin.MediaItem',
'This type of presentation is not supported'),
QtGui.QMessageBox.Ok)
continue
controller = self.controllers[controller_name]
doc = controller.add_doc(unicode(file))
thumb = os.path.join(doc.get_thumbnail_folder(), u'icon.png')
preview = doc.get_thumbnail_path(1, True)
if not preview:
doc.load_presentation()
preview = doc.get_thumbnail_path(1, True) preview = doc.get_thumbnail_path(1, True)
doc.close_presentation() if not preview and not initialLoad:
if preview and self.validate(preview, thumb): doc.load_presentation()
icon = build_icon(thumb) preview = doc.get_thumbnail_path(1, True)
doc.close_presentation()
if preview and self.validate(preview, thumb):
icon = build_icon(thumb)
else:
icon = build_icon(u':/general/general_delete.png')
else: else:
icon = build_icon(u':/general/general_delete.png') if initialLoad:
icon = build_icon(u':/general/general_delete.png')
else:
QtGui.QMessageBox.critical(
self, translate('PresentationPlugin.MediaItem',
'Unsupported file'),
translate('PresentationPlugin.MediaItem',
'This type of presentation is not supported'),
QtGui.QMessageBox.Ok)
continue
item_name = QtGui.QListWidgetItem(filename) item_name = QtGui.QListWidgetItem(filename)
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file)) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
item_name.setIcon(icon) item_name.setIcon(icon)

View File

@ -130,9 +130,11 @@ class PptviewDocument(PresentationDocument):
rect = rendermanager.screens.current[u'size'] rect = rendermanager.screens.current[u'size']
rect = RECT(rect.x(), rect.y(), rect.right(), rect.bottom()) rect = RECT(rect.x(), rect.y(), rect.right(), rect.bottom())
filepath = str(self.filepath.replace(u'/', u'\\')) filepath = str(self.filepath.replace(u'/', u'\\'))
if not os.path.isdir(self.get_temp_folder()):
os.makedirs(self.get_temp_folder())
self.pptid = self.controller.process.OpenPPT(filepath, None, rect, self.pptid = self.controller.process.OpenPPT(filepath, None, rect,
str(self.get_temp_folder()) + '\\') str(self.get_temp_folder()) + '\\slide')
if self.pptid: if self.pptid >= 0:
self.create_thumbnails() self.create_thumbnails()
self.stop_presentation() self.stop_presentation()
return True return True
@ -147,8 +149,8 @@ class PptviewDocument(PresentationDocument):
if self.check_thumbnails(): if self.check_thumbnails():
return return
for idx in range(self.get_slide_count()): for idx in range(self.get_slide_count()):
path = u'%s\\%s.bmp' % (self.get_temp_folder(), unicode(idx + 1)) path = u'%s\\slide%s.bmp' % (self.get_temp_folder(), unicode(idx + 1))
self.convert_image(path, idx) self.convert_thumbnail(path, idx + 1)
def close_presentation(self): def close_presentation(self):
""" """