| View previous topic :: View next topic |
| Author |
Message |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Sun May 27, 2012 2:05 am Post subject: [Solved][Python]Tabbed windows |
|
|
Hi,
I'm trying to write a extension in Python. My problem is whether it is possible to create tabbed windows in OOO? (like shown in this link http://www.codeproject.com/KB/dialog/AndLawtabsetdlg/tabsetdlg1.png ).
If possible, can somebody post how to do it? Some example code may be..?
Thank you very much for the support 
Last edited by ishanthilina on Sat Aug 04, 2012 10:09 pm; edited 1 time in total |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Sun May 27, 2012 7:59 am Post subject: |
|
|
Thanks Hanya (as always ).
I'll be creating the extension for LibreOffice. But because of my lack of knowledge in OOBasic, I cannot convert the first few lines to python.
| Code: | dlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
model = dlg.getModel() |
Can you please help me to convert those two lines to python..? |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Sun May 27, 2012 8:21 am Post subject: |
|
|
| ishanthilina wrote: | | Code: | dlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
model = dlg.getModel() |
Can you please help me to convert those two lines to python..? | So, dialogs placed in extension package can be created using css.awt.DialogProvider service.
| Code: | dp = ctx.getServiceManager().createInstanceWithContext("com.sun.star.awt.DialogProvider", ctx)
d = dp.createDialog("vnd.sun.star.extension://" + EXTENSION_ID + "/dialogs/Dialog1.xdl")
model = d.getModel() | EXTENSION_ID is your extension identifier defined in description.xml file. |
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Sun May 27, 2012 9:06 am Post subject: |
|
|
| What if I need to create a dialog from the scratch..? Say using the com.sun.star.awt.UnoControlDialogModel and com.sun.star.awt.UnoControlDialog related stuff? |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Sun May 27, 2012 10:40 am Post subject: |
|
|
| ishanthilina wrote: | | What if I need to create a dialog from the scratch..? Say using the com.sun.star.awt.UnoControlDialogModel and com.sun.star.awt.UnoControlDialog related stuff? | Here is an example to make a dialog by xdl file: | Code: | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="Dialog1" dlg:left="96" dlg:top="30" dlg:width="168" dlg:height="129" dlg:closeable="true" dlg:moveable="true">
<dlg:bulletinboard>
<dlg:button dlg:id="CommandButton1" dlg:tab-index="0" dlg:left="17" dlg:top="110" dlg:width="62" dlg:height="14" dlg:value="CommandButton1"/>
<!-- dlg:value is number of tab pages. -->
<dlg:multipage dlg:id="Multipage" dlg:tab-index="1" dlg:left="3" dlg:top="3" dlg:width="150" dlg:height="100" dlg:withtabs="true" dlg:value="2">
<dlg:bulletinboard>
<dlg:page dlg:id="Multipage1" dlg:tab-index="2" dlg:left="3" dlg:top="3" dlg:width="150" dlg:height="100" dlg:title="Foo" dlg:visible="true">
<dlg:bulletinboard>
<dlg:button dlg:id="Button1" dlg:tab-index="0" dlg:left="17" dlg:top="51" dlg:width="62" dlg:height="14" dlg:value="Button 1"/>
</dlg:bulletinboard>
</dlg:page>
<dlg:page dlg:id="Multipage2" dlg:tab-index="3" dlg:left="13" dlg:top="3" dlg:width="150" dlg:height="100" dlg:title="Bar">
<dlg:bulletinboard>
<dlg:button dlg:id="Button2" dlg:tab-index="0" dlg:left="17" dlg:top="60" dlg:width="62" dlg:height="14" dlg:value="Button 2"/>
</dlg:bulletinboard>
</dlg:page>
</dlg:bulletinboard>
</dlg:multipage>
</dlg:bulletinboard>
</dlg:window> |
|
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Sun May 27, 2012 8:20 pm Post subject: |
|
|
Hanya, I'm really sorry for causing this trouble. It seems that my previous question is not clear enough (Which is my mistake, I'm really sorry for that).
What I meant was that in python the usual way of creating a dialog is by a code like the following.
| Code: | oDialogModel = self.ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialogModel", self.ctx )
# Initialize the dialog model's properties.
oDialogModel.PositionX = 200
oDialogModel.PositionY = 200
oDialogModel.Width = 200
oDialogModel.Height = 200
oDialogModel.Title = "Title"
oDialogControl = self.ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialog", self.ctx )
oDialogControl.setModel( oDialogModel )
print "setModel Ok"
#segfault on next line
oDialogControl.setVisible( True )
print "visible"
oDialogControl.execute()
print "execute" |
As we can see, the dialog is nod loaded from a xdl. I asked if we wanted to create the window using that way, how we can do that. How can we initilialize the dlg and model variables in that way..?
Thanks for the support once again. |
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Sun May 27, 2012 10:47 pm Post subject: |
|
|
I ported the code to Python and it's working(in LibreOffice) . Thanks a lot Hanya. Now the only problem I am left with is this http://www.oooforum.org/forum/viewtopic.phtml?p=496884#496884. I'm glad if you can help me with that too. Thanks a lot for the support you are providing  |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Sun May 27, 2012 11:26 pm Post subject: |
|
|
| Quote: | | What I meant was that in python the usual way of creating a dialog is by a code like the following. | I suppose such way is introduced by translating examples in dev guide written in Java to Python. Most part of the DevGuide was written for OpenOffice.org 1.0. As described in http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/Accessing_Dialogs, we have easy way to instantiate dialog from xdl file. I do not suggest you which way should be use.
If you are wanting to make a window, not a dialog, I needed to suggest you to code to create your dialog few years ago. But now we have the way to instantiate dialog as part of window to embed.
So, your mission is translating the extension from Java to Python. If your extension create dialog by the code, it can be convert from Java to Python in the code, use coding way.
| Quote: | | How can we initilialize the dlg and model variables in that way..? | Done in your example shown above. |
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Wed Aug 01, 2012 4:59 am Post subject: |
|
|
Hi Hanya,
Really sorry for troubling you back with this old thread. I tried to create a tabbed window without using a xdl. Following is the code I used.
| Code: |
dlg = self.ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialog", self.ctx )
model = self.ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialogModel", self.ctx )
dlg.setModel(model)
# Initialize the dialog model's properties.
model.PositionX = 200
model.PositionY = 200
model.Width = 200
model.Height = 200
model.Title = "Title"
tab_model = model.createInstance("com.sun.star.awt.UnoMultiPageModel")
tab_model.PositionX = 0
tab_model.PositionY = 0
tab_model.Width = 150
tab_model.Height = 150
model.insertByName("tab", tab_model)
tab = dlg.getControl("tab")
page_model1 = self.__AddTabPage(tab, "page1", "Page 1")
page_model2 = self.__AddTabPage(tab, "page2", "Page 2")
btn_model = page_model1.createInstance("com.sun.star.awt.UnoControlButtonModel")
btn_model.PositionX = 10
btn_model.PositionY = 10
btn_model.Width = 30
btn_model.Height = 15
btn_model.Label = "btn 1"
page_model1.insertByName("btn", btn_model)
dlg.setVisible( True )
dlg.execute()
dlg.dispose()
def __Array(self, *args ):
"""This is just sugar coating so that code from OOoBasic which
contains the Array() function can work perfectly in python."""
tArray = ()
for arg in args:
tArray += (arg,)
return tArray
def __AddTabPage(self, tab, name, title):
"""
Arguments:
- `tab`:
- `name`:
- `title`:
"""
args=uno.createUnoStruct("com.sun.star.beans.NamedValue")
args.Name = "Title"
args.Value = title
tab_model = tab.getModel()
page_model = tab_model.createInstance("com.sun.star.awt.UnoPageModel")
tab_model.insertByName(name, page_model)
n=len(tab_model.getElementNames())
tab.setTabProps(n, self.__Array(args))
return page_model
|
But I get the following exception
| Code: |
Traceback (most recent call last):
File "/home/ishan/.libreoffice/3/user/uno_packages/cache/uno_packages/luqrt4k8.tmp_/out.oxt/CcOOoAddin.py", line 178, in do
page_model1 = self.__AddTabPage(tab, "page1", "Page 1")
File "/home/ishan/.libreoffice/3/user/uno_packages/cache/uno_packages/luqrt4k8.tmp_/out.oxt/CcOOoAddin.py", line 125, in __AddTabPage
tab.setTabProps(n, self.__Array(args))
com.sun.star.uno.RuntimeException
|
What is that I'm doing wrong?
The same code works when I load dlg from an xdl and get the model from dlg.
Thanks a lot for the support Hanya . |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Wed Aug 01, 2012 9:11 am Post subject: |
|
|
Because the dialog does not have peer yet. When we make a dialog using DialogProvider service, it has peer. But if we create a dialog by instantiating UnoControlDialog, no peer created.
Create it like as follows before you add new tab page:
| Code: | # ....
model.insertByName("tab", tab_model)
toolkit = self.ctx.getServiceManager().createInstanceWithContext(
"com.sun.star.awt.Toolkit", self.ctx)
dlg.createPeer(toolkit, None)
tab = dlg.getControl("tab") |
In my opinion, the toolkit should be the same with the parent of the dialog but the above way is also working. |
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Fri Aug 03, 2012 9:26 am Post subject: |
|
|
Thanks Hanya, it worked!.
One more question. If you observe the above code,you'll notice that I'm adding a button by | Code: | | page_model1.insertByName("btn", btn_model) | . So how can I obtain the xButton interface of this button to add an action listener to it?
Really sorry for the novice questions . I tried to solve this using the OO API docs(and googled without a success), but could not find the documentation related to models such as com.sun.star.awt.UnoMultiPageModel |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Fri Aug 03, 2012 9:49 am Post subject: |
|
|
Please keep in mind that not documented means unpublished API.
See: http://opengrok.libreoffice.org/xref/core/toolkit/inc/toolkit/controls/dialogcontrol.hxx#158
Tab control is container like dialog. You can get tabpage from it by css.awt.XControlContainer interface methods. Something like: | Code: | page1 = tab.getControl("page1")
print(page1)
btn1 = page1.getControl("btn")
print(btn1) |
Please use object inspector to know well about UNO components. |
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Sat Aug 04, 2012 9:56 pm Post subject: |
|
|
I finally got it working Hanya,thanks!.
Also thanks a lot for the tip on Object inspector and MRI tool! |
|
| Back to top |
|
 |
|