home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / tclMotif-1.4 / examples / progDH11.2 < prev    next >
Encoding:
Text File  |  1995-06-29  |  1.5 KB  |  53 lines

  1. # program 11.2 from Dan's book, p368
  2.  
  3. # I'm cheating here. I know how to specify multiple fonts in a fontlist
  4. # <fontname1>=charset1, <fontname2>=charset2
  5. # and I know how to create XmStrings using C code to use these charsets,
  6. # but I don't know how to do it in resource files. So I use 2 fontlists
  7.  
  8. set fontlist1 "-*-courier-bold-r-*--12-*"
  9. set fontlist2 "-*-courier-medium-r-*--12-*"
  10.  
  11. set months "January February March April May June \
  12. July August September October November December"
  13.  
  14. # find the current month/year
  15. set this_month [exec date "+%m"]
  16. # this_month is a 2-digit number possibly starting with 0 
  17. # this signals an octal number, so lose any starting 0
  18. if { [regexp {^0} $this_month] } {
  19.   regsub {^0} $this_month "" this_month
  20. }
  21. set year  [exec date "+%y"]
  22. set this_year "19$year"
  23.  
  24. proc set_month {label month} {
  25.     global this_year
  26.  
  27.     # quote the text to preserve formatting in it
  28.     # when it gets converted to XmString
  29.     set text \{[exec cal $month $this_year]\}
  30.     $label setValues -labelString "$text"
  31. }
  32.  
  33. # now the objects:
  34. xtAppInitialize -class Program
  35.  
  36. xmRowColumn .rowcol managed -orientation horizontal
  37. xmFrame .rowcol.frame managed
  38. xmLabel .rowcol.frame.month managed \
  39.     -alignment alignment_beginning \
  40.     -fontList $fontlist1
  41.  
  42. xmScrolledList .rowcol.list managed \
  43.     -itemCount 12 \
  44.     -items $months \
  45.     -fontList $fontlist2
  46. .rowcol.list browseSelectionCallback \
  47.     {set_month .rowcol.frame.month %item_position}
  48. .rowcol.list selectPosition $this_month true
  49.  
  50. . realizeWidget
  51.  
  52. . mainLoop
  53.