Python- OpenOffice.org RAD

Recently I have strenghten my will to start developing seriously under the PyUNO platform. For that i want to generate a series of tools that will allow me to achieve the applications that I have talked and dream for so much.Recently I have been documenting the Python scripts that are packed with OpenOffice.org at the OOo’s Wiki page. I have also asked for peer review from Laurent Godard so the documentation can be as easy to understand as possible. However the experience was very eye-opener since I was able to learn about some modules that let me save some code regarding the scripting framework called XSCRIPTCONTEXT.I have also looked at one of the best PyUNO scripts around called PyXray. I like this script because it has a very complex GUI and uses a lot of the widgets available on the VCL (OOo’s toolkt). One thing that I learned is the use of all these different widgets on the python code, here is some snippets from the code: #create the dialog model and set the propertiesdialog_model = self.smgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel',self.ctx)dialog_model.PositionX = 50dialog_model.Step = 1dialog_model.TabIndex = 7dialog_model.Width = 270dialog_model.Height = 261dialog_model.PositionY = 63dialog = self.smgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog',self.ctx)Here is a snippet that will generate the UnoControlDialog which is one of the main ones, another the main widgets is the ListBox Modules.a_list= dialog_model.createInstance('com.sun.star.awt.UnoControlListBoxModel')a_list.PositionX = 38a_list.TabIndex = 14a_list.Width = 230a_list.Height = 10a_list.PositionY = 73a_list.HelpText = self.gui_rsc['ListObj']a_list.Dropdown = Truea_list.LineCount = 15a_list.Tag = ''dialog_model.insertByName('ListObj', a_list )Then there were the listeners which basically put the ListObj and add a listener that will wait for us to generate a signal, this signal is the one for listen to objects. The signal is also referred as an Action such as a_control.addActionListener(the_listener). We also have to remove the listeners by a method called removeItemListener(self.lst_listeners[‘ListObj’]). All this things go into just one object, our interface has somewhere around 10 widgets hold on the dialog which is a widget itself.I would need to better understand this model so I can be more proficient on PyUNO space and GUI programming to create extensions. I started by making a class to automatically instantiate the OOo service so Python can connect within it. The next step is to instantiate the Python modules so python can directly write into the document as opposed to be on the application layer. The process of instantiation is this:import unoimport unohelper localContext = uno.getComponentContext()resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext )ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )smgr = ctx.ServiceManagerdesktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)model = desktop.getCurrentComponent()The original idea is to create a class that will open, connect and instantiate OOo and make it ready for Python to just code directly into the Document. Another point would be to simplify the functions to write in the document, either generate tables, frames, text or insert an image in the document. But when constructing this code I hit some hit and miss so I can generate definitions and where to put what code. I sent an email to my friend that has more expertise in python and hope I can get it solved soon. So far there seem to be opportunities on this space.

Advertisements