RE: text in a widget, text-widget @ 1146167556
"Van Nieuwenhuize, Mike" <[email protected]> Fri, 28 Apr 2006 09:18:27 -0700
| Newsgroups | gmane.comp.lang.perl.tk |
|---|---|
| Message-ID | <[email protected]> |
Johan,
Got to thinking about something that may work for you. Please see my
modified code.
Basically The only thing that I give it a is a list of words, the tag
and
tag bind is generated on the fly. Maybe using an approach like this will
get
you closer to what you wanted.
Still kinda lame as you have to create a new tag for each word or in
this case
url but it at least will allow you to do it on the fly.
Mike
use strict;
use Tk;
use Tk::Dialog;
my $mainWindow = MainWindow->new(-title => "Test Tags");
my $sc_width = 100;
my $sc_height = 15;
my $scrolled = $mainWindow->Scrolled(
"Text",
-scrollbars => 'se',
-background => 'white',
-wrap => 'none',
-width => $sc_width,
-height => $sc_height,
)->pack(
-fill => 'both',
-expand => '0',
);
#lets set up some color tags for text
$scrolled->tagConfigure('BLUE',-foreground => 'blue');
$scrolled->tagConfigure('LINK',-underline => 1);
$scrolled->tagConfigure('RED',-background => 'red'); my $frame =
$mainWindow->Frame( -relief => 'ridge',-borderwidth => 3,);
my $exitB = $frame->Button(
-text => 'EXIT',
-width => 5,
-command => sub { exit 0},
)->pack(
-side => 'left',
-anchor => 'n',
);
$frame->pack(
-expand => 1,
-fill => 'x',
);
$scrolled->insert('end',"Here is a green text\n",['GREEN']);
$scrolled->insert('end',"Here is a blue link\n",['BLUE','LINK']);
$scrolled->insert('end',"Here is a blue text with red
background\n",['BLUE','RED']);
foreach my $string (qw/qualcomm ibm nokia tsmc microshoft gentoo
redhat/){
my $url = "www.${string}.com";
my $tag = create_link($string,$url);
$scrolled->insert('end',"Click here to goto home page for
$string\n",['BLUE','LINK',$tag]);
}
MainLoop();
{
my $strings_hash = {};
sub create_link {
my $string = shift;
my $url = shift;
unless(exists $strings_hash->{$string}) {
print "DEBUG: create link for $string\n";
my $sub = sub { $scrolled->Dialog(-text => "Hey are you sure you
want to open page for $string which has the url $url")->Show() ;
openLink($string)};
$scrolled->tagBind(uc($string),"<Button-1>",$sub);
$strings_hash->{$string} = $url;
};#unless
return uc($string);
}
sub openLink {
my $string = shift;
if(exists $strings_hash->{$string}) {
$scrolled->Dialog(-text => "Warning: I can't open the url
$strings_hash->{$string}")->Show();
}
else {
$scrolled->Dialog(-text => "Error: I can't find the link for
$string")->Show();
}
}
};#hide the hash
-----Original Message-----
From: [email protected] [mailto:[email protected]]
On Behalf Of Johan Meskens CS3 jmcs3
Sent: Thursday, April 27, 2006 12:59 PM
To: [email protected]
Subject: Re: text in a widget, text-widget @ 1146167556
Intrah onat Diria .. Tue, 25 Apr 2006 13:55:44 -0700
,Van Nieuwenhuize, Mike wrote "Noalim y":
>
> Johan,
>
> Here this will give you an idea how to create a link in a text widget
> as well as some other tags.
>
> HTH
>
> Mike
>
> use strict;
> use Tk;
> use Tk::Dialog;
>
> my $mainWindow = MainWindow->new(-title => "Test Tags");
>
> my $sc_width = 100;
> my $sc_height = 15;
>
> my $scrolled = $mainWindow->Scrolled(
> "Text",
> -scrollbars => 'se',
> -background => 'white',
> -wrap => 'none',
> -width => $sc_width,
> -height => $sc_height,
>
>
> )->pack(
> -fill => 'both',
> -expand => '0',
>
> );
>
> #lets set up some color tags for text
> $scrolled->tagConfigure('BLUE',-foreground => 'blue');
> $scrolled->tagConfigure('LINK',-underline => 1);
> $scrolled->tagConfigure('RED',-background => 'red');
> $scrolled->tagBind('LINK',"<Button-1>",sub { $scrolled->Dialog(-text
> => "Hey you pushed the link")->Show()});
i have a textfield where i have multiple pieces of text tagged with
'LINK'
$scrolled->tagBind('LINK',"<Button-1>",sub { print
$scrolled->GetTextTaggedWith( 'LINK' ) } );
thus the above line prints all LINK-tagged texts how do i get to the
text of the specific link i klik on ?
thanks for your help
kind regards
jmcs3
>
> my $frame = $mainWindow->Frame( -relief => 'ridge',-borderwidth =>
> 3,);
>
> my $exitB = $frame->Button(
> -text => 'EXIT',
> -width => 5,
> -command => sub { exit 0},
>
> )->pack(
> -side => 'left',
> -anchor => 'n',
>
> );
>
> $frame->pack(
> -expand => 1,
> -fill => 'x',
>
> );
>
>
> $scrolled->insert('end',"Here is a green text\n",['GREEN']);
> $scrolled->insert('end',"Here is a blue link\n",['BLUE','LINK']);
> $scrolled->insert('end',"Here is a blue text with red
> background",['BLUE','RED']);
>
>
> MainLoop();
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]
> On Behalf Of Johan Meskens CS3 jmcs3
> Sent: Tuesday, April 25, 2006 11:12 AM
> To: [email protected]
> Subject: text in a widget, text-widget
>
>
> hello
>
>
> i have an application with a couple of text widgets but i would like
> to add some functionalities that at first and second sight are not
> directly supported by the plain text widget itself
> - ?
>
> for example i would like certain lines of text within the textwidget
> to take different background colors according to certain parameters
>
> also i would like to be able to detect certain sentences or words that
> would become 'links' and by clicking them i would open up different
> windows
>
> any suggestions to solutions and widgets for the above problems ?
>
> - i probably could use the canvas for the color-thing .. as i write
> this ..
>
> kind regards
> jmcs3
>
>
>
>
>
>
>
>
> --------the following could be unreadable @ 1145988711 :::
> --a-=-t-g-i-
> , Bottom:
> , particular
> , ||
> , |2
> , },
> , oo,loent,uaha
> , ::::::opthe
> , lead
> , |
> , |---|
> , _________________
> ,
>
>
>
>
> -++**==--++**==--++**==--++**==--++**==--++**==--++**==
> This message was posted through the Stanford campus mailing list
server.
> If you wish to unsubscribe from this mailing list, send the message
> body of "unsubscribe ptk" to [email protected]
>
> -++**==--++**==--++**==--++**==--++**==--++**==--++**==
> This message was posted through the Stanford campus mailing list
> server. If you wish to unsubscribe from this mailing list, send the
> message body of "unsubscribe ptk" to [email protected]
--------the following could be unreadable @ 1146167912 :::
?
, >
, =>
, paars
, doubling
, ,
,
670670670670670670670670670670670670e670e670i670iaiiaii670670i2670ei670i
2670670e670fagi670670ga670670ib670PLETATOANITAPLEe
, |
, o::m
, takened
, t,
, |
,
-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list server.
If you wish to unsubscribe from this mailing list, send the message body
of "unsubscribe ptk" to [email protected]
-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to [email protected]