Custom confirmation window

Hi,
I’m trying to make a custom confirmation window for my application. But I can’t figure out how to make a window return a value. Has anyone figured out a “simple” way to do this? or is it best to just stick with system.gui.confirm() ?

The simplest way would be to have custom parameters on the root of the confirm window that specify a window name and property name the confirmation window should look up and write to with its result. The caller would supply its own name and a suitable property when opening the confirm window, then catch the result with a propertyChange event.
This won’t work if there can be multiple instances of the calling window – you’d need some kind of callback registry in a script module. If you have to go that route, be sure to use the weakref module to hold window objects.

I’m not nearly as experienced as pturmel, but I like it Barney style. I use a client tag Boolean. I write to it with a button on my custom popup and rewrite the tag with a propertyChange event attached to the source which fired the confirmation sequence.

1 Like

Thanks for the advice. I got it working now. I don’t think I will get a problem with multiple instances. But just out of curiosity, do you have a example (for dummies) of using weakref module with a Ignition object?

Not handy, no. Or I would have posted it. Instead of just brainstorming in public. (-:

1 Like

I was just about to implement a full callback mechanism for this when I had a thought - now that we have custom functions, we can use Phil’s property idea, but get it to call a custom function on the window instead…

The custom popup has callbackWindow and callbackProperty (both strings), which are passed by the parent window like this:

system.nav.openWindow('Custom popup', {
	'callbackWindow': 'Parent window',
	'callbackProperty': 'callback',
})

Then the save button for the custom popup does this:

root = system.gui.getParentWindow(event).getRootContainer()
fn = getattr(system.gui.getWindow(root.callbackWindow), root.callbackProperty)
fn(result)

Which calls the callback custom function defined on ‘Parent window’:

def callback(self, result):
    # Do something with result

This seems to work well. It’s far easier than a full callback system with weakrefs and far better than messing around with propertyChange events (which tend to fire too often, like when the window is opened or the project is updated).

2 Likes

That’s pretty close to the “simplest way” that I suggested, but with a custom method instead of a propertyChange event. What it lacks is any way to use this when the calling window is one of multiple instances. That’s where the suggestion to use weakrefs to actual window objects comes in. For the pedants among us. (-:

Attached is what I am using to authorize a user within the application and execute code on success or failure.

calling:

window = system.nav.openWindow('WindowsAuthorization', {'Role':'SMF-Ignition-Admin'})
window.setActions(lambda caller: system.nav.openWindow('LaneManagement2'))

TEMPLATE_1_WindowsAuthorization_2017-11-07_0734.proj (11.0 KB)

I’m not worthy. Any of you guys do jobs on the side for coffee and doughnuts?

Thanks for the ideas!!

I’ve been known to do things for pizza and beer… (-:

Beer and friends sounds fine