Presentation cleanups

bzr-revno: 591
This commit is contained in:
Jon Tibble 2009-10-09 23:37:18 +01:00
commit 61e6cc5f4e
5 changed files with 81 additions and 23 deletions

View File

@ -109,19 +109,16 @@ class ImpressController(PresentationController):
if os.name == u'nt': if os.name == u'nt':
desktop = self.get_com_desktop() 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')
thumbdir = u'file:///' + self.thumbnailpath.replace(
u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
else: else:
desktop = self.get_uno_desktop() desktop = self.get_uno_desktop()
url = uno.systemPathToFileUrl(presentation) url = uno.systemPathToFileUrl(presentation)
thumbdir = uno.systemPathToFileUrl(self.thumbnailpath)
if desktop is None: if desktop is None:
return return
try: try:
properties = [] properties = []
properties = tuple(properties) properties = tuple(properties)
doc = desktop.loadComponentFromURL(url, u'_blank', 0, properties) self.document = desktop.loadComponentFromURL(url, u'_blank',
self.document = doc 0, properties)
self.presentation = self.document.getPresentation() self.presentation = self.document.getPresentation()
self.presentation.Display = self.plugin.render_manager.current_display + 1 self.presentation.Display = self.plugin.render_manager.current_display + 1
self.presentation.start() self.presentation.start()
@ -130,6 +127,20 @@ class ImpressController(PresentationController):
except: except:
log.exception(u'Failed to load presentation') log.exception(u'Failed to load presentation')
return return
self.create_thumbnails()
def create_thumbnails(self):
"""
Create thumbnail images for presentation
"""
if self.check_thumbnails():
return
if os.name == u'nt':
thumbdir = u'file:///' + self.thumbnailpath.replace(
u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
else:
thumbdir = uno.systemPathToFileUrl(self.thumbnailpath)
props = [] props = []
if os.name == u'nt': if os.name == u'nt':
prop = self.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue') prop = self.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')
@ -139,6 +150,7 @@ class ImpressController(PresentationController):
prop.Value = u'impress_png_Export' prop.Value = u'impress_png_Export'
props.append(prop) props.append(prop)
props = tuple(props) props = tuple(props)
doc = self.document
pages = doc.getDrawPages() pages = doc.getDrawPages()
for idx in range(pages.getCount()): for idx in range(pages.getCount()):
page = pages.getByIndex(idx) page = pages.getByIndex(idx)
@ -255,4 +267,4 @@ class ImpressController(PresentationController):
The slide an image is required for, starting at 1 The slide an image is required for, starting at 1
""" """
return os.path.join(self.thumbnailpath, return os.path.join(self.thumbnailpath,
self.thumbnailprefix + slide_no + u'.png') self.thumbnailprefix + unicode(slide_no) + u'.png')

View File

@ -98,11 +98,22 @@ class PresentationMediaItem(MediaManagerItem):
self.DisplayTypeComboBox.addItem(item) self.DisplayTypeComboBox.addItem(item)
def loadList(self, list): def loadList(self, list):
currlist = self.getFileList()
titles = []
for file in currlist:
titles.append(os.path.split(file)[1])
for file in list: for file in list:
if currlist.count(file) > 0:
continue
(path, filename) = os.path.split(unicode(file)) (path, filename) = os.path.split(unicode(file))
item_name = QtGui.QListWidgetItem(filename) if titles.count(filename) > 0:
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file)) QtGui.QMessageBox.critical(self, u'File exists',
self.ListView.addItem(item_name) u'A presentation with that filename already exists.',
QtGui.QMessageBox.Ok)
else:
item_name = QtGui.QListWidgetItem(filename)
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
self.ListView.addItem(item_name)
def onDeleteClick(self): def onDeleteClick(self):
item = self.ListView.currentItem() item = self.ListView.currentItem()
@ -111,7 +122,10 @@ class PresentationMediaItem(MediaManagerItem):
row = self.ListView.row(item) row = self.ListView.row(item)
self.ListView.takeItem(row) self.ListView.takeItem(row)
self.parent.config.set_list( self.parent.config.set_list(
self.ConfigSection, self.ListData.getFileList()) self.ConfigSection, self.getFileList())
filepath = unicode((item.data(QtCore.Qt.UserRole)).toString())
for cidx in self.controllers:
self.controllers[cidx].presentation_deleted(filepath)
def generateSlideData(self, service_item): def generateSlideData(self, service_item):
items = self.ListView.selectedIndexes() items = self.ListView.selectedIndexes()

View File

