system.util.invokeLater with Arguments

system.util.invokeLater can be awkward to use when you need to pass in arguments to the function that will be called.

That’s why I wrote the function app.util.invokeLaterWithArgs().

This function works the same way as system.util.invokeLater except you can pass in positional or keyword arguments for the function that will run, and it will still be invoked later.

Here is an example of its use:

Some function like the setNum function could be defined somewhere:

def setNum(e,num):
  e.source.text = num

Then setNum could be invoked later with keyword arguments like this:


Or it could be invoked later with positional arguments like this:


Here is the code that implements app.util.invokeLaterWithArgs()

def invokeLaterWithArgs(f,*args,**kwargs):
  def func(f=f,args=args,kwargs=kwargs):

You might need to add “import system” to the invokeLaterWithArgs function. I didn’t because I usually add this to the top of all my Jython modules:

global system,app
import system,app