Jump to content

XControls


Recommended Posts

I have a question for you. How do you change the background colour of a numeric control based on the value of the control as you enter the data. I want the control to change colour when the value of the entered data is outside the coerc range. when the data is within the range I would like to know that the value I have typed is going to be accepted before I move the mouse off the control or press enter.

Link to comment

There are many ways to skin this cat!

XControl is one way, but you would be using a 298 piece mechanics tool set to hammer a nail into a wall that would work w/ a stiff shoe.

I would reccommend making a 'Brat' VI (as in child... not sausage). I'll describe what this means in a minute.

This VI would sit outside of any loops in your VI that contains the numeric.

  • You would pass a reference or array of numeric reference into this Brat VI with the limits and colors corresponding
  • Inside of the Brat you would take the reference and register it for the value changed event.
  • Then you would setup the brat to respond to the event and change the background based upon the limits and colors passed in.

Once you do your first one, you'll be amazed at the ability this gives you w/ a little work.

And the best part is that these are some of the most reuseable VIs around.

2008-07-28_1346.png

Now more on what a 'Brat' is.

It is a Child (vi) that controls the Parent (vi)

the idea is that you can easily drop 1 SubVI into your code and it does things varying from resizing windows or moving origin or changing the cursor and so on.

For your example, it's modifying the BG color of a numeric on the parent VI

They usually weigh heavily on dynamic events thus making them very light utilities that don't use much memory or processor.

there used to be some examples on LAVA but I can't find them through the search

Link to comment

Actually that's the best way to do it.

If not you'll have to double respon..... wait no... triple respond to events.... no wait. Quadruple respond.

you would need to catch

key down

drop

mouse down

value change

maybe even more.

There is no silver bullet to catch all events for controls as they are in change mode except to use the update while typing for a string.

It actually even makes it more flexible as there are less restrictions on a string from what you can do with a numeric control.

Link to comment

I can see that the value of the last button press is available in an event but where is the cursor.

(and therefore you don't know what the value is)

I take your point that strings might be the best way to do it in LabVIEW. (but is it the only way?)

So how do I make my string look and behave just like a numeric. or perhaps I should stop using numerics altogether?

Link to comment

QUOTE (GreatVIEW @ Jul 28 2008, 03:30 PM)

...I take your point that strings might be the best way to do it in LabVIEW. (but is it the only way?)

...

Strings are the only data type I know that will allow update while typing. If you know what is the string at last update you can figure what was added. Since the numerics don't allow update while... you are faced with a pile of work to implement all of the numeric behaviour as a string (numerics only, no text...).

Either done as a brat or turned into an XControl, there is a lot of work.

On the plus side for the XControl...

Once develeoped your diagram will be clean.

Ben

Link to comment

QUOTE (GreatVIEW @ Jul 28 2008, 11:20 AM)

I have a question for you. How do you change the background colour of a numeric control based on the value of the control as you enter the data. I want the control to change colour when the value of the entered data is outside the coerc range. when the data is within the range I would like to know that the value I have typed is going to be accepted before I move the mouse off the control or press enter.

Maybe what you should do is look at your application design more carefully. You may need to separate the GUI layer (for example, the value that is input on the front panel) from you application logic (ie, don't just automatically use the value the user entered in your application). This could be done in conjunction with using Norm's "brat" concept or an Xcontrol.

Link to comment

QUOTE (GreatVIEW @ Jul 28 2008, 03:52 PM)

I'm not sure that I know the event for reading the numeric before the value has been commited to the diagram. does it exist...

Say the limit for your numeric is 100 and you highlight the last zero and replace with 94859485. how do you read that value?

Convoluted idea follows:

Watch for control to get key fucus

Declare events to watch key strokes

In event for key strokes collect your keys and act as you choose?

Ben

Link to comment

QUOTE (GreatVIEW @ Jul 28 2008, 02:52 PM)

I'm not sure that I know the event for reading the numeric before the value has been commited to the diagram.

Thats because there is none.

The best* you could do is to catch each interaction w/ the control and do your own interpretation as to what has happened (like the drop or keydown)

Link to comment

QUOTE (neB @ Jul 28 2008, 08:58 PM)

Convoluted idea follows:

Watch for control to get key fucus

Declare events to watch key strokes

In event for key strokes collect your keys and act as you choose?

Ben

how do you know where the cursor is a the start?

or how much of the original value has been highlighted?

I hear you but I really want to show the operator that the number that they are trying to enter is out of range. I want as few key presses as possible.

Link to comment

You might try creating an event handler, then in a single event case for the control, registering at least key down/up/repeat, plus value change (of course), perhaps a few others.... then in the event case, read the property of the numeric "Numeric Text->Text". I would take this text into a "Scan From String" node, plus probably a "Match Pattern" as well, and check both the numeric value of the scanned string to your limits and also whether the Match Pattern finds non-numeric cruft. Not exactly easy, but from this you might be able to get an as-they-type peek at what the user is doing, and recolor the numeric's background in response, even before the control is validated. If that's really what you need to do...

Just my 2 cents' worth.

Dave

Link to comment

QUOTE (Aitor Solar @ Jul 29 2008, 02:42 AM)

Interesting idea this "brat" ;) . The (minor) problem I see is the need to stop the brat loop from outside. ...

I've used the control ref to climb back up the tree to the VI that owns it. Register an event for the screen close and monitor its running state. Exit if either happen. "look Ma, no-hands!"

Ben

Link to comment

QUOTE (GreatVIEW @ Jul 28 2008, 02:35 PM)

Could be. the point stands for any UI

I think Norm's point was that you have to account for all the possible ways a user could change the value. These include drag'n'drop, cut and paste, etc. If you restrict certain avenues (like no mouse) then you don't have to worry about that in your code.

It really depends on how full and robust you want it to be. If you want to handle only the nominal keyboard entry of a value, then you might ignore the rest. You have chosen something difficult to put into the UI. Until the user commits the value, it really isn't a number -- it is just some numeric characters. That is, the block diagram end of things doesn't see a new number until it is committed.

Making a string act just like a numeric would be painful as well. Scanning all the characters entered and only allowing numerics...

Is coercing the value to something within range an option? You can easily implement that without any code. There might be other solutions that are much more reasonable to implement.

Link to comment

QUOTE (GreatVIEW @ Jul 28 2008, 09:30 PM)

String.selection.start

QUOTE (neB @ Jul 28 2008, 09:49 PM)

Either done as a brat or turned into an XControl, there is a lot of work.

On the plus side for the XControl...

Once develeoped your diagram will be clean.

Ok, I posted here an XControl to have an InputMask function, this could quite easily be expanded to the functionality you need.

Ton

Link to comment

gallery_12122_90_14136.jpg

Required Functionality

Numeric background colours goes yellow when you click into it.

Then as you edit the value it goes red if the number is too high or too low.

Then press Enter.

Background colour goes green. and stays green until the diagram reads the value. (which depends on the speed and activity in the loop)

when the value has been commited the colour returns to default.

Link to comment

QUOTE (GreatVIEW @ Jul 30 2008, 03:54 PM)

Required Functionality

Numeric background colours goes yellow when you click into it.

Then as you edit the value it goes red if the number is too high or too low.

Then press Enter.

Background colour goes green. and stays green until the diagram reads the value. (which depends on the speed and activity in the loop)

when the value has been commited the colour returns to default.

Yes, uhm, what do you want?

Is this a challenge?

Ton

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.