Changeset 1342 for trunk/gui/scripts/service.tcl
- Timestamp:
- Mar 18, 2009, 2:59:21 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/service.tcl
r115 r1342 45 45 itcl::body Rappture::Service::constructor {owner path args} { 46 46 if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { 47 47 error "bad object \"$owner\": should be Rappture::ControlOwner" 48 48 } 49 49 set _owner $owner … … 55 55 set intf [$_owner xml get $path.interface] 56 56 if {"" == $intf} { 57 57 puts "can't find <interface> description for tool at $path" 58 58 } else { 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 59 set installdir [[$_owner tool] installdir] 60 regsub -all @tool $intf $installdir intf 61 62 set xmlobj [Rappture::library $intf] 63 set installdir [file dirname $intf] 64 set _tool [Rappture::Tool ::#auto $xmlobj $installdir] 65 set _control [$_tool xml get tool.control] 66 67 # 68 # Scan through the <tool> and establish all of the 69 # relationships: 70 # 71 # <show> ... Add to list of "input" for this service. 72 # Caller will add controls to the interface. 73 # 74 # <link> ... Link this value to another input/output 75 # that exists in the containing tool. 76 # 77 # <set> .... Hard-code the value for this input/output. 78 # 79 foreach dir {input output} { 80 set _show($dir) "" 81 foreach cname [$_owner xml children $path.$dir] { 82 set ppath $path.$dir.$cname 83 84 set spath [$_owner xml get $ppath.path] 85 if {"" == $spath} { 86 error "missing <path> at $ppath" 87 } 88 89 set type [$_owner xml element -as type $ppath] 90 switch -- $type { 91 show { 92 92 puts "show: $spath" 93 94 95 96 97 93 set tpath [$_owner xml get $ppath.to] 94 if {"" == $tpath && $dir == "input"} { 95 error "missing <to> at $ppath" 96 } 97 set obj [$_tool xml element -as object $spath] 98 98 puts " => $obj" 99 100 101 102 99 lappend _show($dir) $obj 100 set _obj2path($obj) $spath 101 102 if {$dir == "input"} { 103 103 puts "link: $tpath => $spath" 104 105 106 107 108 109 110 111 112 113 114 115 116 104 $_owner notify add $this $tpath \ 105 [itcl::code $this _link $tpath $spath] 106 } 107 } 108 link { 109 set tpath [$_owner xml get $ppath.to] 110 if {"" == $tpath} { 111 error "missing <to> at $ppath" 112 } 113 if {"" == [$_owner xml element $tpath]} { 114 error "bad <to> path \"$tpath\" at $ppath" 115 } 116 if {$dir == "input"} { 117 117 puts "link: $tpath => $spath" 118 119 120 118 $_owner notify add $this $tpath \ 119 [itcl::code $this _link $tpath $spath] 120 } else { 121 121 puts "path2path: $spath => $tpath" 122 123 124 125 126 127 128 122 set _path2path($spath) $tpath 123 } 124 } 125 set { 126 if {"" == [$_owner xml element $ppath.value]} { 127 error "missing <value> at $ppath" 128 } 129 129 puts "set: $spath from $ppath.value" 130 131 132 133 134 135 136 137 138 139 140 141 130 $_tool xml copy $spath from \ 131 [$_owner xml object] $ppath.value 132 } 133 } 134 } 135 } 136 137 if {$_control != "auto"} { 138 set _show(control) [$_tool xml element -as object tool.control] 139 } else { 140 set _show(control) "" 141 } 142 142 } 143 143 … … 150 150 itcl::body Rappture::Service::destructor {} { 151 151 foreach dir [array names _show] { 152 153 154 152 foreach obj $_show($dir) { 153 itcl::delete object $obj 154 } 155 155 } 156 156 } … … 194 194 itcl::body Rappture::Service::output {args} { 195 195 if {[llength $args] == 0} { 196 196 return $_show(output) 197 197 } 198 198 set option [lindex $args 0] 199 199 switch -- $option { 200 201 202 203 204 205 206 207 200 for { 201 if {[llength $args] != 3} { 202 error "wrong # args: should be \"output for object widget\"" 203 } 204 set obj [lindex $args 1] 205 set win [lindex $args 2] 206 if {[info exists _obj2path($obj)]} { 207 set path $_obj2path($obj) 208 208 puts "OUTPUT $path => $win" 209 210 211 212 213 214 215 216 209 set _path2widget($path) $win 210 } else { 211 puts "error: don't recognize output object $obj" 212 } 213 } 214 default { 215 error "bad option \"$option\": should be for" 216 } 217 217 } 218 218 } … … 235 235 236 236 if {$status == 0 && $result != "ABORT"} { 237 238 239 240 241 242 243 237 if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} { 238 set xmlobj [Rappture::library $file] 239 # 240 # Scan through all outputs and copy them to the final output 241 # for the tool. If they have widgets associated with them, 242 # set the value for the widget. 243 # 244 244 puts "showing output..." 245 246 245 foreach cname [$xmlobj children output] { 246 set path output.$cname 247 247 puts " for $path" 248 249 250 251 248 $_owner xml copy $path from $xmlobj $path 249 250 if {[info exists _path2widget($path)]} { 251 set obj [$xmlobj element -as object $path] 252 252 puts " sending $obj to $_path2widget($path)" 253 254 255 253 $_path2widget($path) value $obj 254 } 255 if {[info exists _path2path($path)]} { 256 256 puts " sending $path to $_path2path($path)" 257 258 259 260 261 262 263 264 265 266 267 268 269 257 $_owner xml copy $_path2path($path) from $xmlobj $path 258 set w [$_owner widgetfor $_path2path($path)] 259 if {$w != ""} { 260 set obj [$_owner xml element -as object $_path2path($path)] 261 $w value $obj 262 } 263 } 264 } 265 set _result $xmlobj 266 } else { 267 set status 1 268 set result "Can't find result file in output:\n\n$result" 269 } 270 270 } 271 271 } … … 288 288 itcl::body Rappture::Service::clear {} { 289 289 if {"" != $_result} { 290 291 292 293 294 295 296 297 298 290 foreach cname [$_result children output] { 291 set path output.$cname 292 293 if {[info exists _path2widget($path)]} { 294 $_path2widget($path) value "" 295 } 296 } 297 itcl::delete object $_result 298 set _result "" 299 299 } 300 300 } … … 312 312 313 313 if {$_control == "auto" && [regexp -nocase {^input\.} $to]} { 314 315 316 } 317 } 314 after cancel [itcl::code $this run] 315 after idle [itcl::code $this run] 316 } 317 }
Note: See TracChangeset
for help on using the changeset viewer.