home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / angela-1.28-BETA-bin-Linux-i586.tar.gz / angela-1.28-BETA-bin-Linux-i586.tar / angela-1.28-BETA / module_plingexternal.tcl < prev    next >
Text File  |  1998-05-05  |  6KB  |  257 lines

  1. # This is a module for PLING external calling
  2.  
  3. proc pling_exec { command { arg1 "" } { arg2 "" } { arg3 "" } { arg4 "" } } {
  4. global pling_exec_option
  5.  
  6.     switch $command {
  7.  
  8.     long_info
  9.     {
  10.         return "{ Pling external }\
  11.                     { Pling external Filter module }\
  12.                     { Oliver Pabst }\
  13.                     { 1.0 }\
  14.                     { Pling external/Tcl } \
  15.                     { Pling external Filter layer for angela! }\
  16.                     { Oliver Pabst }\
  17.                     { 1.0 }\
  18.                     { filter_exec }\
  19.                     { pling }"
  20.     }
  21.  
  22.     init
  23.     {
  24.          set menu [angela:msg TOOL:ADD:CASCADE "PLING External command" pling_exec:do]
  25.         set pling_exec_option(menu) $menu
  26.         pling_exec:menu:rebuild
  27.     }
  28.  
  29.     }
  30.  
  31. }
  32.  
  33. proc pling_exec:menu:rebuild { } {
  34. global angela_option pling_exec_option
  35.  
  36.     set menu $pling_exec_option(menu)
  37.  
  38.     $menu delete 0 end
  39.  
  40.     foreach { name command } \
  41.     $angela_option(module:filter_exec/pling:command) {
  42.     
  43.     $menu add command -label "$name" \
  44.         -command "pling_exec:do \"$command\""
  45.  
  46.     }
  47.  
  48.     $menu add separator
  49.     $menu add command -label "Configure..." \
  50.     -command "pling_exec:configure $menu"
  51. }
  52.  
  53. proc pling_exec:configure:refresh { w } {
  54. global angela_option
  55.  
  56.     catch { destroy $w.delete.m }
  57.     catch { destroy $w.edit.m }
  58.  
  59.     menu $w.delete.m -tearoff 0
  60.     menu $w.edit.m -tearoff 0
  61.     set index 0
  62.     foreach { name command } \
  63.     $angela_option(module:filter_exec/pling:command) {
  64.     
  65.     $w.delete.m add command -label "Delete $name" \
  66.         -command "pling_exec:configure:delete $index $w" 
  67.     $w.edit.m add command -label "Edit $name" \
  68.         -command "pling_exec:configure:edit $index $w" 
  69.     incr index
  70.     }
  71.  
  72.     pling_exec:menu:rebuild
  73.  
  74. }
  75.  
  76. proc pling_exec:configure { menu } {
  77. global angela_option
  78.  
  79.     set w .pling_exec_config
  80.     catch { destroy $w }
  81.     toplevel $w
  82.     wm title $w "filter_exec/pling:configure"
  83.  
  84.     frame $w.top
  85.     frame $w.bottom
  86.     pack $w.top $w.bottom -side top -fill both -expand yes
  87.  
  88.     menubutton $w.top.delete -text "Delete item" -menu $w.top.delete.m \
  89.     -anchor e
  90.     menubutton $w.top.edit   -text "Edit item" -menu $w.top.edit.m \
  91.     -anchor e
  92.  
  93.     pling_exec:configure:refresh $w.top
  94.  
  95.     pack $w.top.delete $w.top.edit -side left
  96.  
  97.     tixButtonBox $w.bottom.box -orientation horizontal 
  98.     $w.bottom.box add insert -text "Insert new item" \
  99.     -command "pling_exec:configure:insert $w.top"
  100.     $w.bottom.box add ok     -text Done   -underline 0 \
  101.     -command "pling_exec:configure:done $w" \
  102.     -width 6
  103.  
  104.     pack $w.bottom.box -fill both -expand yes -side bottom
  105. }
  106.  
  107. proc pling_exec:configure:done { w } {
  108.  
  109.     destroy $w
  110.  
  111. }
  112.  
  113. proc pling_exec:configure:insert { w } {
  114. global angela_option
  115.  
  116.     lappend angela_option(module:filter_exec/pling:command) Unnamed Unknown
  117.     pling_exec:configure:edit \
  118.     [ expr [llength $angela_option(module:filter_exec/pling:command)] / 2 -1] $w
  119.     pling_exec:configure:refresh $w
  120. }
  121.  
  122. proc pling_exec:configure:delete { id w } {
  123. global angela_option
  124.  
  125.     # Must remove entry $id
  126.     set angela_option(module:filter_exec/pling:command) \
  127.     [lreplace $angela_option(module:filter_exec/pling:command) [expr $id*2] [expr ($id+1)*2-1]]
  128.  
  129.     pling_exec:configure:refresh $w
  130. }
  131.  
  132. proc pling_exec:configure:edit { id w } {
  133. global angela_option
  134.  
  135.     set v .pling_exec_config.editdialog
  136.     catch { destroy $v }
  137.     toplevel $v
  138.     wm title $v "filter_exec/pling:configure:edit"
  139.  
  140.     set command $angela_option(module:filter_exec/pling:command)
  141.     set name [lindex $command [expr $id*2]]
  142.     set command [lindex $command [expr $id*2+1]]
  143.  
  144.  
  145.     tixLabelEntry $v.name -label "Name:" \
  146.     -options {
  147.     entry.width 25
  148.     label.width 15
  149.     label.anchor e
  150.     }
  151.  
  152.     $v.name subwidget entry insert end $name
  153.     
  154.     tixLabelEntry $v.command -label "Command:" \
  155.     -options {
  156.     entry.width 25
  157.     label.width 15
  158.     label.anchor e
  159.     }
  160.  
  161.     $v.command subwidget entry insert end $command
  162.  
  163.     focus $v.name
  164.  
  165.     pack $v.name $v.command -side top -fill both -expand yes
  166.  
  167.     tixButtonBox $v.box -orientation horizontal
  168.     $v.box add ok     -text Done   -underline 0 \
  169.     -command "pling_exec:configure:edit:done $v $id $w" \
  170.     -width 6
  171.  
  172.     pack $v.box -fill both -expand yes
  173. }
  174.  
  175. proc pling_exec:configure:edit:done { v id w } {
  176. global angela_option
  177.  
  178.     set name [$v.name subwidget entry get]
  179.     set command [$v.command subwidget entry get]
  180.  
  181.     set angela_option(module:filter_exec/pling:command) \
  182.     [lreplace $angela_option(module:filter_exec/pling:command) \
  183.      [expr $id*2] [expr ($id+1)*2-1] $name $command]
  184.  
  185.     debug $angela_option(module:filter_exec/pling:command)
  186.  
  187.     destroy $v
  188.  
  189.     pling_exec:configure:refresh $w
  190.     
  191. }
  192.  
  193. proc pling_exec:do { command } {
  194. global angela_option
  195.  
  196.     set mustsave 1
  197.     set mustload 1
  198.  
  199.     if { [ string first %i $command ] == -1 } {
  200.     set mustsave 0
  201.     }
  202.     if { [ string first %o $command ] == -1 } {
  203.     set mustload 0 
  204.     }
  205.  
  206.     set filename "tempfile"
  207.     set index 0
  208.  
  209.     if { $mustsave } {
  210.     while { [file exists $filename$index.pling] } {
  211.         incr index
  212.     }
  213.     
  214.     set outname "$filename$index.pling"
  215.     regsub %i $command $outname command
  216.     }
  217.     
  218.     if { $mustload } {
  219.     incr index
  220.     while { [file exists $filename$index.pling] } {
  221.         incr index
  222.     }
  223.     
  224.     set inname "$filename$index.pling"
  225.     regsub %o $command $inname command
  226.     }
  227.  
  228.     if { $mustsave } {
  229.     angela:msg GRAPH:SAVE $outname
  230.     }
  231.     
  232.     # Must execute function.
  233.  
  234.     debug "Executing sh -c \"$command\""
  235.     catch { exec sh -c $command }
  236.  
  237.     if { $mustsave } {
  238.     file delete $outname
  239.     }
  240.  
  241.     if { $mustload } {
  242.     if { ![file exists $inname] } {
  243.         tk_dialog .error \
  244.         "Error !!!" \
  245.         "An error occured while processing external\
  246.              program. The output file $inname was not\
  247.              created and therefore cannot be loaded."\
  248.         "" \
  249.         0 \
  250.         "Ok"
  251.     } else {
  252.         angela:msg GRAPH:OPEN $inname
  253.         file delete $inname
  254.     }
  255.     }
  256. }
  257.