Button refreshing text as script runs

Because your script is running in the EDT. The EDT controls painting as well. To elevate into a background thread, you will need to do the following:


def doLater():

	import time
	event.source.text  = "Waiting 2 seconds"
	time.sleep(2)
	event.source.text  = "Waiting 5 seconds"
	time.sleep(5)
	event.source.text  = event,"Finished"
system.util.invokeAsynchronous(doLater)

Technically, we should be moving the setting of text back into the EDT to prevent thread locks. It gets messier, but should look something like this.

In app.gui, place the following method

def setText():
	evt.source.text = text

In you button actionPerformed script, place the following

def doLater(event=event):
	#Initialize global variables to pass into back to edt
	global evt
	evt = event
	global text
	text = ""
	
	#import stuff
	import time,system
	from app.gui import setText

	text="Waiting 2 seconds"
	system.util.invokeLater(setText)
	
	time.sleep(2)
	text="Waiting 5 seconds"

	system.util.invokeLater(setText)
	time.sleep(5)

	text="Finished"
	system.util.invokeLater(setText)
system.util.invokeAsynchronous(doLater)