Jump to content
Sign in to follow this  
Michael Aivaliotis

Manipulating text with the text selection property

Recommended Posts

Here is an example VI (LV7.0) that shows how to manipulate text in a text box. The focus of this example is the Selection Start + Selection End property. This can be very powerful in performing custom live formatting of front panel text.

The trick here is to perform formatting on the text after you highlite the section of interest. The Font property is then used within the same property node.

text_hi_lite.vi - Image:

post-2-1089818933.gif?width=400

Download File:post-19-1088657566.vi

Share this post


Link to post
Share on other sites

[attachmentid=undefined]Wouldn't you want to do this more efficiently with event structure? .... Don

Here is an example VI (LV7.0) that shows how to manipulate text in a text box. The focus of this example is the Selection Start + Selection End property. This can be very powerful in performing custom live formatting of front panel text.

The trick here is to perform formatting on the text after you highlite the section of interest. The Font property is then used within the same property node.

1084[/snapback]

Download File:post-115-1089650321.vi

Share this post


Link to post
Share on other sites
Wouldn't you want to do this more efficiently with event structure? .... Don

1131[/snapback]

Yes! Thank You Don for the updated version. My goal was to show how the specific property node would be used. The event structure as you show it would be a much better, and preferred, implementation. Thanks for the improvement. :thumbup:

post-2-1089650995.gif?width=400

Share this post


Link to post
Share on other sites

Don't know how the event structure improves the following because I don't have access to >6.1 at the moment ...

When I originally was after this sort of thing I was using it to create a ?simple? text editor and the highlighting was for the FIND method. It works nicely (apart from a brief flash as the text is highlighted). Now is it possible to extend this to give me real time <cough> syntax highlighting?

By that I mean as I type 'word' and word is in my list of defined text strings to be green, it gets coloured green. I reckon this could be done with the text select and highlight method outlined before, but it might be pretty ugly (flash, flash, etc), especially when loading and parsing a file for syntax highlighting at startup.

Does anyone have any better ideas?

Share this post


Link to post
Share on other sites
Don't know how the event structure improves the following because I don't have access to >6.1 at the moment ...
LV6.1 has event structures.
Now is it possible to extend this to give me real time <cough> syntax highlighting?
I don't see why not? Have you tried it? What problems are you seeing?
I reckon this could be done with the text select and highlight method outlined before, but it might be pretty ugly (flash, flash, etc).
I didn't see any flashing on my end in the examples posted previously.

I saved the LV7.0 version into 6.1 however I noticed that the behavior changed. The 6.1 version behaves very buggy. It does not remove the hi-lighting... :(

Open the attached VI using LV6.1 to see bug.

Download File:post-2-1090558621.vi

Share this post


Link to post
Share on other sites

In a recent Info-LabVIEW thread there was a need for HTML display.

I have wired this SimpleFormatter.vi that accepts tagged (markup text) and display it in a string. With a syntax parser that will wrap keywords with property tags, it can be used for syntax highlight.

It still require some work (to handle the character "<") and has merely been tested with the provided example. The font property also needs to be implemented. Correct syntax is assumed.

I defer panel updates when formatting the string but the string indicator is still drawn twice.

Download File:post-447-1091080666.vi

Download File:post-447-1091080685.vi

Share this post


Link to post
Share on other sites
I saved the LV7.0 version into 6.1 however I noticed that the behavior changed. The 6.1 version behaves very buggy. It does not remove the hi-lighting...

Indeed, the behaviour in LV6.1 is strange, but there is a workaround to revert a formatting of a portion of the text:

1. select the whole text in your control/indicator

2. format it the way your text portion was formatet (e.g. make whole text bold)

3. revert the formatting on the whole text (e.g. bold set to false)

4. reformat the portions that should have kept their format.

post-253-1091172104.jpg?width=400

Didier

Share this post


Link to post
Share on other sites

It's again me...

I made some tests and got (hope so) the problem on LV6.1 with undoing a text format.

It seems that the SelStart and SelEnd marker have to reside on a text that is formated the way you want to undo. In between have as much different formatings as you want.

E.g. if you want to undo bold on a text portion, the character after SelStart and the one before SelEnd have to be bold. The other way nothing happens.

I've rewritten Michael's example with an event structure. It gives back the new value of the slider (to format the new portion) and the old value (to unformat).

Didier

Download File:post-253-1091175663.vi

Share this post


Link to post
Share on other sites

:yes:

Excellent! I fiddled with this for an hour on Wednesday and could not figure out the odd behavior in LV 6.1. Your solution is great, it solves the problem exactly.

Thanks,

Share this post


Link to post
Share on other sites

:oops:

I downloaded SimpleFormatter.vi and after using it, I found a small bug. All text after the last text formatter is truncated. I also modified the search for tags to be case independent, so now <b> = <B>. This new version is in LabVIEW 7.1.

Thanks for this cool new tool jpdrolet.

In a recent Info-LabVIEW thread there was a need for HTML display.

I have wired this SimpleFormatter.vi that accepts tagged (markup text) and display it in a string. With a syntax parser that will wrap keywords with property tags, it can be used for syntax highlight.

It still require some work (to handle the character "<") and has merely been tested with the provided example. The font property also needs to be implemented. Correct syntax is assumed.

I defer panel updates when formatting the string but the string indicator is still drawn twice.

1250[/snapback]

Download File:post-151-1094751483.vi

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

×
×
  • Create New...

Important Information

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