Setting the text style of certain words in a field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 4
- Joined: Mon Oct 03, 2016 8:11 pm
Setting the text style of certain words in a field
Hi,
I've played around, searched, but not found anything...
(Sounds like the first line of a Country & Western song
Anyway, I have a field which contains a Python Script.
I'd like to set the text style of certain words...
eg
def, return, import, for : bold, blue
numbers should all be red
comments should be green
I'm happy to parse the field to find the relevant sections and words, but how do I apply the text style atrributes.
Thanks
Louis
I've played around, searched, but not found anything...
(Sounds like the first line of a Country & Western song
Anyway, I have a field which contains a Python Script.
I'd like to set the text style of certain words...
eg
def, return, import, for : bold, blue
numbers should all be red
comments should be green
I'm happy to parse the field to find the relevant sections and words, but how do I apply the text style atrributes.
Thanks
Louis
Re: Setting the text style of certain words in a field
I believe the htmlText property in the dictionary may be what you want. You can set many aspects of text styling with it, including colors. Alternately, textStyle / textColor could be used. Just type "text" in the dictionary, there is a lot there
-
- VIP Livecode Opensource Backer
- Posts: 9582
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Setting the text style of certain words in a field
What Bogs said.
The HTML text will allow you to attach style tags to text within, say, a variable. You need to research this as per his suggestion, since this is a powerful tool indeed.
But just to get back to basics, put some numbers and ordinary words in a field. Put this in a button script somewhere:
This will require forethought to parse text , as you say, into several different categories. The "offset" function might come in handy...
Craig Newman
The HTML text will allow you to attach style tags to text within, say, a variable. You need to research this as per his suggestion, since this is a powerful tool indeed.
But just to get back to basics, put some numbers and ordinary words in a field. Put this in a button script somewhere:
Code: Select all
on mouseUp
repeat with y = 1 to the number of words of fld 1
if word y of fld 1 is a number then set the textColor of word y of fld 1 to "yellow"
else set the textColor of word y of fld 1 to "blue"
end repeat
end mouseUp
Craig Newman
Re: Setting the text style of certain words in a field
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Setting the text style of certain words in a field
Hi Craig, one could quibble, but when I put the following text into a field and ran the code above...dunbarx wrote: ↑Thu Jul 13, 2017 1:50 pmBut just to get back to basics, put some numbers and ordinary words in a field. Put this in a button script somewhere:Code: Select all
on mouseUp repeat with y = 1 to the number of words of fld 1 if word y of fld 1 is a number then set the textColor of word y of fld 1 to "red" else set the textColor of word y of fld 1 to "blue" end repeat end mouseUp
I expected all the numbers to turn red. Only 100 and 10000 did. Note 10000 is also followed by punctuation, as is 3 and 4, but 3 and 4 were ignored. I am sure some complicated logic but a numbers a number. If it captures 10000 why not 3 and 4?How do you style some text in a field? One, two, 3, 4, who are we for? 100 times 100 is 10000.
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 9802
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Setting the text style of certain words in a field
You'll want to use the trueWord chunk type rather than word. TrueWord is both Unicode-aware and uses natural-language rules to account for punctuation and other details, where word (for compatibility with older dialects) only uses simple space boundaries.
I've been looking for some Python examples I might use to run comparative benchmarks. This task may be a good fit. How would you do this in Python?
I've been looking for some Python examples I might use to run comparative benchmarks. This task may be a good fit. How would you do this in Python?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn