Adding arbitrary attributes to tagged text 
Author Message
 Adding arbitrary attributes to tagged text

I have a Text widget that contains tagged text.  I want to add an extra
attribute to each tag, so that when I retrieve the tag I can also get at
the saved attribute.  Is there any way to do this?  I can't find any
documented methods that seem to do the trick.

Thanks,

Alan Burlison
==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Sun, 08 Jul 2001 03:00:00 GMT  
 Adding arbitrary attributes to tagged text

Quote:


> >         -tag => [qw/tag1 tag2 attr3 etc/]

> > Does that help?

> Hmm.  Given I know, say "tag1", how do I get back tag2 attr3 and etc?
> Would $text->tag("names", "tag1") give me back the list?

No, $t->tagNames(index) returns the tag list for the text at "index".
Text isn't really made for what you appear to want to do - what
do you really want to do? (-:

I can imagine games with closures..... but only in a nightmare...

Steve
==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Sun, 08 Jul 2001 03:00:00 GMT  
 Adding arbitrary attributes to tagged text

Quote:

> > Would $text->tag("names", "tag1") give me back the list?

> No, $t->tagNames(index) returns the tag list for the text at "index".
> Text isn't really made for what you appear to want to do - what
> do you really want to do? (-:

I want to store some additional attributes with the tagged text, so that
when the text is clicked on, the associated callback can get at the
attributes.  The exact example is I have a window of SQL statements, and
when I click on them I need to retrieve the userid of the person who
first executed the query.

Nick has pointed out the best way of doing this - the undocumented -data
attribute that can be used to tie info on to a tagged section of text.
I've posted a brief demo of it to the ptk list.

Many thanks for your help,

Alan Burlison
==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Sun, 08 Jul 2001 03:00:00 GMT  
 Adding arbitrary attributes to tagged text

Quote:


> > > Would $text->tag("names", "tag1") give me back the list?

> > No, $t->tagNames(index) returns the tag list for the text at "index".
> > Text isn't really made for what you appear to want to do - what
> > do you really want to do? (-:

> I want to store some additional attributes with the tagged text, so that
> when the text is clicked on, the associated callback can get at the
> attributes.  The exact example is I have a window of SQL statements, and
> when I click on them I need to retrieve the userid of the person who
> first executed the query.

Then tagNames would work fine, since you know the index.  Or the callback
can return the data, via a closure.

Quote:

> Nick has pointed out the best way of doing this - the undocumented -data
> attribute that can be used to tie info on to a tagged section of text.
> I've posted a brief demo of it to the ptk list.

That would have been nice to know long ago (-:..... added to the next rev
of the pocket ref!

awaiting demo code...

Thanks to all.
==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Sun, 08 Jul 2001 03:00:00 GMT  
 Adding arbitrary attributes to tagged text

Quote:

> Nick,

> > You could (obviously) index a hash with the tag.

> Yes, but my code is groaning with global data structures already ;-)

> > Hmm, I was considering a Tix-item-like -data attribute for tags.
> > I really cannot rememebr if I implemented/released it. (I was going to
> hang
> > reference to HTML parse tree of the tagged region off it.)

> > Try it and see - if it is not there it would be easy to add - but would
> > cost 1 32-bit word (a pointer) per tag.

> The Text documentation mentions a -data option with the comment
> "?intentionally undocumented?", so I guess you *did* mean to put it in at
> some time ;-)

> I hacked together the following little test:

...

Quote:

> And every time I double click on "hello there" I get "some data" on stdout
> - yippee! The important question is will this remain in place?  I don't
> want to depend on a feature that might disappear.

> I assume "data" can be anything - a hashref for example?

Yep, I shall document "any scalar" unless I hear or find otherwise:

#!/usr/local/bin/perl -w
use Tk;

sub cb($$) {

    my $data = $text->tagCget($tag, -data);
    print "data=$data, value1=", $data->{k1}, "!\n";

Quote:
}

my $main = MainWindow->new();
$text = $main->ROText(-height => 15, -width => 80, -borderwidth => 0,
                      -wrap => "word")
    ->pack(-fill => "both", -expand => 1);
$text->insert("1.0", "hello there", "tag");
%h = (qw/k1 v1 k2 v2/);
$text->tagConfigure("tag", -data => \%h);
$text->tagBind("tag", "<Double-1>" => [ \&cb, "tag" ]);
MainLoop();

This is nice ...
==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Sun, 08 Jul 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Adding arbitrary attributes to tagged text

2. How can I add tags to http text in HTML file

3. SRC: petags 0.1 -- generate emacs TAGS for arbitrary file types

4. ANNOUNCE: Attribute::Protected, Attribute::Profiled, Attribute::Unimplemented

5. Tagged text --> list of tags, revisited

6. regex to search for img tags with no alt attribute (Section 508 compliance)

7. Converting HTML tag and attribute case - Regular Expression help

8. Tag attributes

9. Parsing html tag attributes & values in Perl

10. Adding attributes using perLDAP?

11. Tag for all new text in Tk::Text

12. Text Tags and Text Selection

 

 
Powered by phpBB® Forum Software