home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / lib / combobox-2.3 / example.tcl < prev    next >
Encoding:
Text File  |  2003-09-30  |  5.3 KB  |  164 lines

  1. # A simple font display utility.
  2. # This program uses two variations of the combobox. One, for the font
  3. # family, is non-editable (ie: the user can only pick from the list). 
  4. # The other, for font size, is editable. The user can pick from the list 
  5. # or enter their own size
  6.  
  7. # substitute your favorite method here...
  8. source combobox.tcl
  9. package require combobox 2.3
  10. catch {namespace import combobox::*}
  11.  
  12. proc main {} {
  13.     # this lets us be reentrant...
  14.     destroy .fontpicker .msg
  15.  
  16.     # default values
  17.     set ::size       12
  18.     set ::family     [lindex [lsort [font families]] 0]
  19.     set ::slant      roman
  20.     set ::weight     normal
  21.     set ::overstrike 0
  22.     set ::underline  0
  23.  
  24.     wm title . "Combobox Example"
  25.  
  26.     # the main two areas: a frame to hold the font picker widgets
  27.     # and a label to display a sample from the font
  28.     set fp [frame .fontpicker]
  29.     set msg [label .msg -borderwidth 2 -relief groove -width 30 -height 4]
  30.  
  31.     pack $fp -side top -fill x
  32.     pack $msg -side top -fill both -expand y -pady 2
  33.  
  34.     $msg configure -text [join [list \
  35.         "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
  36.         "abcdefghijklmnopqrstuvwxyz" \
  37.         "0123456789~`!@#$%^&*()_-+=" \
  38.         "{}[]:;\"'<>,.?/"] "\n"]
  39.  
  40.     # this will set the font of the message according to our defaults
  41.     changeFont $msg
  42.  
  43.     # font family...
  44.     label $fp.famLabel -text "Font Family:"
  45.     combobox $fp.famCombo \
  46.         -borderwidth 1 \
  47.         -textvariable family \
  48.         -editable false \
  49.         -highlightthickness 1 \
  50.         -command [list changeFont $msg]
  51.  
  52.  
  53.     grid $fp.famLabel -row 0 -column 0 -sticky e
  54.     grid $fp.famCombo -row 0 -column 1 -sticky ew
  55.     grid columnconfigure $fp 1 -weight 1
  56.  
  57.     # we'll do these one at a time so we can find the widest one and
  58.     # set the width of the combobox accordingly (hmmm... wonder if this
  59.     # sort of thing should be done by the combobox itself...?)
  60.     set widest 0
  61.     foreach family [lsort [font families]] {
  62.     if {[set length [string length $family]] > $widest} {
  63.         set widest $length
  64.     }
  65.     $fp.famCombo list insert end $family
  66.     }
  67.     $fp.famCombo configure -width $widest
  68.  
  69.     # the font size. We know we are puting a fairly small, finite
  70.     # number of items in this combobox, so we'll set its maxheight
  71.     # to zero so it will grow to fit the number of items
  72.     label $fp.sizeLabel -text "Font Size:"
  73.     combobox $fp.sizeCombo \
  74.         -borderwidth 1 \
  75.         -highlightthickness 1 \
  76.         -maxheight 0 \
  77.         -width 3 \
  78.         -textvariable size \
  79.         -editable true \
  80.         -command [list changeFont $msg]
  81.  
  82.     grid $fp.sizeLabel -row 0 -column 2 -sticky e -padx 2
  83.     grid $fp.sizeCombo -row 0 -column 3 -sticky new 
  84.     grid columnconfigure $fp 3 -weight 1
  85.     eval $fp.sizeCombo list insert end [list 8 9 10 12 14 16 18 20 24 28 32 36]
  86.  
  87.     # a dummy frame to give a little spacing...
  88.     frame $fp.dummy -width 5
  89.     grid $fp.dummy -row 0 -column 4 
  90.  
  91.     # bold
  92.     set bold "bold"
  93.     checkbutton $fp.bold -variable weight -indicatoron false \
  94.         -onvalue bold -offvalue normal \
  95.         -text "B" -width 2 -height 1 \
  96.         -font {-weight bold -family Times -size 12} \
  97.         -highlightthickness 1 -padx 0 -pady 0 -borderwidth 1 \
  98.         -command [list changeFont $msg]
  99.     grid $fp.bold -row 0 -column 5 -sticky nsew
  100.  
  101.     # underline
  102.     checkbutton $fp.underline -variable underline -indicatoron false \
  103.         -onvalue 1 -offvalue 0 \
  104.         -text "U" -width 2 -height 1 \
  105.         -font {-underline 1 -family Times -size 12} \
  106.         -highlightthickness 1 -padx 0 -pady 0 -borderwidth 1 \
  107.         -command [list changeFont $msg]
  108.     grid $fp.underline -row 0 -column 6 -sticky nsew
  109.  
  110.     # italic
  111.     checkbutton $fp.italic -variable slant -indicatoron false \
  112.         -onvalue italic -offvalue roman \
  113.         -text "I" -width 2 -height 1 \
  114.         -font {-slant italic -family Times -size 12} \
  115.         -highlightthickness 1 -padx 0 -pady 0 -borderwidth 1 \
  116.         -command [list changeFont $msg]
  117.     grid $fp.italic -row 0 -column 7 -sticky nsew
  118.  
  119.     # overstrike
  120.     checkbutton $fp.overstrike -variable overstrike -indicatoron false \
  121.         -onvalue 1 -offvalue 0 \
  122.         -text "O" -width 2 -height 1 \
  123.         -font {-overstrike 1 -family Times -size 12} \
  124.         -highlightthickness 1 -padx 0 -pady 0 -borderwidth 1 \
  125.         -command [list changeFont $msg]
  126.     grid $fp.overstrike -row 0 -column 8 -sticky nsew
  127.  
  128.     # this gives us relatively square buttons that fill the frame
  129.     # in the Y direction
  130.     bind $fp <Configure> {
  131.     grid columnconfigure %W 5 -minsize %h
  132.     grid columnconfigure %W 6 -minsize %h
  133.     grid columnconfigure %W 7 -minsize %h
  134.     grid columnconfigure %W 8 -minsize %h
  135.     }
  136.     # put focus on the first widget
  137.     catch {focus $fp.famCombo}
  138.  
  139.     return ""
  140. }
  141.  
  142. # this proc changes the font. It is called by various methods, so
  143. # the only parameter we are guaranteed is the first one since
  144. # we supply it ourselves...
  145. proc ::changeFont {w args} {
  146.     foreach foo [list family size weight underline slant overstrike] {
  147.     if {[set ::$foo] == ""} {
  148.         return
  149.     }
  150.     }
  151.     set ::fontspec [list \
  152.         -family     $::family \
  153.         -size       $::size \
  154.         -weight     $::weight \
  155.         -underline  $::underline \
  156.         -slant      $::slant \
  157.         -overstrike $::overstrike \
  158.     ]
  159.     $w configure -font $::fontspec
  160. }
  161.  
  162. main
  163.