Skip to content

Commit dc8929d

Browse files
committed
Module ntext - update to 1.0b1
1 parent 48e7440 commit dc8929d

File tree

14 files changed

+2396
-550
lines changed

14 files changed

+2396
-550
lines changed

examples/ntext/ntextDemoBindings.tcl

100644100755
Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
#!/usr/bin/env wish
2-
## -*- tcl -*-
3-
# Copyright (c) 2005-2007 Keith Nash.
1+
#!/bin/sh
2+
# the next line restarts using tclsh \
3+
exec tclsh "$0" "$@"
4+
5+
package require Tk
6+
7+
# Copyright (c) 2005-2017 Keith Nash.
48
#
59
# See the file "license.terms" for information on usage and redistribution
610
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
711

812
### This demo explores the ntext options
13+
914
### For a short example, see ntextExample.tcl
1015
### To explore ntext indentation, try ntextDemoIndent.tcl
16+
### To explore vertical scrolling on the Mac, try ntextDemoMacScrolling.tcl
1117

1218
# This string defines the text that will be displayed in each widget:
1319
set message {QOTW: "C/C++, which is used by 16% of users, is the most popular programming language, but Tcl, used by 0%, seems to be the language of choice for the highest scoring users."
@@ -26,15 +32,15 @@ Try word-by-word navigation (Control key with left cursor or right cursor key);
2632
The classicMouseSelect and classicAnchor options are discussed in the man page for ntextBindings.}
2733
# End of string for widget text.
2834

29-
package require ntext
35+
package require ntext 1.0
3036

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

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

37-
# Whether the traditional "extra" bindings are activated:
43+
# Whether the traditional "extra" bindings are activated (default is 0):
3844
set ::ntext::classicExtras 1
3945

4046
# Whether to use new or classic word boundary detection:
@@ -43,43 +49,57 @@ set ::ntext::classicWordBreak 0
4349
# Set to 0 to align wrapped display lines with the first display line of the logical line:
4450
set ::ntext::classicWrap 1
4551

46-
pack [frame .rhf] -side right -anchor nw
47-
pack [text .rhf.new ]
52+
# Set to 0 to follow Mac Aqua conventions on placement of the insert mark
53+
# when a selection is cancelled by keyboard navigation:
54+
# Has effect on all platforms. Default value is 0 on Aqua, 1 on other platforms.
55+
# set ::ntext::classicSelection 1
56+
57+
58+
set col #e0dfde
59+
. configure -bg $col
60+
61+
pack [frame .rhf -bg $col] -side right -anchor nw
62+
pack [text .rhf.new ] -padx 2
4863
bindtags .rhf.new {.rhf.new Ntext . all}
4964

5065
.rhf.new configure -wrap word -undo 1
5166
.rhf.new configure -width 42 -height 29 -font {{Courier} -15} -bg white
5267
.rhf.new insert end " I use the Ntext bindings.\n\n$message"
5368
.rhf.new edit separator
5469

55-
pack [frame .lhf] -side left -anchor ne
56-
pack [text .lhf.classic ]
57-
.lhf.classic configure -width 42 -height 29 -wrap word -undo 1 -font {{Courier} -15} -bg #FFFFEE
70+
pack [frame .lhf -bg $col] -side left -anchor ne
71+
pack [text .lhf.classic ] -padx 2
72+
.lhf.classic configure -width 42 -height 29 -wrap word -undo 1 -font {{Courier} -15} -bg #FFFFCC
5873
.lhf.classic insert end " I use the (default) Text bindings.\n\n$message"
5974
.lhf.classic edit separator
60-
pack [label .lhf.m -text "(The controls do not apply\nto the left-hand text widget)"]
75+
pack [label .lhf.m -bg $col -text "(The radiobutton controls do not\napply to the left-hand text widget)"]
6176

