forked from openlp/openlp
Presentation cleanups
bzr-revno: 591
This commit is contained in:
commit
61e6cc5f4e
@ -109,19 +109,16 @@ class ImpressController(PresentationController):
|
||||
if os.name == u'nt':
|
||||
desktop = self.get_com_desktop()
|
||||
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:
|
||||
desktop = self.get_uno_desktop()
|
||||
url = uno.systemPathToFileUrl(presentation)
|
||||
thumbdir = uno.systemPathToFileUrl(self.thumbnailpath)
|
||||
if desktop is None:
|
||||
return
|
||||
try:
|
||||
properties = []
|
||||
properties = tuple(properties)
|
||||
doc = desktop.loadComponentFromURL(url, u'_blank', 0, properties)
|
||||
self.document = doc
|
||||
self.document = desktop.loadComponentFromURL(url, u'_blank',
|
||||
0, properties)
|
||||
self.presentation = self.document.getPresentation()
|
||||
self.presentation.Display = self.plugin.render_manager.current_display + 1
|
||||
self.presentation.start()
|
||||
@ -130,6 +127,20 @@ class ImpressController(PresentationController):
|
||||
except:
|
||||
log.exception(u'Failed to load presentation')
|
||||
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 = []
|
||||
if os.name == u'nt':
|
||||
prop = self.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')
|
||||
@ -139,6 +150,7 @@ class ImpressController(PresentationController):
|
||||
prop.Value = u'impress_png_Export'
|
||||
props.append(prop)
|
||||
props = tuple(props)
|
||||
doc = self.document
|
||||
pages = doc.getDrawPages()
|
||||
for idx in range(pages.getCount()):
|
||||
page = pages.getByIndex(idx)
|
||||
@ -255,4 +267,4 @@ class ImpressController(PresentationController):
|
||||
The slide an image is required for, starting at 1
|
||||
"""
|
||||
return os.path.join(self.thumbnailpath,
|
||||
self.thumbnailprefix + slide_no + u'.png')
|
||||
self.thumbnailprefix + unicode(slide_no) + u'.png')
|
||||
|
@ -98,11 +98,22 @@ class PresentationMediaItem(MediaManagerItem):
|
||||
self.DisplayTypeComboBox.addItem(item)
|
||||
|
||||
def loadList(self, list):
|
||||
currlist = self.getFileList()
|
||||
titles = []
|
||||
for file in currlist:
|
||||
titles.append(os.path.split(file)[1])
|
||||
for file in list:
|
||||
if currlist.count(file) > 0:
|
||||
continue
|
||||
(path, filename) = os.path.split(unicode(file))
|
||||
item_name = QtGui.QListWidgetItem(filename)
|
||||
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
|
||||
self.ListView.addItem(item_name)
|
||||
if titles.count(filename) > 0:
|
||||
QtGui.QMessageBox.critical(self, u'File exists',
|
||||
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):
|
||||
item = self.ListView.currentItem()
|
||||
@ -111,7 +122,10 @@ class PresentationMediaItem(MediaManagerItem):
|
||||
row = self.ListView.row(item)
|
||||
self.ListView.takeItem(row)
|
||||
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):
|
||||
items = self.ListView.selectedIndexes()
|
||||
|
@ -107,12 +107,25 @@ class PowerpointController(PresentationController):
|
||||
self.store_filename(presentation)
|
||||
self.process.Presentations.Open(presentation, False, False, True)
|
||||
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, '')
|
||||
, 'png', 600, 480)
|
||||
# self.presentation.Slides[n].Copy()
|
||||
# thumbnail = QClipboard.image()
|
||||
self.start_presentation()
|
||||
|
||||
|
||||
|
||||
def close_presentation(self):
|
||||
"""
|
||||
Close presentation and clean up objects
|
||||
@ -207,4 +220,4 @@ class PowerpointController(PresentationController):
|
||||
The slide an image is required for, starting at 1
|
||||
"""
|
||||
return os.path.join(self.thumbnailpath,
|
||||
self.thumbnailprefix + slide_no + u'.png')
|
||||
self.thumbnailprefix + unicode(slide_no) + u'.png')
|
||||
|
@ -198,5 +198,5 @@ class PptviewController(PresentationController):
|
||||
The slide an image is required for, starting at 1
|
||||
"""
|
||||
return os.path.join(self.thumbnailpath,
|
||||
self.thumbnailprefix + slide_no + u'.bmp')
|
||||
self.thumbnailprefix + unicode(slide_no) + u'.bmp')
|
||||
|
||||
|
@ -20,6 +20,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from PyQt4 import QtCore
|
||||
|
||||
@ -35,7 +36,7 @@ class PresentationController(object):
|
||||
Make sure it inhetits PresentationController
|
||||
Then fill in the blanks. If possible try and make sure it loads
|
||||
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
|
||||
for examples.
|
||||
|
||||
@ -61,6 +62,9 @@ class PresentationController(object):
|
||||
|
||||
``check_available()``
|
||||
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 a presentation file
|
||||
@ -136,11 +140,8 @@ class PresentationController(object):
|
||||
self.thumbnailroot = os.path.join(plugin.config.get_data_path(),
|
||||
name, u'thumbnails')
|
||||
self.thumbnailprefix = u'slide'
|
||||
try:
|
||||
if not os.path.isdir(self.thumbnailroot):
|
||||
os.makedirs(self.thumbnailroot)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def check_available(self):
|
||||
"""
|
||||
@ -148,6 +149,14 @@ class PresentationController(object):
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
Loads a running version of the presentation application in the background.
|
||||
@ -179,10 +188,20 @@ class PresentationController(object):
|
||||
self.filepath = presentation
|
||||
self.filename = os.path.split(presentation)[1]
|
||||
self.thumbnailpath = os.path.join(self.thumbnailroot, self.filename)
|
||||
try:
|
||||
if not os.path.isdir(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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user