Tk Source Code

View Ticket
Login
Ticket UUID: 1ef1ae217757417cec746edaa1c77d6ea4b6add5
Title: widgets indices enhancement
Type: RFE Version: 8.7a4
Submitter: emiliano Created on: 2020-05-27 19:02:16
Subsystem: 99. Other Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2023-03-05 13:01:25
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2023-03-05 13:01:25
Description:
Currently, [menu] indexing (as described by man page) accepts the following
forms:

"active" "end" (eq "last") "none", "@number" "number" and "pattern"

The indexes of [listbox] are

"number" "active" "anchor" "end" "@x,y"

Those indexes are accepted by some of the widget subcommands to operate on
widget's items. Those items can be thought as items on a list, and should
be possible to address them the same way items on a list are addressed,
supporting simple index arithmetic

examples (now not possible):

$menu activate end-2
$menu delete active+1 end

$listbox get 0 end-3
$listbox insert active-1 $value

To overcome any *potential incompatibility*, this form should be applied
after all the current forms are tested (and failed). Nowadays the form
[$menu index teststring+1] is valid if there's an entry with a literal
label "teststring+1".

Another point is to put [menu] indexing in line with TIP 323 
"Do nothing gracefully", as [listbox] is currently doing:

% $listbox index -1
-1
% $listbox index -10
-1
% $listbox get -1
% $menu index 0
none
% $menu index -1
bad menu entry index "-1"

as seen, [menu] errors out when out of range indices are provided.

This RFE mentions [menu] and [listbox] but encourages to enhance all indexing
schemes on widgets where it makes sense, and leaves out [text] explicitly
since indexing in such widget is not compatible with Tcl lists.
User Comments: jan.nijtmans added on 2023-03-05 13:01:25:

I suggest to simply close this ticket. I'm not planning to implement the remaining "active[+-]x", since "$menu delete active+1 end" can be written as "$menu delete [$menu active]+1 end" too, using the already available syntax.

If anyone is interested to implement this, it's always possible to provide a patch and re-open this ticket.

Thanks!


fvogel added on 2023-03-05 10:25:33:

TIP #577 has been voted on and merged into trunk [95b2bdbd2bff87b3|here]. What work remains to be done before we can close this RFE ticket?


jan.nijtmans added on 2020-07-06 07:28:36:
Implementation ongoing in "strict-index" branch. Only the construct active+-integer will be left out: I don't really see a use-case for that and it would have more inpact than really useful (IMHO).

Will be part of TIP #577.

jan.nijtmans added on 2020-06-07 20:57:06:
Looks like a good idea