OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [demos/] [widget] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#!/bin/sh
2
# the next line restarts using tixwish \
3
exec tixwish "$0" "$@"
4
 
5
# widget --
6
#
7
#       This is a demo program of all the available Tix widgets. If
8
#       have installed Tix properly, you can execute this program
9
#       directly:
10
#
11
#               % widget
12
#
13
#       Otherwise try the following in csh
14
#
15
#               % env TIX_LIBRARY=../library tixwish widget
16
#
17
#       Or this in sh
18
#
19
#               $ TIX_LIBRARY=../library tixwish widget
20
#
21
#
22
#
23
#----------------------------------------------------------------------
24
#
25
#
26
#       This file has not been properly documented. It is NOT intended
27
#       to be used as an introductory demo program about Tix
28
#       programming. For such demos, please see the files in the
29
#       demos/samples directory or go to the "Samples" page in the
30
#       "widget demo"
31
#
32
#
33
# Copyright (c) 1996, Expert Interface Technologies
34
#
35
# See the file "license.terms" for information on usage and redistribution
36
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
37
#
38
 
39
 
40
proc MkMainWindow {w} {
41
    global demo auto_path demo_dir
42
 
43
    if ![info exists demo_dir] {
44
        # Initialize the auto_path and the bitmap directory. The demo_dir
45
        # variable would be already set by the test program, if we are
46
        # running in the self test more
47
        #
48
        set script [info script]
49
        if {$script != {}} {
50
            set demo_dir [file dirname $script]
51
        } else {
52
            set demo_dir [pwd]
53
        }
54
 
55
        set demo_dir [tixFSAbsPath $demo_dir]
56
    }
57
 
58
    lappend auto_path $demo_dir
59
    tix addbitmapdir [tixFSJoin $demo_dir bitmaps]
60
 
61
    toplevel $w
62
    wm title $w "Tix Widget Demonstration"
63
    wm geometry $w 830x566+100+100
64
 
65
    set demo(balloon) [tixBalloon .demos_balloon]
66
 
67
    set frame1 [MkMainMenu     $w]
68
    set frame2 [MkMainNoteBook $w]
69
    set frame3 [MkMainStatus   $w]
70
 
71
    pack $frame1 -side top    -fill x
72
    pack $frame3 -side bottom -fill x
73
    pack $frame2 -side top    -expand yes -fill both -padx 4 -pady 4
74
 
75
    $demo(balloon) config -statusbar $demo(statusbar)
76
    set demo(notebook) $frame2
77
}
78
 
79
proc MkMainMenu {top} {
80
    global demo usebal
81
 
82
    set w [frame $top.f1 -bd 2 -relief raised]
83
 
84
    menubutton $w.file -menu $w.file.m -text File -underline 0 \
85
        -takefocus 0
86
    menubutton $w.help -menu $w.help.m -text Help -underline 0 \
87
        -takefocus 0
88
 
89
    menu $w.file.m
90
    $w.file.m add command -label "Open ... " -command FileOpen -underline 1 \
91
        -accelerator "Ctrl+O"
92
    $w.file.m add sep
93
    $w.file.m add command -label "Exit     " -command exit -underline 1 \
94
        -accelerator "Ctrl+X"
95
 
96
    menu $w.help.m
97
 
98
    $w.help.m add checkbutton -under 0  -label "Balloon Help " \
99
        -variable usebal -onvalue 1 -offvalue 0
100
 
101
    tixForm $w.file
102
    tixForm $w.help -right -0
103
 
104
    trace variable usebal w BalloonHelp
105
 
106
    set usebal 1
107
 
108
    # Accelerator bindings
109
 
110
    bind all  "exit"
111
    bind all  "FileOpen"
112
 
113
    return $w
114
}
115
 
