OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Solved][Python]Tabbed windows

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Sun May 27, 2012 2:05 am    Post subject: [Solved][Python]Tabbed windows Reply with quote

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 Smile


Last edited by ishanthilina on Sat Aug 04, 2012 10:09 pm; edited 1 time in total
Back to top
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Sun May 27, 2012 6:01 am    Post subject: Reply with quote

If target of your extension is LibreOffice 3.4 and 3.5, see: http://hermione.s41.xrea.com/pukiwiki/pukiwiki.php?OOoBasic%2FDialog%2FTabControl2
Or if target is Apache OpenOffice 3.4, see: http://hermione.s41.xrea.com/pukiwiki/pukiwiki.php?OOoBasic%2FDialog%2FTabControl
Back to top
View user's profile Send private message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Sun May 27, 2012 7:59 am    Post subject: Reply with quote

Thanks Hanya (as always Smile ).

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
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Sun May 27, 2012 8:21 am    Post subject: Reply with quote

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
View user's profile Send private message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Sun May 27, 2012 9:06 am    Post subject: Reply with quote

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
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Sun May 27, 2012 10:40 am    Post subject: Reply with quote

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
View user's profile Send private message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Sun May 27, 2012 8:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Sun May 27, 2012 10:47 pm    Post subject: Reply with quote

hanya wrote:
If target of your extension is LibreOffice 3.4 and 3.5, see: http://hermione.s41.xrea.com/pukiwiki/pukiwiki.php?OOoBasic%2FDialog%2FTabControl2
Or if target is Apache OpenOffice 3.4, see: http://hermione.s41.xrea.com/pukiwiki/pukiwiki.php?OOoBasic%2FDialog%2FTabControl


I ported the code to Python and it's working(in LibreOffice) Smile. 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 Smile
Back to top
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Sun May 27, 2012 11:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Wed Aug 01, 2012 4:59 am    Post subject: Reply with quote

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 Confused

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? Confused

The same code works when I load dlg from an xdl and get the model from dlg.

Thanks a lot for the support Hanya Smile .
Back to top
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Wed Aug 01, 2012 9:11 am    Post subject: Reply with quote

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
View user's profile Send private message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Fri Aug 03, 2012 9:26 am    Post subject: Reply with quote

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 Confused . 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
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Fri Aug 03, 2012 9:49 am    Post subject: Reply with quote

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
View user's profile Send private message
ishanthilina
General User
General User


Joined: 17 Mar 2012
Posts: 46

PostPosted: Sat Aug 04, 2012 9:56 pm    Post subject: Reply with quote

I finally got it working Hanya,thanks!.

Also thanks a lot for the tip on Object inspector and MRI tool!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group