1 |
578 |
markom |
# style.tcl --
|
2 |
|
|
#
|
3 |
|
|
# This demonstration script creates a text widget that illustrates the
|
4 |
|
|
# various display styles that may be set for tags.
|
5 |
|
|
#
|
6 |
|
|
# SCCS: @(#) style.tcl 1.8 97/04/18 11:41:47
|
7 |
|
|
|
8 |
|
|
if {![info exists widgetDemo]} {
|
9 |
|
|
error "This script should be run from the \"widget\" demo."
|
10 |
|
|
}
|
11 |
|
|
|
12 |
|
|
set w .style
|
13 |
|
|
catch {destroy $w}
|
14 |
|
|
toplevel $w
|
15 |
|
|
wm title $w "Text Demonstration - Display Styles"
|
16 |
|
|
wm iconname $w "style"
|
17 |
|
|
positionWindow $w
|
18 |
|
|
|
19 |
|
|
frame $w.buttons
|
20 |
|
|
pack $w.buttons -side bottom -fill x -pady 2m
|
21 |
|
|
button $w.buttons.dismiss -text Dismiss -command "destroy $w"
|
22 |
|
|
button $w.buttons.code -text "See Code" -command "showCode $w"
|
23 |
|
|
pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
|
24 |
|
|
|
25 |
|
|
text $w.text -yscrollcommand "$w.scroll set" -setgrid true \
|
26 |
|
|
-width 70 -height 32 -wrap word
|
27 |
|
|
scrollbar $w.scroll -command "$w.text yview"
|
28 |
|
|
pack $w.scroll -side right -fill y
|
29 |
|
|
pack $w.text -expand yes -fill both
|
30 |
|
|
|
31 |
|
|
# Set up display styles
|
32 |
|
|
|
33 |
|
|
$w.text tag configure bold -font {Courier 12 bold italic}
|
34 |
|
|
$w.text tag configure big -font {Courier 14 bold}
|
35 |
|
|
$w.text tag configure verybig -font {Helvetica 24 bold}
|
36 |
|
|
if {[winfo depth $w] > 1} {
|
37 |
|
|
$w.text tag configure color1 -background #a0b7ce
|
38 |
|
|
$w.text tag configure color2 -foreground red
|
39 |
|
|
$w.text tag configure raised -relief raised -borderwidth 1
|
40 |
|
|
$w.text tag configure sunken -relief sunken -borderwidth 1
|
41 |
|
|
} else {
|
42 |
|
|
$w.text tag configure color1 -background black -foreground white
|
43 |
|
|
$w.text tag configure color2 -background black -foreground white
|
44 |
|
|
$w.text tag configure raised -background white -relief raised \
|
45 |
|
|
-borderwidth 1
|
46 |
|
|
$w.text tag configure sunken -background white -relief sunken \
|
47 |
|
|
-borderwidth 1
|
48 |
|
|
}
|
49 |
|
|
$w.text tag configure bgstipple -background black -borderwidth 0 \
|
50 |
|
|
-bgstipple gray12
|
51 |
|
|
$w.text tag configure fgstipple -fgstipple gray50
|
52 |
|
|
$w.text tag configure underline -underline on
|
53 |
|
|
$w.text tag configure overstrike -overstrike on
|
54 |
|
|
$w.text tag configure right -justify right
|
55 |
|
|
$w.text tag configure center -justify center
|
56 |
|
|
$w.text tag configure super -offset 4p -font {Courier 10}
|
57 |
|
|
$w.text tag configure sub -offset -2p -font {Courier 10}
|
58 |
|
|
$w.text tag configure margins -lmargin1 12m -lmargin2 6m -rmargin 10m
|
59 |
|
|
$w.text tag configure spacing -spacing1 10p -spacing2 2p \
|
60 |
|
|
-lmargin1 12m -lmargin2 6m -rmargin 10m
|
61 |
|
|
|
62 |
|
|
$w.text insert end {Text widgets like this one allow you to display information in a
|
63 |
|
|
variety of styles. Display styles are controlled using a mechanism
|
64 |
|
|
called }
|
65 |
|
|
$w.text insert end tags bold
|
66 |
|
|
$w.text insert end {. Tags are just textual names that you can apply to one
|
67 |
|
|
or more ranges of characters within a text widget. You can configure
|
68 |
|
|
tags with various display styles. If you do this, then the tagged
|
69 |
|
|
characters will be displayed with the styles you chose. The
|
70 |
|
|
available display styles are:
|
71 |
|
|
}
|
72 |
|
|
$w.text insert end "\n1. Font." big
|
73 |
|
|
$w.text insert end " You can choose any X font, "
|
74 |
|
|
$w.text insert end large verybig
|
75 |
|
|
$w.text insert end " or "
|
76 |
|
|
$w.text insert end "small.\n"
|
77 |
|
|
$w.text insert end "\n2. Color." big
|
78 |
|
|
$w.text insert end " You can change either the "
|
79 |
|
|
$w.text insert end background color1
|
80 |
|
|
$w.text insert end " or "
|
81 |
|
|
$w.text insert end foreground color2
|
82 |
|
|
$w.text insert end "\ncolor, or "
|
83 |
|
|
$w.text insert end both {color1 color2}
|
84 |
|
|
$w.text insert end ".\n"
|
85 |
|
|
$w.text insert end "\n3. Stippling." big
|
86 |
|
|
$w.text insert end " You can cause either the "
|
87 |
|
|
$w.text insert end background bgstipple
|
88 |
|
|
$w.text insert end " or "
|
89 |
|
|
$w.text insert end foreground fgstipple
|
90 |
|
|
$w.text insert end {
|
91 |
|
|
information to be drawn with a stipple fill instead of a solid fill.
|
92 |
|
|
}
|
93 |
|
|
$w.text insert end "\n4. Underlining." big
|
94 |
|
|
$w.text insert end " You can "
|
95 |
|
|
$w.text insert end underline underline
|
96 |
|
|
$w.text insert end " ranges of text.\n"
|
97 |
|
|
$w.text insert end "\n5. Overstrikes." big
|
98 |
|
|
$w.text insert end " You can "
|
99 |
|
|
$w.text insert end "draw lines through" overstrike
|
100 |
|
|
$w.text insert end " ranges of text.\n"
|
101 |
|
|
$w.text insert end "\n6. 3-D effects." big
|
102 |
|
|
$w.text insert end { You can arrange for the background to be drawn
|
103 |
|
|
with a border that makes characters appear either }
|
104 |
|
|
$w.text insert end raised raised
|
105 |
|
|
$w.text insert end " or "
|
106 |
|
|
$w.text insert end sunken sunken
|
107 |
|
|
$w.text insert end ".\n"
|
108 |
|
|
$w.text insert end "\n7. Justification." big
|
109 |
|
|
$w.text insert end " You can arrange for lines to be displayed\n"
|
110 |
|
|
$w.text insert end "left-justified,\n"
|
111 |
|
|
$w.text insert end "right-justified, or\n" right
|
112 |
|
|
$w.text insert end "centered.\n" center
|
113 |
|
|
$w.text insert end "\n8. Superscripts and subscripts." big
|
114 |
|
|
$w.text insert end " You can control the vertical\n"
|
115 |
|
|
$w.text insert end "position of text to generate superscript effects like 10"
|
116 |
|
|
$w.text insert end "n" super
|
117 |
|
|
$w.text insert end " or\nsubscript effects like X"
|
118 |
|
|
$w.text insert end "i" sub
|
119 |
|
|
$w.text insert end ".\n"
|
120 |
|
|
$w.text insert end "\n9. Margins." big
|
121 |
|
|
$w.text insert end " You can control the amount of extra space left"
|
122 |
|
|
$w.text insert end " on\neach side of the text:\n"
|
123 |
|
|
$w.text insert end "This paragraph is an example of the use of " margins
|
124 |
|
|
$w.text insert end "margins. It consists of a single line of text " margins
|
125 |
|
|
$w.text insert end "that wraps around on the screen. There are two " margins
|
126 |
|
|
$w.text insert end "separate left margin values, one for the first " margins
|
127 |
|
|
$w.text insert end "display line associated with the text line, " margins
|
128 |
|
|
$w.text insert end "and one for the subsequent display lines, which " margins
|
129 |
|
|
$w.text insert end "occur because of wrapping. There is also a " margins
|
130 |
|
|
$w.text insert end "separate specification for the right margin, " margins
|
131 |
|
|
$w.text insert end "which is used to choose wrap points for lines.\n" margins
|
132 |
|
|
$w.text insert end "\n10. Spacing." big
|
133 |
|
|
$w.text insert end " You can control the spacing of lines with three\n"
|
134 |
|
|
$w.text insert end "separate parameters. \"Spacing1\" tells how much "
|
135 |
|
|
$w.text insert end "extra space to leave\nabove a line, \"spacing3\" "
|
136 |
|
|
$w.text insert end "tells how much space to leave below a line,\nand "
|
137 |
|
|
$w.text insert end "if a text line wraps, \"spacing2\" tells how much "
|
138 |
|
|
$w.text insert end "space to leave\nbetween the display lines that "
|
139 |
|
|
$w.text insert end "make up the text line.\n"
|
140 |
|
|
$w.text insert end "These indented paragraphs illustrate how spacing " spacing
|
141 |
|
|
$w.text insert end "can be used. Each paragraph is actually a " spacing
|
142 |
|
|
$w.text insert end "single line in the text widget, which is " spacing
|
143 |
|
|
$w.text insert end "word-wrapped by the widget.\n" spacing
|
144 |
|
|
$w.text insert end "Spacing1 is set to 10 points for this text, " spacing
|
145 |
|
|
$w.text insert end "which results in relatively large gaps between " spacing
|
146 |
|
|
$w.text insert end "the paragraphs. Spacing2 is set to 2 points, " spacing
|
147 |
|
|
$w.text insert end "which results in just a bit of extra space " spacing
|
148 |
|
|
$w.text insert end "within a pararaph. Spacing3 isn't used " spacing
|
149 |
|
|
$w.text insert end "in this example.\n" spacing
|
150 |
|
|
$w.text insert end "To see where the space is, select ranges of " spacing
|
151 |
|
|
$w.text insert end "text within these paragraphs. The selection " spacing
|
152 |
|
|
$w.text insert end "highlight will cover the extra space." spacing
|