LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Two front panel looks/arrangements, same code

Looking for a way to show different front panels with identical controls but different layout and have one set of code respond to user activity (button presses, mouse down on control, key down).   I can do this by replicating all of the controls on the same front panel and only show one portion or the other but this means complicating the event structure and a lot of monkey business ensuring the correct set of indicators get updated, controls get hidden/enabled, etc.

 

Seems like Subpanel container might be an avenue -- thinking of having the different front panel looks as separate VIs that show in a subpanel but can't quite figure an elegant way to transfer UI event from "whichever one's loaded" back to a single event-handling set of code. 

 


Also thinking OOP might apply here -- do the same thing with inputs from different-looking front panels.  If so, can someone please post an example of how this might be accomplished?

0 Kudos
Message 1 of 6
(2,988 Views)

I think the easiest way to do this is to put a tab control on the front panel, with one page per user interface you want to display. Hide the tabs, so that the user can't click to switch between them. If there are user interface elements that should be visible at the same location in both interfaces, place that control or indicator on top of the tab (it might be displayed with a shadow, but that will disappear when you run it). Yes, you'll still need to handle all the items in an event structure, but you won't need to deal with showing and hiding items as appropriate.

0 Kudos
Message 2 of 6
(2,973 Views)

@Zwired1 wrote:

Looking for a way to show different front panels with identical controls but different layout and have one set of code respond to user activity (button presses, mouse down on control, key down).   I can do this by replicating all of the controls on the same front panel and only show one portion or the other but this means complicating the event structure and a lot of monkey business ensuring the correct set of indicators get updated, controls get hidden/enabled, etc.

 

Seems like Subpanel container might be an avenue -- thinking of having the different front panel looks as separate VIs that show in a subpanel but can't quite figure an elegant way to transfer UI event from "whichever one's loaded" back to a single event-handling set of code. 

 


Also thinking OOP might apply here -- do the same thing with inputs from different-looking front panels.  If so, can someone please post an example of how this might be accomplished?


Do you mean you want to have two different vi's with similar controls but at the backend it should behave differently? If that is the case Sub Panel is one of the right option. If I mis understood your question, please explain your problem.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 3 of 6
(2,960 Views)

I'd like to have two different front panel arrangements (different aspect ratios for laptop versus desktop monitor) but identical qty and type of controls/indicators. 

 

The tab control approach works, and I have used it in the past, but there is signifiant overhead for relatively high control/indicator count and a much-increased oportunity for bugs.  Every time I update an indicator I have to update both tab's worth, every time I use a local variable I have to create/pay attention to both tab's controls, etc. 

 

What I'm after is a way to have a VI load one of two front panel arrangements and process events from whichever one is loaded. 

 

In the simplest case:

     1] a single button is the only control I care about

     2] it is located in different locations on two different front panels

     3] I want to show only one of the front panels

     4] I want to execute the same code if the button is pressed, regardless of which front panel is shown

     5] I want one set of code to handle the controls/indicators so that I don't have to remember to always update both versions

 

 

0 Kudos
Message 4 of 6
(2,949 Views)

Rather than two separate front panels, have you considered adding some code to rearrange the existing controls on a single front panel when the program starts? You could keep the window hidden until this happens if you don't want the user seeing it. It wouldn't be difficult to write a VI that accepts a front-panel reference, gets the label and location (and possibly font size or whatever other properties) of every control and indicator on the front panel, and writes them to a file. Then your program reads that file at startup and sets all the control properties as desired. You could have as many different layouts as you want, each in separate files (or separate sections of the same file) and it would be easy to create them - just move the controls to the desired locations, and run the property-saving VI. The work may even have been done for you already - check out the Property Saver (scroll down a bit on that page; note, I haven't used it).

0 Kudos
Message 5 of 6
(2,947 Views)

The usually recommended way of doing this is by completely separating the UI from the logic using patterns such as model-view-controller and communicating between the components, but those architectures usually tend to be more complex. If you want to do something like this relatively simply you can create a cluster of references to the FP elements and pass that cluster into a subVI which will contain all the logic. It will register for events, do all the updates, etc. The UI VI then only bundles the references and passes them to the subVI. Then, you can simply create as many separate UI VIs as you like and call the correct one.


___________________
Try to take over the world!
0 Kudos
Message 6 of 6
(2,921 Views)