Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #409: The vulcan-death-grip ping has been applied.


comp / comp.lang.tcl / Re: Operate only on the visible lines in a text window

SubjectAuthor
* Operate only on the visible lines in a text windowShaun Deacon
+- Re: Operate only on the visible lines in a text windowet99
+- Operate only on the visible lines in a text windowclt.to.davebr
`* Re: Operate only on the visible lines in a text windowRalf Fassel
 `- Re: Operate only on the visible lines in a text windowShaun Deacon

1
Subject: Operate only on the visible lines in a text window
From: Shaun Deacon
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Wed, 10 Jul 2024 00:57 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: sdeacon@us.socionext.com (Shaun Deacon)
Newsgroups: comp.lang.tcl
Subject: Operate only on the visible lines in a text window
Date: Tue, 9 Jul 2024 17:57:17 -0700
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <v6kmal$1jhpc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 10 Jul 2024 02:57:58 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="db322dc0cb279ba3e16fe8c0158af72d";
logging-data="1689388"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lfQ4vKzcOnKP+PWl1ybtO"
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.18.2
Cancel-Lock: sha1:AsJegjh02r40IUNMniD/RzVswOc=
X-Mozilla-News-Host: news://news.eternal-september.org:119
View all headers

My application uses a text widget to display chip 'test vectors' from a
loaded file. Each vector occupies a line - for example :

0011010XXLLLHH
0100110XXLHHLH
....
0110110XXHHHHH

