How to change visibility during a event script to hide the table that is updating?

I’m using an event scrip to update a table from opc tags, with browse. The browse and read takes a few seconds, in that time the table is out of date. I tried to fill the table with an empty header and data, and I’ve tried covering it with a label.

if event.propertyName == "path":
    import system, time, mfg_IgnitionLib as tb
    
    Updating = event.source.getComponent('Updating')
    Updating.visible = True
    ####### Start    
    start = time.time()            
    
    opcServer = "TcOpcUaServer@Factory1"
    rootOPCPath = event.source.path
    ConfigTagTable = event.source.getComponent('Configuration Tags')
    ConfigTagTable.data = tb.getTableData(opcServer, tb.browseCfg(opcServer,rootOPCPath,0,1))
    Updating.visible = False
    #results = writeOPCfromTable(opcServer, rootOPCPath, ConfigTagTable.data)
    tb.logger.info('Read OPC Complete : { "totalTime" : "%s"}' %(time.time() - start))

You can move long running tasks you want to do to an asynchronous thread, using system.util.invokeAsynchronous.

Note the caution at the top of the manual, which I'll repeat here:

Caution

This function should not be used to asynchronously interacts with the GUI in Vision. This means interacting with window navigation, setting and getting component properties, showing error/message popups, and really any other methods that can interact with components and windows. If you need to do something with the GUI in Vision with this function, this must be achieved through a subsequent call to system.util.invokeLater.

1 Like

A bit of clarification:

Your event script runs in the foreground, and Java Swing is single threaded for all component updates. Which means your attempts to hide or alter a component will not be drawn until you give up the CPU (finish your event script).

Long old thread here, but still valid:

2 Likes

Thank you!

Little clean up note on your script - you never need to import system and you never should import your own library scripts - it can cause caching issues.

3 Likes

It sounds like you have a browse button that they click and then it updates the table? You could have the browse button first have an event to enable the visibility of a loading message then at the end of your script revert said visibility setting. One option for a work around rather than doing it mid script.