From 0c518c95e4d1c3270fbc67143a6351ee81bb68f0 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Fri, 7 May 2004 10:51:56 +0000 Subject: Switched from pack to grid; Demos are put in a namespace --- demos/labelformat.tcl | 126 +++++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 62 deletions(-) (limited to 'demos/labelformat.tcl') diff --git a/demos/labelformat.tcl b/demos/labelformat.tcl index d7c0781..2a18854 100644 --- a/demos/labelformat.tcl +++ b/demos/labelformat.tcl @@ -5,80 +5,82 @@ if {![info exists zincDemo]} { error "This script should be run from the zinc-widget demo." } -set w .labelformat -catch {destroy $w} -toplevel $w -wm title $w "Zinc Label Format Demonstration" -wm iconname $w Label - -set defaultfont [font create -family Helvetica -size 10 -weight bold] - -frame $w.buttons -pack $w.buttons -side bottom -fill x -pady 2m -button $w.buttons.dismiss -text Dismiss -command "destroy $w" -button $w.buttons.code -text "See Code" -command "showCode $w" -pack $w.buttons.dismiss $w.buttons.code -side left -expand 1 - -########################################### -# Text zone -########################################### - -text $w.text -relief sunken -borderwidth 2 -height 4 -pack $w.text -expand yes -fill both - -$w.text insert end {This scipt demonstrates the use of labelformat for tabular items. -The fieldPos (please, refer to the labelformat type description -in the Zinc reference manual) of each field as described in -the labelformat is displayed inside the field.} - - -########################################### -# Zinc -########################################## -zinc $w.zinc -width 600 -height 500 -font 10x20 -borderwidth 3 -relief sunken -pack $w.zinc - -### this function displays in each field, the corresponding -### part of the labelformat -proc setLabelContent {item labelformat} { - global w - set i 0 - foreach fieldSpec $labelformat { - set posSpec $i - regexp {^.\d+.\d+(.*)} $fieldSpec "" posSpec - $w.zinc itemconfigure $item $i -text "$i: $posSpec" -border "contour" - incr i +namespace eval labelFormat { + variable w .labelformat + catch {destroy $w} + toplevel $w + wm title $w "Zinc Label Format Demonstration" + wm iconname $w Label + + variable defaultfont [font create -family Helvetica -size 10 -weight bold] + + grid [button $w.dismiss -text Dismiss -command "destroy $w"] -row 2 -column 0 -pady 10 + grid [button $w.code -text "See Code" -command "showCode $w"] -row 2 -column 1 -pady 10 + + ########################################### + # Text zone + ########################################### + + grid [text $w.text -relief sunken -borderwidth 2 -height 4] \ + -row 0 -column 0 -columnspan 2 -sticky ew + + $w.text insert end {This scipt demonstrates the use of labelformat for tabular items. + The fieldPos (please, refer to the labelformat type description + in the Zinc reference manual) of each field as described in + the labelformat is displayed inside the field.} + + + ########################################### + # Zinc + ########################################## + grid [zinc $w.zinc -width 600 -height 500 -font 10x20 -borderwidth 3 \ + -relief sunken] -row 1 -column 0 -columnspan 2 -sticky news + grid columnconfigure $w 0 -weight 1 + grid columnconfigure $w 1 -weight 1 + grid rowconfigure $w 1 -weight 2 + + ### this function displays in each field, the corresponding + ### part of the labelformat + proc setLabelContent {item labelformat} { + variable w + set i 0 + foreach fieldSpec $labelformat { + set posSpec $i + regexp {^.\d+.\d+(.*)} $fieldSpec "" posSpec + $w.zinc itemconfigure $item $i -text "$i: $posSpec" -border "contour" + incr i + } } -} -########################################### -# Tabulars -########################################### + ########################################### + # Tabulars + ########################################### -### first labelformat and tabular -set labelformat1 {x100x20+0+0 x100x20+100+0 x100x20+0+20 x100x20+100+20 x100x20+50+55} + ### first labelformat and tabular + variable labelformat1 {x100x20+0+0 x100x20+100+0 x100x20+0+20 x100x20+100+20 x100x20+50+55} -set tabular1 [$w.zinc add tabular 1 5 -position {10 10} -labelformat $labelformat1] + variable tabular1 [$w.zinc add tabular 1 5 -position {10 10} -labelformat $labelformat1] -setLabelContent $tabular1 $labelformat1 + setLabelContent $tabular1 $labelformat1 -$w.zinc add text 1 -position {10 100} -text "All fields positions\nare given in pixels" + $w.zinc add text 1 -position {10 100} -text "All fields positions\nare given in pixels" -### second labelformat and tabular -set labelformat2 {x110x20+100+30 x80x20<0<0 x80x20<0>0 x80x20>0>0 x80x20>0<0} + ### second labelformat and tabular + variable labelformat2 {x110x20+100+30 x80x20<0<0 x80x20<0>0 x80x20>0>0 x80x20>0<0} -set tabular2 [$w.zinc add tabular 1 5 -position {270 10} -labelformat $labelformat2] -setLabelContent $tabular2 $labelformat2 + variable tabular2 [$w.zinc add tabular 1 5 -position {270 10} -labelformat $labelformat2] + setLabelContent $tabular2 $labelformat2 -$w.zinc add text 1 -position {260 100} -text "All fields positions are given\nrelatively to field 0.\nThey are either on the left/right\nand up/down the field 0." + $w.zinc add text 1 -position {260 100} -text "All fields positions are given\nrelatively to field 0.\nThey are either on the left/right\nand up/down the field 0." -### third labelformat and tabular -set labelformat3 {x200x70+100+70 x80x26^0<0 x80x26^0>0 x80x29$0$0 x80x32$0^0 x90x20<1^1 x90x20<2$2 x90x20^4<4 x90x20^3>3} + ### third labelformat and tabular + variable labelformat3 {x200x70+100+70 x80x26^0<0 x80x26^0>0 x80x29$0$0 x80x32$0^0 x90x20<1^1 x90x20<2$2 x90x20^4<4 x90x20^3>3} -set tabular3 [$w.zinc add tabular 1 9 -position {150 180} -labelformat $labelformat3] + variable tabular3 [$w.zinc add tabular 1 9 -position {150 180} -labelformat $labelformat3] -setLabelContent $tabular3 $labelformat3 + setLabelContent $tabular3 $labelformat3 -$w.zinc add text 1 -position {40 360} -text "Fields 1-4 are positionned relatively to field 0.\nField 5 is positionned relatively to field 1\nField 6 is positionned relatively to field 2..." + $w.zinc add text 1 -position {40 360} -text "Fields 1-4 are positionned relatively to field 0.\nField 5 is positionned relatively to field 1\nField 6 is positionned relatively to field 2..." +} -- cgit v1.1