Apendice 2-1 (DRS.tk)

#!/sw3/common/agent.1.1/binex/bin/agent-tk # ____________________________________________________________________________________ # | This system was designed to perform data seeking using MG and Agent Technology. | # | Program: DRS.tk | # | Designers: E. Odette Castellanos Cervantes is085855 | # | Edgar Sandoval Reyes is091892 | # | Date: 25/8/97 | # |____________________________________________________________________________________| if {[catch {agent_begin}]} { ;# try to start an mobil agent return -code error "ERROR: unable to register on $agent(actual-server)" } agent_name Search_Agent ;# agent's name main create -name retrieval -display $agent(local-server):0 ;# create a window wm title . "Data Retrieval System" ;# windows's name wm protocol . WM_DELETE_WINDOW { if {[StatusBox "Do you really want to quit ?" 3] == 1} { agent_end; exit } } #______________________________________________________________________________ # the data that follows preserves data to build new search agents set Data(name) "" ;# var that keeps current agent's name (just for dialog box) set Data(topic) "" ;# var that keeps current agent's topic (just for dialog box) set Data(keyword) "" ;# var that keeps current agent's keyword (just for dialog box) set Data(all) 0 ;# var that keeps current agent's all_option (just for dialog box) set Data(some) 1 ;# var that keeps current agent's some_option (just for dialog box) set Data(number) "" ;# var that keeps current agent's number_of_nodes (just for dialog box) set Agents(agent) "" ;# list of mobile agents set Nodes "" ;# list of nodes that is passed to an agent mobile when created set number 0 ;# number of agents set Places(place) "" ;# array that contains all nodes of each agent to visit set Arrives(place) "" ;# places where an agent could arrive set prompt(okay) 0 ;# it is used to create modal dialog boxes set file(0) "" ;# var used to keep files to use with "save as" dialog box set print 1 set used 0 ;# to check if the desktop is used set status 0 ;# var to know which kind of agent sends data set viewed 0 #______________________________________________________________________________ set events 0 ;# var that keeps the number of events proc CatchEvent {source tag string} { ;# this procedure receives asyncronous messages global events ;# from created subagents global agent ;# "source" is the place where the message comes global Data ;# "tag" is a string which represents a command global Places ;# "string" is the content of the message global print global used global status set status 0 if {[llength [split [lindex [split $source " "] 2] "_"]] == 2 && $tag == "DATA"} { set status 1 } else {set status 0} puts "Event $events" ;# display all messages that comes puts "Source ==> $source" puts "Tag ==> $tag" if {$tag != "DATA"} { puts "String ==> $string" } ;# except data sent puts "" incr events if {$tag == "CREATE"} { } if {$tag == "ARRIVAL"} { ;# when an agent arrives in a computer, contact this agent set nodes [split $source " "] ;# to know about set temp $Places($string) set temp "$temp [lindex $nodes 0]" set Arrives($string) $temp unset nodes temp } if {$tag == "DATA"} { ;# when data sent from other agent put it on the desktop if {$used == 1} { set temp [StatusBox "An agent has sent data to you. Do you desire remove data from desktop?" 3 ] if {$temp == 1} { set used 1 .text config -state normal .text delete 1.0 end .text insert insert $string .text config -state disabled } } else { set used 1 .text config -state normal .text insert insert $string .text config -state disabled } } if {$tag == "ERROR"} { } if {$tag == "STATUS"} { } } #______________________________________________________________________________ # procedure to stop this agent's process if the programer wants proc stopEvent {source tag string} { puts "Received STOP so stopping ..." } #______________________________________________________________________________ set m [mask new] ;# create an array to make masks mask handler $m CatchEvent ;# proc's declaration to receive messages mask add $m "ANY ANY -tag STOP -handler stopEvent" mask_replace event $m ;# active the mask #______________________________________________________________________________ # this procedure creates a message dialog box with the "msg" argument proc MessageBox { msg } { global prompt set d [toplevel .msgbox] wm title $d "Data Retrieval System" set prompt(okay) 0 frame $d.one -relief raised -bd 1 frame $d.buttons -relief raised -bd 1 pack $d.one -side top -fill both pack $d.buttons -side top -fill both set img [image create photo -file /home/u/raid/vol07/is091892/html/exc.gif] label $d.bitmap -image $img message $d.msgtext -aspect 1000 -justify center -text $msg pack $d.bitmap -in $d.one -side left -padx 2m -pady 2m pack $d.msgtext -in $d.one -side right -padx 2m -pady 2m set img [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] button $d.ok -image $img -command {set prompt(okay) 1} pack $d.ok -in $d.buttons -side right -expand 1 -padx 2m -pady 2m grab set $d tkwait variable prompt(okay) grab release $d destroy $d } #______________________________________________________________________________ # this procedure create three types of dialog boxes like the procedure before, # "state" equals type of dialog box proc StatusBox { msg state } { global prompt global status set d [toplevel .statusbox] wm title $d "Data Retrieval System" set prompt(okay) 0 frame $d.one -relief raised -bd 1 frame $d.buttons -relief raised -bd 1 pack $d.one -side top -fill both pack $d.buttons -side top -fill both if {$state == 1} { set img [image create photo -file /home/u/raid/vol07/is091892/html/i.gif] label $d.bitmap -image $img message $d.msgtext -aspect 1000 -justify center -text $msg pack $d.bitmap -in $d.one -side left -padx 2m -pady 2m pack $d.msgtext -in $d.one -side right -padx 2m -pady 2m set img [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] button $d.ok -image $img -command {set prompt(okay) 1} pack $d.ok -in $d.buttons -side right -expand 1 -padx 2m -pady 2m set status 0 } elseif {$state == 2} { wm title $d "Data Retrieval System: ERROR" set img [image create photo -file /home/u/raid/vol07/is091892/html/hand.gif] label $d.bitmap -image $img message $d.msgtext -aspect 1000 -justify center -text $msg pack $d.bitmap -in $d.one -side left -padx 2m -pady 2m pack $d.msgtext -in $d.one -side right -padx 2m -pady 2m set img [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] button $d.ok -image $img -command {set prompt(okay) 1} pack $d.ok -in $d.buttons -side right -expand 1 -padx 2m -pady 2m set status 0 } elseif {$state == 3} { wm title $d "Data Retrieval System: Question" set img [image create photo -file /home/u/raid/vol07/is091892/html/question.gif] label $d.bitmap -image $img message $d.msgtext -aspect 1000 -justify center -text $msg pack $d.bitmap -in $d.one -side left -padx 2m -pady 2m pack $d.msgtext -in $d.one -side right -padx 2m -pady 2m button $d.yes -text Yes -command {set status 1; set prompt(okay) 1} button $d.no -text No -command {set status 2; set prompt(okay) 1} pack $d.yes $d.no -in $d.buttons -side left -expand 1 -padx 2m -pady 2m } grab set .statusbox tkwait variable prompt(okay) grab release .statusbox destroy .statusbox return $status } #______________________________________________________________________________ # this procedure creates a dialog box which displays information about # this agent. proc DisplayAgentInfo{ } { global agent global prompt set f [toplevel .displayAgentInfo -borderwidth 5] wm title $f "Agent Properties" bell frame $f.data -relief sunken -bd 1 pack $f.data -side top -fill both set data "Logical Agent Name: " append data $agent(local-name) label $f.name -text $data pack $f.name -in $f.data -side top -padx 0 -fill x set data "Full ID: " append data $agent(local) label $f.full -text $data pack $f.full -in $f.data -side top -padx 0 -fill x set data "Agent ID: " append data $agent(local-id) label $f.id -text $data pack $f.id -in $f.data -side top -padx 0 -fill x set data "Name of Machine: " append data $agent(actual-server) label $f.server -text $data pack $f.server -in $f.data -side top -padx 0 -fill x set data "Address of Machine: " append data $agent(actual-ip) label $f.ip -text $data pack $f.ip -in $f.data -side top -padx 0 -fill x set data "Local server: " append data $agent(local-server) label $f.localServer -text $data pack $f.localServer -in $f.data -side top -padx 0 -fill x set data "Server IP: " append data $agent(local-ip) label $f.localip -text $data pack $f.localip -in $f.data -side top -padx 0 -fill x set data "Script: " append data [info script] label $f.scpt -text $data pack $f.scpt -in $f.data -side top -padx 0 -fill x set data "Tcl Version: " append data [info tclversion] label $f.version -text $data pack $f.version -in $f.data -side top -padx 0 -fill x frame $f.button -relief flat -bd 1 pack $f.button -side top -fill both set img [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] button $f.ok -image $img -command {set prompt(okay) 1} pack $f.ok -in $f.button -side left -expand 1 -padx 2m -pady 2m grab set $f tkwait variable prompt(okay) grab release $f destroy $f } #______________________________________________________________________________ # this procedure is one of the most important because it receives the data to # create an seeker agent proc GetAgentInfo{ } { global prompt global Data(name) global Data(topic) global Data(keyword) global Data(all) global Data(some) global Data(number) global Nodes set f [toplevel .getAgentInfo -borderwidth 5 -class Dialog] wm title $f "Agent Creation" label $f.label1 -text "Aglet Creation Information" pack $f.label1 -side top -fill x frame $f.one -relief groove -bd 1 frame $f.two -relief flat -bd 1 frame $f.three -relief flat -bd 1 frame $f.four -relief flat -bd 1 frame $f.five -relief flat -bd 1 frame $f.six -relief flat -bd 1 frame $f.seven -relief flat -bd 1 frame $f.eight -relief ridge -bd 1 pack $f.one -side top -fill both pack $f.two -side top -fill both pack $f.three -side top -fill both pack $f.four -side top -fill both pack $f.five -side top -fill both pack $f.six -side top -fill both pack $f.seven -side top -fill both pack $f.eight -side top -fill both set Data(name) "" set Data(topic) "" set Data(keyword) "" set Data(all) 0 set Data(some) 1 set Data(number) "" set Nodes "" set which 0 label $f.label2 -text "Agent name:" entry $f.agentname -textvariable Data(name) pack $f.label2 -in $f.one -side left pack $f.agentname -in $f.one -side right -fill x -expand 1 bind $f.agentname {set prompt(okay) 1} bind $f.agentname {set prompt(okay) 0} label $f.label3 -text "Topic:" entry $f.topic -textvariable Data(topic) pack $f.label3 -in $f.two -side left pack $f.topic -in $f.two -side right -fill x -expand 1 label $f.label4 -text "Data to seek:" entry $f.seekdata -textvariable Data(keyword) pack $f.label4 -in $f.three -side left pack $f.seekdata -in $f.three -side right -fill x -expand 1 label $f.label5 -text "How do you want the agent travel?" pack $f.label5 -in $f.four -side left -fill x checkbutton $f.some -text "Travel to some nodes" -variable Data(some) \ -command { set Data(all) 0; puts "Data(some): $Data(some)"; puts "Data(all): $Data(all)" } entry $f.number -textvariable Data(number) -width 4 pack $f.some -in $f.five -side left pack $f.number -in $f.five -side left -fill x bind $f.some <1> { .getAgentInfo.number config -state normal; .getAgentInfo.number delete 0 4; .getAgentInfo.number insert 0 ""; focus .getAgentInfo.list; set which 1 puts "which: $which" } checkbutton $f.all -text "Travel to all nodes" -variable Data(all) \ -command { set Data(some) 0; puts "Data(some): $Data(some)"; puts "Data(all): $Data(all)" } pack $f.all -in $f.six -side left -fill x bind $f.all <1> { set nodes [.getAgentInfo.list get 0 end]; .getAgentInfo.number delete 0 4; .getAgentInfo.number insert 0 [llength $nodes]; .getAgentInfo.number config -state disabled; focus .getAgentInfo.ok; set which 2 puts "which: $which" } $f.agentname delete 0 30 $f.topic delete 0 30 $f.seekdata delete 0 30 $f.number delete 0 4 listbox $f.list -yscrollcommand [list $f.scroll set] -selectmode extended bind $f.list <1> { set nodes [%W curselection]; set howmany [llength $nodes]; .getAgentInfo.number delete 0 4; .getAgentInfo.number insert 0 $howmany; } bind $f.list { set nodes [%W curselection]; set howmany [llength $nodes]; .getAgentInfo.number delete 0 4; .getAgentInfo.number insert 0 $howmany; } scrollbar $f.scroll -command [list $f.list yview] pack $f.list -in $f.seven -side left -fill both -expand true pack $f.scroll -in $f.seven -side left -fill y set file [open /home/u/raid/vol07/is091892/Agent_Tcl/nodes.txt] while {[gets $file line] >= 0} { $f.list insert end $line } set img1 [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] set img2 [image create photo -file /home/u/raid/vol07/is091892/html/cancel.gif] set img3 [image create photo -file /home/u/raid/vol07/is091892/html/help.gif] button $f.ok -image $img1 -command {set prompt(okay) 1} button $f.cancel -image $img2 -command {set prompt(okay) 0} button $f.help -image $img3 -command {} pack $f.ok -in $f.eight -side left -expand 1 -padx 2m -pady 2m pack $f.cancel -in $f.eight -side left -expand 1 -padx 2m -pady 2m pack $f.help -in $f.eight -side right -expand 1 -padx 2m -pady 2m focus $f.agentname grab set $f tkwait variable prompt(okay) set places "" set places [$f.list curselection] # puts "Data(some): $Data(some)"; puts "Data(all): $Data(all)" # if { $which == 1} { set places [$f.list curselection] # } elseif { $which == 2 } { set places [.getAgentInfo.list get 0 end]; } foreach node $places { lappend Nodes [$f.list get $node $node] } grab release $f destroy $f } #______________________________________________________________________________ proc ValidateInputs{ } { global prompt global Data global Nodes global Places set flag 1; set Okname 0 set Oktopic 0; set Okkeyword 0 GetAgentInfo{ } if {$prompt(okay) == 1} { while {$flag == 1} { set msg ""; set Okname 0; set Oktopic 0; set Okkeyword 0 if {$Data(name) == ""} { set flag 1; set msg "No agent name gotten." } else { set Okname 1 } if {$Data(topic) == ""} { set flag 1; set msg "$msg No topic string to search." } else { set Oktopic 1 } if {$Data(keyword) == ""} { set flag 1; set msg "$msg No keyword string to search." } else { set Okkeyword 1 } set value [expr ($Okname != 1) || ($Oktopic != 1) || ($Okkeyword != 1)] if { ($value == 1)} { StatusBox $msg 2; GetAgentInfo{ } if {$prompt(okay) == 1} { set flag 1 } else { set flag 0 } } else { set flag 0} } if {$prompt(okay) == 1} { exec /home/u/raid/vol07/is091892/Agent_Tcl/who.tk $Data(name) $Nodes $Data(topic) $Data(keyword); set Places($Data(name)) $Nodes; NewAgent $Data(name) } } } #______________________________________________________________________________ proc DisplayNodes{ } { global prompt set place "" set d [toplevel .displayNodes] wm title $d "Data Retrieval System" label $d.label1 -text "Available Current Nodes" pack $d.label1 -side top -padx 0 -fill x frame $d.one -relief raised -bd 1 frame $d.two -relief raised -bd 1 frame $d.three -relief raised -bd 1 pack $d.one -side top -fill both pack $d.two -side top -fill both pack $d.three -side top -fill both listbox $d.list -yscrollcommand [list $d.scroll set] -selectmode extended scrollbar $d.scroll -command [list $d.list yview] pack $d.list -in $d.one -side left -fill both -expand true pack $d.scroll -in $d.one -side left -fill y label $d.new -text "New place:" entry $d.place -textvariable place button $d.enter -text "Enter" \ -command { .displayNodes.list insert end $place; .displayNodes.place delete 0 20;} bind $d.place { .displayNodes.list insert end $place;.displayNodes.place delete 0 20;} pack $d.new -side left -in $d.two pack $d.place -side left -in $d.two pack $d.enter -side right -in $d.two set img [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] button $d.save -text "Save to disk" \ -command { set handler [open /home/u/raid/vol07/is091892/Agent_Tcl/nodes.txt w] set nodes [.displayNodes.list get 0 end] for {set i 0} {$i < [llength $nodes] } { incr i} { puts $handler [lindex $nodes $i] } close $handler } button $d.remove -text "Remove(s) from list" \ -command { set nodes [.displayNodes.list curselection]; .displayNodes.list delete [lindex $nodes 0] [lindex $nodes 0]; set nodes [lrange $nodes 1 end]; set index 0; set step 1; for {set i 0} {$i < [llength $nodes] } { incr i} { set index [lindex $nodes $i]; set index [expr $index-$step] set step [expr $step+1] .displayNodes.list delete $index $index } } button $d.ok -image $img -command {set prompt(okay) 1} pack $d.save -in $d.three -side left -expand 1 -padx 2m -pady 2m pack $d.remove -in $d.three -side left -expand 1 -padx 2m -pady 2m pack $d.ok -in $d.three -side right -expand 1 -padx 2m -pady 2m set f [open /home/u/raid/vol07/is091892/Agent_Tcl/nodes.txt] while {[gets $f line] >= 0} { $d.list insert end $line } grab set $d tkwait variable prompt(okay) set Nodes [$d.list curselection] grab release $d destroy $d } #______________________________________________________________________________ proc Trace{ } { global Places set d [toplevel .displayAgents] wm title $d "Agent Tracking" frame $d.one -relief raised -bd 1 frame $d.two -relief raised -bd 1 pack $d.one -side top -fill both pack $d.two -side top -fill both listbox $d.list -yscrollcommand [list $d.scroll set] scrollbar $d.scroll -command [list $d.list yview] pack $d.list -in $d.one -side left -fill both -expand true pack $d.scroll -in $d.one -side left -fill y set img [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] button $d.ok -image $img -command {set prompt(okay) 1} pack $d.ok -in $d.two -side right -expand 1 -padx 2m -pady 2m foreach places [array names Arrives] { if {$places != "place"} { $d.list insert end $Arrives($places) } } grab set $d tkwait variable prompt(okay) grab release $d destroy $d } #______________________________________________________________________________ proc DisplayAgents{ } { global prompt global Agents global Places set d [toplevel .displayAgents] wm title $d "Agent List" frame $d.one -relief raised -bd 1 frame $d.two -relief raised -bd 1 frame $d.three -relief raised -bd 1 frame $d.four -relief raised -bd 1 frame $d.five -relief raised -bd 1 pack $d.one -side top -fill both pack $d.two -side top -fill both pack $d.three -side top -fill both pack $d.four -side top -fill both pack $d.five -side top -fill both listbox $d.list -selectmode extended -yscrollcommand [list $d.scroll set] scrollbar $d.scroll -command [list $d.list yview] pack $d.list -in $d.one -side left -fill both -expand true pack $d.scroll -in $d.one -side left -fill y text $d.proper -width 40 -height 10 -bd 1 -yscrollcommand [ list $d.properscrolly set ] \ -xscrollcommand [ list $d.properscrollx set ] scrollbar $d.properscrolly -command "$d.proper yview" scrollbar $d.properscrollx -orient horizontal -command "$d.proper xview" pack $d.properscrolly -in $d.two -side right -fill y pack $d.properscrollx -in $d.two -side bottom -fill x pack $d.proper -in $d.two -side left -fill both -expand 1 button $d.dispose -text Dispose -command { } button $d.retract -text Retract -command { } button $d.properties -text Properties -command { .displayAgents.proper delete 1.0 end set indixes [.displayAgents.list curselection]; foreach index $indixes { set ma [.displayAgents.list get $index $index] .displayAgents.proper insert insert "Agent: $ma\n\n" foreach node $Places($ma) { .displayAgents.proper insert insert "$node\n" } .displayAgents.proper insert insert \n } } pack $d.dispose $d.retract $d.properties -in $d.three -side left -expand true label $d.timeTo -text "Time to" entry $d.time -textvariable time -width 5 button $d.desactivate -text Desactivate pack $d.timeTo $d.time $d.desactivate -in $d.four -side left -expand true set img [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] button $d.ok -image $img -command {set prompt(okay) 1} pack $d.ok -in $d.five -side right -expand 1 -padx 2m -pady 2m foreach agent [array names Agents] { if { $agent != "agent"} { $d.list insert end $agent } } grab set $d tkwait variable prompt(okay) grab release $d destroy $d } #______________________________________________________________________________ proc TempDialog { AgentName topic } { set Place "" global Places global Compound global Nodes global Files "" global viewed set viewed 1 set Nodes "" set Files "" set d [toplevel .tempDialog] wm title $d "Retriever Agent" frame $d.main -relief raised -bd 1 frame $d.one -relief raised -bd 1 frame $d.two -relief raised -bd 1 frame $d.three -relief raised -bd 1 frame $d.four -relief raised -bd 1 frame $d.buttons -relief raised -bd 1 pack $d.main -side top -fill both pack $d.one -side top -fill both pack $d.two -side top -fill both pack $d.three -side top -fill both pack $d.four -side top -fill both pack $d.buttons -side bottom -fill both label $d.text -text "Agent:" entry $d.name -textvariable name pack $d.text -in $d.main -side left pack $d.name -in $d.main -side left .tempDialog.name delete 0 40 .tempDialog.name insert 0 [append AgentName "_Puller"] .tempDialog.name config -state disabled label $d.text1 -text "Place:" entry $d.place -textvariable Place -width 25 button $d.save -text "Save place" -command { lappend Nodes $Place foreach node [.tempDialog.list1 get 0 end] { set temp "$Place:$node" lappend Files $temp } } .tempDialog.place delete 0 end pack $d.text1 $d.place -in $d.one -side left pack $d.save -in $d.one -side right label $d.text2 -text "Topic:" entry $d.topic -textvariable topic pack $d.text2 -in $d.two -side left pack $d.topic -in $d.two -side left .tempDialog.topic delete 0 40 .tempDialog.topic insert 0 $topic .tempDialog.topic config -state disabled label $d.text3 -text "Files" label $d.text4 -text "Images" pack $d.text3 -in $d.three -side left pack $d.text4 -in $d.three -side right listbox $d.list1 -yscrollcommand [list $d.scroll1 set] -selectmode extended scrollbar $d.scroll1 -command [list $d.list1 yview] pack $d.list1 -in $d.four -side left -fill both pack $d.scroll1 -in $d.four -side right -fill y listbox $d.list2 -yscrollcommand [list $d.scroll2 set] -selectmode extended scrollbar $d.scroll2 -command [list $d.list2 yview] pack $d.list2 -in $d.four -side right -fill both pack $d.scroll2 -in $d.four -side right -fill y bind $d.list1 <3> { set lines [.tempDialog.list1 curselection]; .tempDialog.list1 delete [lindex $lines 0] [lindex $lines 0]; set lines [lrange $lines 1 end]; set index 0; set step 1; for {set i 0} {$i < [llength $lines] } { incr i} { set index [lindex $lines $i]; set index [expr $index-$step]; set step [expr $step+1]; .tempDialog.list1 delete $index $index; } } bind $d.list2 <3> { set lines [.tempDialog.list2 curselection]; .tempDialog.list2 delete [lindex $lines 0] [lindex $lines 0]; set lines [lrange $lines 1 end]; set index 0; set step 1; for {set i 0} {$i < [llength $lines] } { incr i} { set index [lindex $lines $i]; set index [expr $index-$step]; set step [expr $step+1]; .tempDialog.list2 delete $index $index; } } set img1 [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] set img2 [image create photo -file /home/u/raid/vol07/is091892/html/cancel.gif] button $d.ok -image $img1 -command { destroy .tempDialog set Places($name) ""; NewAgent $name; set viewed 0 exec /home/u/raid/vol07/is091892/Agent_Tcl/Trapper.tk $name $Nodes $topic $Files } button $d.cancel -image $img2 -command { set viewed 0; destroy .tempDialog } button $d.delete -text "Delete all" -command { .tempDialog.list1 delete 0 end; \ .tempDialog.list2 delete 0 end; .tempDialog.place delete 0 25 } pack $d.ok $d.cancel $d.delete -in $d.buttons -side left -expand 1 -padx 2m -pady 2m } #______________________________________________________________________________ proc AboutTcl{ } { global prompt set d [toplevel .aboutTcl -borderwidth 3] wm title $d "A b o u t A g e n t T c l . . . " frame $d.one -relief raised -bd 1 frame $d.two -relief raised -bd 1 frame $d.buttons -relief raised -bd 1 pack $d.one -side top -fill both pack $d.two -side top -fill both pack $d.buttons -side top -fill both set img [image create photo -file /home/u/raid/vol07/is091892/html/agenttcl.gif] label $d.agent -image $img label $d.title -text "Agent Tcl" pack $d.agent -in $d.one -side left -padx 2m -pady 2m pack $d.title -in $d.one -side left -expand 1 -padx 2m -pady 2m text $d.text -bd 2 -yscrollcommand [list $d.scroll set] scrollbar $d.scroll -command [list $d.text yview] pack $d.scroll -in $d.two -side right -fill y pack $d.text -in $d.two -side left -fill both -expand 1 set img [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] button $d.ok -image $img -command {set prompt(okay) 1} pack $d.ok -in $d.buttons -side right -expand 1 -padx 2m -pady 2m #set f [open /home/u/raid/vol07/is091892/Agent_Tcl/contents.txt] #while {[gets $f line] >= 0} { # $d.text insert end $line # $d.text insert end "\n" # } grab set $d tkwait variable prompt(okay) grab release $d destroy $d } #______________________________________________________________________________ proc About{ } { global prompt set d [toplevel .about] wm title $d "A b o u t . . . " frame $d.one -relief raised -bd 2 frame $d.two -relief raised -bd 2 frame $d.buttons -relief raised -bd 2 pack $d.one -side top -fill both pack $d.two -side top -fill both pack $d.buttons -side bottom -fill both set img [image create photo -file /home/u/raid/vol07/is091892/html/Sun.gif] label $d.image -image $img message $d.title -text "Data Seeking System\n Alpha System 1.01" pack $d.image -in $d.one -side left -padx 3m -pady 2m pack $d.title -in $d.one -side left -expand true -padx 1m text $d.text -bd 2 -yscrollcommand [list $d.scroll set] scrollbar $d.scroll -command [list $d.text yview] pack $d.scroll -in $d.two -side right -fill y pack $d.text -in $d.two -side left -fill both -expand 1 set img [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] button $d.ok -image $img -command {set prompt(okay) 1} pack $d.ok -in $d.buttons -side right -expand 1 -padx 2m -pady 2m set f [open /home/u/raid/vol07/is091892/Agent_Tcl/contents.txt] while {[gets $f line] >= 0} { $d.text insert end $line $d.text insert end "\n" } grab set $d tkwait variable prompt(okay) grab release $d destroy $d } #______________________________________________________________________________ proc fileList { path } { global file .fileDialog.path config -state normal .fileDialog.path delete 0 end .fileDialog.path insert 0 $path .fileDialog.path config -state disabled .fileDialog.path xview moveto 1 set file(path) $path .fileDialog.list1 delete 0 end .fileDialog.list2 delete 0 end .fileDialog.list1 insert 0 Listing... update idletasks .fileDialog.list1 delete 0 end set files [glob -nocomplain $file(path)/*] .fileDialog.list1 insert end ../ set dirs {} set others {} foreach f [lsort $files] { if [file isdirectory $f] { lappend dirs [file tail $f]/ } else { lappend others [file tail $f] } } if {[llength $dirs] != 0} { foreach f $dirs { .fileDialog.list1 insert end $f } } if {[llength $others] != 0} { foreach f $others { .fileDialog.list2 insert end $f } } } #______________________________________________________________________________ proc fileDialog{ } { global file set d [toplevel .fileDialog -bd 2] wm title $d "Save as" frame $d.one -relief raised -bd 1 frame $d.two -relief raised -bd 1 frame $d.three -relief raised -bd 1 frame $d.four -relief raised -bd 1 frame $d.buttons -relief raised -bd 1 pack $d.one -side top -fill both pack $d.two -side top -fill both pack $d.three -side top -fill both pack $d.four -side top -fill both pack $d.buttons -side bottom -fill both set img1 [image create photo -file /home/u/raid/vol07/is091892/html/yes.gif] set img2 [image create photo -file /home/u/raid/vol07/is091892/html/cancel.gif] set file(path) [entry $d.path -width 30 -relief flat -state disabled] pack $d.path -in $d.one -side top -fill x label $d.text1 -text "File:" -padx 0 set e [entry $d.file -relief sunken -textvariable file(file)] .fileDialog.file delete 0 end pack $d.text1 -side left -in $d.two pack $d.file -side left -in $d.two label $d.text2 -text "Directories:" -padx 35 label $d.text3 -text "Files:" -padx 75 pack $d.text2 -in $d.three -side left pack $d.text3 -in $d.three -side right listbox $d.list1 -yscrollcommand [list $d.scroll2 set] bind $d.list1 { set id [.fileDialog.list1 get active active] if {$id == "../"} { set files $file(path) set files [split $files /] set len [expr [llength $files] - 2] set dir {} for {set i 0} { $i < $len} {incr i} { append dir "[lindex $files $i]/" } # append dir [lindex $files $i] set path $dir } else { set path "$file(path)$id" } fileList $path } scrollbar $d.scroll1 -command [list $d.list2 yview] pack $d.list1 -in $d.four -side left -fill both pack $d.scroll1 -in $d.four -side right -fill y listbox $d.list2 -yscrollcommand [list $d.scroll1 set] scrollbar $d.scroll2 -command [list $d.list1 yview] pack $d.list2 -in $d.four -side right -fill both pack $d.scroll2 -in $d.four -side right -fill y button $d.ok -image $img1 -command {set prompt(okay) 1} button $d.cancel -image $img2 -command {set prompt(okay) 0} pack $d.ok $d.cancel -in $d.buttons -side left -expand 1 -padx 2m -pady 2m focus .fileDialog.file set path "[pwd]/" tkwait visibility .fileDialog.list1 fileList $path grab set $d tkwait variable prompt(okay) grab release $d destroy $d return "$file(path)$file(file)" } #______________________________________________________________________________ proc ValidateFile{ } { global prompt global file set flag 1; set Okname 0 fileDialog{ } if {$prompt(okay) == 1} { while {$flag == 1} { set msg ""; set Okname 0 if {$file(file) == ""} { set flag 1; set msg "No filename gotten." } else { set Okname 1 } # set value [expr ($Okname != 1) || ($flag == 1)] if {$Okname != 1} { StatusBox $msg 2; fileDialog{ } if {$prompt(okay) == 1} { set flag 1 } else { set flag 0 } } else { set flag 0} } if {$prompt(okay) == 1} { if {[file exists $file(path)$file(file)]} { StatusBox "The file $file(file) already exists." 1 } else { set handler [open $file(path)$file(file) w]; puts $handler [.text get 1.0 end] close $handler StatusBox "The file $file(file) has been saved succesfully." 1 } } } } #______________________________________________________________________________ proc NewAgent { name } { global number global Agents set Agents($name) $name incr number } #______________________________________________________________________________ proc Change { w msg } { $w config -state normal $w delete 0 25 $w insert 0 $msg $w config -state disabled } #______________________________________________________________________________ proc Erase { w } { $w config -state normal $w delete 0 50 $w config -state disabled } #______________________________________________________________________________ frame .mbar -relief raised -bd 2 pack .mbar -side top -fill x menubutton .mbar.agent -text Agent -underline 0 -menu .mbar.agent.menu menubutton .mbar.options -text Options -underline 0 -menu .mbar.options.menu menubutton .mbar.help -text Help -underline 0 -menu .mbar.help.menu pack .mbar.agent .mbar.options -side left pack .mbar.help -side right menubutton .float -text float -menu .float.menu menu .float.menu -tearoff 0 .float.menu add command -label "Create a seeker" -command { ValidateInputs{ } } .float.menu add command -label "Create a retriever" -command { if {$used == 1} { set topic [lindex [split [lindex [split [.text get 1.0 1.end] "\t"] 0] :] 1] set agent_name [lindex [split [lindex [split [.text get 1.0 1.end] "\t"] 2] :] 1] TempDialog $agent_name $topic } else { StatusBox "There is no information on desktop to create a pull-agent" 2 } } .float.menu add command -label "Save to disk" -command { if {$used == 1} { ValidateFile{ } } } .float.menu add command -label "Delete desktop" -command { .text config -state normal; .text delete 1.0 end .text config -state disabled; set used 0 } menu .mbar.agent.menu .mbar.agent.menu add cascade -label Create -menu .mbar.agent.menu.submenu menu .mbar.agent.menu.submenu -tearoff 0 .mbar.agent.menu.submenu add command -label Seeker -command { ValidateInputs{ } } .mbar.agent.menu.submenu add command -label Retriever -command { set topic [lindex [split [lindex [split [.text get 1.0 1.end] "\t"] 0] :] 1] set agent_name [lindex [split [lindex [split [.text get 1.0 1.end] "\t"] 2] :] 1] TempDialog $agent_name $topic } .mbar.agent.menu add command -label List -command { DisplayAgents{ } } .mbar.agent.menu add command -label Save -command { if {$used == 1} { ValidateFile{ } } } .mbar.agent.menu add separator .mbar.agent.menu add command -label Exit -command { if {[StatusBox "Do you really want to quit ?" 3] == 1} { agent_end; exit } } menu .mbar.options.menu .mbar.options.menu add command -label "Agent Info" -command { DisplayAgentInfo{ } } .mbar.options.menu add command -label "Current nodes" -command { DisplayNodes{ } } menu .mbar.help.menu .mbar.help.menu add command -label Contents -command { } .mbar.help.menu add command -label "About Agent Tcl" -command { AboutTcl{ } } .mbar.help.menu add separator .mbar.help.menu add command -label "About..." -command { About{ } } tk_menuBar .mbar .mbar.agent .mbar.message .mbar.options .mbar.help focus .mbar bind .mbar.agent { Change .status1 "Actions regard with Agents"} bind .mbar.agent { Erase .status1} bind .mbar.options { Change .status1 "System features"} bind .mbar.options { Erase .status1} bind .mbar.help { Change .status1 "System's help"} bind .mbar.help { Erase .status1} frame .top -relief raised -bd 1 frame .middle -relief raised -bd 1 frame .bot -relief groove -bd 1 pack .top -side top -fill both -expand 1 pack .middle -side top -fill both -expand true pack .bot -side bottom -fill both -expand true set img1 [image create photo -file /home/u/raid/vol07/is091892/html/disco.gif] set img2 [image create photo -file /home/u/raid/vol07/is091892/html/printer.gif] set img3 [image create photo -file /home/u/raid/vol07/is091892/html/tw.GIF] set img4 [image create photo -file /home/u/raid/vol07/is091892/html/world2.gif] button .new -image $img3 -command { ValidateInputs{ } } button .saveas -image $img1 -command { if {$used ==1} { ValidateFile{ } } } button .printer -image $img2 -command { } button .pull -image $img4 -command { if {$used == 1} { set topic [lindex [split [lindex [split [.text get 1.0 1.end] "\t"] 0] :] 1] set agent_name [lindex [split [lindex [split [.text get 1.0 1.end] "\t"] 2] :] 1] TempDialog $agent_name $topic } else { StatusBox "There is no information on desktop to create a retriever agent" 2 } } button .delete -text "Delete" -command { .text config -state normal; .text delete 1.0 end; \ .text config -state disabled; set used 0 } pack .new .saveas .printer .pull -in .top -side left pack .delete -in .top -side right bind .new { Change .status1 "Create a seeker agent" } bind .new { Erase .status1 } bind .saveas { Change .status1 "Save desktop's info to disk" } bind .saveas { Erase .status1 } bind .printer { Change .status1 "Print desktop's info" } bind .printer { Erase .status1 } bind .pull { Change .status1 "Create a retriever agent" } bind .pull { Erase .status1 } bind .delete { Change .status1 "Delete desktop" } bind .delete { Erase .status1 } text .text -bd 2 -yscrollcommand ".scroll set" -state disabled scrollbar .scroll -command ".text yview" pack .scroll -in .middle -side right -fill y pack .text -in .middle -side left -fill both -expand 1 set used 0 bind .text { if {$used == 1} { set text [.text get "insert wordstart" "insert lineend"] set text [split $text " "] } } bind .text <2> { if {$used == 1 && $status == 0} { if {$viewed == 0} { set topic [lindex [split [lindex [split [.text get 1.0 1.end] "\t"] 0] :] 1] set agent_name [lindex [split [lindex [split [.text get 1.0 1.end] "\t"] 2] :] 1] TempDialog $agent_name $topic } if {[lindex $text end] == "##########>"} { .tempDialog.place delete 0 25; .tempDialog.place insert 0 [lindex $text 0] } elseif {[lindex [split [lindex $text 0] .] end] == "gif"} { .tempDialog.list2 insert end [lindex $text 0] } else { .tempDialog.list1 insert end [lindex $text 0]} } } bind .text { Change .status1 "Area for discharging Agent's info" } bind .text { Erase .status1 } bind .text <3> { tk_popup .float.menu %x %y} entry .status1 -width 70 -state disabled entry .status2 -width 10 pack .status1 -in .bot -side left pack .status2 -in .bot -side right #______________________________________________________________________________