| 1 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | # FILE : bfont.tcl |
|---|
| 3 | # PURPOSE : Bayes Font selector is a widget that provides an interface |
|---|
| 4 | # to select an available font. |
|---|
| 5 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 6 | |
|---|
| 7 | package require byscommon |
|---|
| 8 | package require snit |
|---|
| 9 | package require BWidget |
|---|
| 10 | |
|---|
| 11 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 12 | ::snit::widget bfont { |
|---|
| 13 | # |
|---|
| 14 | # Specific options: |
|---|
| 15 | # -showlabel-> shows a label next to the button |
|---|
| 16 | # -variable-> the font |
|---|
| 17 | # -label-> text for the label |
|---|
| 18 | # |
|---|
| 19 | # variables: |
|---|
| 20 | # widget-> widgets path |
|---|
| 21 | # data-> widgets data |
|---|
| 22 | # created-> created flag |
|---|
| 23 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 24 | widgetclass Bfont |
|---|
| 25 | |
|---|
| 26 | option -variable {} |
|---|
| 27 | option -showlabel 0 |
|---|
| 28 | option -label "" |
|---|
| 29 | |
|---|
| 30 | variable widget |
|---|
| 31 | variable data |
|---|
| 32 | variable created |
|---|
| 33 | |
|---|
| 34 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 35 | constructor {args} { |
|---|
| 36 | # |
|---|
| 37 | # PURPOSE: bfont constructor. An instance of bfont is created. |
|---|
| 38 | # |
|---|
| 39 | # PARAMETERS: |
|---|
| 40 | # args -> options |
|---|
| 41 | # |
|---|
| 42 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 43 | set created 0 |
|---|
| 44 | #Label |
|---|
| 45 | set widget(label) [label $self.lb -text [$self cget -label]] |
|---|
| 46 | #Button |
|---|
| 47 | install font using Button $self.bt -image [::Bitmap::get font] \ |
|---|
| 48 | -command [list $self _FontChange] |
|---|
| 49 | |
|---|
| 50 | set data(tracecmd) [list $self _FontUpdate] |
|---|
| 51 | |
|---|
| 52 | $self configure -variable [from args -variable ""] |
|---|
| 53 | |
|---|
| 54 | $self createwidget |
|---|
| 55 | |
|---|
| 56 | $self configure -showlabel [from args -showlabel ""] |
|---|
| 57 | $self configure -label [from args -label ""] |
|---|
| 58 | |
|---|
| 59 | $self configurelist $args |
|---|
| 60 | |
|---|
| 61 | # The widget is created |
|---|
| 62 | set created 1 |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 66 | # |
|---|
| 67 | # PURPOSE: Methods cget & configure |
|---|
| 68 | # |
|---|
| 69 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 70 | onconfigure -showlabel { lst } { |
|---|
| 71 | set options(-showlabel) $lst |
|---|
| 72 | if {$lst == 0} { |
|---|
| 73 | grid remove $widget(label) |
|---|
| 74 | } else { |
|---|
| 75 | grid $widget(label) |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | onconfigure -variable { var } { |
|---|
| 80 | set options(-variable) $var |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | onconfigure -label { lst } { |
|---|
| 84 | $widget(label) configure -text $lst |
|---|
| 85 | set options(-label) $lst |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 89 | method createwidget { } { |
|---|
| 90 | # |
|---|
| 91 | # PURPOSE: The widget is created and packed |
|---|
| 92 | # |
|---|
| 93 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 94 | grid $widget(label) $font |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 98 | method _FontChange { } { |
|---|
| 99 | # |
|---|
| 100 | # PURPOSE: Changes the font when OK button is pressed. If CANCEL is pressed |
|---|
| 101 | # leaves the previous font. |
|---|
| 102 | # |
|---|
| 103 | #//////////////////////////////////////////////// /////////////////////////// |
|---|
| 104 | eval set fon $[$self cget -variable] |
|---|
| 105 | set newfont [SelectFont .sf -parent $self \ |
|---|
| 106 | -title [mc "Font selection"] \ |
|---|
| 107 | -sampletext [mc "Sample text"] \ |
|---|
| 108 | -font $fon] |
|---|
| 109 | |
|---|
| 110 | if { $newfont != "" } { |
|---|
| 111 | set [$self cget -variable] $newfont |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | # delegation of methods and options |
|---|
| 116 | delegate method * to font |
|---|
| 117 | delegate option * to font |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | package provide bfont 1.0 |
|---|
| 121 | |
|---|
| 122 | # ------- TEST CODE ---- |
|---|
| 123 | |
|---|
| 124 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 125 | proc test_bfont {} { |
|---|
| 126 | # |
|---|
| 127 | # PURPOSE: Test function bfont |
|---|
| 128 | # |
|---|
| 129 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 130 | destroy .top |
|---|
| 131 | toplevel .top |
|---|
| 132 | global mifont |
|---|
| 133 | set mifont {lucida 9 bold} |
|---|
| 134 | |
|---|
| 135 | set bfont [bfont .top.font -variable ::mifont -showlabel 1 -label [mc Font]:] |
|---|
| 136 | |
|---|
| 137 | pack $bfont |
|---|
| 138 | } |
|---|