source: tol/tolbase/lib/mkWidgets1.3/demos/metademo.tcl @ 32535cc

1941-docker-image-to-testdevel
Last change on this file since 32535cc was 32535cc, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

adding more types to config, added mkWidget1.3

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@16 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 17.7 KB
Line 
1#!/usr/local/bin/wish
2
3package require mkWidgets
4
5proc metaDemo { lWidgets } {
6  . config -minsize {320 200}
7
8  menu .menu -tearoff 0
9  menu .menu.file -tearoff 0
10  .menu.file add command -label About... -command aboutBox
11  .menu.file add separator
12  .menu.file add command -label Exit -command exit
13  menu .menu.view -tearoff 0
14  menu .menu.wind -tearoff 0
15  .menu.wind add command -label {Tile across}       -command {arrangeDocs tile}
16  .menu.wind add command -label {Tile horizontally} -command {arrangeDocs horizontally}
17  .menu.wind add command -label {Tile vertically}   -command {arrangeDocs vertically}
18  .menu.wind add command -label {Cascade}           -command {arrangeDocs cascade}
19  .menu.wind add separator
20  .menu.wind add command -label {Arrange icons}     -command {arrangeDocs icons}
21  .menu.wind add command -label {Minimize all}      -command {arrangeDocs minimize}
22  .menu add cascade -menu .menu.file -label File
23  .menu add cascade -menu .menu.view -label Metawidgets
24  .menu add cascade -menu .menu.wind -label Window
25  . config -menu .menu
26
27  pack [frame .work -bg gray50] -fill both -expand 1
28
29  tooltip   .ttip
30  toolbar   .tbar
31  statusbar .sbar
32
33  foreach sFile [glob ./images/*.gif] {
34    set sImage img[file rootname [file tail $sFile]]
35    image create photo $sImage -file $sFile
36  }
37
38  set iCount 0
39  foreach sWidget $lWidgets {
40    if { $sWidget == {} } {
41      .tbar add separator sep$iCount
42    } else {
43      set sToolb [.tbar add button tool$sWidget -image img$sWidget -command ".menu.view invoke $sWidget"]
44      .ttip add $sToolb $sWidget
45      .menu.view add command -label $sWidget -command test$sWidget
46      incr iCount
47    }
48  }
49
50  .sbar add statTime -image imgTinyclock
51  .sbar push "$iCount metawidgets loaded"
52  updateTime
53}
54
55proc updateTime {} {
56  .sbar itemconf statTime -text [clock format [clock seconds] -format {%H:%M:%S }]
57  after 1000 updateTime
58}
59
60proc aboutBox {} {
61  window .about -title {About mkWidgets Demo}
62
63  pack [label .about.icon -image imgLlama] -side left -padx 5
64  pack [label .about.txt1 -text {Metawidgets with mkWidgets 1.0}] -pady 5
65  pack [label .about.txt2 -text {http://ourworld.compuserve.com/homepages/mmg_kraus}]
66  pack [button .about.okay -text {  Close  } -command {destroy .about} -pady 0] -pady 5
67  grab .about
68}
69
70proc arrangeDocs { sHow } {
71  ::Document::Arrange $sHow
72}
73
74proc testToolbar {} {
75  if { ! [winfo exists .work.dtoo] } {
76    document .work.dtoo -title Toolbar -image imgToolbar -width 160 -height 220
77    .work.dtoo menu entryconf Close -command "destroy .work.dtoo"
78    .work.dtoo pack [frame .work.dtoo.test -border 0 -bg white] -fill both -expand 1
79
80    toolbar .work.dtoo.test.tbar
81    .work.dtoo.test.tbar add button b1 -image imgFile
82    .work.dtoo.test.tbar add button b2 -image imgFolder
83    .work.dtoo.test.tbar add separator s1
84    .work.dtoo.test.tbar add radiobutton r1 -group g1 -image imgLarge
85    .work.dtoo.test.tbar add radiobutton r2 -group g1 -image imgIconbox
86    .work.dtoo.test.tbar add radiobutton r3 -group g1 -image imgSmall
87    .work.dtoo.test.tbar add radiobutton r4 -group g1 -image imgList
88    .work.dtoo.test.tbar add separator s2
89    .work.dtoo.test.tbar add checkbutton c1 -image imgNodes
90    .work.dtoo.test.tbar add checkbutton c2 -image imgCompass
91
92    pack [label .work.dtoo.test.text -bg white -wrap 200 -text {This toolbar has buttons, radiobuttons and checkbuttons. Drag it to other sides!}]
93  } else {
94    .work.dtoo raise
95  }
96}
97
98proc testStatusbar {} {
99  if { ! [winfo exists .work.dsta] } {
100    document .work.dsta -title Statusbar -image imgStatusbar -width 160 -height 220
101    .work.dsta menu entryconf Close -command "destroy .work.dsta"
102    .work.dsta pack [frame .work.dsta.test -border 0] -fill both -expand 1
103
104    pack [button .work.dsta.test.anim -text Animate -command {
105      .work.dsta.test.tbar push {Loading something...}
106      for { set f 0 } { $f <= 1 } { set f [expr $f+.2] } {
107        .work.dsta.test.tbar config -progress $f
108        after 100
109      }
110      .work.dsta.test.tbar config -progress 0
111      .work.dsta.test.tbar pop
112    } -pady 0] -fill x
113
114    statusbar .work.dsta.test.tbar -text {Status Bar} -ticks 5
115    .work.dsta.test.tbar add field1 -text { Any text } -image imgNotebook
116  } else {
117    .work.dsta raise
118  }
119}
120
121proc testCalendar {} {
122  if { ! [winfo exists .work.dcal] } {
123    document .work.dcal -title Calendar -image imgCalendar -width 160 -height 220
124    .work.dcal menu entryconf Close -command "destroy .work.dcal"
125    .work.dcal pack [label .work.dcal.txt1 -text "Use the cursor keys or\nthe arrow symbols"]
126    .work.dcal pack [calendar .work.dcal.cale]
127    .work.dcal pack [label .work.dcal.txt2 -text "Double-click on the date\nto set today's date"]
128  } else {
129    .work.dcal raise
130  }
131}
132
133proc testAclock {} {
134  if { ! [winfo exists .work.dclk] } {
135    document .work.dclk -title Clock -image imgAclock -width 160 -height 220
136    .work.dclk menu entryconf Close -command "destroy .work.dclk"
137    .work.dclk pack [label .work.dclk.txt1 -text "Drag the pointers or\nuse the cursor keys"]
138    .work.dclk pack [label .work.dclk.txt2 -text "Double-click on the time to\nset the actual time"] -side bottom
139    .work.dclk pack [aclock .work.dclk.clck] -fill both -expand 1
140  } else {
141    .work.dclk raise
142  }
143}
144
145proc testCombobox {} {
146  if { ! [winfo exists .work.dcbx] } {
147    document .work.dcbx -title Combobox -image imgCombobox -width 160 -height 150
148    .work.dcbx menu entryconf Close -command "destroy .work.dcbx"
149    .work.dcbx pack [label .work.dcbx.txt1 -text "Below is a combobox:"]
150    .work.dcbx pack [combobox .work.dcbx.cbx1 -entries {{Select a value} {from the list.} {Or just key in} {something else.}}]
151    .work.dcbx pack [label .work.dcbx.txt2 -text "This one is restricted:"]
152    .work.dcbx pack [combobox .work.dcbx.cbx2 -entries {{Select a value} {from the list.} {But you cannot} {enter anything.}} -state restricted]
153    .work.dcbx pack [label .work.dcbx.txt3 -text "Cursor keys work, too.\nUse 'Esc' to get out."]
154  } else {
155    .work.dcbx raise
156  }
157}
158
159proc testDocument {} {
160  if { ! [winfo exists .work.ddoc] } {
161    document .work.ddoc -title {Document Windows} -image imgDocument -width 250 -height 100
162    .work.ddoc menu entryconf Close -command "destroy .work.ddoc"
163    .work.ddoc pack [label .work.ddoc.txt1 -text "This and all the others are document windows\nAnything can be placed inside them.  " -border 1 -relief sunken -bg yellow] -fill both -expand 1
164  } else {
165    .work.ddoc raise
166  }
167}
168
169proc testPane {} {
170  if { ! [winfo exists .work.dpan] } {
171    document .work.dpan -title {Paned Windows} -image imgPane -width 160 -height 220
172    .work.dpan menu entryconf Close -command "destroy .work.dpan"
173    .work.dpan pack [frame .work.dpan.frm0 -border 0] -fill both -expand 1
174    pack [label .work.dpan.frm0.txt1 -text "This one resizes proportionally:"]
175    pack [pane  .work.dpan.frm0.pan1 -width 3 -resize both] -fill both -expand 1
176    .work.dpan.frm0.pan1 pack first  [text  .work.dpan.frm0.frm1 -border 1 -relief sunken -bg white -wrap word] -fill both -expand 1
177    .work.dpan.frm0.pan1 pack second [frame .work.dpan.frm0.frm2 -border 1 -relief sunken -bg white] -fill both -expand 1
178    .work.dpan.frm0.frm1 insert end "Use the mouse to drag the panes. Also, resize the window."
179
180    pack [label .work.dpan.frm0.txt2 -text "The left window does not resize:"]
181    pack [pane  .work.dpan.frm0.pan2 -width 3 -resize second] -fill both -expand 1
182    .work.dpan.frm0.pan2 pack first  [frame .work.dpan.frm0.frm3 -border 1 -relief sunken -bg white] -fill both -expand 1
183    .work.dpan.frm0.pan2 pack second [frame .work.dpan.frm0.frm4 -border 1 -relief sunken -bg white] -fill both -expand 1
184  } else {
185    .work.dpan raise
186  }
187}
188
189proc testProgressbar {} {
190  if { ! [winfo exists .work.dpro] } {
191    document .work.dpro -title {Progress Bar} -image imgProgressbar -width 160 -height 120
192    .work.dpro menu entryconf Close -command "destroy .work.dpro"
193    .work.dpro pack [label .work.dpro.txt1 -text "Press the button below."]
194    .work.dpro pack [progressbar .work.dpro.prog -width 120 -height 22] -padx 15 -pady 5
195    .work.dpro pack [button .work.dpro.anim -text Animate -command {
196      for { set i 0 } { $i <= 100 } { incr i 5 } {
197        .work.dpro.prog set $i
198        after 100
199      }
200      .work.dpro.prog set 0
201    } -pady 0] -fill x
202  } else {
203    .work.dpro raise
204  }
205}
206
207proc testScrollbox {} {
208  if { ! [winfo exists .work.dsbx] } {
209    document .work.dsbx -title {Scrollbox} -image imgScrollbox -width 160 -height 220
210    .work.dsbx menu entryconf Close -command "destroy .work.dsbx"
211    .work.dsbx pack [label .work.dsbx.txt1 -text "A scrollbox is a listbox\nwith automatic scrollbars"]
212    .work.dsbx pack [scrollbox .work.dsbx.sbox] -fill both -expand 1
213    .work.dsbx.sbox insert end {Here is some text.} {There's some more.} "It is [clock format [clock seconds]]" \
214                               {Current directory:} "[glob ./*]"
215    .work.dsbx.sbox config -scrollbar auto
216  } else {
217    .work.dsbx raise
218  }
219}
220
221proc testTabcontrol {} {
222  if { ! [winfo exists .work.dtab] } {
223    document .work.dtab -title {Tab Control} -image imgTabcontrol -width 220 -height 160
224    .work.dtab menu entryconf Close -command "destroy .work.dtab"
225    .work.dtab pack [label .work.dtab.txt1 -text "These tabs look quite nice:"]
226    .work.dtab pack [tabcontrol .work.dtab.tabc -width auto] -fill both -expand 1 -padx 10 -pady 10
227
228    label .work.dtab.tabc.gnrl -bg white -border 1 -relief sunken -text "Tabs can be dynamically\ncreated and deleted."
229    label .work.dtab.tabc.size -bg white -border 1 -relief sunken -text "Tabs can have a constant size\nor resize with their parent widget."
230    label .work.dtab.tabc.rows -bg white -border 1 -relief sunken -text "A tab control can have\nmore than one row of tabs."
231    .work.dtab.tabc insert general 0 -text " General " -window .work.dtab.tabc.gnrl
232    .work.dtab.tabc insert edit    0 -text " Size "    -window .work.dtab.tabc.size
233    .work.dtab.tabc insert find    0 -text " Rows "    -window .work.dtab.tabc.rows
234    .work.dtab.tabc invoke general
235  } else {
236    .work.dtab raise
237  }
238}
239
240proc testTextframe {} {
241  if { ! [winfo exists .work.dtfr] } {
242    document .work.dtfr -title {Text Frame} -image imgTextframe -width 180 -height 140
243    .work.dtfr menu entryconf Close -command "destroy .work.dtfr"
244    .work.dtfr pack [label .work.dtfr.txt1 -text "A frame with some text:"]
245    .work.dtfr pack [textframe .work.dtfr.tfrm -text " Language "]
246
247    foreach sLang {English German Spanish French} iCol {0 0 1 1} iRow {0 1 0 1} {
248      radiobutton .work.dtfr.tfrm.l$sLang -value $sLang -border 0 -text $sLang
249      .work.dtfr.tfrm grid .work.dtfr.tfrm.l$sLang -col $iCol -row $iRow -sticky w
250    }
251    .work.dtfr.tfrm.lEnglish invoke
252  } else {
253    .work.dtfr raise
254  }
255}
256
257proc testTooltip {} {
258  if { ! [winfo exists .work.dtip] } {
259    document .work.dtip -title Tooltip -image imgTooltip -width 125 -height 115
260    .work.dtip menu entryconf Close -command "destroy .work.dtip"
261    .work.dtip pack [label .work.dtip.txt1 -text "Move the mouse over\nthe sqares and wait"] -fill x
262    .work.dtip pack [label .work.dtip.txt2 -text "Tooltips are also\nactive in the toolbar"] -side bottom -fill x
263
264    tooltip .work.dtip.ttip -delay 500
265    foreach sColor {red green blue yellow black white} {
266      frame .work.dtip.r$sColor -bg $sColor
267      .work.dtip pack .work.dtip.r$sColor -side left -fill both -expand 1
268      .work.dtip.ttip add .work.dtip.r$sColor "A $sColor rectangle"
269    }
270  } else {
271    .work.dtip raise
272  }
273}
274
275proc testGridcontrol {} {
276  if { ! [winfo exists .work.dgri] } {
277    document .work.dgri -title Gridcontrol -image imgGridcontrol -width 125 -height 115
278    .work.dgri menu entryconf Close -command "destroy .work.dgri"
279    .work.dgri pack [gridcontrol .work.dgri.grid -font {Courier 12}] -fill both -expand 1
280
281    .work.dgri.grid column insert Col1 end -text Word   -width 60
282    .work.dgri.grid column insert Col2 end -text Number -width 60 -align right
283    .work.dgri.grid column insert Col3 end -text Read!  -width 60 -align center
284
285    set i 0
286    foreach sWord {The quick brown fox jumps over the lazy dog} \
287            sRead {Resize the column and see some nice text clipping!} {
288      incr i
289      .work.dgri.grid insert end [list $sWord $i $sRead]
290    }
291
292    .work.dgri.grid tag add tYellow Col3.*
293    .work.dgri.grid tag config tYellow -background yellow
294  } else {
295    .work.dgri raise
296  }
297}
298
299proc testListcontrol {} {
300  if { ! [winfo exists .work.dlis] } {
301    document .work.dlis -title Listcontrol -image imgListcontrol -width 125 -height 115
302    .work.dlis menu entryconf Close -command "destroy .work.dlis"
303    .work.dlis pack [listcontrol .work.dlis.list] -fill both -expand 1
304
305    .work.dlis.list column insert Col1 end -text Icon  -width 120
306    .work.dlis.list column insert Col2 end -text Size  -width 60
307    .work.dlis.list column insert Col3 end -text Type  -width 60
308
309    set iRow 1
310    foreach sImage [image names] \
311            sRead {Drag the column and see some nice text clipping!} {
312      if { [image width $sImage] != 16 } continue
313
314      set sSize [image width $sImage]x[image height $sImage]
315      set sType [image type $sImage]
316
317      .work.dlis.list insert end [list " $sImage" $sSize $sType]
318      .work.dlis.list image create Col1.$iRow -image $sImage
319      incr iRow
320    }
321  } else {
322    .work.dlis raise
323  }
324}
325
326proc testIconbox {} {
327  if { ! [winfo exists .work.dibo] } {
328    document .work.dibo -title Iconbox -image imgIconbox -width 125 -height 115
329    .work.dibo menu entryconf Close -command "destroy .work.dibo"
330
331    .work.dibo pack [frame .work.dibo.view -border 0] -side top -anchor w
332    pack [button .work.dibo.view.lrge -image imgLarge -command {.work.dibo.ibox config -view large}] -side left
333    pack [button .work.dibo.view.smll -image imgSmall -command {.work.dibo.ibox config -view small}] -side left
334    pack [button .work.dibo.view.list -image imgList  -command {.work.dibo.ibox config -view list}] -side left
335    .work.dibo pack [iconbox .work.dibo.ibox -columns {Object {Description l 200}}] -fill both -expand 1
336
337    .work.dibo.ibox insert end object1 -text "A Folder"   -image imgFolder32 -smallimage imgFolder -values {{These objects here are hard coded}}
338    .work.dibo.ibox insert end object2 -text "Another Folder" -image imgFolder32 -smallimage imgFolder -values {{... and don't have any real meaning}}
339    .work.dibo.ibox insert end object3 -text "File ABC"  -image imgFile32 -smallimage imgFile -values {{This could represent a file.}}
340    .work.dibo.ibox insert end object4 -text "Compass"   -image imgCompass32 -smallimage imgCompass -values {{No fancy icons, no user acceptance...}}
341    .work.dibo.ibox insert end object5 -text "Text File" -image imgNotebook32 -smallimage imgNotebook -values {{Icons can have individual bindings}}
342
343    .work.dibo.ibox selection set object1
344  } else {
345    .work.dibo raise
346  }
347}
348
349proc testTreecontrol {} {
350  global lWidgets
351
352  if { ! [winfo exists .work.dtre] } {
353    document .work.dtre -title Treecontrol -image imgTreecontrol -width 125 -height 115
354    .work.dtre menu entryconf Close -command "destroy .work.dtre"
355    .work.dtre pack [treecontrol .work.dtre.tree -text {A Static Tree} -image imgNodes] -fill both -expand 1
356
357    .work.dtre.tree insert framework -text Framework      -image imgFolder
358    .work.dtre.tree insert metawids  -text Metawidgets    -image imgFolder      -parent framework
359    .work.dtre.tree insert toolbars  -text Toolbars       -image imgFolder      -parent framework
360    .work.dtre.tree insert toolbar1  -text CommonElements -image imgToolbar     -parent toolbars
361    .work.dtre.tree insert toolbar2  -text DrawingTools   -image imgToolbar     -parent toolbars
362    .work.dtre.tree insert statusbar -text Statusbar      -image imgStatusbar   -parent framework
363
364    .work.dtre.tree insert dialogs   -text Dialogs        -image imgFolder
365    .work.dtre.tree insert dialog1   -text Preferences    -image imgTabcontrol  -parent dialogs
366    .work.dtre.tree insert dialog2   -text DatabaseQuery  -image imgCompass     -parent dialogs
367    .work.dtre.tree insert dialog3   -text WhateverElse   -image imgNotebook    -parent dialogs
368
369    .work.dtre.tree insert windows   -text Windows        -image imgFolder
370    .work.dtre.tree insert window1   -text Spreadsheet    -image imgGridcontrol -parent windows
371    .work.dtre.tree insert window2   -text Treeview       -image imgTreecontrol -parent windows
372    .work.dtre.tree insert window3   -text ObjectBrowser  -image imgListcontrol -parent windows
373
374    foreach sWidget $lWidgets {
375      if { $sWidget == {} } continue
376      .work.dtre.tree insert mw$sWidget -text $sWidget -image img$sWidget -parent metawids
377    }
378  } else {
379    .work.dtre raise
380  }
381}
382
383proc testIbutton {} {
384  if { ! [winfo exists .work.dibu] } {
385    document .work.dibu -title {Iconic Button} -image imgIbutton -width 200 -height 120
386    .work.dibu menu entryconf Close -command "destroy .work.dibu"
387    .work.dibu pack [label .work.dibu.txt1 -text "Ibuttons are buttons with an image"] -fill x
388    .work.dibu pack [ibutton .work.dibu.ibut1 -image imgFolder -text "Create a folder..."] -fill x
389    .work.dibu pack [ibutton .work.dibu.ibut2 -image imgNotebook -text "Make a note..."] -fill x
390  } else {
391    .work.dibu raise
392  }
393}
394
395proc testSpinentry {} {
396  if { ! [winfo exists .work.dspi] } {
397    document .work.dspi -title {Spinentry} -image imgSpinentry -width 100 -height 100
398    .work.dspi menu entryconf Close -command "destroy .work.dspi"
399    .work.dspi pack [label .work.dspi.txt1 -text "A spinentry is almost\nlike an entry"] -fill x
400    .work.dspi pack [spinentry .work.dspi.spi1 -value 123] -fill x
401    .work.dspi pack [spinentry .work.dspi.spi2 -value 0 -minimum -10 -maximum 10 -step .2] -fill x
402  } else {
403    .work.dspi raise
404  }
405}
406
407set lWidgets {Textframe Ibutton Scrollbox Combobox Spinentry Tabcontrol Pane {} \
408              Document Toolbar Statusbar Tooltip {} \
409              Gridcontrol Listcontrol Iconbox Treecontrol {} \
410              Progressbar Calendar Aclock}
411
412metaDemo $lWidgets
413
Note: See TracBrowser for help on using the repository browser.