116
# Create the main display area of the widget programm. This area should
117
# utilize the "tixNoteBook" widget once it is available. But now
118
# we use the cheap substitute "tixStackWindow"
119
#
120
proc MkMainNoteBook {top} {
121
    global demo
122
    set hasGL 0
123
 
124
    option add *TixNoteBook.tagPadX 6
125
    option add *TixNoteBook.tagPadY 4
126
    option add *TixNoteBook.borderWidth 2
127
    option add *TixNoteBook.font\
128
        -*-helvetica-bold-o-normal-*-14-*-*-*-*-*-*-*
129
 
130
    set w [tixNoteBook $top.f2 -ipadx 5 -ipady 5]
131
 
132
 
133
    $w add wel -createcmd "CreatePage MkWelcome  $w wel" \
134
        -label "Welcome" \
135
        -under 0
136
    $w add cho -createcmd "CreatePage MkChoosers $w cho" \
137
        -label "Choosers" \
138
        -under 0
139
    $w add scr -createcmd "CreatePage MkScroll   $w scr" \
140
        -label "Scrolled Widgets" \
141
        -under 0
142
    $w add mgr -createcmd "CreatePage MkManager  $w mgr" \
143
        -label "Manager Widgets" \
144
        -under 0
145
    $w add dir -createcmd "CreatePage MkDirList  $w dir" \
146
        -label "Directory List" \
147
        -under 0
148
    $w add exp -createcmd "CreatePage MkSample   $w exp" \
149
        -label "Run Sample Programs" \
150
        -under 0
151
 
152
    if {$hasGL} {
153
        $w add glw -createcmd "MkGL $w glw" -tag "GL Widgets"
154
    }
155
 
156
    return $w
157
}
158
 
159
proc CreatePage {command w name} {
160
    tixBusy $w on
161
    set id [after 10000 tixBusy $w off]
162
    $command $w $name
163
    after cancel $id
164
    after 0 tixBusy $w off
165
}
166
 
167
proc MkMainStatus {top} {
168
    global demo
169
 
170
    set w [frame $top.f3 -relief raised -bd 1]
171
    set demo(statusbar) \
172
        [label $w.status -font -*-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*\
173
         -relief sunken -bd 1]
174
 
175
    tixForm $demo(statusbar) -padx 3 -pady 3 -left 0 -right %70
176
 
177
    return $w
178
}
179
 
180
proc MkWelcome {nb page} {
181
    set w [$nb subwidget $page]
182
 
183
    set bar  [MkWelcomeBar  $w]
184
    set text [MkWelcomeText $w]
185
 
186
    pack $bar  -side top -fill x -padx 2 -pady 2
187
    pack $text -side top -fill both -expand yes
188
}
189
 
190
proc MkWelcomeBar {top} {
191
    global demo
192
 
193
    set w [frame $top.bar -bd 2 -relief groove]
194
 
195
    # Create and configure comboBox 1
196
    #
197
    tixComboBox $w.cbx1 -command "MainTextFont $top" \
198
        -options {
199
            entry.width    15
200
            listbox.height 3
201
        }
202
    tixComboBox $w.cbx2 -command "MainTextFont $top" \
203
        -options {
204
            entry.width 4
205
            listbox.height 3
206
        }
207
    set demo(welfont) $w.cbx1
208
    set demo(welsize) $w.cbx2
209
 
210
    $w.cbx1 insert end "Courier"
211
    $w.cbx1 insert end "Helvetica"
212
    $w.cbx1 insert end "Lucida"
213
    $w.cbx1 insert end "Times Roman"
214
 
215
    $w.cbx2 insert end 8
216
    $w.cbx2 insert end 10
217
    $w.cbx2 insert end 12
218
    $w.cbx2 insert end 14
219
    $w.cbx2 insert end 18
220
 
221
    $w.cbx1 pick 1
222
    $w.cbx2 pick 3
223
 
224
    # Pack the comboboxes together
225
    #
226
    pack $w.cbx1 $w.cbx2 -side left -padx 4 -pady 4
227
 
228
    $demo(balloon) bind $w.cbx1\
229
        -msg "Choose\na font" -statusmsg "Choose a font for this page"
230
    $demo(balloon) bind $w.cbx2\
231
        -msg "Point size" -statusmsg "Choose the font size for this page"
232
 
233
 
234
    tixDoWhenIdle MainTextFont $top
235
    return $w
236
}
237
 