A highlighting operation colors specified values (for example all 1's)
for all lines of text in the widget. For small and medium sized files
this is fine. However, test files can often be large (over 500,000
vectors). The highlight operation applied to all lines is too slow in
this case - the vectors are much longer strings in real life too.

The obvious solution to me is to just highlight the currently visible
lines (or a range of lines spanning the current view - say 1000 or so)
and when the user scrolls the window, highlight the new set of lines.

Suggestions on the best way to find the indexes for the currently
visible lines when the widget has been scrolled would be great.

Can someone please point me in the right direction ?

For some reason, I can't seem to find what I'm looking for in CLT, the
wiki or the man pages.

thanks
Shaun

Subject: Re: Operate only on the visible lines in a text window
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Wed, 10 Jul 2024 05:26 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: Operate only on the visible lines in a text window
Date: Tue, 9 Jul 2024 22:26:54 -0700
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <v6l62u$1pbbd$1@dont-email.me>
References: <v6kmal$1jhpc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 10 Jul 2024 07:26:55 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7ce27fdf532a3aad608f7e71b5318448";
logging-data="1879405"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1SISLNGhZaLRRmjdsm0Hk"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:svzs6ZIkInLarE4YksJBvP8mylQ=
In-Reply-To: <v6kmal$1jhpc$1@dont-email.me>
Content-Language: en-US
View all headers

On 7/9/2024 5:57 PM, Shaun Deacon wrote:
> My application uses a text widget to display chip 'test vectors' from a loaded file. Each vector occupies a line - for example :
>
> 0011010XXLLLHH
> 0100110XXLHHLH
> ...
> 0110110XXHHHHH
>
> A highlighting operation colors specified values (for example all 1's) for all lines of text in the widget. For small and medium sized files this is fine. However, test files can often be large (over 500,000 vectors). The highlight operation applied to all lines is too slow in this case - the vectors are much longer strings in real life too.
>
> The obvious solution to me is to just highlight the currently visible lines (or a range of lines spanning the current view - say 1000 or so) and when the user scrolls the window, highlight the new set of lines.
>
> Suggestions on the best way to find the indexes for the currently visible lines when the widget has been scrolled would be great.
>
> Can someone please point me in the right direction ?
>
> For some reason, I can't seem to find what I'm looking for in CLT, the wiki or the man pages.
>
> thanks
> Shaun
>

Can't you use the current cursor position? How is it scrolled, mouse wheel? scroll bar? The current cursor is at,

..textwidget index insert

You could likely estimate it using scrollbar info. But if there are 500k lines, how might someone get to the middle, by some sort of search?

The only way I know to find what lines in a text widget are on screen without any other info is using the bbox method. You can test if any particular $line is visible by using

..textwidget bbox $line.0

which will return a null list if not on screen, otherwise a list of numbers.

This could involve a large search to find the first and last line on-screen. I don't know how fast or slow that would be. You could likely test every Nth line if you know how many lines fit on screen.

et

Subject: Operate only on the visible lines in a text window
From: clt.to.davebr@dfgh.net
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Wed, 10 Jul 2024 05:41 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: clt.to.davebr@dfgh.net
Newsgroups: comp.lang.tcl
Subject: Operate only on the visible lines in a text window
Date: Wed, 10 Jul 24 05:41:30 GMT
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <75917205900901001@llp>
References: <v6kmal$1jhpc$1@dont-email.me>
Injection-Date: Wed, 10 Jul 2024 07:43:14 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7bf582ba0e491c60adbbfd83b86ab08b";
logging-data="1890603"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Ap/+3u4I8UP5sk8/Is/gc"
Cancel-Lock: sha1:8Wgx2WCr8nnB5LYgsdmJW3lnZeM=
In-Reply-To: <v6kmal$1jhpc$1@dont-email.me>
View all headers

>
>Suggestions on the best way to find the indexes for the currently
>visible lines when the widget has been scrolled would be great.

Try using the @x,y indices (see INDICES in the man page) and the text box index subcommand

For a text box named .t

..t index @0,0

returns the line number and column number of the character in the top left corner.

lindex [split [.t index @0,0] .] 0

returns just the line number of the top left character (droping the column number)

use winfo height .t to get the last line in the text box. perhaps using:

lindex [split [.t index @0,[winfo height .t]] .] 0

Dave B

Subject: Re: Operate only on the visible lines in a text window
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Wed, 10 Jul 2024 08:59 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: Operate only on the visible lines in a text window
Date: Wed, 10 Jul 2024 10:59:00 +0200
Lines: 41
Message-ID: <ygaikxdy65n.fsf@akutech.de>
References: <v6kmal$1jhpc$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net mq09UKqUObkB+W+AcVDHeQ+pTU0bHv/2q9oM2oT0unyoNUMOk=
Cancel-Lock: sha1:wcRvNDxj//ZGawQ1HEBSmLHw70s= sha1:JN9lfNKpFK1bL7w72Lnvv2w9Tdc= sha256:cQI09OLUHpMOD7wPuhIZupCSFQGs1H+hICcGlFJUIAs=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
View all headers

* Shaun Deacon <sdeacon@us.socionext.com>
| The obvious solution to me is to just highlight the currently visible
| lines (or a range of lines spanning the current view - say 1000 or so)
| and when the user scrolls the window, highlight the new set of lines.
>
| Suggestions on the best way to find the indexes for the currently
| visible lines when the widget has been scrolled would be great.
>
| Can someone please point me in the right direction ?

You could try 'text yview' and derive the displayed lines from that:

grid [text .t -yscrollcommand {recalc {.s set}}] -sticky ewns -row 0 -column 0
grid [scrollbar .s -command {recalc {.t yview}} -orient vertical] -sticky ns -row 0 -column 1
grid [label .l] - -sticky ewns
grid rowconfigure . 0 -weight 1
grid columnconfigure . 0 -weight 1
for {set l 1} {$l < 1000} {incr l} {
.t insert end "Line $l\n"
}

proc recalc {cmd args} {
# scroll if required
if {$cmd ne ""} {
{*}$cmd {*}$args
}
# Determine the visible range
lassign [.t yview] start end
# Get line count
set lines [lindex [split [.t index end] "."] 0]
# Get first and last line displayed.
# Here you need to determine what to do with the partially displayed lines
set first [format %.1f [expr {$start*$lines+1}]]
set last [format %.1f [expr {$end*$lines}]]

.l configure -text "visible Lines $first ... $last"
}
bind . <Configure> [list recalc ""]

HTH
R'

Subject: Re: Operate only on the visible lines in a text window
From: Shaun Deacon
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Wed, 10 Jul 2024 17:38 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: sdeacon@us.socionext.com (Shaun Deacon)
Newsgroups: comp.lang.tcl
Subject: Re: Operate only on the visible lines in a text window
Date: Wed, 10 Jul 2024 10:38:03 -0700
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <v6mgts$20kdd$1@dont-email.me>
References: <v6kmal$1jhpc$1@dont-email.me> <ygaikxdy65n.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 10 Jul 2024 19:38:05 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="db322dc0cb279ba3e16fe8c0158af72d";
logging-data="2118061"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/UcUXl8cBYF6k/l+Xye1h"
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.18.2
Cancel-Lock: sha1:gGdac2DioFX6n8DafDnwAPDc1A0=
In-Reply-To: <ygaikxdy65n.fsf@akutech.de>
View all headers

Ralf Fassel wrote:
> * Shaun Deacon <sdeacon@us.socionext.com>
> | The obvious solution to me is to just highlight the currently visible
> | lines (or a range of lines spanning the current view - say 1000 or so)
> | and when the user scrolls the window, highlight the new set of lines.
>>
> | Suggestions on the best way to find the indexes for the currently
> | visible lines when the widget has been scrolled would be great.
>>
> | Can someone please point me in the right direction ?
>
> You could try 'text yview' and derive the displayed lines from that:
>
> grid [text .t -yscrollcommand {recalc {.s set}}] -sticky ewns -row 0 -column 0
> grid [scrollbar .s -command {recalc {.t yview}} -orient vertical] -sticky ns -row 0 -column 1
> grid [label .l] - -sticky ewns
> grid rowconfigure . 0 -weight 1
> grid columnconfigure . 0 -weight 1
> for {set l 1} {$l < 1000} {incr l} {
> .t insert end "Line $l\n"
> }
>
> proc recalc {cmd args} {
> # scroll if required
> if {$cmd ne ""} {
> {*}$cmd {*}$args
> }
> # Determine the visible range
> lassign [.t yview] start end
> # Get line count
> set lines [lindex [split [.t index end] "."] 0]
> # Get first and last line displayed.
> # Here you need to determine what to do with the partially displayed lines
> set first [format %.1f [expr {$start*$lines+1}]]
> set last [format %.1f [expr {$end*$lines}]]
>
> .l configure -text "visible Lines $first ... $last"
> }
> bind . <Configure> [list recalc ""]
>
> HTH
> R'
>

Thanks Ralf, this looks promising to me.
Shaun

1

rocksolid light 0.9.8
clearnet tor