Jump to content

Key focus lost


Guenther

Recommended Posts

Hi guys,

I'm working on an application where the main VI repeatatly (every few sec) calls a sub-VI, which is visible in order to display some information. This call is made in the consumer loop of a state machine. On the other hand, the user should be able to edit the content of a control (numeric within an array within a cluster) in the main VI. However, each time the sub-VI gets called, the control in the main VI immediately looses key focus, which makes it very cumbersome to edit its contents..

Of course you can prevent the loss of key focus by making the main VI modal, but that also prevents any user interaction with any sub-VI, so I'd like to avoid this.

In this thread Yair showed a way how to keep the key focus on a control using the "FocusObj" property, which is available in some key-related events. I haven't found this property outside these events.

So, is the any way to prevent the loss of key focus without making the main VI modal?

Thanks a lot,

Guenther

Link to comment

I don't think that key focus is the right thing to consider here - what I think is happening is that you probably have "Show Front Panel When Called" enabled in the sub VI or in the SubVI Node Setup, so all LabVIEW knows to do is switch the panel (window) focus to that sub VI whenever your main routine calls it. As soon as that happens, the Main VI is in the background. You might want to dynamically open the subVI panel (don't enable "Show Front Panel When Called" in the sub VI or the SubVI Node Setup) and then when you execute the sub VI it will show its current data but it won't bring the panel to the front or cause a control in use on the main panel to lose focus.

Mark

Link to comment

I'm not sure, but if memory serves, you can't open a VI's front panel without it taking focus, even if you use the method Mark mention, unless the caller is modal. It's possible that this will work with a floating VI, but I'm not sure.

Here are some ideas for workarounds. I'm not sure if they're all workable:

  1. Use the input VIs to read the keyboard all the time, regardless of control and VI focus. This will require polling and some additional logic.
  2. Use the IsFrontmost VI property and KeyFocus property to return the VI and the control to focus automatically. This is probably bad, as this could happen while the user was typing.
  3. Use a subpanel to display the subVI instead of a popup.

Link to comment

Yair,

I think you're probably correct that as you open the front panel it will take focus but if you leave it open and then don't invoke the "Show Front Panel when Called" method I don't think it will take focus on subsequent calls. So once the sub VI is open the user can bring the main VI to the top and it will stay there. I can't try this right now and confirm this to be true (since I'm not at a computer with LabVIEW) but I think this is correct.

Mark

QUOTE (Yair @ Nov 29 2008, 09:14 AM)

I'm not sure, but if memory serves, you can't open a VI's front panel without it taking focus, even if you use the method Mark mention, unless the caller is modal. It's possible that this will work with a floating VI, but I'm not sure.

Here are some ideas for workarounds. I'm not sure if they're all workable:

  1. Use the input VIs to read the keyboard all the time, regardless of control and VI focus. This will require polling and some additional logic.
  2. Use the IsFrontmost VI property and KeyFocus property to return the VI and the control to focus automatically. This is probably bad, as this could happen while the user was typing.
  3. Use a subpanel to display the subVI instead of a popup.

Link to comment

QUOTE (mesmith @ Nov 29 2008, 06:19 PM)

Yair,

I think you're probably correct that as you open the front panel it will take focus but if you leave it open and then don't invoke the "Show Front Panel when Called" method I don't think it will take focus on subsequent calls. So once the sub VI is open the user can bring the main VI to the top and it will stay there. I can't try this right now and confirm this to be true (since I'm not at a computer with LabVIEW) but I think this is correct.

Mark

Yes, this works indeed. I disabled "Show Front Panel when Called" in the sub-VI and called the FP.Open property for the sub-VI during initialization of the main VI. As expected, the window of the sub-VI pops open immediately, but the sub-VI does not grab focus anymore when called.

Thanks for the solution!

Cheers,

Guenther

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.