diff options
author | andreask <andreask> | 2013-01-22 19:30:43 (GMT) |
---|---|---|
committer | andreask <andreask> | 2013-01-22 19:30:43 (GMT) |
commit | 48c9fcb7281cc6aa076113db874c7ae0e105795d (patch) | |
tree | 7187940ff056462bfa41705a2ce04d0ed07d424e /library/demos/cscroll.tcl | |
parent | 41f5d19540b0b3f053da352e1569c9a4ed019dd5 (diff) | |
download | tk-contrib_patrick_fradin_code_cleanup.zip tk-contrib_patrick_fradin_code_cleanup.tar.gz tk-contrib_patrick_fradin_code_cleanup.tar.bz2 |
Contribution by Patrick Fradin <patrick.fradin@planar.com>contrib_patrick_fradin_code_cleanup
Quoting his mail:
<pre>
==========================================================
Hi Jeff,
I spent some of my time to contribute to the TclTk community ! I'm in
late for Christmas gift but like we said in French : "Mieux vaut tard
que jamais". ;-)
I've use TclDevKit 5.3.0 tclchecker to analyse TclTk code in Tcl and
Tk library directories (library, tools and tests) to correct a lot of
warnings and few errors. (encapsulate some expr, use 'chan xxx'
instead of fconfigure, fileevent...)
I've made some improvements too :
Examples :
- Use 'lassign' instead of many 'lindex' of 'foreach/break' loop.
- Use 'in' or 'ni' operators instead of 'lsearch -exact' or to
factorise some eq/ne && / || tests.
- Use 'eq' or 'ne' to tests strings instead of '==' or '!='.
- Use 'unset -nocomplain' to avoid 'catch {unset...}'.
- Remove some useless catch around 'destroy' calls.
- Use expand {*} instead of 'eval'. Don't touch a lot of code because
I don't know all structs and lists. I think it could be a greater
improvement to reduce 'eval' calls.
Due to previous experience, I dot not change any indentation ! ;-)
==========================================================
</pre>
Diffstat (limited to 'library/demos/cscroll.tcl')
-rw-r--r-- | library/demos/cscroll.tcl | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/library/demos/cscroll.tcl b/library/demos/cscroll.tcl index f6e88f4..db8c7c4 100644 --- a/library/demos/cscroll.tcl +++ b/library/demos/cscroll.tcl @@ -10,7 +10,7 @@ if {![info exists widgetDemo]} { package require Tk set w .cscroll -catch {destroy $w} +destroy $w toplevel $w wm title $w "Scrollable Canvas Demonstration" wm iconname $w "cscroll" @@ -41,14 +41,13 @@ grid $w.vscroll -in $w.grid -padx 1 -pady 1 \ grid $w.hscroll -in $w.grid -padx 1 -pady 1 \ -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news - -set bg [lindex [$c config -bg] 4] +set bg [lindex [$c configure -background] 4] for {set i 0} {$i < 20} {incr i} { - set x [expr {-10 + 3*$i}] + set x [expr {-10 + (3 * $i)}] for {set j 0; set y -10} {$j < 10} {incr j; incr y 3} { - $c create rect ${x}c ${y}c [expr {$x+2}]c [expr {$y+2}]c \ + $c create rect ${x}c ${y}c [expr {$x + 2}]c [expr {$y + 2}]c \ -outline black -fill $bg -tags rect - $c create text [expr {$x+1}]c [expr {$y+1}]c -text "$i,$j" \ + $c create text [expr {$x + 1}]c [expr {$y + 1}]c -text "$i,$j" \ -anchor center -tags text } } @@ -73,36 +72,36 @@ if {[tk windowingsystem] eq "aqua"} { } } -proc scrollEnter canvas { +proc scrollEnter {canvas} { global oldFill set id [$canvas find withtag current] - if {[lsearch [$canvas gettags current] text] >= 0} { - set id [expr {$id-1}] + if {"text" in [$canvas gettags current]} { + set id [expr {$id - 1}] } set oldFill [lindex [$canvas itemconfig $id -fill] 4] if {[winfo depth $canvas] > 1} { $canvas itemconfigure $id -fill SeaGreen1 } else { $canvas itemconfigure $id -fill black - $canvas itemconfigure [expr {$id+1}] -fill white + $canvas itemconfigure [expr {$id + 1}] -fill white } } -proc scrollLeave canvas { +proc scrollLeave {canvas} { global oldFill set id [$canvas find withtag current] - if {[lsearch [$canvas gettags current] text] >= 0} { - set id [expr {$id-1}] + if {"text" in [$canvas gettags current]} { + set id [expr {$id - 1}] } $canvas itemconfigure $id -fill $oldFill - $canvas itemconfigure [expr {$id+1}] -fill black + $canvas itemconfigure [expr {$id + 1}] -fill black } -proc scrollButton canvas { +proc scrollButton {canvas} { global oldFill set id [$canvas find withtag current] - if {[lsearch [$canvas gettags current] text] < 0} { - set id [expr {$id+1}] + if {"text" ni [$canvas gettags current]} { + set id [expr {$id + 1}] } puts stdout "You buttoned at [lindex [$canvas itemconf $id -text] 4]" } |