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 >
Wrap
Text File
|
1998-05-05
|
6KB
|
257 lines
# This is a module for PLING external calling
proc pling_exec { command { arg1 "" } { arg2 "" } { arg3 "" } { arg4 "" } } {
global pling_exec_option
switch $command {
long_info
{
return "{ Pling external }\
{ Pling external Filter module }\
{ Oliver Pabst }\
{ 1.0 }\
{ Pling external/Tcl } \
{ Pling external Filter layer for angela! }\
{ Oliver Pabst }\
{ 1.0 }\
{ filter_exec }\
{ pling }"
}
init
{
set menu [angela:msg TOOL:ADD:CASCADE "PLING External command" pling_exec:do]
set pling_exec_option(menu) $menu
pling_exec:menu:rebuild
}
}
}
proc pling_exec:menu:rebuild { } {
global angela_option pling_exec_option
set menu $pling_exec_option(menu)
$menu delete 0 end
foreach { name command } \
$angela_option(module:filter_exec/pling:command) {
$menu add command -label "$name" \
-command "pling_exec:do \"$command\""
}
$menu add separator
$menu add command -label "Configure..." \
-command "pling_exec:configure $menu"
}
proc pling_exec:configure:refresh { w } {
global angela_option
catch { destroy $w.delete.m }
catch { destroy $w.edit.m }
menu $w.delete.m -tearoff 0
menu $w.edit.m -tearoff 0
set index 0
foreach { name command } \
$angela_option(module:filter_exec/pling:command) {
$w.delete.m add command -label "Delete $name" \
-command "pling_exec:configure:delete $index $w"
$w.edit.m add command -label "Edit $name" \
-command "pling_exec:configure:edit $index $w"
incr index
}
pling_exec:menu:rebuild
}
proc pling_exec:configure { menu } {
global angela_option
set w .pling_exec_config
catch { destroy $w }
toplevel $w
wm title $w "filter_exec/pling:configure"
frame $w.top
frame $w.bottom
pack $w.top $w.bottom -side top -fill both -expand yes
menubutton $w.top.delete -text "Delete item" -menu $w.top.delete.m \
-anchor e
menubutton $w.top.edit -text "Edit item" -menu $w.top.edit.m \
-anchor e
pling_exec:configure:refresh $w.top
pack $w.top.delete $w.top.edit -side left
tixButtonBox $w.bottom.box -orientation horizontal
$w.bottom.box add insert -text "Insert new item" \
-command "pling_exec:configure:insert $w.top"
$w.bottom.box add ok -text Done -underline 0 \
-command "pling_exec:configure:done $w" \
-width 6
pack $w.bottom.box -fill both -expand yes -side bottom
}
proc pling_exec:configure:done { w } {
destroy $w
}
proc pling_exec:configure:insert { w } {
global angela_option
lappend angela_option(module:filter_exec/pling:command) Unnamed Unknown
pling_exec:configure:edit \
[ expr [llength $angela_option(module:filter_exec/pling:command)] / 2 -1] $w
pling_exec:configure:refresh $w
}
proc pling_exec:configure:delete { id w } {
global angela_option
# Must remove entry $id
set angela_option(module:filter_exec/pling:command) \
[lreplace $angela_option(module:filter_exec/pling:command) [expr $id*2] [expr ($id+1)*2-1]]
pling_exec:configure:refresh $w
}
proc pling_exec:configure:edit { id w } {
global angela_option
set v .pling_exec_config.editdialog
catch { destroy $v }
toplevel $v
wm title $v "filter_exec/pling:configure:edit"
set command $angela_option(module:filter_exec/pling:command)
set name [lindex $command [expr $id*2]]
set command [lindex $command [expr $id*2+1]]
tixLabelEntry $v.name -label "Name:" \
-options {
entry.width 25
label.width 15
label.anchor e
}
$v.name subwidget entry insert end $name
tixLabelEntry $v.command -label "Command:" \
-options {
entry.width 25
label.width 15
label.anchor e
}
$v.command subwidget entry insert end $command
focus $v.name
pack $v.name $v.command -side top -fill both -expand yes
tixButtonBox $v.box -orientation horizontal
$v.box add ok -text Done -underline 0 \
-command "pling_exec:configure:edit:done $v $id $w" \
-width 6
pack $v.box -fill both -expand yes
}
proc pling_exec:configure:edit:done { v id w } {
global angela_option
set name [$v.name subwidget entry get]
set command [$v.command subwidget entry get]
set angela_option(module:filter_exec/pling:command) \
[lreplace $angela_option(module:filter_exec/pling:command) \
[expr $id*2] [expr ($id+1)*2-1] $name $command]
debug $angela_option(module:filter_exec/pling:command)
destroy $v
pling_exec:configure:refresh $w
}
proc pling_exec:do { command } {
global angela_option
set mustsave 1
set mustload 1
if { [ string first %i $command ] == -1 } {
set mustsave 0
}
if { [ string first %o $command ] == -1 } {
set mustload 0
}
set filename "tempfile"
set index 0
if { $mustsave } {
while { [file exists $filename$index.pling] } {
incr index
}
set outname "$filename$index.pling"
regsub %i $command $outname command
}
if { $mustload } {
incr index
while { [file exists $filename$index.pling] } {
incr index
}
set inname "$filename$index.pling"
regsub %o $command $inname command
}
if { $mustsave } {
angela:msg GRAPH:SAVE $outname
}
# Must execute function.
debug "Executing sh -c \"$command\""
catch { exec sh -c $command }
if { $mustsave } {
file delete $outname
}
if { $mustload } {
if { ![file exists $inname] } {
tk_dialog .error \
"Error !!!" \
"An error occured while processing external\
program. The output file $inname was not\
created and therefore cannot be loaded."\
"" \
0 \
"Ok"
} else {
angela:msg GRAPH:OPEN $inname
file delete $inname
}
}
}