summaryrefslogtreecommitdiffstats
path: root/library/demos/items.tcl
diff options
context:
space:
mode:
authorandreask <andreask>2013-01-22 19:30:43 (GMT)
committerandreask <andreask>2013-01-22 19:30:43 (GMT)
commit48c9fcb7281cc6aa076113db874c7ae0e105795d (patch)
tree7187940ff056462bfa41705a2ce04d0ed07d424e /library/demos/items.tcl
parent41f5d19540b0b3f053da352e1569c9a4ed019dd5 (diff)
downloadtk-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/items.tcl')
-rw-r--r--library/demos/items.tcl37
1 files changed, 18 insertions, 19 deletions
diff --git a/library/demos/items.tcl b/library/demos/items.tcl
index 177e9a4..1404779 100644
--- a/library/demos/items.tcl
+++ b/library/demos/items.tcl
@@ -10,7 +10,7 @@ if {![info exists widgetDemo]} {
package require Tk
set w .items
-catch {destroy $w}
+destroy $w
toplevel $w
wm title $w "Canvas Item Demonstration"
wm iconname $w "Items"
@@ -106,14 +106,14 @@ $c create polygon 22c 4.5c 25c 4.5c 25c 6.75c 28c 6.75c \
$c create text 5c 8.2c -text Rectangles -anchor n
$c create rectangle 1c 9.5c 4c 12.5c -outline $red -width 3m -tags item
$c create rectangle 0.5c 13.5c 4.5c 15.5c -fill $green -tags item
-$c create rectangle 6c 10c 9c 15c -outline {} \
+$c create rectangle 6c 10c 9c 15c -outline "" \
-stipple @[file join $tk_demoDirectory images gray25.xbm] \
-fill $blue -tags item
$c create text 15c 8.2c -text Ovals -anchor n
$c create oval 11c 9.5c 14c 12.5c -outline $red -width 3m -tags item
$c create oval 10.5c 13.5c 14.5c 15.5c -fill $green -tags item
-$c create oval 16c 10c 19c 15c -outline {} \
+$c create oval 16c 10c 19c 15c -outline "" \
-stipple @[file join $tk_demoDirectory images gray25.xbm] \
-fill $blue -tags item
@@ -136,9 +136,9 @@ $c create arc 6.5c 17c 9.5c 20c -width 4m -style arc \
-outline $blue -start -135 -extent 270 -tags item \
-outlinestipple @[file join $tk_demoDirectory images gray25.xbm]
$c create arc 0.5c 20c 9.5c 24c -width 4m -style pieslice \
- -fill {} -outline $red -start 225 -extent -90 -tags item
+ -fill "" -outline $red -start 225 -extent -90 -tags item
$c create arc 5.5c 20.5c 9.5c 23.5c -width 4m -style chord \
- -fill $blue -outline {} -start 45 -extent 270 -tags item
+ -fill $blue -outline "" -start 45 -extent 270 -tags item
image create photo items.ousterhout \
-file [file join $tk_demoDirectory images ouster.png]
@@ -183,26 +183,25 @@ proc itemEnter {c} {
global restoreCmd
if {[winfo depth $c] == 1} {
- set restoreCmd {}
+ set restoreCmd ""
return
}
set type [$c type current]
- if {$type == "window" || $type == "image"} {
- set restoreCmd {}
+ if {$type in "window image"} {
+ set restoreCmd ""
return
- } elseif {$type == "bitmap"} {
+ } elseif {$type eq "bitmap"} {
set bg [lindex [$c itemconf current -background] 4]
set restoreCmd [list $c itemconfig current -background $bg]
$c itemconfig current -background SteelBlue2
return
- } elseif {$type == "image"} {
+ } elseif {$type eq "image"} {
set restoreCmd [list $c itemconfig current -state normal]
$c itemconfig current -state active
return
}
set fill [lindex [$c itemconfig current -fill] 4]
- if {(($type == "rectangle") || ($type == "oval") || ($type == "arc"))
- && ($fill == "")} {
+ if {($type in "rectangle oval arc") && ($fill eq "")} {
set outline [lindex [$c itemconfig current -outline] 4]
set restoreCmd "$c itemconfig current -outline $outline"
$c itemconfig current -outline SteelBlue2
@@ -228,10 +227,10 @@ proc itemMark {c x y} {
$c delete area
}
-proc itemStroke {c x y} {
+proc itemStroke {c a_x a_y} {
global areaX1 areaY1 areaX2 areaY2
- set x [$c canvasx $x]
- set y [$c canvasy $y]
+ set x [$c canvasx $a_x]
+ set y [$c canvasy $a_y]
if {($areaX1 != $x) && ($areaY1 != $y)} {
$c delete area
$c addtag area withtag [$c create rect $areaX1 $areaY1 $x $y \
@@ -273,11 +272,11 @@ proc itemStartDrag {c x y} {
set lastY [$c canvasy $y]
}
-proc itemDrag {c x y} {
+proc itemDrag {c a_x a_y} {
global lastX lastY
- set x [$c canvasx $x]
- set y [$c canvasy $y]
- $c move current [expr {$x-$lastX}] [expr {$y-$lastY}]
+ set x [$c canvasx $a_x]
+ set y [$c canvasy $a_y]
+ $c move current [expr {$x - $lastX}] [expr {$y - $lastY}]
set lastX $x
set lastY $y
}