Changeset 1761 for branches/blt4/gui
- Timestamp:
- Jun 15, 2010, 10:19:57 PM (14 years ago)
- Location:
- branches/blt4/gui/scripts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/gui/scripts/sidebarframe.tcl
r1710 r1761 457 457 release { 458 458 set minw [winfo reqwidth $itk_component(controlbar)] 459 if { $_width-$minw< 40} {459 if { $_width != "auto" && ($_width-$minw) < 40} { 460 460 set _width "auto" 461 461 pop close -
branches/blt4/gui/scripts/xylegend.tcl
r1759 r1761 1 2 proc lsave { file values } { 3 set f [open $file "w"] 4 puts $f $values 5 close $f 6 } 1 7 2 8 # ---------------------------------------------------------------------- … … 25 31 inherit itk::Widget 26 32 27 private variable autocolors_{33 private variable _autocolors { 28 34 #0000cd 29 35 #cd0000 … … 59 65 #551a8b 60 66 } 61 private variable lastColorIndex_""67 private variable _lastColorIndex "" 62 68 private variable _dispatcher "" ;# dispatcher for !events 63 private variable graph_""69 private variable _graph "" 64 70 private variable _tree "" 65 private variable diff_""; # Polygon marker used for difference.66 private variable rename_""; # Node selected to be renamed.67 private variable diffelements_71 private variable _diff ""; # Polygon marker used for difference. 72 private variable _rename ""; # Node selected to be renamed. 73 private variable _diffelements 68 74 69 75 constructor {args} { graph } … … 71 77 72 78 public method reset {} 73 public method Average {} 74 public method Recolor {} 75 public method Check {} 76 public method Delete { args } 77 public method Difference {} 78 public method Editor { option args } 79 public method Hide { args } 80 public method Lower { args } 81 public method Raise { args } 82 public method Rename {} 83 public method Show { args } 84 public method Toggle { args } 79 80 private method Add { elem label {flags ""}} 81 private method Average {} 82 private method Check {} 83 private method Delete { args } 84 private method Difference {} 85 private method Editor { option args } 85 86 private method GetData { elem what } 86 private method Add { elem label {flags ""}} 87 private method Hide { args } 88 private method Lower { args } 89 private method Raise { args } 90 private method Recolor {} 91 private method Rename {} 87 92 private method SelectAll {} 93 private method Show { args } 94 private method Toggle { args } 88 95 } 89 96 … … 138 145 $itk_component(legend) column configure "show" -style "check" -pad {0 0} \ 139 146 -edit yes 147 set m $itk_component(hull).mb.menu 148 blt::combobutton $itk_component(hull).mb -text "Operations" \ 149 -icon [Rappture::icon wrench] \ 150 -menu $m -activerelief raised -relief flat 151 140 152 itk_component add controls { 141 frame $itk_component(hull).controls -width 100 -relief sunken -bd 2 142 } 143 set controls $itk_component(controls) 144 grid $itk_component(controls) -column 0 -row 1 -sticky nsew 145 grid columnconfigure $itk_component(hull) 0 -weight 1 146 grid rowconfigure $itk_component(hull) 1 \ 147 -minsize [winfo reqheight $itk_component(scrollbars)] 148 grid rowconfigure $itk_component(hull) 0 -weight 1 149 grid $itk_component(scrollbars) -column 0 -row 0 -sticky nsew 150 set commands { 151 hide "" 152 show "" 153 toggle "" 154 raise findup 155 lower finddn 156 average "" 157 difference "" 158 delete "" 159 rename "" 160 recolor "" 161 } 162 foreach { but icon} $commands { 163 set title [string totitle $but] 164 button $controls.$but -text $title \ 165 -relief flat -pady 0 -padx 0 -font "Arial 9" \ 166 -command [itcl::code $this $title] -overrelief flat \ 167 -activebackground grey90 168 } 169 grid $controls.hide -column 0 -row 0 -sticky w 170 grid $controls.show -column 0 -row 1 -sticky w 171 grid $controls.toggle -column 0 -row 2 -sticky w 172 grid $controls.raise -column 0 -row 3 -sticky w 173 grid $controls.lower -column 0 -row 4 -sticky w 174 grid $controls.difference -column 1 -row 0 -sticky w 175 grid $controls.average -column 1 -row 1 -sticky w 176 grid $controls.rename -column 1 -row 2 -sticky w 177 grid $controls.delete -column 1 -row 3 -sticky w 178 grid $controls.recolor -column 1 -row 4 -sticky w 179 180 grid columnconfigure $controls 0 -weight 1 181 grid columnconfigure $controls 1 -weight 1 182 183 set graph_ $graph 153 blt::combomenu $m \ 154 -yscrollbar $m.ys \ 155 -xscrollbar $m.xs 156 } 157 blt::tk::scrollbar $m.xs 158 blt::tk::scrollbar $m.ys 159 160 $m add -text "Hide" -command [itcl::code $this Hide] 161 $m add -text "Show" -command [itcl::code $this Show] 162 $m add -text "Toggle" -command [itcl::code $this Toggle] 163 $m add -type separator 164 $m add -text "Lower" -command [itcl::code $this Lower] 165 $m add -text "Raise" -command [itcl::code $this Raise] 166 $m add -type separator 167 $m add -text "Average" -command [itcl::code $this Average] 168 $m add -text "Difference" -command [itcl::code $this Difference] 169 $m add -type separator 170 $m add -text "Recolor" -command [itcl::code $this Recolor] 171 $m add -text "Rename" -command [itcl::code $this Rename] 172 $m add -text "Delete" -command [itcl::code $this Delete] 173 174 set _graph $graph 184 175 set cmd [itcl::code $this Toggle current] 185 176 $itk_component(legend) bind CheckBoxStyle <ButtonRelease-1> \ … … 207 198 -applycommand [itcl::code $this Editor apply] 208 199 } 209 set lastColorIndex_ [llength $autocolors_] 200 set _lastColorIndex [llength $_autocolors] 201 blt::table $itk_interior \ 202 0,0 $itk_interior.mb -anchor w \ 203 1,0 $itk_component(scrollbars) -fill both 204 blt::table configure $itk_interior r0 -resize none 210 205 Check 211 206 eval itk_initialize $args … … 219 214 $_tree delete $node 220 215 } 221 if { $ diff_!= "" } {222 catch { $ graph_ marker delete $diff_}216 if { $_diff != "" } { 217 catch { $_graph marker delete $_diff } 223 218 } 224 219 } 225 220 226 221 itcl::body Rappture::XyLegend::Add { elem label {flags ""} } { 227 set hide [$ graph_element cget $elem -hide]222 set hide [$_graph element cget $elem -hide] 228 223 set im [image create picture] 229 $ graph_legend icon $elem $im224 $_graph legend icon $elem $im 230 225 set data(show) $hide 231 226 set data(delete) [expr { $flags == "-delete" }] … … 247 242 $_tree delete $node 248 243 } 249 foreach elem [$ graph_element show] {250 set label [$ graph_element cget $elem -label]244 foreach elem [$_graph element show] { 245 set label [$_graph element cget $elem -label] 251 246 if { $label == "" } { 252 247 set label $elem … … 266 261 foreach node $nodes { 267 262 set elem [$_tree label $node] 268 if { ![$ graph_element exists $elem] } {263 if { ![$_graph element exists $elem] } { 269 264 continue 270 265 } 271 $ graph_element configure $elem -hide yes266 $_graph element configure $elem -hide yes 272 267 $_tree set $node "show" 1 273 268 } … … 282 277 foreach node $nodes { 283 278 set elem [$_tree label $node] 284 if { ![$ graph_element exists $elem] } {279 if { ![$_graph element exists $elem] } { 285 280 continue 286 281 } 287 $ graph_element configure $elem -hide no282 $_graph element configure $elem -hide no 288 283 $_tree set $node "show" 0 289 284 } … … 298 293 foreach node $nodes { 299 294 set elem [$_tree label $node] 300 if { ![$ graph_element exists $elem] } {295 if { ![$_graph element exists $elem] } { 301 296 continue 302 297 } 303 set hide [$ graph_element cget $elem -hide]298 set hide [$_graph element cget $elem -hide] 304 299 set hide [expr $hide==0] 305 300 $_tree set $node "show" $hide 306 $ graph_element configure $elem -hide $hide301 $_graph element configure $elem -hide $hide 307 302 } 308 303 } … … 324 319 } 325 320 set list {} 326 foreach elem [$ graph_element show] {321 foreach elem [$_graph element show] { 327 322 if { [info exists found($elem)] } { 328 323 continue … … 330 325 lappend list $elem 331 326 } 332 $ graph_element show [concat $list $elements]327 $_graph element show [concat $list $elements] 333 328 } 334 329 … … 353 348 354 349 set list {} 355 foreach elem [$ graph_element show] {350 foreach elem [$_graph element show] { 356 351 if { [info exists found($elem)] } { 357 352 continue … … 359 354 lappend list $elem 360 355 } 361 $ graph_element show [concat $elements $list]356 $_graph element show [concat $elements $list] 362 357 } 363 358 … … 377 372 lappend elements $elem 378 373 lappend delnodes $node 379 if { $ diff_ != "" && [info exists diffelements_($elem)] } {380 $ graph_ marker delete $diff_381 array unset diffelements_382 set diff_""374 if { $_diff != "" && [info exists _diffelements($elem)] } { 375 $_graph marker delete $_diff 376 array unset _diffelements 377 set _diff "" 383 378 } 384 379 } … … 387 382 } 388 383 $itk_component(legend) selection clearall 389 eval $ graph_element delete $elements384 eval $_graph element delete $elements 390 385 } 391 386 392 387 itcl::body Rappture::XyLegend::Check {} { 393 388 set nodes [$itk_component(legend) curselection] 394 foreach n { hide show toggle raise lower395 rename average difference delete recolor } {396 $itk_component(controls) .$n configure-state disabled389 foreach n { Hide Show Toggle Raise Lower Rename Average Difference 390 Delete Recolor } { 391 $itk_component(controls) item configure $n -state disabled 397 392 } 398 393 foreach node $nodes { 399 394 if { [$_tree get $node "delete" 0] } { 400 $itk_component(controls) .delete configure -state normal395 $itk_component(controls) item configure delete -state normal 401 396 break 402 397 } 403 398 } 404 399 if { [$_tree degree 0] > 1 && [llength $nodes] > 0 } { 405 foreach n { raise lower } {406 $itk_component(controls) .$n configure-state normal400 foreach n { Raise Lower } { 401 $itk_component(controls) item configure $n -state normal 407 402 } 408 403 } … … 411 406 } 412 407 1 { 413 foreach n { hide show toggle rename recolor } {414 $itk_component(controls) .$n configure-state normal408 foreach n { Hide Show Toggle Rename Recolor } { 409 $itk_component(controls) item configure $n -state normal 415 410 } 416 411 } 417 412 2 { 418 foreach n { hide show toggle difference average recolor } {419 $itk_component(controls) .$n configure-state normal413 foreach n { Hide Show Toggle Difference Average Recolor } { 414 $itk_component(controls) item configure $n -state normal 420 415 } 421 416 } 422 417 default { 423 foreach n { hide show toggle average recolor } { 424 $itk_component(controls).$n configure -state normal 425 } 426 } 427 } 428 } 429 430 itcl::body Rappture::XyLegend::GetData { elem what } { 431 foreach {name col} [$graph_ element cget $elem $what] break 432 if { [blt::vector names $name] == $name } { 433 set y [$name range 0 end] 434 } elseif { [blt::datatable names $name] == $name } { 435 set y [$name column values $col] 436 } 437 return $y 418 foreach n { Hide Show Toggle Average Recolor } { 419 $itk_component(controls) item configure $n -state normal 420 } 421 } 422 } 423 } 424 425 itcl::body Rappture::XyLegend::GetData { elem axis } { 426 set data [$_graph element cget $elem $axis] 427 switch [llength $data] { 428 1 { 429 # Vector name 430 set vector $data 431 if { [blt::vector names $vector] == $vector } { 432 return [$vector range 0 end] 433 } 434 } 435 2 { 436 # Table and column name 437 foreach {table column} $data break 438 if { [blt::datatable names $table] == $table } { 439 set data [$table column values $column] 440 $table export csv -file $table.csv 441 lsave $table [$table column get -labels $column] 442 return $data 443 } 444 } 445 } 446 # Otherwise assume it's a list of numbers. 447 return $data 438 448 } 439 449 … … 457 467 foreach node $nodes { 458 468 set elem [$_tree label $node] 459 set label [$ graph_element cget $elem -label]469 set label [$_graph element cget $elem -label] 460 470 $xcoords append [GetData $elem -x] 461 471 set elements [linsert $elements 0 $elem] … … 478 488 $x set [GetData $elem -x] 479 489 $y set [GetData $elem -y] 480 if { [catch { 481 blt::spline natural $x $y $xcoords $ycoords 482 }] != 0 } { 483 } 490 blt::spline natural $x $y $xcoords $ycoords 491 484 492 # Sum the interpolated y-coordinate values. 485 493 $sum expr "$sum + $ycoords" … … 494 502 495 503 set count 0 496 while {[$ graph_element exists avg$count] } {504 while {[$_graph element exists avg$count] } { 497 505 incr count 498 506 } … … 503 511 # Don't use the vector because we don't know when it will be cleaned up. 504 512 505 if { $ lastColorIndex_== 0 } {506 set lastColorIndex_ [llength $autocolors_]507 } 508 incr lastColorIndex_-1509 set color [lindex $ autocolors_ $lastColorIndex_]510 $ graph_element create $name -label $label -x [$xcoords range 0 end]\513 if { $_lastColorIndex == 0 } { 514 set _lastColorIndex [llength $_autocolors] 515 } 516 incr _lastColorIndex -1 517 set color [lindex $_autocolors $_lastColorIndex] 518 $_graph element create $name -label $label -x [$xcoords range 0 end]\ 511 519 -y [$sum range 0 end] -symbol scross -pixels 3 -color $color 512 520 blt::vector destroy $xcoords $ycoords $sum … … 518 526 itcl::body Rappture::XyLegend::Difference {} { 519 527 520 if { $ diff_!= "" } {521 $ graph_ marker delete $diff_522 set diff_""528 if { $_diff != "" } { 529 $_graph marker delete $_diff 530 set _diff "" 523 531 } 524 532 set nodes [$itk_component(legend) curselection] 525 533 set elem1 [$_tree label [lindex $nodes 0]] 526 534 set elem2 [$_tree label [lindex $nodes 1]] 527 if { [info exists diffelements_($elem1)] &&528 [info exists diffelements_($elem2)] } {529 array unset diffelements_; # Toggle the difference.535 if { [info exists _diffelements($elem1)] && 536 [info exists _diffelements($elem2)] } { 537 array unset _diffelements; # Toggle the difference. 530 538 return; 531 539 } 532 array unset diffelements_540 array unset _diffelements 533 541 set x [blt::vector create \#auto -command ""] 534 542 set y [blt::vector create \#auto -command ""] … … 541 549 $y append [GetData $elem2 -y] 542 550 $m merge $x $y 543 set diff_ [$graph_marker create polygon \551 set _diff [$_graph marker create polygon \ 544 552 -coords [$m range 0 end] \ 545 553 -element $elem1 \ … … 547 555 -outline "" -fill "#cd69c9"] 548 556 blt::vector destroy $m $x $y 549 set diffelements_($elem1) 1550 set diffelements_($elem2) 1557 set _diffelements($elem1) 1 558 set _diffelements($elem2) 1 551 559 } 552 560 … … 559 567 foreach node $nodes { 560 568 set elem [$_tree label $node] 561 if { $ lastColorIndex_== 0 } {562 set lastColorIndex_ [llength $autocolors_]563 } 564 incr lastColorIndex_-1565 set color [lindex $ autocolors_ $lastColorIndex_]566 $ graph_element configure $elem -color $color569 if { $_lastColorIndex == 0 } { 570 set _lastColorIndex [llength $_autocolors] 571 } 572 incr _lastColorIndex -1 573 set color [lindex $_autocolors $_lastColorIndex] 574 $_graph element configure $elem -color $color 567 575 set im [$itk_component(legend) entry cget $node -icon] 568 $ graph_legend icon $elem $im576 $_graph legend icon $elem $im 569 577 } 570 578 } … … 596 604 } 597 605 activate { 598 set rename_[$itk_component(legend) curselection]599 if { $ rename_== "" } {606 set _rename [$itk_component(legend) curselection] 607 if { $_rename == "" } { 600 608 return; 601 609 } 602 set label [$itk_component(legend) entry cget $ rename_-label]603 foreach { l r w h } [$itk_component(legend) bbox $ rename_] break610 set label [$itk_component(legend) entry cget $_rename -label] 611 foreach { l r w h } [$itk_component(legend) bbox $_rename] break 604 612 set info(text) $label 605 613 set info(x) [expr $l + [winfo rootx $itk_component(legend)]] … … 619 627 } 620 628 set label [lindex $args 0] 621 $itk_component(legend) entry configure $ rename_-label $label622 set elem [$_tree label $ rename_]623 $ graph_element configure $elem -label $label629 $itk_component(legend) entry configure $_rename -label $label 630 set elem [$_tree label $_rename] 631 $_graph element configure $elem -label $label 624 632 } 625 633 menu {
Note: See TracChangeset
for help on using the changeset viewer.