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/ruler.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/ruler.tcl')
-rw-r--r-- | library/demos/ruler.tcl | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/library/demos/ruler.tcl b/library/demos/ruler.tcl index 557b680..0a6990f 100644 --- a/library/demos/ruler.tcl +++ b/library/demos/ruler.tcl @@ -19,12 +19,12 @@ package require Tk proc rulerMkTab {c x y} { upvar #0 demo_rulerInfo v - $c create polygon $x $y [expr {$x+$v(size)}] [expr {$y+$v(size)}] \ - [expr {$x-$v(size)}] [expr {$y+$v(size)}] + $c create polygon $x $y [expr {$x + $v(size)}] [expr {$y + $v(size)}] \ + [expr {$x - $v(size)}] [expr {$y + $v(size)}] } set w .ruler -catch {destroy $w} +destroy $w toplevel $w wm title $w "Ruler Demonstration" wm iconname $w "ruler" @@ -61,7 +61,7 @@ if {[winfo depth $c] > 1} { $c create line 1c 0.5c 1c 1c 13c 1c 13c 0.5c -width 1 for {set i 0} {$i < 12} {incr i} { - set x [expr {$i+1}] + set x [expr {$i + 1}] $c create line ${x}c 1c ${x}c 0.6c -width 1 $c create line $x.25c 1c $x.25c 0.8c -width 1 $c create line $x.5c 1c $x.5c 0.7c -width 1 @@ -108,7 +108,7 @@ proc rulerNewTab {c x y} { proc rulerSelectTab {c x y} { upvar #0 demo_rulerInfo v set v(x) [$c canvasx $x $v(grid)] - set v(y) [expr {$v(top)+2}] + set v(y) [expr {$v(top) + 2}] $c addtag active withtag current eval "$c itemconf active $v(activeStyle)" $c raise active @@ -125,7 +125,7 @@ proc rulerSelectTab {c x y} { proc rulerMoveTab {c x y} { upvar #0 demo_rulerInfo v - if {[$c find withtag active] == ""} { + if {[$c find withtag active] eq ""} { return } set cx [$c canvasx $x $v(grid)] @@ -137,13 +137,13 @@ proc rulerMoveTab {c x y} { set cx $v(right) } if {($cy >= $v(top)) && ($cy <= $v(bottom))} { - set cy [expr {$v(top)+2}] + set cy [expr {$v(top) + 2}] eval "$c itemconf active $v(activeStyle)" } else { - set cy [expr {$cy-$v(size)-2}] + set cy [expr {($cy - $v(size)) - 2}] eval "$c itemconf active $v(deleteStyle)" } - $c move active [expr {$cx-$v(x)}] [expr {$cy-$v(y)}] + $c move active [expr {$cx - $v(x)}] [expr {$cy - $v(y)}] set v(x) $cx set v(y) $cy } @@ -157,15 +157,15 @@ proc rulerMoveTab {c x y} { # c - The canvas widget. # x, y - The coordinates of the mouse. -proc rulerReleaseTab c { +proc rulerReleaseTab {c} { upvar #0 demo_rulerInfo v - if {[$c find withtag active] == {}} { + if {[$c find withtag active] eq ""} { return } - if {$v(y) != $v(top)+2} { + if {$v(y) != ($v(top) + 2)} { $c delete active } else { - eval "$c itemconf active $v(normalStyle)" + eval "$c itemconfigure active $v(normalStyle)" $c dtag active } } |