Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tk text: memory footprint of tags?

52 views
Skip to first unread message

Ralf Fassel

unread,
Oct 9, 2018, 10:12:45 AM10/9/18
to
I'd like to mark text in text(n) widgets with tags, so that if I click
on a certain text in the widget, a file is openend, file contents
presented in another text widget, and the current file/view position
adjusted as given by a tag:

% wish8.5
pack [text .t] -fill both -expand yes
# if clicked upon text with tag 'filename', open the given file
.t tag bind filename <Button-1> {load_file .t %x %y}

proc load_file {w x y} {
set idx [$w index @$x,$y]
set prev [$w tag prevrange filename $idx]
if {[llength $prev] != 0} {
set file [$w get {*}$prev]
set tags [$w tag names [lindex $prev 0]]
puts stderr "filename {$file}, tags {$tags} prev {$prev} "
} else {
puts stderr tag-not-found?
}
}

# Insertion may get repeated many times with different positional
# tags (1042 1043 ...) each time
.t delete 100.0 end
.t insert 1.0 \
"Example text (no tags)\n" "" \
/some/file/name1 {filename 1042} \
"\n" "" \
"Other example text (no tags)\n" "" \
/some/file/name2 {filename 1043} \
"\n"

The contents of the text widgets is limited to say 100 lines, but the
positional tags added might be different for each inserted text.

Now I'm concerned about the memory usage if this keeps running for a
long time and many tags are added: will a [.t tag delete ...] keep the
memory footprint down?

(Tcl/Tk 8.5.19 if it matters).

TNX
R'

Mike Griffiths

unread,
Oct 9, 2018, 5:37:31 PM10/9/18
to
Having lots of different tags is something that can slow a text widget down quite dramatically (I think performance for this was improved in 8.6, but I'm not sure how much). One workaround is to use a single tag which hides text (tag configure -elide 1, if memory serves) and use this to plant metadata directly into the text widget. When you have a click, you can then use a small amount of softcode to find the next bit of text with the hidden tag to retrieve the filename/position to act on.

Ralf Fassel

unread,
Oct 10, 2018, 5:27:26 AM10/10/18
to
* Mike Griffiths <mi...@keyboardzombie.com>
| On Tuesday, 9 October 2018 15:12:45 UTC+1, Ralf Fassel wrote:
| > I'd like to mark text in text(n) widgets with tags, so that if I click
| > on a certain text in the widget, a file is openend, file contents
| > presented in another text widget, and the current file/view position
| > adjusted as given by a tag:
--<snip-snip>--
| Having lots of different tags is something that can slow a text widget
| down quite dramatically (I think performance for this was improved in
| 8.6, but I'm not sure how much). One workaround is to use a single tag
| which hides text (tag configure -elide 1, if memory serves) and use
| this to plant metadata directly into the text widget.

Mike,
exactly what I was looking for.

TNX1e6!
R'
0 new messages