123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- import uno
- import traceback
- from unohelper import systemPathToFileUrl, absolutize
- from ..common.Desktop import Desktop
- from ..common.SystemDialog import SystemDialog
- from com.sun.star.awt import WindowDescriptor
- from com.sun.star.awt import Rectangle
- from com.sun.star.awt.WindowClass import TOP
- from com.sun.star.task import ErrorCodeIOException
- com_sun_star_awt_WindowAttribute_BORDER \
- = uno.getConstantByName( "com.sun.star.awt.WindowAttribute.BORDER" )
- com_sun_star_awt_WindowAttribute_SIZEABLE \
- = uno.getConstantByName( "com.sun.star.awt.WindowAttribute.SIZEABLE" )
- com_sun_star_awt_WindowAttribute_MOVEABLE \
- = uno.getConstantByName( "com.sun.star.awt.WindowAttribute.MOVEABLE" )
- com_sun_star_awt_VclWindowPeerAttribute_CLIPCHILDREN \
- = uno.getConstantByName(
- "com.sun.star.awt.VclWindowPeerAttribute.CLIPCHILDREN" )
- class OfficeDocument(object):
- '''Creates a new instance of OfficeDocument '''
- def __init__(self, _xMSF):
- self.xMSF = _xMSF
- @classmethod
- def attachEventCall(self, xComponent, EventName, EventType, EventURL):
- try:
- oEventProperties = list(range(2))
- oEventProperties[0] = uno.createUnoStruct(
- 'com.sun.star.beans.PropertyValue')
- oEventProperties[0].Name = "EventType"
- oEventProperties[0].Value = EventType
-
- oEventProperties[1] = uno.createUnoStruct(
- 'com.sun.star.beans.PropertyValue')
- oEventProperties[1].Name = "Script"
- oEventProperties[1].Value = EventURL
- uno.invoke(xComponent.Events, "replaceByName",
- (EventName, uno.Any("[]com.sun.star.beans.PropertyValue",
- tuple(oEventProperties))))
- except Exception:
- traceback.print_exc()
- def dispose(self, xMSF, xComponent):
- try:
- if xComponent is not None:
- xFrame = xComponent.CurrentController.Frame
- if xComponent.isModified():
- xComponent.setModified(False)
- Desktop.dispatchURL(xMSF, ".uno:CloseDoc", xFrame)
- except Exception:
- traceback.print_exc()
- @classmethod
- def createNewFrame(self, xMSF, listener, FrameName="_blank"):
- xFrame = None
- if FrameName.lower() == "WIZARD_LIVE_PREVIEW".lower():
- xFrame = self.createNewPreviewFrame(xMSF, listener)
- else:
- xF = Desktop.getDesktop(xMSF)
- xFrame = xF.findFrame(FrameName, 0)
- if listener is not None:
- xFF = xF.getFrames()
- xFF.remove(xFrame)
- xF.addTerminateListener(listener)
- return xFrame
- @classmethod
- def createNewPreviewFrame(self, xMSF, listener):
- xToolkit = None
- try:
- xToolkit = xMSF.createInstance("com.sun.star.awt.Toolkit")
- except Exception:
-
- traceback.print_exc()
-
- aDescriptor = WindowDescriptor()
- aDescriptor.Type = TOP
- aDescriptor.WindowServiceName = "window"
- aDescriptor.ParentIndex = -1
- aDescriptor.Parent = None
- aDescriptor.Bounds = Rectangle(10, 10, 640, 480)
-
- gnDefaultWindowAttributes = \
- com_sun_star_awt_WindowAttribute_BORDER + \
- com_sun_star_awt_WindowAttribute_MOVEABLE + \
- com_sun_star_awt_WindowAttribute_SIZEABLE + \
- com_sun_star_awt_VclWindowPeerAttribute_CLIPCHILDREN
- aDescriptor.WindowAttributes = gnDefaultWindowAttributes
-
- xPeer = None
- try:
- xPeer = xToolkit.createWindow(aDescriptor)
- except Exception:
- traceback.print_exc()
-
-
-
-
- xFrame = None
- try:
- xFrame = xMSF.createInstance("com.sun.star.frame.Frame")
- except Exception:
- traceback.print_exc()
- xFrame.initialize(xPeer)
-
-
-
- if listener is not None:
- Desktop.getDesktop(xMSF).addTerminateListener(listener)
- return xFrame
- @classmethod
- def load(self, xInterface, sURL, sFrame, xValues):
- xComponent = None
- try:
- if not sURL.startswith("file://"):
- sURL = systemPathToFileUrl(sURL)
- xComponent = xInterface.loadComponentFromURL(
- sURL, sFrame, 0, tuple(xValues))
- except Exception:
- traceback.print_exc()
- return xComponent
- @classmethod
- def store(self, xMSF, xComponent, StorePath, FilterName):
- try:
- if len(FilterName):
- oStoreProperties = list(range(2))
- oStoreProperties[0] = uno.createUnoStruct(
- 'com.sun.star.beans.PropertyValue')
- oStoreProperties[0].Name = "FilterName"
- oStoreProperties[0].Value = FilterName
- oStoreProperties[1] = uno.createUnoStruct(
- 'com.sun.star.beans.PropertyValue')
- oStoreProperties[1].Name = "InteractionHandler"
- oStoreProperties[1].Value = xMSF.createInstance(
- "com.sun.star.comp.uui.UUIInteractionHandler")
- else:
- oStoreProperties = list(range(0))
- StorePath = systemPathToFileUrl(StorePath)
- sPath = StorePath[:(StorePath.rfind("/") + 1)]
- sFile = StorePath[(StorePath.rfind("/") + 1):]
- xComponent.storeToURL(
- absolutize(sPath, sFile), tuple(oStoreProperties))
- return True
- except ErrorCodeIOException:
-
-
-
- return True
- pass
- except Exception:
- traceback.print_exc()
- return False
- def close(self, xComponent):
- bState = False
- if xComponent is not None:
- try:
- xComponent.close(True)
- bState = True
- except Exception:
- print ("could not close doc")
- bState = False
- else:
- bState = True
- return bState
- def showMessageBox(
- self, xMSF, windowServiceName, windowAttribute, MessageText):
- return SystemDialog.showMessageBox(
- xMSF, windowServiceName, windowAttribute, MessageText)
|