I want in my script get a confirmation from user for running some code so I wonder as perspective is single thread per session how can I open a popup and wait until the user click on cancel or confirm and base on that I run my code?
In vision it is very easy with system.util functions.
I think may be I have to pass my code as function to popup and in popup it run the function base on user action.
Is any there any other solutions for this?
If you make it a modal, the gui being single threaded shouldn’t be an issue, I think ?
Or is there something else that gets blocked and that must keep running ?
I’m guessing you could use messages to make a more generic version of an action popup, with the message handler configured on the button/whatever opens the popup, and passing it the message handler’s name as parameter… Then you can have two buttons on that popup, one that closes it and the other one that sends the message.
The problem of message is the view that call the popup has many instances in the primary view so for each Lister I have to have a different msg type which is not possible since the msg type is hard coded in perspective.
Perspective components have the java.lang.Object.wait() and notify functions .
I think it makes them pauze the thread untill something else notifies it… i have never used it tho so im not sure it will do what you want
Even from Java code, you should basically never call wait() or notify(). I would definitely not do it from scripting.
I strongly suspect the only real way out here is rearchitecting; perhaps message handlers reacting to each 'stage' in this process accordingly. There's no way to do 'blocking' work like this in scripting.
I handle all my code through project scripts, and then will essentially call a universal popup that is provided a callback function, and on submit it calls back the same function with keyword arguments for response data. This way I can call the same function multiple times in a row and the second time I know just to skip to the response code because a response is present.
I use this pretty heavily in an app that requires a ton of dynamic user confirmations and inputs.
Technically this doesn’t “wait” for the popup, it just splits the code into two executions of “the first half” and the “back half” in the same function.
EDIT: I actually also use this to cancel currently running threads as well, a bit more complicated to explain, but that’s possible as well.