[Solved] [Python][UI] Refresh window/widget

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
OlivierR
Posts: 38
Joined: Sun Jul 25, 2010 3:13 pm

[Solved] [Python][UI] Refresh window/widget

Post by OlivierR »

Hello everyone,

I created an window with Python. There are several widgets and especially several FixedTexts.

Once the action is performed, I would like to refresh some of these FixedTexts, so I modify the property “Label” of these widgets. But it doesn’t update the UI. What should I do?

Here is the simplified code:

Code: Select all

class TextFormatter (unohelper.Base, XActionListener, XJobExecutor):
    def __init__ (self, ctx):
        self.ctx = ctx
        self.xSvMgr = self.ctx.ServiceManager
        self.container = None
        self.dialog = None
        
    def addWidget (self, name, wtype, x, y, w, h, **kwargs):
        widget = self.dialog.createInstance('com.sun.star.awt.UnoControl%sModel' % wtype)
        widget.Name = name
        widget.PositionX = x
        widget.PositionY = y
        widget.Width = w
        widget.Height = h
        for k, w in kwargs.items():
            setattr(widget, k, w)
        self.dialog.insertByName(name, widget)
        return widget

    def run (self):
        # dialog
        self.dialog = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx)
        self.dialog.Width = 200
        self.dialog.Height = 345
        self.dialog.Title = self.dUI.get('title', "#title#")

        [...]
        
        self.myFixedText = self.addWidget('ssp1_res', 'FixedText', 10, 10, 10, 10, Label = "")
        
        [...]
        
        button = self.addWidget('apply', 'Button', 95, 325, 80, 14, Label = self.dUI.get('apply', "#error#"))

        # container
        self.container = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog', self.ctx)
        self.container.setModel(self.dialog)
        self.container.getControl('apply').addActionListener(self)
        self.container.setVisible(False)
        xToolkit = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.ExtToolkit', self.ctx)
        self.container.createPeer(xToolkit, None)
        self.container.execute()
        
    def actionPerformed (self, actionEvent):
        try:
            [...]
            
            self.myFixedText.Label = "OK"
            
            self.container.endExecute()
        except:
            traceback.print_exc()
    
    def trigger (self, args):
        try:
            dialog = TextFormatter(self.ctx)
            dialog.run()
        except:
            traceback.print_exc()


g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(TextFormatter, 'dicollecte.TextFormatter', ('com.sun.star.task.Job',))
Specifically, the line:

Code: Select all

 self.myFixedText.Label = "OK"
doesn’t update the FixedText.

BUT if I use xRay just after setting a new label, it works:

Code: Select all

self.myFixedText.Label = "OK"
xray(self.myFixedText)
Then, the widget FixedText is updated.
Last edited by OlivierR on Thu Apr 25, 2013 9:33 pm, edited 2 times in total.
LibreOffice 6.4Windows 10
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: [Python][UI] Refresh window/widget

Post by hanya »

How about to set the dialog model to the dialog control before you to add some controls to the dialog model?
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
OlivierR
Posts: 38
Joined: Sun Jul 25, 2010 3:13 pm

Re: [Python][UI] Refresh window/widget

Post by OlivierR »

I did that, but it changes nothing.
LibreOffice 6.4Windows 10
OlivierR
Posts: 38
Joined: Sun Jul 25, 2010 3:13 pm

Re: [Python][UI] Refresh window/widget

Post by OlivierR »

Writing

Code: Select all

self.container.setVisible(True)
after updating the FieldTexts solves this issue.
LibreOffice 6.4Windows 10
Post Reply