1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"
# Copyright (c) 2017-2018 Keith Nash.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# ------------------------------------------------------------------------------
# Demo of the persistent selection module persistentSelection.
# ------------------------------------------------------------------------------
# This demo is for text, ntext and all widgetPlus widgets.
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Load package(s) and create bindings.
# ------------------------------------------------------------------------------
package require Tk
package require persistentSelection
package require ntext
package require snit
package require widgetPlus
namespace import widgetPlus::*
persistentSelection::fixText
bind Text <<Selection>> {persistentSelection::report text %W}
bind Ntext <<Selection>> {persistentSelection::report text %W}
bind EntryPlus <<Selection>> {persistentSelection::report entry %W}
bind TEntryPlus <<Selection>> {persistentSelection::report entry %W}
bind SpinboxPlus <<Selection>> {persistentSelection::report entry %W}
bind TSpinboxPlus <<Selection>> {persistentSelection::report entry %W}
bind TComboboxPlus <<Selection>> {persistentSelection::report entry %W}
# ------------------------------------------------------------------------------
# Create, initialize, and map a widgetPlus widget.
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Command CreateWidget
# ------------------------------------------------------------------------------
# Command to create a widgetPlus widget, initialize it, and map it.
# If there is an existing widget with the same name it is destroyed.
#
# When debugging, note that the Undo/Redo innards differ if $w has or does not
# have a -textvariable.
#
# The options added by widgetPlus are shown on the first line of each widgetPlus
# command. The options on continuation lines are those of the widget hull.
# ------------------------------------------------------------------------------
proc CreateWidget {w} {
destroy $w
switch -exact -- $::hullType {
entry {entryPlus $w -undo 1 -maxundo 0 \
-bg white}
spinbox {spinboxPlus $w -undo 1 -maxundo 0 \
-values {1 2 3 4 5} \
-bg white}
ttk::entry {ttkEntryPlus $w -undo 1 -maxundo 0}
ttk::spinbox {ttkSpinboxPlus $w -undo 1 -maxundo 0 \
-values {1 2 3 4 5}}
ttk::combobox {ttkComboboxPlus $w -undo 1 -maxundo 0 \
-values {1 2 3 4 5}}
default {error {set ::hullType to entry, ttk::entry, spinbox,\
ttk::spinbox, or ttk::combobox}}
}
pack $w -side left
$w delete 0 end
$w insert end {Initial Text}
$w edit reset
return
}
# ------------------------------------------------------------------------------
# Command CreateDemo
# ------------------------------------------------------------------------------
# Command to create a megawidget with a descriptive label, a radiobutton widget
# selector, and a widgetPlus widget.
# ------------------------------------------------------------------------------
proc CreateDemo {w} {
frame $w
label $w.lab -text {Use radiobuttons to choose widget:}
pack $w.lab -pady 10
frame $w.f
radiobutton $w.f.rb0 -value entry -text entry
radiobutton $w.f.rb1 -value spinbox -text spinbox
radiobutton $w.f.rb2 -value ttk::entry -text ttk::entry
radiobutton $w.f.rb3 -value ttk::spinbox -text ttk::spinbox
radiobutton $w.f.rb4 -value ttk::combobox -text ttk::combobox
foreach rb {.f.rb0 .f.rb1 .f.rb2 .f.rb3 .f.rb4} {
$w$rb configure -variable ::hullType -command [list CreateWidget $w.g.e]
}
pack $w.f.rb0 $w.f.rb1 $w.f.rb2 $w.f.rb3 $w.f.rb4 -side left -padx 5
pack $w.f
set ::hullType entry
frame $w.g
pack $w.g -padx 20 -pady {20 10}
frame $w.g.filler -height 30 -width 1
pack $w.g.filler -side left
# Start with "entry", specified by ::hullType.
CreateWidget $w.g.e
return $w
}
CreateDemo .wpdemo
pack .wpdemo
# ------------------------------------------------------------------------------
# Create, initialize, and map text widget.
# ------------------------------------------------------------------------------
text .top -height 22 -bg white -wrap word -undo 1 -maxundo 0
pack .top
set RR \u00ae
.top insert end {Try using the persistent PRIMARY selection on the widget modified with widgetPlus (above) and the text widget (here).
When the selection is cleared in the widget that owns the PRIMARY selection, usually Tk also clears the PRIMARY selection. The persistentSelection package ensures that, instead, the PRIMARY selection retains the last non-empty selected string.
Also try using Undo/Redo on these widgets.}
.top insert end "
On X11 systems (Linux$RR, BSD$RR, Solaris$RR ...)
<<Undo>> is mapped to <Control-z>
<<Redo>> is mapped to <Control-Shift-z>
On Windows$RR systems
<<Undo>> is mapped to <Control-z>
<<Redo>> is mapped to <Control-y>
On Aqua$RR systems (i.e. Apple$RR macOS$RR or OS X$RR)
<<Undo>> is mapped to <Command-z>
<<Redo>> is mapped to <Command-Shift-z>
"
.top edit reset
# ------------------------------------------------------------------------------
# Create, initialize, and map ntext widget.
# ------------------------------------------------------------------------------
# Create and map a ntext widget.
text .mid -height 5 -bg white -wrap word -undo 1 -maxundo 0
pack .mid -pady {10 0}
bindtags .mid {.mid Ntext . all}
.mid insert end "Also try the persistent PRIMARY selection, and Undo/Redo, on this ntext widget."
.mid edit reset
# ------------------------------------------------------------------------------
# Code for monitoring tools can be copied here from allWidgetsDebugDemo.tcl.
# These tools are not necessary for the demo to work, but they show what is
# happening.
# ------------------------------------------------------------------------------
|