Changeset 3636
- Timestamp:
- Apr 25, 2013, 7:04:34 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/builder/scripts/templates/ruby.tl
r3177 r3636 86 86 code "\n# save output value for $path" 87 87 code "# data should be base64-encoded image data" 88 code "io.put(\"$path.current\", imdata )"88 code "io.put(\"$path.current\", imdata, Rappture::OVERWRITE)" 89 89 } 90 90 output * { 91 91 code "\n# save output value for $path" 92 code "io.put(\"$path.current\",$id )"92 code "io.put(\"$path.current\",$id, Rappture::OVERWRITE)" 93 93 } 94 94 } -
trunk/examples/zoo/drawing/tool.xml
r3077 r3636 93 93 <anchor>nw</anchor> 94 94 </text> 95 <hotspot id="feature_height">96 <coords>.95 .53</coords>97 <controls>input.choice(analysis)</controls>98 <controls>input.number(feature_height)</controls>99 <controls>input.number(feature_length)</controls>100 <controls>input.number(substrate_length)</controls>101 </hotspot>102 95 <line id="substrate_length"> 103 96 <coords>0 .8 1 .8</coords> … … 133 126 <linewidth>2</linewidth> 134 127 </line> 128 <rectangle id="border"> 129 <coords>-0.05 0.05 0.3 0.35</coords> 130 <outline>black</outline> 131 <linewidth>5</linewidth> 132 </rectangle> 135 133 <picture id="analysis"> 136 <coords>-.08 .06 0.17 0.15</coords> 137 <contents>file:images/${analysis}_F-d.png</contents> 138 <anchor>nw</anchor> 134 <coords>-0.05 0.05 0.3 0.35</coords> 135 <contents>file://images/${analysis}_F-d.png</contents> 139 136 </picture> 140 137 <text id="analysis"> 141 <coords>. 05 .4</coords>138 <coords>.125 .36</coords> 142 139 <color>black</color> 143 140 <text>${analysis}</text> 144 141 <font>Arial 11</font> 145 142 <anchor>n</anchor> 146 <hotspot>inline</hotspot>147 143 </text> 148 144 <text id="string"> -
trunk/gui/scripts/Makefile.in
r3471 r3636 44 44 $(srcdir)/dispatcher.tcl \ 45 45 $(srcdir)/drawing.tcl \ 46 $(srcdir)/drawingcontrols.tcl \47 46 $(srcdir)/drawingentry.tcl \ 48 47 $(srcdir)/dropdown.tcl \ -
trunk/gui/scripts/contourresult.tcl
r3330 r3636 591 591 return 592 592 } 593 puts stderr "ContourResult: dataobj=$dataobj mesh=$mesh "594 593 switch -- [$mesh GetClassName] { 595 594 vtkPoints { -
trunk/gui/scripts/controlOwner.tcl
r3330 r3636 40 40 protected variable _xmlobj "" ;# Rappture XML description 41 41 private variable _path2widget ;# maps path => widget on this page 42 private variable _path2controls ;# maps path => panel containing widget 42 43 private variable _owner2paths ;# for notify: maps owner => interests 43 44 private variable _type2curpath ;# maps type(path) => path's current value … … 96 97 # ControlOwner knows what widgets to look at when syncing itself 97 98 # to the underlying XML data. 99 # 100 # There can only be one widget per path, since the control owner will 101 # later query the widgets for current values. If there is already an 102 # existing widget registered for the <path>, then it will be deleted 103 # and the new <widget> will take its place. If the caller doesn't 104 # want to replace an existing widget, it should check before calling 105 # this method and make sure that the return value is "". 98 106 # ---------------------------------------------------------------------- 99 107 itcl::body Rappture::ControlOwner::widgetfor {path args} { … … 101 109 if {[llength $args] == 0} { 102 110 set owner [ownerfor $path] 103 if {$owner != $this && $owner !=""} {111 if {$owner ne $this && $owner ne ""} { 104 112 return [$owner widgetfor $path] 105 113 } … … 112 120 # otherwise, associate the path with the given widget 113 121 set widget [lindex $args 0] 114 if {"" != $widget} { 122 if {$widget ne ""} { 123 # is there already a widget registered for this path? 115 124 if {[info exists _path2widget($path)]} { 116 error "$path already associated with widget $_path2widget($path)" 117 } 125 # delete old widget and replace 126 set panel $_path2controls($path) 127 $panel delete $path 128 set _path2controls($path) "" 129 } 130 131 # register the new widget for the path 118 132 set _path2widget($path) $widget 133 134 # look up the containing panel and store it too 135 set w [winfo parent $widget] 136 while {$w ne ""} { 137 if {[string match *Controls [winfo class $w]]} { 138 set _path2controls($path) $w 139 break 140 } 141 set w [winfo parent $w] 142 } 119 143 } else { 144 # empty name => forget about this widget 120 145 catch {unset _path2widget($path)} 146 catch {unset _path2controls($path)} 121 147 } 122 148 } -
trunk/gui/scripts/controls.tcl
r3513 r3636 115 115 # ---------------------------------------------------------------------- 116 116 itcl::body Rappture::Controls::insert {pos path} { 117 if {"end" == $pos} { 118 set pos [llength $_controls] 119 } elseif {![string is integer $pos]} { 120 error "bad index \"$pos\": should be integer or \"end\"" 117 if {$pos ne "end" && ![string is integer $pos]} { 118 set pos [index $pos] 121 119 } 122 120 … … 267 265 } 268 266 set _name2info($name-enable) $enable 269 270 set hidden [string trim [$_owner xml get $_name2info($name-path).hide]]271 if { $hidden != "" } {272 set _name2info($name-enable) [expr !$hidden]273 }274 267 $_owner widgetfor $path $w 275 268 276 if {[lsearch {control group separator note} $type] < 0} {269 if {[lsearch {control group drawing separator note} $type] < 0} { 277 270 # make a label for this control 278 271 set label [$w label] 279 if { "" != $label} {272 if {$label ne ""} { 280 273 set _name2info($name-label) $_frame.l$name 281 274 set font [option get $itk_component(hull) labelFont Font] … … 286 279 # register the tooltip for this control 287 280 set tip [$w tooltip] 288 if { "" != $tip} {281 if {$tip ne ""} { 289 282 Rappture::Tooltip::for $w $tip -log $path 290 283 291 284 # add the tooltip to the label too, if there is one 292 if {$_name2info($name-label) !=""} {285 if {$_name2info($name-label) ne ""} { 293 286 Rappture::Tooltip::for $_name2info($name-label) $tip -log $path 294 287 } … … 321 314 set last $first 322 315 } 323 if {![ regexp {^[0-9]+|end$}$first]} {324 error "bad index \"$first\": should be integer or \"end\""325 } 326 if {![ regexp {^[0-9]+|end$}$last]} {327 error "bad index \"$last\": should be integer or \"end\""316 if {![string is integer $first]} { 317 set first [index $first] 318 } 319 if {![string is integer $last]} { 320 set last [index $last] 328 321 } 329 322 … … 346 339 347 340 # ---------------------------------------------------------------------- 348 # USAGE: index <name>| @n341 # USAGE: index <name>|<path>|@n|end 349 342 # 350 343 # Clients use this to convert a control <name> into its corresponding 351 344 # integer index. Returns an error if the <name> is not recognized. 352 345 # ---------------------------------------------------------------------- 353 itcl::body Rappture::Controls::index { name} {354 set i [lsearch $_controls $ name]346 itcl::body Rappture::Controls::index {val} { 347 set i [lsearch $_controls $val] 355 348 if {$i >= 0} { 356 349 return $i 357 350 } 358 if {[regexp {^@([0-9]+)$} $ namematch i]} {351 if {[regexp {^@([0-9]+)$} $val match i]} { 359 352 return $i 360 353 } 361 if {$ name =="end"} {354 if {$val eq "end"} { 362 355 return [expr {[llength $_controls]-1}] 363 356 } 364 error "bad control name \"$name\": should be @int or one of [join [lsort $_controls] {, }]" 357 358 # treat as a path name and search for this path 359 foreach name $_controls { 360 if {$_name2info($name-path) eq $val} { 361 set i [lsearch $_controls $name] 362 if {$i >= 0} { 363 return $i 364 } 365 } 366 } 367 368 error "bad control name \"$name\": should be @int or \"end\" or path name or one of [join [lsort $_controls] {, }]" 365 369 } 366 370 … … 439 443 set show 1 440 444 set cond $_name2info($name-enable) 441 if {[string is boolean $cond] && !$cond} { 442 # hard-coded "off" -- ignore completely 443 } elseif {[catch {expr $cond} show] == 0} { 445 if {[catch {expr $cond} show] == 0} { 444 446 set type $_name2info($name-type) 445 447 set disablestyle $_name2info($name-disablestyle) -
trunk/gui/scripts/drawingentry.tcl
r3330 r3636 20 20 itk_option define -state state State "normal" 21 21 22 private variable _dispatcher "" 23 private variable _path 24 private variable _owner 25 private variable _monitoring "" 26 private variable _xmlobj "" 27 28 # slave interpreter where all substituted variables are stored 29 private variable _parser "" 30 31 # unique counter for popup names 32 private common _popupnum 0 33 22 34 private variable _canvasHeight 0 23 35 private variable _canvasWidth 0 24 private variable _cname2controls 36 private variable _cpath2popup 37 private variable _takedown "" 25 38 private variable _cname2id 26 39 private variable _cname2image 27 40 private variable _name2path 41 private variable _name2map 28 42 private variable _drawingHeight 0 29 43 private variable _drawingWidth 0 30 private variable _owner31 private variable _xmlobj ""32 private variable _parser ""; # Slave interpreter where all33 # substituted variables are stored.34 private variable _path35 44 private variable _showing "" 36 45 private variable _xAspect 0 … … 56 65 private method Activate { tag } 57 66 private method AdjustDrawingArea { xAspect yAspect } 58 private method ControlValue {path {units ""}}59 67 private method Deactivate { tag } 60 68 private method Highlight { tag } 61 private method InitSubstitutions {}62 69 private method Invoke { name x y } 63 70 private method ParseBackground {} … … 71 78 private method ParseRectangle { cpath cname } 72 79 private method ParseScreenCoordinates { values } 73 private method ParseSubstitutions {}74 80 private method ParseText { cpath cname } 75 81 private method Redraw {} … … 77 83 private method ScreenX { x } 78 84 private method ScreenY { y } 85 private method UpdateSubstitutions {} 79 86 private method XmlGet { path } 80 87 private method XmlGetSubst { path } 81 private method Withdraw { cname }82 88 private method Hotspot { option cname item args } 83 private method IsEnabled { path }84 private method NumControlsEnabled { cname }85 89 } 86 90 … … 102 106 set _owner $owner 103 107 set _xmlobj [$_owner xml object] 108 109 Rappture::dispatcher _dispatcher 110 $_dispatcher register !redraw 111 $_dispatcher dispatch $this !redraw "[itcl::code $this Redraw]; list" 112 104 113 # 105 114 # Display the current drawing. … … 112 121 } 113 122 pack $itk_component(drawing) -expand yes -fill both 114 bind $itk_component(drawing) <Configure> [itcl::code $this Redraw] 123 bind $itk_component(drawing) <Configure> \ 124 [itcl::code $_dispatcher event -idle !redraw] 125 126 # scan through all variables and attach notifications for changes 127 foreach cpath [$_xmlobj children -as path -type variable $_path.substitutions] { 128 set map "" 129 set name "" 130 set path "" 131 foreach elem [$_xmlobj children $cpath] { 132 switch -glob -- $elem { 133 "name*" { 134 set name [XmlGet $cpath.$elem] 135 } 136 "path*" { 137 set path [XmlGet $cpath.$elem] 138 } 139 "map*" { 140 set from [XmlGet $cpath.$elem.from] 141 set to [XmlGet $cpath.$elem.to] 142 if {$from eq "" || $to eq ""} { 143 puts stderr "empty translation in map table \"$cpath\"" 144 } 145 lappend map $from $to 146 } 147 } 148 } 149 if {$name eq ""} { 150 puts stderr "no name defined for substituion variable \"$cpath\"" 151 continue 152 } 153 if {[info exists _name2path($name)]} { 154 puts stderr "substitution variable \"$name\" already defined" 155 continue 156 } 157 set _name2path($name) $path 158 if {$path eq ""} { 159 puts stderr "no path defined for substituion variable \"$cpath\"" 160 continue 161 } 162 set _name2map($name) $map 163 164 # keep track of controls built for each variable (see below) 165 set controls($path) unused 166 167 # whenever variable changes, update drawing to report new values 168 if {[lsearch $_monitoring $path] < 0} { 169 $_owner notify add $this $path \ 170 [itcl::code $_dispatcher event -idle !redraw] 171 lappend _monitoring $path 172 } 173 } 174 175 # find all embedded controls and build a popup for each hotspot 176 foreach cpath [$_xmlobj children -type hotspot -as path $_path.components] { 177 set listOfControls [$_xmlobj children -type controls $cpath] 178 if {[llength $listOfControls] > 0} { 179 set popup .drawingentrypopup[incr _popupnum] 180 Rappture::Balloon $popup -title "Change values..." 181 set inner [$popup component inner] 182 Rappture::Controls $inner.controls $_owner 183 pack $inner.controls -fill both -expand yes 184 set _cpath2popup($cpath) $popup 185 186 # Add control widgets to this popup. 187 # NOTE: if the widget exists elsewhere, it is deleted at this 188 # point and "sucked in" to the popup. 189 foreach cname $listOfControls { 190 set cntlpath [XmlGetSubst $cpath.$cname] 191 $inner.controls insert end $cntlpath 192 } 193 } 194 } 195 196 set c $itk_component(drawing) 197 foreach cpath [$_xmlobj children -type text -as path $_path.components] { 198 set popup "" 199 set mode [XmlGetSubst $cpath.hotspot] 200 if {$mode eq "off"} { 201 # no popup if hotspot is turned off 202 continue 203 } 204 205 # easiest way to parse embedded variables is to create a hotspot item 206 set id [$c create hotspot 0 0 -text [XmlGet $cpath.text]] 207 foreach varName [Rappture::hotspot variables $c $id] { 208 if {[info exists _name2path($varName)]} { 209 set cntlpath $_name2path($varName) 210 211 if {$controls($cntlpath) ne "unused"} { 212 puts stderr "WARNING: drawing variable \"$varName\" is used in two hotspots, but will appear in only one of them." 213 continue 214 } 215 set controls($cntlpath) "--" 216 217 if {$popup eq ""} { 218 # create the popup for this item, if we haven't already 219 set popup .drawingentrypopup[incr _popupnum] 220 Rappture::Balloon $popup -title "Change values..." 221 set inner [$popup component inner] 222 Rappture::Controls $inner.controls $_owner 223 pack $inner.controls -fill both -expand yes 224 } 225 226 # Add the control widget for this variable to this popup. 227 # NOTE: if the widget exists elsewhere, it is deleted at this 228 # point and "sucked in" to the popup. 229 set inner [$popup component inner] 230 $inner.controls insert end $cntlpath 231 set _cpath2popup($cntlpath) $popup 232 } else { 233 puts stderr "unknown variable \"$varName\" in drawing item at $cpath" 234 } 235 } 236 $c delete $id 237 } 238 239 # create a parser to manage substitions of variable values 115 240 set _parser [interp create -safe] 116 Redraw 241 117 242 eval itk_initialize $args 243 244 # initialize the drawing at some point 245 $_dispatcher event -idle !redraw 118 246 } 119 247 120 248 itcl::body Rappture::DrawingEntry::destructor {} { 121 if { $_parser != "" } { 249 # stop monitoring controls for value changes 250 foreach cpath $_monitoring { 251 $_owner notify remove $this $cpath 252 } 253 254 # tear down the value subsitution parser 255 if {$_parser != ""} { 122 256 $_parser delete 123 257 } … … 130 264 # ---------------------------------------------------------------------- 131 265 itcl::body Rappture::DrawingEntry::label {} { 132 return "" 133 set label [$_xmlobj get $_path.about.label] 134 if {"" == $label} { 266 set label [$_owner xml get $_path.about.label] 267 if {$label eq ""} { 135 268 set label "Drawing" 136 269 } … … 147 280 # ---------------------------------------------------------------------- 148 281 itcl::body Rappture::DrawingEntry::tooltip {} { 149 return ""150 282 set str [$_xmlobj get $_path.about.description] 151 283 return [string trim $str] … … 163 295 164 296 itcl::body Rappture::DrawingEntry::Redraw {} { 297 # If a popup is pending, redraw signals a value change; take it down 298 if {$_takedown ne ""} { 299 $_takedown deactivate 300 set _takedown "" 301 } 302 165 303 # Remove exists canvas items and hints 166 304 $itk_component(drawing) delete all 305 167 306 # Delete any images that we created. 168 307 foreach name [array names _cname2image] { 169 308 image delete $_cname2image($name) 170 309 } 171 array unset _name2path172 310 array unset _cname2id 173 array unset _cnames2controls174 311 array unset _cname2image 175 312 … … 194 331 # 195 332 itcl::body Rappture::DrawingEntry::ParseDescription {} { 196 #puts stderr "ParseDescription owner=$_owner path=$_path"197 333 ParseBackground 198 ParseSubstitutions334 UpdateSubstitutions 199 335 foreach cname [$_xmlobj children $_path.components] { 200 336 switch -glob -- $cname { … … 231 367 # 232 368 itcl::body Rappture::DrawingEntry::ParseGrid { cpath cname } { 233 #puts stderr "ParseGrid owner=$_owner cpath=$cpath"234 369 array set attr2option { 235 370 "linewidth" "-width" … … 247 382 # Coords 248 383 set xcoords [XmlGetSubst $cpath.xcoords] 249 set xcoords [string trim $xcoords]250 384 set ycoords [XmlGetSubst $cpath.ycoords] 251 set ycoords [string trim $ycoords]252 385 if { $ycoords == "" } { 253 386 set ycoords "0 1" … … 290 423 set xcoords $list 291 424 } 292 #puts stderr "ParseGrid owner=$_owner cpath=$cpath xcoords=$xcoords ycoords=$ycoords" 425 293 426 set list {} 294 427 foreach attr [$_xmlobj children $cpath] { … … 321 454 "anchor" "-anchor" 322 455 } 323 #puts stderr "ParseHotspot owner=$_owner cpath=$cpath" 456 324 457 # Set default options first and then let tool.xml override them. 325 458 array set options { … … 327 460 -anchor c 328 461 } 329 array unset _cname2controls $cname330 462 foreach attr [$_xmlobj children $cpath] { 331 463 if { [info exists attr2option($attr)] } { … … 333 465 set value [XmlGetSubst $cpath.$attr] 334 466 set options($option) $value 335 } elseif { [string match "controls*" $attr] } {336 set value [XmlGetSubst $cpath.$attr]337 lappend _cname2controls($cname) $value338 $_xmlobj put $value.hide 1339 467 } 340 468 } 341 469 # Coordinates 342 470 set coords [XmlGetSubst $cpath.coords] 343 set coords [ScreenCoords $coords] 344 if { $coords == "" } { 471 if {$coords eq ""} { 345 472 set coords "0 0 1 1" 346 } 473 } 347 474 set c $itk_component(drawing) 348 set img [Rappture::icon hotspot_normal] 349 foreach { x1 y1 } $coords break 475 foreach {x1 y1} [ScreenCoords $coords] break 350 476 set id [$itk_component(drawing) create image $x1 $y1] 351 477 array unset options -fill 352 478 set options(-tags) $cname 353 set options(-image) $img479 set options(-image) [Rappture::icon hotspot_normal] 354 480 eval $c itemconfigure $id [array get options] 355 481 set _cname2id($cname) $id 356 482 $c bind $id <Enter> [itcl::code $this Activate $cname] 357 483 $c bind $id <Leave> [itcl::code $this Deactivate $cname] 358 #$c bind $id <ButtonPress-1> [itcl::code $this Depress $cname]359 484 set bbox [$c bbox $id] 360 485 set y1 [lindex $bbox 1] 361 $c bind $id <ButtonPress-1> [itcl::code $this Invoke $c name$x1 $y1]486 $c bind $id <ButtonPress-1> [itcl::code $this Invoke $cpath $x1 $y1] 362 487 } 363 488 … … 380 505 } 381 506 # Coords 382 set coords {}383 507 set coords [XmlGetSubst $cpath.coords] 384 set coords [string trim $coords] 385 if { $coords == "" } { 508 if {$coords eq ""} { 386 509 set coords "0 0" 387 } else { 388 set coords [ScreenCoords $coords] 389 } 390 #puts stderr "ParseLine owner=$_owner cpath=$cpath coords=$coords" 510 } 511 set coords [ScreenCoords $coords] 512 391 513 set list {} 392 514 foreach attr [$_xmlobj children $cpath] { … … 412 534 "linewidth" "-width" 413 535 } 414 #puts stderr "ParseOval owner=$_owner cpath=$cpath"415 536 416 537 # Set default options first and then let tool.xml override them. … … 428 549 } 429 550 # Coordinates 430 set coords {}431 551 set coords [XmlGetSubst $cpath.coords] 432 set coords [string trim $coords] 433 if { $coords == "" } { 552 if {$coords eq ""} { 434 553 set coords "0 0 1 1" 435 554 } … … 447 566 "anchor" "-anchor" 448 567 } 449 #puts stderr "ParsePicture owner=$_owner cpath=$cpath" 568 450 569 # Set default options first and then let tool.xml override them. 451 570 array set options { … … 462 581 set img "" 463 582 if { [string compare -length 7 $contents "file://"] == 0 } { 464 set fileName [string range $contents 5end]583 set fileName [string range $contents 7 end] 465 584 if { [file exists $fileName] } { 466 585 set img [image create photo -file $fileName] 467 } 586 } else { 587 puts stderr "WARNING: can't find picture contents \"$fileName\"" 588 } 468 589 } elseif { [string compare -length 7 $contents "http://"] == 0 } { 469 590 puts stderr "don't know how to handle http" … … 472 593 set img [image create photo -data $contents] 473 594 } 474 if { $img == ""} {595 if {$img eq ""} { 475 596 return 476 597 } 477 598 # Coordinates 478 599 set coords [XmlGetSubst $cpath.coords] 479 set coords [ScreenCoords $coords]480 600 if { [llength $coords] == 2 } { 481 foreach { x1 y1 } $coordsbreak601 foreach { x1 y1 } [ScreenCoords $coords] break 482 602 set w [XmlGetSubst $cpath.width] 483 603 if { $w == "" || ![string is number $w] || $w <= 0.0 } { … … 494 614 if { $width != [image width $img] || $height != [image height $img] } { 495 615 set dst [image create photo -width $width -height $height] 496 blt::winop resample $img $d est616 blt::winop resample $img $dst 497 617 image delete $img 498 618 set img $dst 499 619 } 500 620 } elseif { [llength $coords] == 4 } { 501 foreach { x1 y1 x2 y2 } $coordsbreak621 foreach { x1 y1 x2 y2 } [ScreenCoords $coords] break 502 622 if { $x1 > $x2 } { 503 623 set tmp $x1 … … 510 630 set x2 $tmp 511 631 } 512 set width [expr $x2 - $x1 + 1]513 set height [expr $x2 - $x1 + 1]632 set width [expr {$x2 - $x1 + 1}] 633 set height [expr {$y2 - $y1 + 1}] 514 634 if { $width != [image width $img] || $height != [image height $img] } { 515 635 set dst [image create photo -width $width -height $height] … … 548 668 -outline black 549 669 } 670 550 671 # Coords 551 672 set coords [XmlGetSubst $cpath.coords] 552 set coords [string trim $coords] 553 if { $coords == "" } { 673 if {$coords eq ""} { 554 674 set coords "0 0" 555 } else { 556 set coords [ScreenCoords $coords] 557 } 558 set x1 [lindex $coords 0] 559 set y1 [lindex $coords 1] 560 lappend coords $x1 $y1 561 #puts stderr "ParsePolygon owner=$_owner cpath=$cpath coords=$coords" 675 } 676 set coords [ScreenCoords $coords] 677 562 678 set list {} 563 679 foreach attr [$_xmlobj children $cpath] { … … 583 699 "linewidth" "-width" 584 700 } 585 #puts stderr "ParseRectangle owner=$_owner cpath=$cpath"586 701 587 702 # Set default options first and then let tool.xml override them. … … 600 715 # Coordinates 601 716 set coords [XmlGetSubst $cpath.coords] 602 set coords [string trim $coords] 603 if { $coords == "" } { 717 if {$coords eq ""} { 604 718 set coords "0 0 1 1" 605 719 } 606 720 foreach { x1 y1 x2 y2 } [ScreenCoords $coords] break 607 set id [$itk_component(drawing) create rectangle $x1 $y1 $x2 $y2]721 set id [$itk_component(drawing) create rectangle $x1 $y1 $x2 $y2] 608 722 set _cname2id($cname) $id 609 723 eval $itk_component(drawing) itemconfigure $id [array get options] … … 621 735 "anchor" "-anchor" 622 736 } 623 #puts stderr "ParseText owner=$_owner cpath=$cpath"624 737 625 738 # Set default options first and then let tool.xml override them. 626 739 array set options { 627 -font {Arial 12}628 -valuefont {Arial 12}740 -font {Arial -14} 741 -valuefont {Arial -14} 629 742 -valueforeground blue3 630 743 -text {} … … 645 758 # Coords 646 759 set coords [XmlGetSubst $cpath.coords] 647 set coords [string trim $coords] 648 if { $coords == "" } { 649 set coords "0 0" 650 } else { 651 set coords [ScreenCoords $coords] 652 } 760 if {$coords eq ""} { 761 set coords "0 0" 762 } 763 foreach {x0 y0} [ScreenCoords $coords] break 764 653 765 set hotspot [XmlGetSubst $cpath.hotspot] 654 if { $hotspot == "inline" } { 766 if {$hotspot eq ""} { 767 # assume inline by default 768 set hotspot "inline" 769 } elseif {[lsearch {inline off} $hotspot] < 0} { 770 puts stderr "WARNING: bad hotspot value \"$hotspot\": should be inline or off" 771 } 772 773 if {$hotspot eq "inline"} { 655 774 set options(-showicons) 1 656 775 } 657 776 set c $itk_component(drawing) 658 777 set options(-tags) $cname 659 set img [Rappture::icon hotspot_normal] 660 set options(-image) $img 661 set img [Rappture::icon hotspot_active] 662 set options(-activeimage) $img 663 set id [eval $c create hotspot $coords] 778 set options(-image) [Rappture::icon hotspot_normal] 779 set options(-activeimage) [Rappture::icon hotspot_active] 780 set id [$c create hotspot $x0 $y0] 664 781 set _cname2id($cname) $id 665 782 set options(-interp) $_parser 666 783 eval $c itemconfigure $id [array get options] 667 if { $hotspot == "inline" } { 668 array unset _cname2controls $cname 669 foreach varName [Rappture::hotspot variables $c $id] { 670 if { [info exists _name2path($varName)] } { 671 set path $_name2path($varName) 672 $_xmlobj put $path.hide 1 673 lappend _cname2controls($cname) $path 674 } else { 675 puts stderr "unknown varName=$varName" 676 } 677 } 784 785 if {$hotspot eq "inline"} { 786 $c bind $id <Enter> \ 787 [itcl::code $this Hotspot activate $cname $id %x %y] 678 788 $c bind $id <Motion> \ 679 [itcl::code $this Hotspot watch$cname $id %x %y]789 [itcl::code $this Hotspot activate $cname $id %x %y] 680 790 $c bind $id <Leave> \ 681 791 [itcl::code $this Hotspot deactivate $cname $id] 682 $c bind $id <Enter> \683 [itcl::code $this Hotspot activate $cname $id %x %y]684 792 $c bind $id <ButtonRelease-1> \ 685 793 [itcl::code $this Hotspot invoke $cname $id %x %y] … … 689 797 690 798 itcl::body Rappture::DrawingEntry::Hotspot { option cname item args } { 691 if { [NumControlsEnabled $cname] == 0 } {692 return693 }694 799 set c $itk_component(drawing) 800 801 # see what variable (if any) that we're touching within the text 802 set varName "" 803 if {[llength $args] >= 2} { 804 foreach {x y} $args break 805 foreach {varName x0 y0 x1 y1} [Rappture::hotspot identify $c $item $x $y] break 806 } 807 695 808 switch -- $option { 696 "activate" { 697 foreach { x y } $args break 698 set varName [Rappture::hotspot identify $c $item $x $y] 699 $c itemconfigure $item -activevalue $varName 700 } 701 "deactivate" { 809 activate { 810 if {$varName ne ""} { 811 set active [$c itemcget $item -activevalue] 812 if {$varName ne $active} { 813 $c itemconfigure $item -activevalue $varName 814 } 815 $itk_component(drawing) configure -cursor center_ptr 816 817 # put up a tooltip for this item 818 set cpath $_name2path($varName) 819 set tip [XmlGet $cpath.about.description] 820 if {$tip ne ""} { 821 set x [expr {[winfo rootx $c]+$x0+10}] 822 set y [expr {[winfo rooty $c]+$y1}] 823 set tag "$c-[string map {. ""} $cpath]" 824 Rappture::Tooltip::text $tag $tip -log $cpath 825 Rappture::Tooltip::tooltip pending $tag @$x,$y 826 } 827 } else { 828 $c itemconfigure $item -activevalue "" 829 $itk_component(drawing) configure -cursor "" 830 Rappture::Tooltip::tooltip cancel 831 } 832 } 833 deactivate { 702 834 $c itemconfigure $item -activevalue "" 703 } 704 "watch" { 705 foreach { x y } $args break 706 set active [$c itemcget $item -activevalue] 707 set varName [Rappture::hotspot identify $c $item $x $y] 708 if { $varName != $active } { 709 $c itemconfigure $item -activevalue $varName 710 } 711 } 712 "invoke" { 713 foreach { x y } $args break 714 set active [$c itemcget $item -activevalue] 715 set varName [Rappture::hotspot identify $c $item $x $y] 716 if { $varName != "" } { 717 set bbox [$c bbox $item] 718 Invoke $cname $x [lindex $bbox 1] 719 } 720 } 835 $itk_component(drawing) configure -cursor "" 836 Rappture::Tooltip::tooltip cancel 837 } 838 invoke { 839 if {$varName ne ""} { 840 set x [expr {($x0+$x1)/2}] 841 Invoke $_name2path($varName) $x $y0 842 } 843 } 844 default { 845 error "bad option \"$option\": should be activate, deactivate, invoke" 846 } 721 847 } 722 848 } … … 724 850 725 851 itcl::body Rappture::DrawingEntry::ScreenX { x } { 726 set norm [expr ($x - $_xMin) * $_xScale]727 set x [expr int($norm * $_drawingWidth) + $_xOffset]852 set norm [expr {($x - $_xMin) * $_xScale}] 853 set x [expr {int($norm * $_drawingWidth) + $_xOffset}] 728 854 return $x 729 855 } 730 856 731 857 itcl::body Rappture::DrawingEntry::ScreenY { y } { 732 set norm [expr ($y - $_yMin) * $_yScale]733 set y [expr int($norm * $_drawingHeight) + $_yOffset]858 set norm [expr {($y - $_yMin) * $_yScale}] 859 set y [expr {int($norm * $_drawingHeight) + $_yOffset}] 734 860 return $y 735 861 } … … 860 986 } 861 987 862 itcl::body Rappture::DrawingEntry::ParseSubstitutions {} {863 foreach var [$_xmlobj children $_path.substitutions] {864 if { ![string match "variable*" $var] } {865 continue866 }867 set varPath $_path.substitutions.$var868 set map ""869 set name ""870 set path ""871 foreach elem [$_xmlobj children $varPath] {872 switch -glob -- $elem {873 "name*" {874 set name [XmlGet $varPath.$elem]875 }876 "path*" {877 set path [XmlGet $varPath.$elem]878 }879 "map*" {880 set from [XmlGet $varPath.$elem.from]881 set to [XmlGet $varPath.$elem.to]882 if { $from == "" || $to == "" } {883 puts stderr "empty translation in map table \"$varPath\""884 }885 lappend map $from $to886 }887 }888 }889 if { $name == "" } {890 puts stderr \891 "no name defined for substituion variable \"$varPath\""892 continue893 }894 if { [info exists _name2path($name)] } {895 puts stderr \896 "substitution variable \"$name\" already defined"897 continue898 }899 set _name2path($name) $path900 if { $path == "" } {901 puts stderr \902 "no path defined for substituion variable \"$varPath\""903 continue904 }905 set _name2map($name) $map906 }907 InitSubstitutions908 }909 910 988 # 911 989 # Invoke -- 912 990 # 913 itcl::body Rappture::DrawingEntry::Invoke { cname x y } { 914 set controls $_cname2controls($cname) 915 if { [llength $controls] == 0 } { 916 puts stderr "no controls defined for $cname" 917 return 918 } 919 # Build a popup with the designated controls 920 set popup .drawingentrypopup 921 if { ![winfo exists $popup] } { 922 # Create a popup for the controls dialog 923 Rappture::Balloon $popup -title "Change values..." \ 924 -deactivatecommand [itcl::code $this Withdraw $cname] 925 set inner [$popup component inner] 926 Rappture::DrawingControls $inner.controls $_owner \ 927 -deactivatecommand [list $popup deactivate] 928 pack $inner.controls -fill both -expand yes 991 itcl::body Rappture::DrawingEntry::Invoke {cpath x y} { 992 if {![info exists _cpath2popup($cpath)]} { 993 error "internal error: no controls for hotspot at $cpath" 994 } 995 set popup $_cpath2popup($cpath) 996 997 # if this popup has only one control, watch for it to change and 998 # take it down automatically 999 set inner [$popup component inner] 1000 set n [expr {[$inner.controls index end]+1}] 1001 if {$n == 1} { 1002 set _takedown $popup 929 1003 } else { 930 set inner [$popup component inner] 931 $inner.controls delete all 932 } 933 set count 0 934 foreach path $controls { 935 if { [IsEnabled $path] } { 936 $inner.controls add $path 937 incr count 938 } 939 } 940 if { $count == 0 } { 941 return 942 } 943 update 1004 set _takedown "" 1005 } 1006 944 1007 # Activate the popup and call for the output. 945 1008 incr x [winfo rootx $itk_component(drawing)] … … 961 1024 # 962 1025 itcl::body Rappture::DrawingEntry::Deactivate { cname } { 963 $itk_component(drawing) configure -cursor left_ptr1026 $itk_component(drawing) configure -cursor "" 964 1027 $itk_component(drawing) itemconfigure $_cname2id($cname) \ 965 1028 -image [Rappture::icon hotspot_normal] 966 }967 968 #969 # Withdraw --970 #971 itcl::body Rappture::DrawingEntry::Withdraw { cname } {972 Redraw973 1029 } 974 1030 … … 987 1043 set libobj [lindex $args 0] 988 1044 if { $libobj != "" } { 989 Redraw1045 $_dispatcher event -idle !redraw 990 1046 } 991 1047 } … … 993 1049 } 994 1050 995 996 # 997 # InitSubstitutions -- 998 # 999 itcl::body Rappture::DrawingEntry::InitSubstitutions {} { 1000 # Load a new parser with the variables representing the substitution 1051 itcl::body Rappture::DrawingEntry::UpdateSubstitutions {} { 1052 # Load parser with the variables representing the substitution 1001 1053 foreach name [array names _name2path] { 1002 1054 set path $_name2path($name) 1003 1055 set w [$_owner widgetfor $path] 1004 if { $w != ""} {1056 if {$w ne ""} { 1005 1057 set value [$w value] 1006 1058 } else { 1007 1059 set value "" 1008 1060 } 1061 if {$_name2map($name) ne ""} { 1062 set value [string map $_name2map($name) $value] 1063 } 1009 1064 $_parser eval [list set $name $value] 1010 1065 } … … 1018 1073 itcl::body Rappture::DrawingEntry::XmlGetSubst { path } { 1019 1074 set value [$_xmlobj get $path] 1020 if { $_parser == ""} {1021 return $value1075 if {$_parser == ""} { 1076 return [string trim $value] 1022 1077 } 1023 1078 return [string trim [$_parser eval [list subst -nocommands $value]]] 1024 1079 } 1025 1026 itcl::body Rappture::DrawingEntry::IsEnabled { path } {1027 set enable [string trim [$_xmlobj get $path.about.enable]]1028 if {"" == $enable} {1029 return 11030 }1031 if {![string is boolean $enable]} {1032 set re {([a-zA-Z_]+[0-9]*|\([^\(\)]+\)|[a-zA-Z_]+[0-9]*\([^\(\)]+\))(\.([a-zA-Z_]+[0-9]*|\([^\(\)]+\)|[a-zA-Z_]+[0-9]*\([^\(\)]+\)))*(:[-a-zA-Z0-9/]+)?}1033 set rest $enable1034 set enable ""1035 set deps ""1036 while {1} {1037 if {[regexp -indices $re $rest match]} {1038 foreach {s0 s1} $match break1039 1040 if {[string index $rest [expr {$s0-1}]] == "\""1041 && [string index $rest [expr {$s1+1}]] == "\""} {1042 # string in ""'s? then leave it alone1043 append enable [string range $rest 0 $s1]1044 set rest [string range $rest [expr {$s1+1}] end]1045 } else {1046 #1047 # This is a symbol which should be substituted1048 # it can be either:1049 # input.foo.bar1050 # input.foo.bar:units1051 #1052 set cpath [string range $rest $s0 $s1]1053 set parts [split $cpath :]1054 set ccpath [lindex $parts 0]1055 set units [lindex $parts 1]1056 1057 # make sure we have the standard path notation1058 set stdpath [$_owner regularize $ccpath]1059 if {"" == $stdpath} {1060 puts stderr "WARNING: don't recognize parameter $cpath in <enable> expression for $path. This may be buried in a structure that is not yet loaded."1061 set stdpath $ccpath1062 }1063 # substitute [_controlValue ...] call in place of path1064 append enable [string range $rest 0 [expr {$s0-1}]]1065 append enable [format {[ControlValue %s %s]} $stdpath $units]1066 lappend deps $stdpath1067 set rest [string range $rest [expr {$s1+1}] end]1068 }1069 } else {1070 append enable $rest1071 break1072 }1073 }1074 }1075 return [expr $enable]1076 }1077 1078 # ----------------------------------------------------------------------1079 # USAGE: ControlValue <path> ?<units>?1080 #1081 # Used internally to get the value of a control with the specified1082 # <path>. Returns the current value for the control.1083 # ----------------------------------------------------------------------1084 itcl::body Rappture::DrawingEntry::ControlValue {path {units ""}} {1085 if {"" != $_owner} {1086 set val [$_owner valuefor $path]1087 if {"" != $units} {1088 set val [Rappture::Units::convert $val -to $units -units off]1089 }1090 return $val1091 }1092 return ""1093 }1094 1095 itcl::body Rappture::DrawingEntry::NumControlsEnabled { cname } {1096 set controls $_cname2controls($cname)1097 set count 01098 foreach path $controls {1099 if { [IsEnabled $path] } {1100 incr count1101 }1102 }1103 return $count1104 } -
trunk/gui/scripts/page.tcl
r3330 r3636 197 197 198 198 # if this is a group, then build that group 199 if {[$xmlobj element -as type $path.$cname] =="group"} {200 if {[$xmlobj element -as id $path.$cname] =="ambient"199 if {[$xmlobj element -as type $path.$cname] eq "group"} { 200 if {[$xmlobj element -as id $path.$cname] eq "ambient" 201 201 && $deveditor != ""} { 202 202 set w [$deveditor component top] 203 203 } else { 204 if {[catch {$frame.cntls insert end $path.$cname} c]} { 204 if {[$_owner widgetfor $path.$cname] ne ""} { 205 # widget already created -- skip this 206 } elseif {[catch {$frame.cntls insert end $path.$cname} c]} { 205 207 global errorInfo 206 208 error $c "$c\n$errorInfo\n (while building control for $path.$cname)" … … 212 214 _buildGroup $w $xmlobj $path.$cname 213 215 } else { 214 if {[catch {$frame.cntls insert end $path.$cname} c]} { 216 if {[$_owner widgetfor $path.$cname] ne ""} { 217 # widget already created -- skip this 218 } elseif {[catch {$frame.cntls insert end $path.$cname} c]} { 215 219 global errorInfo 216 220 error $c "$c\n$errorInfo\n (while building control for $path.$cname)" -
trunk/gui/scripts/pager.tcl
r3330 r3636 490 490 pages { 491 491 pack forget $itk_component(inside) 492 pack $itk_component(controls) -side bottom -fill x -padx 8-pady 8492 pack $itk_component(controls) -side bottom -fill x -padx 32 -pady 8 493 493 pack $itk_component(breadcrumbarea) -side top -fill x 494 494 pack $itk_component(line) -side top -fill x -
trunk/gui/scripts/textentry.tcl
r3513 r3636 492 492 # ---------------------------------------------------------------------- 493 493 itcl::body Rappture::TextEntry::_edit {option args} { 494 puts "_edit $option $args"495 494 if {$itk_option(-state) == "disabled"} { 496 495 return ;# disabled? then bail out here! -
trunk/gui/src/RpCanvHotspot.c
r3405 r3636 1726 1726 } 1727 1727 1728 static const char*1728 static Tcl_Obj * 1729 1729 Identify(Tcl_Interp *interp, HotspotItem *itemPtr, double x, double y) 1730 1730 { 1731 Tcl_Obj* resultPtr = NULL; 1731 1732 ItemSegment *segPtr; 1733 Tcl_Obj* objPtr; 1732 1734 1733 1735 x -= itemPtr->x1; … … 1739 1741 if ((x >= segPtr->x) && (x < (segPtr->x + segPtr->width)) && 1740 1742 (y >= segPtr->y) && (y < (segPtr->y + segPtr->height))) { 1741 return segPtr->text; 1742 } 1743 } 1744 return ""; 1743 1744 /* build return list: {string x0 y0 x1 y1} */ 1745 resultPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); 1746 1747 objPtr = Tcl_NewStringObj(segPtr->text, -1); 1748 Tcl_ListObjAppendElement(interp, resultPtr, objPtr); 1749 1750 objPtr = Tcl_NewIntObj(itemPtr->x1 + segPtr->x); 1751 Tcl_ListObjAppendElement(interp, resultPtr, objPtr); 1752 objPtr = Tcl_NewIntObj(itemPtr->y1 + segPtr->y); 1753 Tcl_ListObjAppendElement(interp, resultPtr, objPtr); 1754 1755 objPtr = Tcl_NewIntObj(itemPtr->x1 + segPtr->x + segPtr->width); 1756 Tcl_ListObjAppendElement(interp, resultPtr, objPtr); 1757 objPtr = Tcl_NewIntObj(itemPtr->y1 + segPtr->y + segPtr->height); 1758 Tcl_ListObjAppendElement(interp, resultPtr, objPtr); 1759 1760 return resultPtr; 1761 } 1762 } 1763 return NULL; 1745 1764 } 1746 1765 … … 1770 1789 } else if ((c == 'i') && (strncmp(string, "identify", length) == 0)) { 1771 1790 double x, y; 1772 const char *token;1773 1791 Tcl_Obj *objPtr; 1774 1792 … … 1778 1796 return TCL_ERROR; 1779 1797 } 1780 token = Identify(interp, itemPtr, x, y); 1781 objPtr = Tcl_NewStringObj(token, -1); 1782 Tcl_SetObjResult(interp, objPtr); 1798 objPtr = Identify(interp, itemPtr, x, y); 1799 if (objPtr != NULL) { 1800 Tcl_SetObjResult(interp, objPtr); 1801 } 1783 1802 } else if ((c == 'v') && (strncmp(string, "variables", length) == 0)) { 1784 1803 Tcl_Obj *listObjPtr;
Note: See TracChangeset
for help on using the changeset viewer.