home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / tcl / 1824 < prev    next >
Encoding:
Text File  |  1992-11-13  |  5.6 KB  |  240 lines

  1. Newsgroups: comp.lang.tcl
  2. Path: sparky!uunet!caen!spencer
  3. From: spencer@med.umich.edu (Spencer W. Thomas)
  4. Subject: Biff revisited
  5. Message-ID: <SPENCER.92Nov13055357@guraldi.med.umich.edu>
  6. Date: Fri, 13 Nov 92 05:53:57 EST
  7. Organization: University of Michigan
  8. Distribution: comp
  9. Nntp-Posting-Host: guraldi.itn.med.umich.edu
  10. Lines: 228
  11.  
  12. I once had an xbiff that had a really nice feature -- if you clicked
  13. on it, it would pop up a list of the message headers.  I thought I'd
  14. see if I could reproduce that behavior.  I started from the recently
  15. posted tclbiff, but then switched to using 'xf' to build the
  16. application.  (This no doubt accounts for the verbosity of the
  17. resulting code...)  Here it is.  The usual disclaimers apply...
  18.  
  19. Press mouse 1 on the mailbox icon and hold it.  A "spring-loaded" list
  20. of your message headers will pop up.
  21.  
  22. =S
  23.  
  24. #!/usr/local/bin/wish -f
  25. # XF
  26. # create the widget hierarchy
  27. #
  28. # startup source
  29.  
  30.  
  31.  
  32.  
  33. # module inclusion
  34.  
  35. # initialize global variables
  36. proc InitGlobals {} {
  37.   global flagDownBitmap
  38.   set flagDownBitmap {/usr/include/X11/bitmaps/flagdown}
  39.   global bitmapState
  40.   set bitmapState {0}
  41.   global symbolicName
  42.   set {symbolicName(root)} {.}
  43.   set {symbolicName(headerList)} {.headers.frame2.listbox}
  44.   global MAIL
  45.   global flagUpBitmap
  46.   set flagUpBitmap {/usr/include/X11/bitmaps/flagup}
  47. }
  48.  
  49. proc ShowWindow.headers { args} {
  50.  
  51.   # build widget .headers
  52.  
  53.   catch "destroy .headers"
  54.  
  55.   toplevel .headers -class tclbiff
  56.   .headers configure     -borderwidth {1}    -relief {raised}
  57.  
  58.   # Window manager configurations
  59.   wm title .headers {headers}
  60.   wm positionfrom .headers program
  61.   wm sizefrom .headers program
  62.   wm maxsize .headers 1000 900
  63.   wm minsize .headers 10 10
  64.   wm transient .headers .
  65.  
  66.   # build widget .headers.frame2
  67.   frame .headers.frame2
  68.   .headers.frame2 configure     -borderwidth {2}    -relief {raised}
  69.  
  70.   # build widget .headers.frame2.listbox
  71.   listbox .headers.frame2.listbox
  72.   .headers.frame2.listbox configure     -borderwidth {1}    -exportselection {false}    -font {-Adobe-Helvetica-Medium-R-Normal-*-120-*}    -geometry {10x1}    -relief {raised}
  73.  
  74.   # pack widget .headers.frame2
  75.   pack append .headers.frame2    .headers.frame2.listbox   {top frame center} 
  76.  
  77.  
  78.   # pack widget .headers
  79.   pack append .headers    .headers.frame2   {top frame center fill} 
  80.  
  81.   wm geometry .headers +[expr [winfo rootx .]+10]+[expr [winfo rooty .]+10]
  82. }
  83.  
  84. proc DestroyWindow.headers {} {
  85.     catch "destroy .headers"
  86.     update
  87. }
  88.  
  89. # contents of .
  90. proc ShowWindow. {args} {
  91.  
  92.   # Window manager configurations
  93.   wm title . {biff}
  94.   wm positionfrom . program
  95.   wm sizefrom . program
  96.   wm maxsize . 1000 900
  97.   wm minsize . 10 10
  98.  
  99.   # build widget .mailbox
  100.   label .mailbox
  101.   .mailbox configure \
  102.     -bitmap {@/usr/include/X11/bitmaps/flagdown}\
  103.     -borderwidth {1}\
  104.     -relief {raised}\
  105.     -text {}
  106.   # bindings
  107.   bind .mailbox <ButtonRelease-1> {wm withdraw .headers} 
  108.   bind .mailbox <Button-1> {ShowWindow.headers
  109. getheaders} 
  110.  
  111.  
  112.   # build widget .time
  113.   label .time
  114.   .time configure \
  115.     -borderwidth {1}\
  116.     -font {*fixed-medium-r-normal--*-200-*}\
  117.     -relief {raised}\
  118.     -text {03:56}
  119.  
  120.   # pack widget .
  121.   pack append .\
  122.     .mailbox   {top frame center expand fill} \
  123.     .time   {top frame center expand fillx} 
  124. }
  125.  
  126.  
  127. # Procedures
  128.  
  129. proc schedule {} {
  130.     check_and_bark
  131.     .time configure -text [fmtclock [getclock] "%H:%M"]
  132.     after 60000 schedule
  133. }
  134.  
  135.  
  136. proc check_and_bark {} {
  137.     global MAIL flagDownBitmap flagUpBitmap bitmapState
  138.  
  139.     if {[file exists $MAIL] && ([file size $MAIL] != 0)        && ([file mtime $MAIL] > [file atime $MAIL])} {
  140.     if {$bitmapState != 1} {
  141.         .mailbox configure -bitmap "@$flagUpBitmap"
  142.         set bitmapState 1
  143.     }
  144.     } else {
  145.     if {$bitmapState != 0} {
  146.         .mailbox configure -bitmap "@$flagDownBitmap"
  147.         set bitmapState 0
  148.     }
  149.     }
  150. }
  151.  
  152. proc getheaders {} {
  153.     global MAIL Inmessage Fromline
  154.  
  155.     set l [SymbolicName headerList]
  156.     $l delete 0 end;
  157.     set w 10;
  158.     set Inmessage 0;
  159.     set Fromline {}
  160.  
  161.     set scanc [scancontext create];
  162.     scanmatch $scanc "^From " {
  163.       global Inmessage Fromline;
  164.       set Inmessage 1;
  165.       set Fromline [lindex $matchInfo(line) 1];
  166.     }
  167.     scanmatch $scanc ^From: {
  168.       global Inmessage Fromline
  169.       if $Inmessage {
  170.         expr {[regexp {<([^>]+)>} $matchInfo(line) x Fromline] ||
  171.             [regexp "From: +(\[^ \t]+)" $matchInfo(line) x Fromline]}
  172.       }
  173.     }
  174.     scanmatch $scanc ^Subject: {
  175.       global Inmessage Fromline
  176.       if $Inmessage {
  177.         [SymbolicName headerList] insert end \
  178.           [concat ${Fromline}:\
  179.            [string trim [string range $matchInfo(line) 8 end]]];
  180.       }
  181.     }
  182.  
  183.     set m [open $MAIL r]
  184.     scanfile $scanc $m
  185.     close $m
  186.  
  187.     set n [$l size]
  188.     loop i 0 $n {
  189.         set w [max $w [string length [$l get $i]]]
  190.     }
  191.     set n [min $n 1]
  192.     $l configure -geometry ${w}x$n
  193. }
  194.  
  195.  
  196. if {[string length [info procs SymbolicName]] == 0} {
  197. proc SymbolicName { {xfName ""}} {
  198.   global symbolicName
  199.  
  200.   if {[string length $xfName] > 0} {
  201.     set xfArrayName ""
  202.     append xfArrayName symbolicName ( $xfName )
  203.     if {[catch "set \"$xfArrayName\"" xfValue] == 0} {
  204.       return $xfValue
  205.     } {
  206.         puts stderr "XF error: unknown symbolic name:\n$xfName"
  207.     }
  208.   }
  209.   return ""
  210. }
  211. }
  212.  
  213.  
  214. # initialize global variables
  215. # remove this call if there are problems at startup
  216. InitGlobals
  217.  
  218.  
  219. # stuff to display and remove toplevel windows
  220. # call the procedures to create the toplevels.
  221. ShowWindow.
  222.  
  223. # end source
  224.  
  225.     if [info exists env(MAIL)] {
  226.     set MAIL $env(MAIL)
  227.     } else {
  228.     set MAIL "/usr/spool/mail/[id user]"
  229.     }
  230.  
  231.     schedule
  232.  
  233.  
  234. # eof
  235. #
  236. --
  237. =Spencer W. Thomas         |  Info Tech and Networking, B1911 CFOB, 0704
  238.    "Genome Informatician"    |  Univ of Michigan, Ann Arbor, MI 48109
  239. Spencer.W.Thomas@med.umich.edu    |  313-747-2778, FAX 313-764-4133
  240.