@ -107,12 +107,25 @@ class PowerpointController(PresentationController):
self.store_filename(presentation) self.store_filename(presentation)
self.process.Presentations.Open(presentation, False, False, True) self.process.Presentations.Open(presentation, False, False, True)
self.presentation = self.process.Presentations(self.process.Presentations.Count) self.presentation = self.process.Presentations(self.process.Presentations.Count)
self.create_thumbnails()
self.start_presentation()
def create_thumbnails(self):
"""
Create the thumbnail images for the current presentation.
Note an alternative and quicker method would be do
self.presentation.Slides[n].Copy()
thumbnail = QApplication.clipboard.image()
But for now we want a physical file since it makes
life easier elsewhere
"""
if self.check_thumbnails():
return
self.presentation.Export(os.path.join(self.thumbnailpath, '') self.presentation.Export(os.path.join(self.thumbnailpath, '')
, 'png', 600, 480) , 'png', 600, 480)
# self.presentation.Slides[n].Copy()
# thumbnail = QClipboard.image()
self.start_presentation()
def close_presentation(self): def close_presentation(self):
""" """
Close presentation and clean up objects Close presentation and clean up objects
@ -207,4 +220,4 @@ class PowerpointController(PresentationController):
The slide an image is required for, starting at 1 The slide an image is required for, starting at 1
""" """
return os.path.join(self.thumbnailpath, return os.path.join(self.thumbnailpath,
self.thumbnailprefix + slide_no + u'.png') self.thumbnailprefix + unicode(slide_no) + u'.png')

View File

@ -198,5 +198,5 @@ class PptviewController(PresentationController):
The slide an image is required for, starting at 1 The slide an image is required for, starting at 1
""" """
return os.path.join(self.thumbnailpath, return os.path.join(self.thumbnailpath,
self.thumbnailprefix + slide_no + u'.bmp') self.thumbnailprefix + unicode(slide_no) + u'.bmp')

View File

@ -20,6 +20,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
import logging import logging
import os import os
import shutil
from PyQt4 import QtCore from PyQt4 import QtCore
@ -35,7 +36,7 @@ class PresentationController(object):
Make sure it inhetits PresentationController Make sure it inhetits PresentationController
Then fill in the blanks. If possible try and make sure it loads Then fill in the blanks. If possible try and make sure it loads
on all platforms, using for example os.name checks, although on all platforms, using for example os.name checks, although
__init__ and check_available should always work. __init__, check_available and presentation_deleted should always work.
See impresscontroller, powerpointcontroller or pptviewcontroller See impresscontroller, powerpointcontroller or pptviewcontroller
for examples. for examples.
@ -61,6 +62,9 @@ class PresentationController(object):
``check_available()`` ``check_available()``
Returns True if presentation application is installed/can run on this machine Returns True if presentation application is installed/can run on this machine
``presentation_deleted()``
Deletes presentation specific files, e.g. thumbnails
``load_presentation(presentation)`` ``load_presentation(presentation)``
Load a presentation file Load a presentation file
@ -136,11 +140,8 @@ class PresentationController(object):
self.thumbnailroot = os.path.join(plugin.config.get_data_path(), self.thumbnailroot = os.path.join(plugin.config.get_data_path(),
name, u'thumbnails') name, u'thumbnails')
self.thumbnailprefix = u'slide' self.thumbnailprefix = u'slide'
try: if not os.path.isdir(self.thumbnailroot):
os.makedirs(self.thumbnailroot) os.makedirs(self.thumbnailroot)
except:
pass
def check_available(self): def check_available(self):
""" """
@ -148,6 +149,14 @@ class PresentationController(object):
""" """
return False return False
def presentation_deleted(self, presentation):
"""
Cleans up/deletes any controller specific files created for
a file, e.g. thumbnails
"""
self.store_filename(presentation)
shutil.rmtree(self.thumbnailpath)
def start_process(self): def start_process(self):
""" """
Loads a running version of the presentation application in the background. Loads a running version of the presentation application in the background.
@ -179,10 +188,20 @@ class PresentationController(object):
self.filepath = presentation self.filepath = presentation
self.filename = os.path.split(presentation)[1] self.filename = os.path.split(presentation)[1]
self.thumbnailpath = os.path.join(self.thumbnailroot, self.filename) self.thumbnailpath = os.path.join(self.thumbnailroot, self.filename)
try: if not os.path.isdir(self.thumbnailpath):
os.mkdir(self.thumbnailpath) os.mkdir(self.thumbnailpath)
except:
pass def check_thumbnails(self):
"""
Returns true if the thumbnail images look to exist and are more
recent than the powerpoint
"""
lastimage = self.get_slide_preview_file(self.get_slide_count())
if not os.path.isfile(lastimage):
return False
imgdate = os.stat(lastimage).st_mtime
pptdate = os.stat(self.filepath).st_mtime
return imgdate >= pptdate
def close_presentation(self): def close_presentation(self):
""" """