11-05-2010 04:07 PM - edited 11-05-2010 04:10 PM
Hi fellows !
I have a question for all the LabVIEW aficionados here.
Today, I answered to a question on the French part of the forum. This question was how to set focus back to a VI front panel (foreground) that was used to call and execute another VI (and show its front panel of course).
I just made an example like this :
The main VI
The sub VI :
As you can see, in order for the sub VI to set focus back to the main VI before it terminates its execution, I use a VI reference control to get the reference of the main VI. But I was wondering if this method is really efficient and correct ? What would you have done in this case to get the reference of the main VI ?
Thanks in advance for your help and advices.
Regards,
11-05-2010 04:32 PM
Two ideas:
11-05-2010 04:42 PM - edited 11-05-2010 04:43 PM
Two ideas:
Hi Altenbach,
Thanks for the quick answer.
Actually the sub VI has to close its front panel so placing it to the background can't be possible. But when doing that does it sets focus back to the main VI ?
I tried the call chain primitive but I only get the sub VI, I think this is normal because I am "dynamically" calling the sub VI. What do you think about that ?
Thanks again !
Regards,
11-05-2010 04:52 PM
Main has already a ref to the dynamically called vi. You can register for the FP.Close Event of that vi in the Main, and when it fires, set the FP to focus and unregister the event.
The advantage is to have the focus methods all in the same VI (so the responsible is inside the main).
Felix
11-05-2010 05:03 PM - edited 11-05-2010 05:04 PM
Main has already a ref to the dynamically called vi. You can register for the FP.Close Event of that vi in the Main, and when it fires, set the FP to focus and unregister the event.
The advantage is to have the focus methods all in the same VI (so the responsible is inside the main).
Hi Felix,
Thanks for the answer.
It seems like it is a good idea, but I cannot manage to make it work because when I registre for the FP.Closed event, I get an error saying that the FP of the sub VI is not open.
I could register for the event after the FP is open but my event structure won't accept it. How would you do that ?
Regards,
11-05-2010 05:14 PM - edited 11-05-2010 05:19 PM
11-05-2010 05:18 PM
I don't have LV available, so I can't test. But I'd place it between the FP.Open and The RunVI method. You can wire the dynamic refnum (out) of the Event structure from the inside.
Felix
11-05-2010 05:27 PM - edited 11-05-2010 05:31 PM
Well, it doesn't work too...The sub VI is opened but it doesn't run maybe because the FP.Close event registering is outputting an error.
When I place it after the Run VI method, the sub VI runs well, but I get an error when I close it.
Well, I hope we'll end up finding out how to do it this way. In the meantime I wish you a nice weekend.
Regards,
11-05-2010 05:37 PM
I'm not sure (as I can't test right now), but propably this isn't working due to the fact mentioned here
The "Panel Close" event can be used with callback however it will only trigger when the subVI exits via the Window Close button (X in the upper right corner).
The way suggested there is to use a callback queue to the main to signal the exit of the dynamically spawned subVI.
In your scenario, why not just use the simple call by reference node with a Window.State=hidden before and a Window.state=standard after?
Felix
11-05-2010 05:51 PM
I'm not sure (as I can't test right now), but propably this isn't working due to the fact mentioned here
The "Panel Close" event can be used with callback however it will only trigger when the subVI exits via the Window Close button (X in the upper right corner).
The way suggested there is to use a callback queue to the main to signal the exit of the dynamically spawned subVI.
I did the test with the Window Close button and the event was not fired. Maybe I am doing something wrong.
I think that using a queue is the best option in this case. I'll try it. I didn't think about this solution thanks for bringing it up.
In your scenario, why not just use the simple call by reference node with a Window.State=hidden before and a Window.state=standard after?
Because with this way, if I have several VIs opened, I am not sure that the calling VI will be the first window on the foreground (I think, I didn't test that).
Thanks again for your help and patience.
Regards,