62-
pack [frame .rhf.h] -fill x
63-
pack [radiobutton .rhf.h.on -text "On " -variable ::ntext::classicMouseSelect -value 1] -side right
64-
pack [radiobutton .rhf.h.off -text "Off" -variable ::ntext::classicMouseSelect -value 0] -side right
65-
pack [label .rhf.h.l -text "classicMouseSelect: "] -side right
77+
pack [frame .rhf.h -bg $col] -fill x
78+
pack [radiobutton .rhf.h.on -bg $col -text "On " -variable ::ntext::classicMouseSelect -value 1] -side right
79+
pack [radiobutton .rhf.h.off -bg $col -text "Off" -variable ::ntext::classicMouseSelect -value 0] -side right
80+
pack [label .rhf.h.l -bg $col -text "classicMouseSelect: "] -side right
6681

67-
pack [frame .rhf.g] -anchor ne
68-
pack [radiobutton .rhf.g.on -text "On " -variable ::ntext::classicAnchor -value 1] -side right
69-
pack [radiobutton .rhf.g.off -text "Off" -variable ::ntext::classicAnchor -value 0] -side right
70-
pack [label .rhf.g.l -text "classicAnchor: "] -side right
82+
pack [frame .rhf.g -bg $col] -anchor ne
83+
pack [radiobutton .rhf.g.on -bg $col -text "On " -variable ::ntext::classicAnchor -value 1] -side right
84+
pack [radiobutton .rhf.g.off -bg $col -text "Off" -variable ::ntext::classicAnchor -value 0] -side right
85+
pack [label .rhf.g.l -bg $col -text "classicAnchor: "] -side right
7186

72-
pack [frame .rhf.k] -anchor ne
73-
pack [radiobutton .rhf.k.on -text "On " -variable ::ntext::classicExtras -value 1] -side right
74-
pack [radiobutton .rhf.k.off -text "Off" -variable ::ntext::classicExtras -value 0] -side right
75-
pack [label .rhf.k.l -text "classicExtras: "] -side right
87+
pack [frame .rhf.k -bg $col] -anchor ne
88+
pack [radiobutton .rhf.k.on -bg $col -text "On " -variable ::ntext::classicExtras -value 1] -side right
89+
pack [radiobutton .rhf.k.off -bg $col -text "Off" -variable ::ntext::classicExtras -value 0] -side right
90+
pack [label .rhf.k.l -bg $col -text "classicExtras: "] -side right
7691

77-
pack [frame .rhf.j] -anchor ne
92+
pack [frame .rhf.j -bg $col] -anchor ne
7893
set wordBreakChoice new
79-
pack [radiobutton .rhf.j.wind -text "On (Windows)" -variable wordBreakChoice -value "windows" -command {setPattern}] -side right
80-
pack [radiobutton .rhf.j.unix -text "On (Unix)" -variable wordBreakChoice -value "unix" -command {setPattern}] -side right
81-
pack [radiobutton .rhf.j.off -text "Off" -variable wordBreakChoice -value "new" -command {setPattern}] -side right
82-
pack [label .rhf.j.l -text "classicWordBreak: "] -side right
94+
pack [radiobutton .rhf.j.wind -bg $col -text "On (Windows)" -variable wordBreakChoice -value "windows" -command {setPattern}] -side right
95+
pack [radiobutton .rhf.j.unix -bg $col -text "On (Unix)" -variable wordBreakChoice -value "unix" -command {setPattern}] -side right
96+
pack [radiobutton .rhf.j.off -bg $col -text "Off" -variable wordBreakChoice -value "new" -command {setPattern}] -side right
97+
pack [label .rhf.j.l -bg $col -text "classicWordBreak: "] -side right
98+
99+
pack [frame .rhf.m -bg $col] -anchor ne
100+
pack [radiobutton .rhf.m.on -bg $col -text "On " -variable ::ntext::classicSelection -value 1] -side right
101+
pack [radiobutton .rhf.m.off -bg $col -text "Off" -variable ::ntext::classicSelection -value 0] -side right
102+
pack [label .rhf.m.l -bg $col -text "classicSelection: "] -side right
83103

