| Ticket UUID: | d3cd4c69494f31a276cf5e3e4b2df3d1bcf71bfd | |||
| Title: | Make the ttk::notebook::CycleTab proc more robust | |||
| Type: | Bug | Version: | trunk, core-8-6-branch | |
| Submitter: | nemethi | Created on: | 2021-02-05 20:15:59 | |
| Subsystem: | 69. Events | Assigned To: | jan.nijtmans | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Closed | Last Modified: | 2021-02-10 10:38:17 | |
| Resolution: | Fixed | Closed By: | jan.nijtmans | |
| Closed on: | 2021-02-10 10:38:17 | |||
| Description: |
The body of the ttk::notebook::CycleTab proc starts with:
if {[$w index end] != 0} {
set current [$w index current]
...
A few lines later, the index $current is used as an operand of +, which will raise an error message if $current is an empty string, which is the case if all the tabs are disabled or hidden. To prevent this, the two lines above should be replaced with:
set current [$w index current]
if {$current ne ""} {
...
Note that the condition {$current ne ""} is stronger than {[$w index end] != 0}.
In core-8-6-branch, a few more improvements should be made:
set current [$w index current]
if {$current ne ""} {
set tabCount [$w index end]
set select [expr {($current + $dir) % $tabCount}]
while {[$w tab $select -state] ne "normal" && ($select != $current)} {
set select [expr {($select + $dir) % $tabCount}]
}
...
- The use of the local variable tabCount (at 2 places) as a replacement for [$w index end] is just an optimization measure, which, in addition, makes the code clearer.
- String comparison (for the tab's state) should be made via "ne" rather than "!=".
These additional improvements are already contained in trunk.
| |||
| User Comments: |
jan.nijtmans added on 2021-02-10 10:38:01:
Thanks for the suggestion. Adapted now. Just one more: in stead of {$current ne ""} I prefer {$current >= 0}. Tk is not consistent in returning either "-1" or the empty string for "not found". This expression would work for both (even though we know it's "" here). See also TIP #577. | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki