#! ./wafepython
#
# This is a test file for python build with the Athena 
# version of Wafe (renamed to wafepython). The script shows, how
# to use the HTML widget from Mosaic in python
# 
# Gustaf Neumann              Mohegan Lake, NY, Sat Jun  4 17:58:27

import wafe

wafe.cmd( """
mergeResources topLevel \
	*foreground black \
	*background gray80 \
	*HTML*background gray90 \
	*Command.background lightblue 


set text {
<H1>Backup Administration Tool</H1>

<H3>Make a backup of of...</H3>

<FORM action="backup">
<UL>
<LI> <INPUT type=radio name=source value=home/neumann CHECKED>
     <i>Gustaf's</i> home directory

<LI> <INPUT type=radio name=source value=home/alkier>
     <i>Lore's</i> home directory

<LI> <INPUT type=radio name=source value="home/ usr/spool/mail/">
     <i>All</i> home directories and mail boxes

<LI> <INPUT type=radio name=source 
     value="usr/local/bin etc/rc.local usr/lib/X11/Xconfig usr/lib/X11/xinit/xini
trc">
     locally installed files and certain configuration files
</UL>

<H3>... using as an archive program ...</H3>
<UL>
<LI> <INPUT type=radio name=archiver 
      value="tar zcf \$target \$source" CHECKED>
     <i>Gnu Tar</i> (compressed)
<LI> <INPUT type=radio name=archiver 
     value="find \$source | cpio -oa &gt \$target ">
     <i>cpio</i> 
</UL>

<H3> ... on  ... </H3>
<UL>
<LI> <INPUT type=radio name=target value="/dev/fd0" CHECKED>
     the <i>first</i> floppy disk drive, or
<LI> <INPUT type=radio name=target value="/dev/mt0">
     on the <i>tape</i> drive, or
<LI> <INPUT type=radio name=target value="/usr/backups/backup-$stamp">
     in the <i>backup directroy</i> on the hard disk
</UL>

<HR>

In order to 
<UL>
<LI> <INPUT type=radio name=show value=0>
     <i>start</i> the backup, or to
<LI> <INPUT type=radio name=show value=1 CHECKED>
     <i>show</i> the backup command,
</UL>
press: <INPUT type=submit value=Backup>
</FORM>
}

proc submit {action names values} {
  for {set i 0} {$i<[llength $names]} {incr i} {
    set [lindex $names $i] [lindex $values $i]
  }
  backup [eval concat $archiver] $show
}

proc backup {cmd show} {
  if $show {
    sV info label $cmd
  } else {
    setBusy f true
    cd /
    catch {eval exec $cmd} result
    setBusy f false
    if [string compare $result ""] {
      if ![isWidget errors] {
        TransientShell errors topLevel
        Form errorForm errors
        Text errorText errorForm width 600 height 300 string $result
        Command dismiss errorForm fromVert errorText \
          callback {popdown errors}
        callback errors popupCallback position info:40
      } else {
        sV errorText string $result
      }
      popup errors none
    }
  }
}


 Form f topLevel
   Label info f shadowWidth 3 width 450 label {}
   HTML h f \
    width 450 height 650 fromVert info text $text \
    submitFormCallback { submit "%h" "%n" "%v" }

  Command quit f \
    fromVert h \
    callback quit

realize
""")

wafe.process_events()

