Menu

#13 Changes Tk8.7 -underline type result in runtime errors

1.0
closed
None
2023-09-13
2023-09-10
No

Values for the canvas widget -underline option have changed in Tk8.7 (Tcl 9) from TIP #577. It has changed from type int to type index, which include values like "end-2", and "" (the empty set).
Existing code uses the old form: {$underline != -1} to test for the empty set, These checks need to change to {$underline ne ""}.

Also note that type index is nolonger a simple integer.

Discussion

  • Peter Spjuth

    Peter Spjuth - 2023-09-10

    I made a fix that makes it handle it a bit more gracefully.
    End-style index will be treated as not existing for now.

    Is there a nice way to parse end-style from Tcl?

     
  • Brian Griffin

    Brian Griffin - 2023-09-11

    I'm not aware of a specific command for this. However, the following should work:

    ~~~~
    set str "Example String Value"
    set index "end-3"
    set intIndex [lindex [lseq [string length $str]] $index]

    This technique should work for both strings and lists.
    

    proc intIndexForString {stringValue index} {
    return [lindex [lseq [string length $stringValue]] $index]
    }

    proc intIndexForList {listValue index} {
    return [lindex [lseq [llength $listValue]] $index]
    }
    ~~~

    These functions should have O(1) performance regardless of string length or list length.

     
  • Peter Spjuth

    Peter Spjuth - 2023-09-13
    • status: open --> closed
     
  • Peter Spjuth

    Peter Spjuth - 2023-09-13

    Fixed it with the lseq trick.

     

Log in to post a comment.