Understanding peer and TabPageContainer

I’m trying to use TabPage and TabContainer but I’m having problems understanding what is a peer and how I need to relate it with TabPage.

I’m able to add a TabPageContainer with Pages and add controls within a TabPage with the following piece of code, dc is a DialogControl and dm is the DialogControlModel

        self.dc.createPeer(self.toolkit, None)  
        book: UnoControlTabPageContainerModel = dm.createInstance(
            "com.sun.star.awt.tab.UnoControlTabPageContainerModel"
        )
        book.Name = "TabControl"
        book.PositionX = "18"
        book.PositionY = "15"
        book.Width = 130
        book.Height = 60
        dm.insertByName("TabControl", book)
        page_ad: UnoControlTabPageModel = book.createTabPage(1)
        page_ad.Title = "🔧 Parameters"
        book.insertByIndex(0, page_ad)
        page_ui: UnoControlTabPageModel = book.createTabPage(2)
        page_ui.Title = "👀 UI"
        book.insertByIndex(1, page_ui)

Note that the first line is

       self.dc.createPeer(self.toolkit, None)

If I don’t do this, I get the error

Traceback (most recent call last):
  File "/home/igor/playground/libreoffice/python-libreoffice-track/src/095_ui_tab_sample.py", line 166, in <module>
    run_hello_tab_sample()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/home/igor/playground/libreoffice/python-libreoffice-track/src/095_ui_tab_sample.py", line 134, in run_hello_tab_sample
    app.showDialog()
    ~~~~~~~~~~~~~~^^
  File "/home/igor/playground/libreoffice/python-libreoffice-track/src/095_ui_tab_sample.py", line 121, in showDialog
    self.dc.setVisible(True)
    ~~~~~~~~~~~~~~~~~~^^^^^^
uno.com.sun.star.uno.RuntimeException: No peer for tabpage container!

But when I do this, I loose NumericField Spinner controls. Is it needed to force a repaint ?

I initally have a sample that shows the increment/decrement for a Numeric Field like
screenshot-2025-09-11-075254

But when I add the code for tabs, the NumericFields look now like

screenshot-2025-09-11-075217

The full source code for the initial code is here

And with tabpagecontainer and tabpage is here

What I’m doing wrong and how can it be fixed?

I’m running libreoffice 25.2 on Debian Forky with Python13. Thanks for hints and help.

Building Compound Dialogs presentation during LibreOffice latest conference in Budapest proposes to combine TabPageContainer, Page/Step dilalog property and the import of dialog controls to simplify the coding of tabbed dialogs.

1 Like

I found a solution to the problem, It was:

  1. Create the components, all from the parent dialog
  2. Make visible the dialog
  3. Insert the components by name that had problems when shown directly.

The revision 3 has working code.

An screencast is here https://youtu.be/x-pbwpxxqzc

Please let me know if there is a better approach to change the code, because it feels like a hack. Can it work without such workaround ? What would a better option? Raw python preferred.

Another approach is given in next example. It uses the Page/Step property of dialogs and dialog controls set by TabPageContainer events.

https://wiki.documentfoundation.org/Macros/ScriptForge/TabbedDialogExample

1 Like

In the wiki there is now some explanation on how to use a TabPageContainer.

If you are making extensions and want to have Tabs and pages, this can be handy. Please do improve it. There are more simple samples of tasks that are more common too.

I’m interested in moving the information to not be under my User, if you have suggestions, please do use the discuss option there.