From 8a4797c9a16ff548b9d7a02b28ac8df76bdb2ff0 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 10 Jul 2020 07:04:29 +0000 Subject: Minor bindings cleanup. Some removal of "expr" when we can do without it. Some KeyPress -> Key changes (which are synonymes). Some implicit specifications in stead of simply <1> (making clear this is not a binding to the "1" key). --- library/bgerror.tcl | 12 +++++----- library/demos/ctext.tcl | 14 +++++------ library/entry.tcl | 63 +++++++++++++++++++++---------------------------- library/tearoff.tcl | 10 ++++---- 4 files changed, 45 insertions(+), 54 deletions(-) diff --git a/library/bgerror.tcl b/library/bgerror.tcl index 8421924..fe8dfe0 100644 --- a/library/bgerror.tcl +++ b/library/bgerror.tcl @@ -41,7 +41,7 @@ proc ::tk::dialog::error::Details {} { set w .bgerrorDialog set caption [option get $w.function text {}] set command [option get $w.function command {}] - if { ($caption eq "") || ($command eq "") } { + if {($caption eq "") || ($command eq "")} { grid forget $w.function } lappend command [$w.top.info.text get 1.0 end-1c] @@ -50,7 +50,7 @@ proc ::tk::dialog::error::Details {} { } proc ::tk::dialog::error::SaveToLog {text} { - if { $::tcl_platform(platform) eq "windows" } { + if {$::tcl_platform(platform) eq "windows"} { set allFiles *.* } else { set allFiles * @@ -129,11 +129,11 @@ proc ::tk::dialog::error::bgerror {err {flag 1}} { set lines 0 set maxLine 45 foreach line [split $err \n] { - if { [string length $line] > $maxLine } { - append displayedErr "[string range $line 0 [expr {$maxLine-3}]]..." + if {[string length $line] > $maxLine} { + append displayedErr "[string range $line 0 $maxLine-3]..." break } - if { $lines > 4 } { + if {$lines > 4} { append displayedErr "..." break } else { @@ -182,7 +182,7 @@ proc ::tk::dialog::error::bgerror {err {flag 1}} { pack $W.text -side left -expand yes -fill both $W.text insert 0.0 "$err\n$info" $W.text mark set insert 0.0 - bind $W.text { focus %W } + bind $W.text {focus %W} $W.text configure -state disabled # 2. Fill the top part with bitmap and message diff --git a/library/demos/ctext.tcl b/library/demos/ctext.tcl index a3b4e8a..502c9d0 100644 --- a/library/demos/ctext.tcl +++ b/library/demos/ctext.tcl @@ -41,16 +41,16 @@ $c create rectangle 245 195 255 205 -outline black -fill red # First, create the text item and give it bindings so it can be edited. $c addtag text withtag [$c create text 250 200 -text "This is just a string of text to demonstrate the text facilities of canvas widgets. Bindings have been defined to support editing (see above)." -width 440 -anchor n -font $textFont -justify left] -$c bind text <1> "textB1Press $c %x %y" +$c bind text "textB1Press $c %x %y" $c bind text "textB1Move $c %x %y" -$c bind text "$c select adjust current @%x,%y" +$c bind text "$c select adjust current @%x,%y" $c bind text "textB1Move $c %x %y" -$c bind text "textInsert $c %A" +$c bind text "textInsert $c %A" $c bind text "textInsert $c \\n" $c bind text "textBs $c" $c bind text "textBs $c" $c bind text "textDel $c" -$c bind text <2> "textPaste $c @%x,%y" +$c bind text "textPaste $c @%x,%y" # Next, create some items that allow the text's anchor position # to be edited. @@ -58,14 +58,14 @@ $c bind text <2> "textPaste $c @%x,%y" proc mkTextConfigBox {w x y option value color} { set item [$w create rect $x $y [expr {$x+30}] [expr {$y+30}] \ -outline black -fill $color -width 1] - $w bind $item <1> "$w itemconf text $option $value" + $w bind $item "$w itemconf text $option $value" $w addtag config withtag $item } proc mkTextConfigPie {w x y a option value color} { set item [$w create arc $x $y [expr {$x+90}] [expr {$y+90}] \ -start [expr {$a-15}] -extent 30 -outline black -fill $color \ -width 1] - $w bind $item <1> "$w itemconf text $option $value" + $w bind $item "$w itemconf text $option $value" $w addtag config withtag $item } @@ -84,7 +84,7 @@ mkTextConfigBox $c [expr {$x+60}] [expr {$y+60}] -anchor nw $color set item [$c create rect \ [expr {$x+40}] [expr {$y+40}] [expr {$x+50}] [expr {$y+50}] \ -outline black -fill red] -$c bind $item <1> "$c itemconf text -anchor center" +$c bind $item "$c itemconf text -anchor center" $c create text [expr {$x+45}] [expr {$y-5}] \ -text {Text Position} -anchor s -font {Times 20} -fill brown diff --git a/library/entry.tcl b/library/entry.tcl index da3f800..6539af7 100644 --- a/library/entry.tcl +++ b/library/entry.tcl @@ -58,7 +58,7 @@ bind Entry <> { } bind Entry <> { # ignore if there is no selection - catch { %W delete sel.first sel.last } + catch {%W delete sel.first sel.last} } bind Entry <> { if {$tk_strictMotif || ![info exists tk::Priv(mouseMoved)] @@ -74,7 +74,7 @@ bind Entry <> { # Standard Motif bindings: -bind Entry <1> { +bind Entry { tk::EntryButton1 %W %x %W selection clear } @@ -82,25 +82,25 @@ bind Entry { set tk::Priv(x) %x tk::EntryMouseSelect %W %x } -bind Entry { +bind Entry { set tk::Priv(selectMode) word tk::EntryMouseSelect %W %x catch {%W icursor sel.last} } -bind Entry { +bind Entry { set tk::Priv(selectMode) line tk::EntryMouseSelect %W %x catch {%W icursor sel.last} } -bind Entry { +bind Entry { set tk::Priv(selectMode) char %W selection adjust @%x } -bind Entry { +bind Entry { set tk::Priv(selectMode) word tk::EntryMouseSelect %W %x } -bind Entry { +bind Entry { set tk::Priv(selectMode) line tk::EntryMouseSelect %W %x } @@ -114,22 +114,22 @@ bind Entry { bind Entry { tk::CancelRepeat } -bind Entry { +bind Entry { %W icursor @%x } bind Entry <> { - tk::EntrySetCursor %W [expr {[%W index insert] - 1}] + tk::EntrySetCursor %W [expr {[%W index insert]-1}] } bind Entry <> { - tk::EntrySetCursor %W [expr {[%W index insert] + 1}] + tk::EntrySetCursor %W [expr {[%W index insert]+1}] } bind Entry <> { - tk::EntryKeySelect %W [expr {[%W index insert] - 1}] + tk::EntryKeySelect %W [expr {[%W index insert]-1}] tk::EntrySeeInsert %W } bind Entry <> { - tk::EntryKeySelect %W [expr {[%W index insert] + 1}] + tk::EntryKeySelect %W [expr {[%W index insert]+1}] tk::EntrySeeInsert %W } bind Entry <> { @@ -190,19 +190,19 @@ bind Entry <> { bind Entry <> { %W selection clear } -bind Entry { +bind Entry { tk::CancelRepeat tk::EntryInsert %W %A } # Ignore all Alt, Meta, and Control keypresses unless explicitly bound. # Otherwise, if a widget binding for one of these is defined, the -# class binding will also fire and insert the character, +# class binding will also fire and insert the character, # which is wrong. Ditto for Escape, Return, and Tab. -bind Entry {# nothing} -bind Entry {# nothing} -bind Entry {# nothing} +bind Entry {# nothing} +bind Entry {# nothing} +bind Entry {# nothing} bind Entry {# nothing} bind Entry {# nothing} bind Entry {# nothing} @@ -210,7 +210,7 @@ bind Entry {# nothing} bind Entry {# nothing} bind Entry {# nothing} if {[tk windowingsystem] eq "aqua"} { - bind Entry {# nothing} + bind Entry {# nothing} } # Tk-on-Cocoa generates characters for these two keys. [Bug 2971663] bind Entry <> {# nothing} @@ -278,7 +278,7 @@ bind Entry <> { dict set ::tk::Priv(IMETextMark) "%W" [%W index insert] } bind Entry <> { - if { [catch {dict get $::tk::Priv(IMETextMark) "%W"} mark] } { + if {[catch {dict get $::tk::Priv(IMETextMark) "%W"} mark]} { bell } else { %W selection range $mark insert @@ -294,7 +294,7 @@ bind Entry <> { # A few additional bindings of my own. if {[tk windowingsystem] ne "aqua"} { - bind Entry <2> { + bind Entry { if {!$tk_strictMotif} { ::tk::EntryScanMark %W %x } @@ -305,7 +305,7 @@ if {[tk windowingsystem] ne "aqua"} { } } } else { - bind Entry <3> { + bind Entry { if {!$tk_strictMotif} { ::tk::EntryScanMark %W %x } @@ -391,10 +391,10 @@ proc ::tk::EntryMouseSelect {w x} { word { if {$cur < $anchor} { set before [tcl_wordBreakBefore [$w get] $cur] - set after [tcl_wordBreakAfter [$w get] [expr {$anchor-1}]] + set after [tcl_wordBreakAfter [$w get] $anchor-1] } elseif {$cur > $anchor} { set before [tcl_wordBreakBefore [$w get] $anchor] - set after [tcl_wordBreakAfter [$w get] [expr {$cur - 1}]] + set after [tcl_wordBreakAfter [$w get] $cur-1] } else { if {[$w index @$Priv(pressX)] < $anchor} { incr anchor -1 @@ -520,7 +520,7 @@ proc ::tk::EntryBackspace w { } else { set x [$w index insert] if {$x > 0} { - $w delete [expr {$x - 1}] + $w delete [expr {$x-1}] } if {[$w index @0] >= [$w index insert]} { set range [$w xview] @@ -580,7 +580,7 @@ proc ::tk::EntryTranspose w { } set first [expr {$i-2}] set data [$w get] - set new [string index $data [expr {$i-1}]][string index $data $first] + set new [string index $data $i-1][string index $data $first] $w delete $first $i $w insert insert $new EntrySeeInsert $w @@ -660,7 +660,7 @@ proc ::tk::EntryScanMark {w x} { proc ::tk::EntryScanDrag {w x} { # Make sure these exist, as some weird situations can trigger the # motion binding without the initial press. [Bug #220269] - if {![info exists ::tk::Priv(x)]} { set ::tk::Priv(x) $x } + if {![info exists ::tk::Priv(x)]} {set ::tk::Priv(x) $x} # allow for a delta if {abs($x-$::tk::Priv(x)) > 2} { set ::tk::Priv(mouseMoved) 1 @@ -677,19 +677,10 @@ proc ::tk::EntryScanDrag {w x} { proc ::tk::EntryGetSelection {w} { set entryString [string range [$w get] [$w index sel.first] \ - [expr {[$w index sel.last] - 1}]] + [$w index sel.last]-1] if {[$w cget -show] ne ""} { return [string repeat [string index [$w cget -show] 0] \ [string length $entryString]] } return $entryString } - - - - - - - - - diff --git a/library/tearoff.tcl b/library/tearoff.tcl index c2d2d6b..4c8b404 100644 --- a/library/tearoff.tcl +++ b/library/tearoff.tcl @@ -39,7 +39,7 @@ proc ::tk::TearOffMenu {w {x 0} {y 0}} { # Shift by height of tearoff entry minus height of window titlebar catch {incr y [expr {[$w yposition 1] - 16}]} # Avoid the native menu bar which sits on top of everything. - if {$y < 22} { set y 22 } + if {$y < 22} {set y 22} } } @@ -155,9 +155,9 @@ proc ::tk::MenuDup {src dst type} { while {[set index [string first $src $tags]] != -1} { if {$index > 0} { - append x [string range $tags 0 [expr {$index - 1}]]$dst + append x [string range $tags 0 $index-1]$dst } - set tags [string range $tags [expr {$index + $srcLen}] end] + set tags [string range $tags $index+$srcLen end] } append x $tags @@ -172,10 +172,10 @@ proc ::tk::MenuDup {src dst type} { while {[set index [string first $event $script]] != -1} { if {$index > 0} { - append x [string range $script 0 [expr {$index - 1}]] + append x [string range $script 0 $index-1] } append x $dst - set script [string range $script [expr {$index + $eventLen}] end] + set script [string range $script $index+$eventLen end] } append x $script -- cgit v0.12