Apache OpenOffice (AOO) Bugzilla – Issue 35199
Dialog creation with python
Last modified: 2013-02-07 22:16:55 UTC
Hi, as suggested by Joerg B., i open an issue to enable using OOo graphical UI dialog outside OOo with python as stated by Joerg "you are trying to execute this code from python executable itself, I guess. I just tried this code vs. a 680, it crashes with the below stacktrace, because toolkit tries to access some data (here ::comphelper::getProcessServiceFactory() ), which is only available within the office process itself. I think, there once was a time, where the toolkit should be useable outside the office, then you should write an issue therefor." at the end, the code that shows tthe problem trying to insert a button on a window. The script segfaults. If i comment the line, oDialogModel.insertByName( "bouton", oButtonModel ) the dialog is opened but the button (obviously is not ther) Thansk a lot Laurent # <ooo>/program/python myScript.py #myTest.py import uno import unohelper import pyuno ctx = uno.getComponentContext() smgr = ctx.ServiceManager oDialogModel = ctx.ServiceManager.createInstanceWithContext( "com.sun.star.awt.UnoControlDialogModel", ctx ) # Initialize the dialog model's properties. oDialogModel.PositionX = 200 oDialogModel.PositionY = 200 oDialogModel.Width = 200 oDialogModel.Height = 200 oDialogModel.Title = "titre" oDialogControl = ctx.ServiceManager.createInstanceWithContext( "com.sun.star.awt.UnoControlDialog", ctx ) oDialogControl.setModel( oDialogModel ) oButtonModel = oDialogModel.createInstance( "com.sun.star.awt.UnoControlButtonModel" ) #Initialize the button model's properties. oButtonModel.PositionX = 50 oButtonModel.PositionY = 30 oButtonModel.Width = 50 oButtonModel.Height = 14 oButtonModel.Name = "bouton" oButtonModel.TabIndex = 1 oButtonModel.Label = "caption" print "before inserting button" oDialogModel.insertByName( "bouton", oButtonModel ) print "after inserting button" oButtonControl = oDialogControl.getControl( "bouton" ) oDialogControl.setVisible( False ) toolkit = ctx.ServiceManager.createInstanceWithContext ( "com.sun.star.awt.Toolkit", ctx ) parent = None oDialogControl.createPeer(toolkit,parent ) oDialogControl.setVisible( True ) oDialogControl.execute()
In general, toolkit contains UNO components only (well, mostly), and should, IMO, adhere to the rules: UNO components should use the factory/context which was used to create them. I suppose every use of getProcessServiceFactory in toolkit is a bug, then (I stumbled upon this, too, as our form controls make heavy use of the toolkit controls).
Frank, your are right, components should use the componenContext they received via the factory method, which offers access to the to be used ServiceManager. So, this is a bug in the UNO AWT, I forward it to Malte.
VCL itself relies on getProcessServiceFactory in some functions...
Time for some cleanups here...
cd: Accepted.