File: ntextExample.tcl

package info (click to toggle)
tklib 0.6%2B20190108-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,008 kB
  • sloc: tcl: 75,757; sh: 5,789; ansic: 792; pascal: 359; makefile: 70; sed: 53; exp: 21
file content (63 lines) | stat: -rwxr-xr-x 2,378 bytes parent folder | download | duplicates (3)
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
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Tk

# Copyright (c) 2005-2018 Keith Nash.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

### This is a short, simple example.  It shows the difference
### between a default text widget and one that uses ntext.

### To explore the ntext options, try ntextDemoBindings.tcl
### To explore ntext indentation, try ntextDemoIndent.tcl
### To explore vertical scrolling on the Mac, try ntextDemoMacScrolling.tcl
### For corner cases in scrolling, try ntextDemoScroll.tcl

. configure -bg #d0cfce

package require ntext 1.0

# This string defines the text that will be displayed in each widget:
set message {The source code for this example shows how simple it is to deploy ntext.  It is necessary to "package require" the ntext package, and then call the "bindtags" command for any text widget in which you wish to use the Ntext bindings...}

# ...and if you do not like the ntext default bindings, you can override some
# of them by setting these variables (ntextDemoBindings.tcl has a live demo):


#  Whether Shift-Button-1 ignores changes made by the kbd to the insert mark:
set ::ntext::classicMouseSelect 0

#  Whether Shift-Button-1 has a variable or fixed anchor:
set ::ntext::classicAnchor      0

# Whether to activate certain traditional "extra" bindings
variable classicExtras          1

#  Whether to use new or classic word boundary detection:
set ::ntext::classicWordBreak   0

# Set to 0 to follow Mac Aqua conventions on placement of the insert mark
# when a selection is cancelled by keyboard navigation:
set ::ntext::classicSelection   1


# Create two identical text widgets:
pack [text .left ] -side left -padx 2 -pady 2
pack [text .right] -side left -padx 2 -pady 2
.left  configure -width 28 -height 14 -wrap word -undo 1 -font {{Courier} -15}
.right configure -width 28 -height 14 -wrap word -undo 1 -font {{Courier} -15}

# Give them different background colors:
.left  configure -bg #FFFFCC
.right configure -bg white

# Write slightly different text to each one:
.left  insert end "  I use the (default) Text bindings.\n\n$message"
.right insert end "  I use the Ntext bindings.\n\n\n$message"

# Finally, enable Ntext for the right-hand widget:
bindtags .right {.right Ntext . all}