238
proc MkWelcomeText {top} {
239
    global demo tix_version
240
 
241
    set w [tixScrolledWindow $top.f3 -scrollbar auto]
242
    set win [$w subwidget window]
243
 
244
    label $win.title -font -*-times-bold-r-normal-*-18-*-*-*-*-*-*-*\
245
        -bd 0 -width 30 -anchor n\
246
        -text "Welcome to TIX version $tix_version"
247
 
248
    message $win.msg -font -*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*\
249
        -bd 0 -width 400 -anchor n\
250
        -text "\
251
Tix $tix_version is a library of mega-widgets based on TK. This program \
252
demonstrates the widgets in the Tix widget. You can choose the pages \
253
in this window to look at the corresponding widgets. \
254
To quit this program, choose the \"File | Exit\" command."
255
 
256
 
257
    pack $win.title -expand yes -fill both -padx 10 -pady 10
258
    pack $win.msg -expand yes -fill both -padx 10 -pady 10
259
    set demo(welmsg) $win.msg
260
    return $w
261
}
262
 
263
proc MainTextFont {w args} {
264
    global demo
265
 
266
    if {![info exists demo(welmsg)]} {
267
        return
268
    }
269
 
270
    set font  [$demo(welfont) cget -value]
271
    set point [$demo(welsize) cget -value]
272
 
273
    case $font {
274
        "Courier" {
275
            set f courier
276
        }
277
        "Helvetica" {
278
            set f helvetica
279
        }
280
        "Lucida" {
281
            set f lucida
282
        }
283
        default {
284
            set f times
285
        }
286
    }
287
 
288
    set xfont [format "-*-%s-bold-r-normal-*-%s-*-*-*-*-*-*-*" $f $point]
289
    if [catch {$demo(welmsg) config -font $xfont} err] {
290
        puts \a$err
291
    }
292
}
293
 
294
proc FileOpen {} {
295
    global demo demo_dir
296
    set filedlg [tix filedialog tixExFileSelectDialog]
297
    if {![info exists demo(filedialog)]} {
298
        $filedlg subwidget fsbox config -pattern *.tcl
299
        $filedlg subwidget fsbox config -directory $demo_dir/samples
300
        $filedlg config -command FileOpen:Doit
301
        set demo(filedialog) $filedlg
302
    }
303
    $filedlg config -title "Open Tix Sample Programs"
304
    $filedlg popup
305
    tixPushGrab $filedlg
306
}
307
 
308
proc FileOpen:Doit {filename} {
309
    global demo
310
 
311
    LoadFile $filename
312
    tixPopGrab
313
    $demo(filedialog) popdown
314
}
315
 
316
#----------------------------------------------------------------------
317
# Balloon Help
318
#----------------------------------------------------------------------
319
proc BalloonHelp {args} {
320
    global demo usebal
321
 
322
    if {$usebal} {
323
        $demo(balloon) config -state "both"
324
    } else {
325
        $demo(balloon) config -state "none"
326
    }
327
}
328
 
329
#----------------------------------------------------------------------
330
# Self-testing
331
#
332
#       The following code are called by the Tix test suite. It opens
333
#       every page in the demo program.
334
#----------------------------------------------------------------------
335
proc Widget:SelfTest {} {
336
    global demo testConfig
337
 
338
    if ![info exists testConfig] {
339
        return
340
    }
341
 
342
    MkMainWindow .widget
343
 
344
    update
345
    foreach p [$demo(notebook) pages] {
346
        $demo(notebook) raise $p
347
        update
348
    }
349
 
350
    destroy .widget
351
}
352
 
353
 
354
#----------------------------------------------------------------------
355
# Start!
356
#----------------------------------------------------------------------
357
if ![info exists testConfig] {
358
    #
359
    # If the testConfig variable exists, we are driven by the regression
360
    # test. In that case, don't open the main window. The test program will
361
    # call Widget:SelfTest
362
    #
363
    wm withdraw .
364
    MkMainWindow .widget
365
    bind .widget  "exit"
366
}
367
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.