Ask Your Question
2

Python UNO LibreOffice UI scripting [closed]

asked 2013-07-09 10:14:49 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I have just started scripting python and UNO components with a long term goal to make LibreOffice UI Extensions. Creating dialogs seems to work (it appears in LibreOffice).
However, I can't set position or size or anything for the buttons, labels or other content of the dialog.
I got the error message AttributeError: ### where ### is the aspect I would like to change. This below code would throw AttributeError: PositionX.

Script Excerpt:

#Creating dialog: This works
control_container = service_manager.createInstanceWithContext( 
"com.sun.star.awt.UnoControlDialog", context); 
dialog_model = service_manager.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialogModel", context)
dialog_model.PositionX = 100
dialog_model.PositionY = 100
dialog_model.Width = 200 
dialog_model.Height = 200
dialog_model.BackgroundColor = 10020050 #rgb=(100,200,50
dialog_model.Title = "Runtime Dialog Demo"
dialog_model.Sizeable = 0
control_container.setModel(dialog_model); #Adds this model to the control container.
control_container.setVisible(False);
control_container.createPeer(toolkit, None);

#Adding button: This does not work
ok_button_container = service_manager.createInstanceWithContext( 
"com.sun.star.awt.UnoControlButton", context);
ok_button_model = service_manager.createInstanceWithContext(
"com.sun.star.awt.UnoControlButtonModel", context)
ok_button_model.PositionX = 50 <- THROWS ERROR
#ok_button_model.PositionY  = 30 
#ok_button_model.Size = [50,14]; 
#ok_button_model.Size.Height = 14; 
#ok_button_model.Name = "button_id"; 
#ok_button_model.TabIndex = 0;         
#ok_button_model.Label = "Ok";
#ok_button_container.setModel(ok_button_model);
#ok_button_container.setVisible(False);
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2015-11-03 08:32:44.871584

1 Answer

Sort by » oldest newest most voted
2

answered 2013-07-09 13:12:57 +0200

newOOo3 gravatar image

Hi, mipmap.

ok_button_model.PositionX = 50 <- THROWS ERROR

'OK button model.Position X = 50' are correct, but I think Code of the previous line is wrong. This means that I will change as follows

dialog_model = service_manager.createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", context)
・・・・
・・・・
ok_button_model = service_manager.createInstanceWithContext("com.sun.star.awt.UnoControlButtonModel", context)
ok_button_model.PositionX = 50 <- THROWS ERROR

=>

oCtx = uno.getComponentContext()
oServiceManager = oCtx.ServiceManager
dialog_model = oServiceManager .createInstance('com.sun.star.awt.UnoControlDialogModel')
・・・・
・・・・
ok_button_model = dialog_model.createInstance('com.sun.star.awt.UnoControlButtonModel')
ok_button_model.PositionX = 50
・・・・・

I think the code of the following URL would be helpful. http://openoffice3.web.fc2.com/Python_Macro_General_No2.html#OOoGDlg05a

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-07-09 10:14:49 +0200

Seen: 1,732 times

Last updated: Jul 09 '13