84104
proc setPattern {} {
85105
global wordBreakChoice

examples/ntext/ntextDemoIndent.tcl

100644100755
Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,52 @@
1-
#!/usr/bin/env wish
2-
## -*- tcl -*-
3-
# Copyright (c) 2005-2007 Keith Nash.
1+
#!/bin/sh
2+
# the next line restarts using tclsh \
3+
exec tclsh "$0" "$@"
4+
5+
package require Tk
6+
7+
# Copyright (c) 2005-2017 Keith Nash.
48
#
59
# See the file "license.terms" for information on usage and redistribution
610
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
711

812
### This demo explores ntext indentation
13+
914
### For a short example, see ntextExample.tcl
1015
### To explore the ntext options, try ntextDemoBindings.tcl
16+
### To explore vertical scrolling on the Mac, try ntextDemoMacScrolling.tcl
1117

12-
### Points to note when using ntext's indent facilities are commented and numbered (1) to (6).
13-
14-
### If the text in your widget is manipulated only by the keyboard and mouse, then (1), (2) and (3) are all you need to do. If the text or its layout are manipulated by the script, then you also need to call the function ::ntext::wrapIndent - see comments (4) to (6), and the man page for ntextIndent.
18+
### - Points to note when using ntext's indent facilities are commented and
19+
### numbered (1) to (6).
20+
### - If the text in your widget is manipulated only by the keyboard and mouse,
21+
### then (1), (2) and (3) are all you need to do.
22+
### - If the text or its layout are manipulated by the script, then you also
23+
### need to call the function ::ntext::wrapIndent - see comments (4) to (6),
24+
### and the man page for ntextIndent.
1525

1626
# This string defines the text that will be displayed in each widget:
1727
set message { This demo shows ntext's indentation facilities. These are switched off by default, but in this demo they have been switched on.
1828

1929
To try the demo - place the cursor at the start of a paragraph and change the amount of initial space. The paragraph is a logical line of text; its first display line may have leading whitespace, and ntext indents any subsequent (wrapped) display lines to match the first.
2030
This paragraph is indented by a tab. Again, the display lines are all indented to match the first.
21-
Try any text-widget operation, and test whether ntext's handling of display line indentation is satisfactory. Please report any bugs - for instructions, see the ntext Wiki page, http://wiki.tcl.tk/14918
31+
Try any text-widget operation, and test whether ntext's handling of display line indentation is satisfactory. Ntext is part of Tklib - please report any bugs to:
32+
33+
http://core.tcl.tk/tklib/reportlist
2234
}
2335
# End of string for widget text.
2436

25-
package require ntext
37+
package require ntext 1.0
2638

2739
### (1) Indentation is disabled by default. Set this variable to 0 to enable it:
2840
set ::ntext::classicWrap 0
2941

3042
# Activate the traditional "extra" bindings so these can be tested too:
3143
set ::ntext::classicExtras 1
3244

33-
pack [frame .rhf] -side right -anchor nw
34-
pack [text .rhf.new ]
45+
set col #e0dfde
46+
. configure -bg $col
47+
48+
pack [frame .rhf -bg $col] -side right -anchor nw
49+
pack [text .rhf.new ] -padx 2
3550

3651
### (2) Set the widget's binding tags to use 'Ntext' instead of the default 'Text':
3752
bindtags .rhf.new {.rhf.new Ntext . all}
@@ -42,32 +57,40 @@ bindtags .rhf.new {.rhf.new Ntext . all}
4257
.rhf.new insert end " I use the Ntext bindings.\n\n$message"
4358
.rhf.new edit separator
4459

45-
### (4) The script (not the keyboard or mouse) has inserted text. Because the widget has not yet been drawn, ::ntext::wrapIndent will be called by the <Configure> binding, so it is not really necessary to call it here. It is necessary in most other cases when the 'insert' command is called by the script.
60+
### (4) The script (not the keyboard or mouse) has inserted text. Because the
61+
### widget has not yet been drawn, ::ntext::wrapIndent will be called by the
62+
### <Configure> binding, so it is not really necessary to call it here. It
63+
### is necessary in most other cases when the 'insert' command is called by
64+
### the script.
4665
::ntext::wrapIndent .rhf.new
4766

48-
pack [frame .lhf] -side left -anchor ne
49-
pack [text .lhf.classic ]
50-
.lhf.classic configure -width 42 -height 26 -wrap word -undo 1 -font {{Courier} -15} -bg #FFFFEE
67+
pack [frame .lhf -bg $col] -side left -anchor ne
68+
pack [text .lhf.classic ] -padx 2
69+
.lhf.classic configure -width 42 -height 26 -wrap word -undo 1 -font {{Courier} -15} -bg #FFFFCC
5170
.lhf.classic insert end " I use the (default) Text bindings.\n\n$message"
5271
.lhf.classic edit separator
53-
pack [label .lhf.m -text "(The controls do not apply\nto the left-hand text widget)"]
72+
pack [label .lhf.m -bg $col -text "(The radiobuttons and tab settings do not\napply to the left-hand text widget)"]
5473

55-
pack [frame .rhf.h] -fill x
56-
### (5) When indentation is switched on or off, call ::ntext::wrapIndent to calculate or clear indentation for the entire widget:
57-
pack [radiobutton .rhf.h.off -text "Indent Off" -variable ::ntext::classicWrap -value 1 -command {::ntext::wrapIndent .rhf.new}] -side right
58-
pack [radiobutton .rhf.h.on -text "Indent On" -variable ::ntext::classicWrap -value 0 -command {::ntext::wrapIndent .rhf.new}] -side right
59-
pack [label .rhf.h.l -text "Switch indentation on/off: "] -side right
74+
pack [frame .rhf.h -bg $col] -fill x
75+
### (5) When indentation is switched on or off, call ::ntext::wrapIndent to
76+
### calculate or clear indentation for the entire widget:
77+
pack [radiobutton .rhf.h.off -bg $col -text "Indent Off" -variable ::ntext::classicWrap -value 1 -command {::ntext::wrapIndent .rhf.new}] -side right
78+
pack [radiobutton .rhf.h.on -bg $col -text "Indent On" -variable ::ntext::classicWrap -value 0 -command {::ntext::wrapIndent .rhf.new}] -side right
79+
pack [label .rhf.h.l -bg $col -text "Switch indentation on/off: "] -side right
6080

61-
pack [frame .rhf.g] -anchor ne
81+
pack [frame .rhf.g -bg $col] -anchor ne
82+
pack [label .rhf.g.l -bg $col -text " "] -side right
6283
pack [entry .rhf.g.e -width 3] -side right -padx 5
63-
pack [button .rhf.g.b -text "Click to set tab spacing to value in box" -command changeTabs] -side right
84+
pack [button .rhf.g.b -bg $col -highlightbackground $col -text "Click to set tab spacing to value in box" -command changeTabs] -side right
6485

6586
proc changeTabs {} {
6687
set nTabs [.rhf.g.e get]
6788
if {[string is integer -strict $nTabs] && $nTabs > 0} {
6889
set font [lindex [.rhf.new configure -font] 4]
6990
.rhf.new configure -tabs "[expr {$nTabs * [font measure $font 0]}] left"
70-
### (6) Changing the tabs may change the indentation of the first display line of a logical line; if so, the indentation of the other display lines must be recalculated:
91+
### (6) Changing the tabs may change the indentation of the first
92+
### display line of a logical line; if so, the indentation of the
93+
### other display lines must be recalculated:
7194
::ntext::wrapIndent .rhf.new
7295
}
7396
}

0 commit comments

Comments
 (0)