import uno import time from com.sun.star.beans import PropertyValue import os HOST = 'localhost' PORT = 2002 LOCATION = (100, 100, 400, 300) OFFSET = 100 NoConnectException = uno.getClass('com.sun.star.connection.NoConnectException') class Testcase: def __init__(self, filename): self.host = HOST self.port = PORT self.filename = filename self.url = "file://%s/%s" % (os.getcwd(),filename) self.location = LOCATION local_context = uno.getComponentContext() resolver = local_context.ServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", local_context) connected = False connectcount = 0 while not connected: try: self.ctx = resolver.resolve("uno:socket,host=%s,port=%s;urp;" "StarOffice.ComponentContext" % (self.host, self.port)) connected = True except NoConnectException: if connectcount == 0: print "OOo not available, retrying..." if connectcount > 10: print "OOo not available, giving up." sys.exit(1) connectcount += 1 time.sleep(1) self.smgr = self.ctx.ServiceManager self.toolkit = self.create_instance("com.sun.star.awt.Toolkit") self.doc = None print "%s" % filename self.create_window() self.create_frame() self.move_offscreen() self.open_url() self.set_visible() time.sleep(1) def create_instance(self,instance_type): return self.smgr.createInstanceWithContext(instance_type, self.ctx) def makePropertyValue(self,Name=None, Value=None, Handle=None, State=None ): """Create a com.sun.star.beans.PropertyValue struct and return it. """ oPropertyValue = uno.getClass( "com.sun.star.beans.PropertyValue" ) if Name != None: oPropertyValue.Name = Name if Value != None: oPropertyValue.Value = Value if Handle != None: oPropertyValue.Handle = Handle if State != None: oPropertyValue.State = State return oPropertyValue def create_window(self): WindowDescriptor = uno.getClass('com.sun.star.awt.WindowDescriptor') Rectangle = uno.getClass('com.sun.star.awt.Rectangle') rect = Rectangle(*self.location) rect = Rectangle(2000,2000,100,100) class WindowAttributeClass: def __getattr__(self, name): return uno.getConstantByName( 'com.sun.star.awt.WindowAttribute.%s' % name) WindowAttribute = WindowAttributeClass() wd = WindowDescriptor() wd.Bounds = rect wd.Parent = None wd.ParentIndex = -1 wd.Type = uno.Enum('com.sun.star.awt.WindowClass', 'TOP') wd.WindowServiceName = "workwindow" self.window = self.toolkit.createWindow(wd) def create_frame(self): self.frame = self.create_instance("com.sun.star.frame.Frame") self.frame.initialize(self.window) self.frame.LayoutManager = None Desktop = self.create_instance('com.sun.star.frame.Desktop') self.frame.setName("OneLan") def set_location(self): x,y,w,h = self.location self.window.setPosSize(x,y,w,h,15) def move_offscreen(self): self.window.setPosSize(2000,2000,100,100,15) def open_url(self): print "Open: %s" % self.url self.doc = self.frame.loadComponentFromURL(self.url, "_self", 2, ()) def set_visible(self): self.set_location() def raise_window(self): self.window.toFront() def start_presentation(self): p = self.doc.getPresentation() p.setPropertyValue("IsFullScreen", False) p.start() t = Testcase('bar.odp') for i in range(10): t.open_url() t.start_presentation() time.sleep(10) os.system("xrestop -b -m 1|grep -A 14 OpenOffice.org")