source: tol/tolbase/lib/mkWidgets1.3/Textframe.tcl

devel
Last change on this file 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: 3.5 KB
Line 
1package require Metawidget
2
3# name: Textframe
4# args: args: option-value pairs
5# creates the widget elements and initializes the metawidget options.
6metawidget create Textframe {
7  frame $this.deco -border 2 -relief groove
8  label $this.text -border 0 -padx 0 -pady 0 -text Headline
9  frame $this.work
10
11  -text $this
12  -offset 12
13  -anchor w
14  -font [$this.text cget -font]
15} {} -default deco
16
17# name: -anchor
18# args: sAnchor: anchor (n, e, s, w, c) for the label
19# option member. sets a new anchor for the label widget.
20metawidget proc Textframe -anchor { sAnchor } {
21  place $this.text -in $this.deco -anchor $sAnchor
22  my -anchor $sAnchor
23}
24
25# name: -offset
26# args: sOffset: offset value for the label.
27# option member. sets a new offset value for the label widget. three different
28# formats: E.g. 20% sets the label 20% of the frame's width off from the left.
29# 20 sets the label 20 pixel from the left border (good with -anchor w).
30# end-20 sets it from the frame's right border (good with -anchor e).
31metawidget proc Textframe -offset { sOffset } {
32  if { [regexp {^([0-9]+)%$} $sOffset sDummy fPct] } {
33    set iX 0;
34    set fRelx [expr $iPct/100.]
35  } elseif { [regexp {^[0-9]+$} $sOffset iX] } {
36    set fRelx 0
37  } elseif { [regexp {^end(-[0-9]+)$} $sOffset sDummy iX] } {
38    set fRelx 1
39  } else {
40    error "Bad offset $sOffset. Must be an integer, end-integer or integer%"
41  }
42
43  place $this.text -in $this.deco -x $iX -relx $fRelx
44  my -offset $sOffset
45}
46
47# name: -font
48# args: sFont: font to set
49# a change in the font size requires a new padding for the decorative frame
50# and the work area, so that the text is fully visible and not overlapped.
51metawidget proc Textframe -font { sFont } {
52  $this.text configure -font $sFont
53
54  set iPad [expr [font metrics $sFont -linespace]/2+1]
55  pack $this.deco -fill both -expand 1 -padx 2 -pady $iPad
56  pack $this.work -fill both -expand 1 -padx 2 -pady $iPad -in $this.deco
57
58  my -font $sFont
59}
60
61# name: -text
62# args: sText: text to set
63# option member. sets a new text to the textframe
64metawidget proc Textframe -text { sText } {
65  $this.text config -text $sText
66  my -text $sText
67}
68
69# name: pack
70# args: sWindow: widget to pack
71#       args: option-value pairs
72# packs widgets inside the work area.
73metawidget proc Textframe pack_ { sWindow args } {
74  eval pack $sWindow -in $this.work $args
75}
76
77# name: grid
78# args: sWindow: widget to grid
79#       args: option-value pairs
80# grids widgets inside the work area.
81metawidget proc Textframe grid_ { sWindow args } {
82  if { [string index $sWindow 0] == "." } {
83    eval grid $sWindow -in $this.work $args
84  } else {
85    eval grid $sWindow $this.work $args
86  }
87}
88
89# name: place
90# args: sWindow: widget to place
91#       args: option-value pairs
92# places widgets inside the work area.
93metawidget proc Textframe place_ { sWindow args } {
94  eval place $sWindow -in $this.work $args
95}
96
97metawidget option  Textframe -anchor -anchor
98metawidget option  Textframe -offset -offset
99metawidget option  Textframe -font   -font
100metawidget option  Textframe -text   -text
101
102metawidget command Textframe pack    pack_
103metawidget command Textframe grid    grid_
104metawidget command Textframe place   place_
105
106proc test {} {
107  pack [textframe .tfrm -text " Change Font "] -fill both -expand 1
108
109  checkbutton .c1 -text "Alternative Font"  -command {.tfrm config -font $c1} -on {Courier 15 bold} -off {Helv 9}
110  checkbutton .c2 -text "Alternative Frame" -command {.tfrm config -relief $c2} -on solid -off groove
111
112  .tfrm pack .c1 -side top -anchor w
113  .tfrm pack .c2 -side top -anchor w
114}
115
116#test
Note: See TracBrowser for help on using the repository browser.