Presentations add code but leave for now - Angels fear to tread

This commit is contained in:
Tim Bentley 2009-10-08 18:31:21 +01:00
commit 05fe475db0
5 changed files with 99 additions and 21 deletions

View File

@ -33,6 +33,7 @@ if os.name == u'nt':
from win32com.client import Dispatch
else:
import uno
from com.sun.star.beans import PropertyValue
from PyQt4 import QtCore
@ -104,19 +105,23 @@ class ImpressController(PresentationController):
The file name of the presentatios to the run.
"""
log.debug(u'LoadPresentation')
self.store_filename(presentation)
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)
self.document = desktop.loadComponentFromURL(
url, "_blank", 0, properties)
properties = tuple(properties)
doc = desktop.loadComponentFromURL(url, u'_blank', 0, properties)
self.document = doc
self.presentation = self.document.getPresentation()
self.presentation.Display = self.plugin.render_manager.current_display + 1
self.presentation.start()
@ -124,6 +129,22 @@ class ImpressController(PresentationController):
desktop.getCurrentComponent().Presentation.getController()
except:
log.exception(u'Failed to load presentation')
return
props = []
if os.name == u'nt':
prop = self.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')
else:
prop = PropertyValue()
prop.Name = u'FilterName'
prop.Value = u'impress_png_Export'
props.append(prop)
props = tuple(props)
pages = doc.getDrawPages()
for idx in range(pages.getCount()):
page = pages.getByIndex(idx)
doc.getCurrentController().setCurrentPage(page)
doc.storeToURL(thumbdir + u'/' + self.thumbnailprefix +
unicode(idx+1) + u'.png', props)
def get_uno_desktop(self):
log.debug(u'getUNODesktop')
@ -139,8 +160,8 @@ class ImpressController(PresentationController):
self.startOpenoffice()
loop += 1
try:
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext(
self.manager = ctx.ServiceManager
desktop = self.manager.createInstanceWithContext(
"com.sun.star.frame.Desktop", ctx )
return desktop
except:
@ -150,8 +171,10 @@ class ImpressController(PresentationController):
def get_com_desktop(self):
log.debug(u'getCOMDesktop')
try:
smgr = self.get_com_servicemanager()
desktop = smgr.createInstance( "com.sun.star.frame.Desktop")
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:
log.exception(u'Failed to get COM desktop')
@ -160,7 +183,7 @@ class ImpressController(PresentationController):
def get_com_servicemanager(self):
log.debug(u'get_com_servicemanager')
try:
return Dispatch("com.sun.star.ServiceManager")
return Dispatch(u'com.sun.star.ServiceManager')
except:
log.exception(u'Failed to get COM service manager')
return None
@ -224,5 +247,12 @@ class ImpressController(PresentationController):
"""
self.controller.gotoPreviousSlide()
# def get_slide_preview_file(self, slide_no):
def get_slide_preview_file(self, slide_no):
"""
Returns an image path containing a preview for the requested slide
``slide_no``
The slide an image is required for, starting at 1
"""
return os.path.join(self.thumbnailpath,
self.thumbnailprefix + slide_no + u'.png')

View File

@ -28,6 +28,7 @@ import logging
if os.name == u'nt':
from win32com.client import Dispatch
import _winreg
import win32ui
from presentationcontroller import PresentationController
@ -52,7 +53,7 @@ class PowerpointController(PresentationController):
PresentationController.__init__(self, plugin, u'Powerpoint')
self.process = None
self.presentation = None
def check_available(self):
"""
PowerPoint is able to run on this machine
@ -102,9 +103,14 @@ class PowerpointController(PresentationController):
``presentation``
The file name of the presentations to run.
"""
self.filename = presentation
log.debug(u'LoadPresentation')
self.store_filename(presentation)
self.process.Presentations.Open(presentation, False, False, True)
self.presentation = self.process.Presentations(self.process.Presentations.Count)
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):
@ -156,8 +162,8 @@ class PowerpointController(PresentationController):
self.presentation.SlideShowWindow.View.GotoSlide(1)
rendermanager = self.plugin.render_manager
rect = rendermanager.screen_list[rendermanager.current_display][u'size']
dpi = 96 # This assumption is good some of the time, but not
# all, but I don't know how to get the screen DPI yet
#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
@ -192,3 +198,13 @@ class PowerpointController(PresentationController):
Triggers the previous slide on the running presentation
"""
self.presentation.SlideShowWindow.View.Previous()
def get_slide_preview_file(self, slide_no):
"""
Returns an image path containing a preview for the requested slide
``slide_no``
The slide an image is required for, starting at 1
"""
return os.path.join(self.thumbnailpath,
self.thumbnailprefix + slide_no + u'.png')

View File

@ -49,9 +49,6 @@ class PptviewController(PresentationController):
self.process = None
PresentationController.__init__(self, plugin, u'Powerpoint Viewer')
self.pptid = None
self.thumbnailpath = os.path.join(plugin.config.get_data_path(),
u'pptview', u'thumbnails')
self.thumbprefix = u'slide'
def check_available(self):
"""
@ -105,15 +102,16 @@ class PptviewController(PresentationController):
The file name of the presentations to run.
"""
log.debug(u'LoadPresentation')
self.store_filename(presentation)
if self.pptid >= 0:
self.close_presentation()
rendermanager = self.plugin.render_manager
rect = rendermanager.screen_list[rendermanager.current_display][u'size']
rect = RECT(rect.x(), rect.y(), rect.right(), rect.bottom())
filename = str(presentation.replace(u'/', u'\\'));
filepath = str(presentation.replace(u'/', u'\\'));
try:
self.pptid = self.process.OpenPPT(filename, None, rect,
str(self.thumbnailpath))
self.pptid = self.process.OpenPPT(filepath, None, rect,
str(os.path.join(self.thumbnailpath, self.thumbnailprefix)))
except:
log.exception(u'Failed to load presentation')
@ -200,5 +198,5 @@ class PptviewController(PresentationController):
The slide an image is required for, starting at 1
"""
return os.path.join(self.thumbnailpath,
self.thumbprefix + slide_no + u'.bmp')
self.thumbnailprefix + slide_no + u'.bmp')

View File

@ -19,6 +19,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
import os
from PyQt4 import QtCore
@ -132,6 +133,14 @@ class PresentationController(object):
name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked
else:
self.enabled = False
self.thumbnailroot = os.path.join(plugin.config.get_data_path(),
name, u'thumbnails')
self.thumbnailprefix = u'slide'
try:
os.makedirs(self.thumbnailroot)
except:
pass
def check_available(self):
"""
@ -159,10 +168,22 @@ class PresentationController(object):
Loads the presentation and starts it
``presentation``
The file name of the presentatios to the run.
The file name of the presentations to the run.
"""
pass
def store_filename(self, presentation):
"""
Set properties for the filename and thumbnail paths
"""
self.filepath = presentation
self.filename = os.path.split(presentation)[1]
self.thumbnailpath = os.path.join(self.thumbnailroot, self.filename)
try:
os.mkdir(self.thumbnailpath)
except:
pass
def close_presentation(self):
"""
Close presentation and clean up objects

View File

@ -51,6 +51,19 @@ class PresentationPlugin(Plugin):
Create the settings Tab
"""
return PresentationTab(self.controllers)
#
# def can_be_disabled(self):
# return True
#
# def initialise(self):
# log.info(u'Presentations Initialising')
# Plugin.initialise(self)
# self.insert_toolbox_item()
#
# def finalise(self):
# log.info(u'Plugin Finalise')
# Plugin.finalise(self)
# self.remove_toolbox_item()
def get_media_manager_item(self):
"""