InvokeLater Function with Args

How do I use system.util.invokeLater() with a function that takes arguments.

For instance, I would normally call

setDockedNavSelections(tier1, windowPath)

How do I effectively call

system.util.invokeLater(setDockedNavSelections(tier1, windowPath), 200)

?

The manual should really be updated with an example for this. I would imagine the use case for with and without args would be split somewhere around 50/50

Look in my later.py script module at callLater for an example.

(It uses closures. You can also use default arguments with def something(...) to capture values. Or jython's partial() function.)

Consider just using later.callLater() instead of system.util.invokeLater() everywhere.

This:

setDockedNavSelections(tier1, windowPath)

Becomes this:

later.callLater(setDockedNavSelections, tier1, windowPath, ms=200)

Thanks, didn't realize I could just define a function in-place with the default arguments assigned as my args. So I have

def setDockedNavSelectsionLater():
	setDockedNavSelections(tier1 = tier1, windowPath = windowPath)
	
system.util.invokeLater(setDockedNavSelectsionLater, 200)

It works too, but I prefer the @pturmel solution because it's easier to read for another person.

I'm a fan of partial for this, or you can just effectively make an inline closure via lambda:

system.util.invokeLater(lambda: setDockedNavSelections(tier1, windowPath), 200)
6 Likes