For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > November 2006 > Find out color attributes for given input in text box









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Find out color attributes for given input in text box
mark.montemuro@sig.com

2006-11-06, 6:57 pm

I need a short example of being able to tell what the color attributes
are of text being entered in a text box. For example if the user
entered 'Google' and the G had the color of Blue, the 1st o was red,
the second o was yellow, the g was blue, the l was green, and the e was
red. Is there a cget or Configure function that will work on character
by character basis that will give me this information? Thanks in
advance for any help in this question.

Ch Lamprecht

2006-11-06, 6:57 pm

mark.montemuro@sig.com wrote:
> I need a short example of being able to tell what the color attributes
> are of text being entered in a text box. For example if the user
> entered 'Google' and the G had the color of Blue, the 1st o was red,
> the second o was yellow, the g was blue, the l was green, and the e was
> red. Is there a cget or Configure function that will work on character
> by character basis that will give me this information? Thanks in
> advance for any help in this question.
>


That sounds interesting,

you do not tell us how your user manages to *enter* colored characters into the
text-widget...
Your color information is most likely stored in tags associated with the characters.
I did not try but $text->dump(index) should give you the information you are
looking for.
perldoc Tk::Text

Christoph

--

perl -e "print scalar reverse q/ed.enilno@ergn.l.hc/"
mark.montemuro@sig.com

2006-11-06, 6:57 pm

Ch Lamprecht wrote:
> mark.montemuro@sig.com wrote:
>
> That sounds interesting,
>
> you do not tell us how your user manages to *enter* colored characters into the
> text-widget...
> Your color information is most likely stored in tags associated with the characters.
> I did not try but $text->dump(index) should give you the information you are
> looking for.
> perldoc Tk::Text
>
> Christoph
>
> --
>
> perl -e "print scalar reverse q/ed.enilno@ergn.l.hc/"



Very good question about how the data will be populated, Sorry about
that. I am going to give the user a browser button in which they will
specify a file which contains the data to be parsed. The file will be
read, and then put into a text box. The users will use wordpad to
modify/create the file. This allows them to put color to a particular
character. A short explanation of why the color. The use of color to
certain characters allows me to create the output message differently
depending on the input color without requiring more data. The user's
input is a key value pair, but I also need to know the datatype of the
value. So by having them colorcode the key or the value to a certain
predefined color, I get what I need without requiring more data. The
input format of the message is very inportant, and can't be changed, so
a color attribute would work very nicely.

Marc Dashevsky

2006-11-06, 6:57 pm

In article <1162849859.206133.151360@m7g2000cwm.googlegroups.com>,
mark.montemuro@sig.com says...
> Ch Lamprecht wrote:
>
>
> Very good question about how the data will be populated, Sorry about
> that. I am going to give the user a browser button in which they will
> specify a file which contains the data to be parsed. The file will be
> read, and then put into a text box. The users will use wordpad to
> modify/create the file. This allows them to put color to a particular
> character.


Do you think the color of the text in the Wordpad document is just
going to appear in the Tk::Text widget? The widget knows nothing
about RTF. You are going to have to parse the RTF and use tags
to load the Text widget the way you want. I apologize in advance
if I have misunderstood your intent.

--
Go to http://MarcDashevsky.com to send me e-mail.
zentara

2006-11-07, 8:04 am

On Mon, 6 Nov 2006 17:20:45 -0500, Marc Dashevsky
<usenet@MarcDashevsky.com> wrote:

[color=darkred]
>
>Do you think the color of the text in the Wordpad document is just
>going to appear in the Tk::Text widget? The widget knows nothing
>about RTF. You are going to have to parse the RTF and use tags
>to load the Text widget the way you want. I apologize in advance
>if I have misunderstood your intent.


Here is a simple example for the OP, to show what Text widget color
is all about.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $mw = MainWindow->new(-title=>'Colored Text');
$mw->geometry('200x200+666+266' );

my $text = $mw->Scrolled('Text', -scrollbars=>'osw',
-background => 'black',
-foreground => 'lightyellow',
)->pack;

#add colors
$text->tagConfigure( 'tag1', -foreground => 'red' );
$text->tagConfigure( 'tag2', -foreground => 'skyblue' );
$text->tagConfigure( 'tag3', -foreground => 'yellow');
$text->tagConfigure( 'tag4', -foreground => 'green' );

#$text->insert('end','some text','tag1');

$text->insert('end',"some text\n",'tag1');
$text->insert('end',"some text\n",'tag2');
$text->insert('end',"some text\n",'tag3');
$text->insert('end',"some text\n",'tag4');

MainLoop;



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
mark.montemuro@sig.com

2006-11-08, 7:58 am


zentara wrote:
> On Mon, 6 Nov 2006 17:20:45 -0500, Marc Dashevsky
> <usenet@MarcDashevsky.com> wrote:
>
>
>
> Here is a simple example for the OP, to show what Text widget color
> is all about.
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use Tk;
>
> my $mw = MainWindow->new(-title=>'Colored Text');
> $mw->geometry('200x200+666+266' );
>
> my $text = $mw->Scrolled('Text', -scrollbars=>'osw',
> -background => 'black',
> -foreground => 'lightyellow',
> )->pack;
>
> #add colors
> $text->tagConfigure( 'tag1', -foreground => 'red' );
> $text->tagConfigure( 'tag2', -foreground => 'skyblue' );
> $text->tagConfigure( 'tag3', -foreground => 'yellow');
> $text->tagConfigure( 'tag4', -foreground => 'green' );
>
> #$text->insert('end','some text','tag1');
>
> $text->insert('end',"some text\n",'tag1');
> $text->insert('end',"some text\n",'tag2');
> $text->insert('end',"some text\n",'tag3');
> $text->insert('end',"some text\n",'tag4');
>
> MainLoop;
>
>
>
> --
> I'm not really a human, but I play one on earth.
> http://zentara.net/japh.html



Thanks for your input. The RTF hint was what I needed. The
documentation on CPAN for the RTF layout was just fine on knowing how
to analyze the data. I have an input routine that takes the colortags
line, creates a hash table. I then use the color tags which preceeds
the text input to assign the correct color for the text. After I
assign the color, I then strip the tags out of the text. It works great.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com