Changeset 2987 for branches/blt4/gui
- Timestamp:
- May 1, 2012, 3:22:07 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/gui/scripts/drawingentry.tcl
r2986 r2987 1 1 2 # ---------------------------------------------------------------------- 2 3 # COMPONENT: DrawingEntry - widget for entering numeric values … … 30 31 private variable _xAspect 0 31 32 private variable _yAspect 0 33 private variable _controls "" 34 private variable _showing "" 35 32 36 constructor {owner path args} { # defined below } 33 37 … … 52 56 private method ScreenX { x } 53 57 private method ScreenY { y } 54 private method Unhighlight { tag } 58 private method Activate { tag } 59 private method Deactivate { tag } 60 private method Invoke { tag } 61 private method Insert { tag } 62 private method ControlChanged { tag } 55 63 } 56 64 … … 163 171 # Remove exists canvas items and hints 164 172 $itk_component(drawing) delete all 173 # Delete any images that we created. 174 foreach name [array names _cname2image] { 175 image delete $_cname2image($name) 176 } 165 177 # Recompute the size of the canvas/drawing area 166 178 set _canvasWidth [winfo width $itk_component(drawing)] … … 182 194 } 183 195 184 itcl::body Rappture::DrawingEntry::ParseLine { cpath cname } { 185 array set attr2option { 186 "linewidth" "-width" 187 "arrow" "-arrow" 188 "dash" "-dash" 189 "color" "-fill" 190 } 191 # Set default options first and then let tool.xml override them. 192 array set options { 193 -arrow none 194 -width 0 195 -fill black 196 -dash "" 197 } 198 # Coords 199 set coords {} 200 set coords [$_owner xml get $cpath.coords] 201 set coords [string trim $coords] 202 if { $coords == "" } { 203 set coords "0 0" 204 } else { 205 set coords [ScreenCoords $coords] 206 } 207 puts stderr "ParseLineDescrption description owner=$_owner cpath=$cpath coords=$coords" 208 set list {} 209 foreach attr [$_owner xml children $cpath] { 210 if { [info exists attr2option($attr)] } { 211 set option $attr2option($attr) 212 set value [$_owner xml get $cpath.$attr] 213 set options($option) $value 214 } 215 } 216 set options(-tags) $cname 217 puts stderr "$itk_component(drawing) create line $coords" 218 set id [eval $itk_component(drawing) create line $coords] 219 set _cname2id($cname) $id 220 eval $itk_component(drawing) itemconfigure $id [array get options] 196 # 197 # ParseDescription -- 198 # 199 itcl::body Rappture::DrawingEntry::ParseDescription {} { 200 puts stderr "ParseDescrption description owner=$_owner path=$_path" 201 ParseBackground 202 ParseSubstitutions 203 foreach cname [$_owner xml children $_path.components] { 204 switch -glob -- $cname { 205 "line*" { 206 ParseLine $_path.components.$cname 207 } 208 "grid*" { 209 ParseGrid $_path.components.$cname 210 } 211 "text*" { 212 ParseText $_path.components.$cname 213 } 214 "picture*" { 215 ParsePicture $_path.components.$cname 216 } 217 "rectangle*" { 218 ParseRectangle $_path.components.$cname 219 } 220 "oval*" { 221 ParseOval $_path.components.$cname 222 } 223 "polygon*" { 224 ParsePolygon $_path.components.$cname 225 } 226 "hotspot*" { 227 ParseHotspot $_path.components.$cname 228 } 229 } 230 } 221 231 } 222 232 … … 310 320 } 311 321 312 itcl::body Rappture::DrawingEntry::ParseText { cpath cname } { 322 # 323 # ParseHotspot -- 324 # 325 itcl::body Rappture::DrawingEntry::ParseHotspot { cpath cname } { 313 326 array set attr2option { 314 "font" "-font" 315 "default" "-text" 316 "color" "-fill" 317 "text" "-text" 318 "anchor" "-anchor" 319 } 320 puts stderr "ParseText description owner=$_owner cpath=$cpath" 321 327 "color" "-fill" 328 "anchor" "-anchor" 329 } 330 puts stderr "ParseHotspot owner=$_owner cpath=$cpath" 322 331 # Set default options first and then let tool.xml override them. 323 332 array set options { 324 -font {Arial 12} 325 -text {} 326 -fill black 333 -fill red 327 334 -anchor c 328 335 } 336 array unset _cname2controls $cname 329 337 foreach attr [$_owner xml children $cpath] { 330 338 if { [info exists attr2option($attr)] } { … … 332 340 set value [$_owner xml get $cpath.$attr] 333 341 set options($option) $value 334 } 342 } elseif { [string match "controls*" $attr] } { 343 set value [$_owner xml get $cpath.$attr] 344 lappend _cname2controls($cname) $value 345 } 346 } 347 # Coordinates 348 set coords [$_owner xml get $cpath.coords] 349 set coords [ScreenCoords $coords] 350 if { $coords == "" } { 351 set coords "0 0 1 1" 352 } 353 set c $itk_component(drawing) 354 set img [image create picture -width 16 -height 16] 355 $img blank 0x0 356 $img draw text "?" 8 8 -anchor c -font "Arial 6" -shadow 1 \ 357 -color $option(-fill) 358 foreach { x1 y1 } [ScreenCoords $coords] break 359 set id [$itk_component(drawing) create image $x1 $y1] 360 set options(-tags) $cname 361 set options(-image) $img 362 eval $c itemconfigure $id [array get options] 363 set _cname2id($cname) $id 364 set _cname2image($cname) $img 365 $c bind $id <Enter> [itcl::code $this Activate $cname] 366 $c bind $id <Leave> [itcl::code $this Deactivate $cname] 367 $c bind $id <ButtonPress-1> [itcl::code $this Depress $cname] 368 $c bind $id <ButtonRelease-1> [itcl::code $this Invoke $cname $x1 $y1] 369 } 370 371 # 372 # ParseLine -- 373 # 374 itcl::body Rappture::DrawingEntry::ParseLine { cpath cname } { 375 array set attr2option { 376 "linewidth" "-width" 377 "arrow" "-arrow" 378 "dash" "-dash" 379 "color" "-fill" 380 } 381 # Set default options first and then let tool.xml override them. 382 array set options { 383 -arrow none 384 -width 0 385 -fill black 386 -dash "" 335 387 } 336 388 # Coords … … 343 395 set coords [ScreenCoords $coords] 344 396 } 397 puts stderr "ParseLineDescrption description owner=$_owner cpath=$cpath coords=$coords" 398 set list {} 399 foreach attr [$_owner xml children $cpath] { 400 if { [info exists attr2option($attr)] } { 401 set option $attr2option($attr) 402 set value [$_owner xml get $cpath.$attr] 403 set options($option) $value 404 } 405 } 406 set options(-tags) $cname 407 puts stderr "$itk_component(drawing) create line $coords" 408 set id [eval $itk_component(drawing) create line $coords] 409 set _cname2id($cname) $id 410 eval $itk_component(drawing) itemconfigure $id [array get options] 411 } 412 413 # 414 # ParseOval -- 415 # 416 itcl::body Rappture::DrawingEntry::ParseOval { cpath cname } { 417 array set attr2option { 418 "outline" "-outline" 419 "fill" "-fill" 420 "linewidth" "-linewidth" 421 } 422 puts stderr "ParseOval description owner=$_owner cpath=$cpath" 423 424 # Set default options first and then let tool.xml override them. 425 array set options { 426 -fill blue 427 -linewidth 1 428 -outline black 429 } 430 foreach attr [$_owner xml children $cpath] { 431 if { [info exists attr2option($attr)] } { 432 set option $attr2option($attr) 433 set value [$_owner xml get $cpath.$attr] 434 set options($option) $value 435 } 436 } 437 # Coordinates 438 set coords {} 439 set coords [$_owner xml get $cpath.coords] 440 set coords [string trim $coords] 441 if { $coords == "" } { 442 set coords "0 0 1 1" 443 } 444 foreach { x1 y1 x2 y2 } [ScreenCoords $coords] break 445 set id [eval $itk_component(drawing) create oval $coords] 446 set _cname2id($cname) $id 447 } 448 449 # 450 # ParsePicture -- 451 # 452 itcl::body Rappture::DrawingEntry::ParsePicture { cpath cname } { 453 array set attr2option { 454 "anchor" "-anchor" 455 } 456 puts stderr "ParsePicture description owner=$_owner cpath=$cpath" 457 # Set default options first and then let tool.xml override them. 458 array set options { 459 -anchor nw 460 } 461 foreach attr [$_owner xml children $cpath] { 462 if { [info exists attr2option($attr)] } { 463 set option $attr2option($attr) 464 set value [$_owner xml get $cpath.$attr] 465 set options($option) $value 466 } 467 } 468 # Coordinates 469 set coords {} 470 set coords [$_owner xml get $cpath.coords] 471 set coords [ScreenCoords $coords] 472 if { [llength $coords] == 2 } { 473 foreach { x1 y1 } $coords break 474 set w [$_owner xml get $cpath.width] 475 if { $w == "" || ![string is number $w] || $w <= 0.0 } { 476 set width [expr [image width $img] / 4] 477 } else { 478 set width [expr [ScreenX $w] - [ScreenX 0]] 479 } 480 set h [$_owner xml get $cpath.height] 481 if { $h == "" || ![string is number $h] || $h <= 0.0 } { 482 set height [expr [image height $img] / 4] 483 } else { 484 set height [expr [ScreenY $h] - [ScreenY 0]] 485 } 486 if { $width != [image width $img] || $height != [image height $img] } { 487 set dst [image create picture -width $width -height $height] 488 $dst resample $img -filter box 489 image delete $img 490 set img $dst 491 } 492 } elseif { [llength $coords] == 4 } { 493 foreach { x1 y1 x2 y2 } $coords break 494 if { $x1 > $x2 } { 495 set tmp $x1 496 set x1 $x2 497 set x2 $tmp 498 } 499 if { $y1 > $y2 } { 500 set tmp $x1 501 set x1 $x2 502 set x2 $tmp 503 } 504 set width [expr $x2 - $x1 + 1] 505 set height [expr $x2 - $x1 + 1] 506 if { $width != [image width $img] || $height != [image height $img] } { 507 set dst [image create picture -width $width -height $height] 508 $dst resample $img -filter box 509 image delete $img 510 set img $dst 511 } 512 } else { 513 set width [expr [image width $img] / 4] 514 set height [expr [image height $img] / 4] 515 set dst [image create picture -width $width -height $height] 516 $dst resample $img -filter box 517 image delete $img 518 set img $dst 519 set x1 0 520 set y1 0 521 } 522 set contents [$_owner xml get $cpath.contents] 523 if { [string compare -length 5 $contents "file:"] } { 524 set fileName [string range $contents 5 end] 525 set img [image create picture -file $fileName] 526 } elseif { [string compare -length 5 $contents "http:"] } { 527 puts stderr "don't know how to handle http" 528 } else { 529 set img [image create picture -data $contents] 530 } 531 set options(-tags) $cname 532 set options(-image) $img 533 set id [eval $itk_component(drawing) create oval $coords] 534 set _cname2image($cname) $img 535 set _cname2id($cname) $id 536 eval $itk_component(drawing) itemconfigure $id [array get options] 537 } 538 539 540 itcl::body Rappture::DrawingEntry::ParsePolygon { cpath cname } { 541 array set attr2option { 542 "linewidth" "-width" 543 "arrow" "-arrow" 544 "color" "-fill" 545 } 546 # Set default options first and then let tool.xml override them. 547 array set options { 548 -arrow none 549 -width 0 550 -fill black 551 } 552 # Coords 553 set coords {} 554 set coords [$_owner xml get $cpath.coords] 555 set coords [string trim $coords] 556 if { $coords == "" } { 557 set coords "0 0" 558 } else { 559 set coords [ScreenCoords $coords] 560 } 561 set x1 [lindex $coords 0] 562 set y1 [lindex $coords 1] 563 lappend coords $x1 $y1 564 puts stderr "ParsePolygon owner=$_owner cpath=$cpath coords=$coords" 565 set list {} 566 foreach attr [$_owner xml children $cpath] { 567 if { [info exists attr2option($attr)] } { 568 set option $attr2option($attr) 569 set value [$_owner xml get $cpath.$attr] 570 set options($option) $value 571 } 572 } 573 set options(-tags) $cname 574 set id [eval $itk_component(drawing) create polygon $coords] 575 set _cname2id($cname) $id 576 eval $itk_component(drawing) itemconfigure $id [array get options] 577 } 578 579 # 580 # ParseRectangle -- 581 # 582 itcl::body Rappture::DrawingEntry::ParseRectangle { cpath cname } { 583 array set attr2option { 584 "outline" "-outline" 585 "fill" "-fill" 586 "linewidth" "-linewidth" 587 } 588 puts stderr "ParseRectangle description owner=$_owner cpath=$cpath" 589 590 # Set default options first and then let tool.xml override them. 591 array set options { 592 -fill blue 593 -linewidth 1 594 -outline black 595 } 596 foreach attr [$_owner xml children $cpath] { 597 if { [info exists attr2option($attr)] } { 598 set option $attr2option($attr) 599 set value [$_owner xml get $cpath.$attr] 600 set options($option) $value 601 } 602 } 603 # Coordinates 604 set coords {} 605 set coords [$_owner xml get $cpath.coords] 606 set coords [string trim $coords] 607 if { $coords == "" } { 608 set coords "0 0 1 1" 609 } 610 foreach { x1 y1 x2 y2 } [ScreenCoords $coords] break 611 set id [eval $itk_component(drawing) create rectangle $coords] 612 set _cname2id($cname) $id 613 } 614 615 # 616 # ParseText -- 617 # 618 itcl::body Rappture::DrawingEntry::ParseText { cpath cname } { 619 array set attr2option { 620 "font" "-font" 621 "color" "-fill" 622 "text" "-text" 623 "anchor" "-anchor" 624 } 625 puts stderr "ParseText description owner=$_owner cpath=$cpath" 626 627 # Set default options first and then let tool.xml override them. 628 array set options { 629 -font {Arial 12} 630 -text {} 631 -fill black 632 -anchor c 633 } 634 foreach attr [$_owner xml children $cpath] { 635 if { [info exists attr2option($attr)] } { 636 set option $attr2option($attr) 637 set value [$_owner xml get $cpath.$attr] 638 set options($option) $value 639 } 640 } 641 # Coords 642 set coords {} 643 set coords [$_owner xml get $cpath.coords] 644 set coords [string trim $coords] 645 if { $coords == "" } { 646 set coords "0 0" 647 } else { 648 set coords [ScreenCoords $coords] 649 } 345 650 set options(-tags) $cname 346 651 puts stderr "$itk_component(drawing) create text $coords" … … 351 656 } 352 657 353 itcl::body Rappture::DrawingEntry::ParseRectangle { cpath cname } {354 array set attr2option {355 "outline" "-outline"356 "fill" "-fill"357 "linewidth" "-linewidth"358 }359 puts stderr "ParseRectangle description owner=$_owner cpath=$cpath"360 361 # Set default options first and then let tool.xml override them.362 array set options {363 -fill blue364 -linewidth 1365 -outline black366 }367 foreach attr [$_owner xml children $cpath] {368 if { [info exists attr2option($attr)] } {369 set option $attr2option($attr)370 set value [$_owner xml get $cpath.$attr]371 set options($option) $value372 }373 }374 # Coordinates375 set coords {}376 set coords [$_owner xml get $cpath.coords]377 set coords [string trim $coords]378 if { $coords == "" } {379 set coords "0 0 1 1"380 }381 foreach { x y } [ScreenCoords $coords] break382 set lx $x383 set ly $y384 385 puts stderr "$itk_component(drawing) itemconfigure $id [array get options]"386 eval $itk_component(drawing) itemconfigure $id [array get options]387 set bbox [$itk_component(drawing) bbox $id]388 puts stderr "cpath=$cpath bbox=$bbox"389 set sid [eval $itk_component(drawing) create rectangle $bbox]390 $itk_component(drawing) itemconfigure $sid -fill "" -outline "" \391 -tag $cname-bg392 set sid [eval $itk_component(drawing) create rectangle $bbox]393 $itk_component(drawing) itemconfigure $sid -fill "" -outline "" \394 -tag $cname-sensor395 $itk_component(drawing) bind $cname-sensor <Enter> \396 [itcl::code $this Highlight $cname]397 $itk_component(drawing) bind $cname-sensor <Leave> \398 [itcl::code $this Unhighlight $cname]399 $itk_component(drawing) lower $cname-bg400 $itk_component(drawing) raise $cname-sensor401 }402 658 403 659 itcl::body Rappture::DrawingEntry::ScreenX { x } { … … 445 701 } 446 702 } 447 448 itcl::body Rappture::DrawingEntry::ParseDescription {} {449 puts stderr "ParseDescrption description owner=$_owner path=$_path"450 ParseBackground451 ParseSubstitutions452 foreach cname [$_owner xml children $_path.components] {453 switch -glob -- $cname {454 "line*" {455 ParseLine $_path.components.$cname456 }457 "grid*" {458 ParseGrid $_path.components.$cname459 }460 "text*" {461 ParseText $_path.components.$cname462 }463 "picture*" {464 ParsePicture $_path.components.$cname465 }466 "rectangle*" {467 ParseRectangle $_path.components.$cname468 }469 "oval*" {470 ParseOval $_path.components.$cname471 }472 "polygon*" {473 ParsePolygon $_path.components.$cname474 }475 "hotspot*" {476 ParseHotspot $_path.components.$cname477 }478 }479 }480 }481 482 483 703 484 704 itcl::body Rappture::DrawingEntry::Highlight { tag } { … … 622 842 } 623 843 } 844 845 # 846 # ParseLine -- 847 # 848 itcl::body Rappture::DrawingEntry::Invoke { cname x y } { 849 850 set controls $_cname2controls($cname) 851 if { [llength $controls] == 0 } { 852 puts stderr "no controls defined for $cname" 853 return 854 } 855 # Build a popup with the designated controls 856 set popup .drawingentrypopup 857 if { ![winfo exists $popup] } { 858 # Create a popup for the print dialog 859 Rappture::Balloon $popup -title "Change values..." 860 set inner [$popup component inner] 861 foreach w [winfo children $inner] { 862 destroy $w 863 } 864 } 865 BuildControls $popup $controls 866 foreach path $controls { 867 Insert $inner $path 868 } 869 button 870 update 871 # Activate the popup and call for the output. 872 incr x [winfo rootx $itk_component(drawing)] 873 incr y [winfo rooty $itk_component(drawing)] 874 $popup activate @$x,$y left 875 set inner [$popup component inner] 876 $inner.print print $itk_component(plot) \ 877 $toolName $plotName] 878 $popup deactivate 879 return $output 880 881 $popup configure \ 882 -deactivatecommand [list $inner.print reset] 883 blt::table $inner 0,0 $inner.print -fill both 884 885 tkwait variable _done 886 887 888 # Create the print dialog widget and add it to the 889 # the balloon popup. 890 891 } 892 } 893 894 itcl::body Rappture::DrawingEntry::Insert { inner path } { 895 set pos [llength $_controls] 896 incr _counter 897 set name "control$_counter" 898 set path [$_owner xml element -as path $path] 899 900 set _name2info($name-path) $path 901 set _name2info($name-label) "" 902 set _name2info($name-type) "" 903 set w $inner.v$name 904 set _name2info($name-value) $w 905 set _name2info($name-enable) "yes" 906 set _name2info($name-disablestyle) "greyout" 907 908 set type [$_owner xml element -as type $path] 909 set _name2info($name-type) $type 910 switch -- $type { 911 choice { 912 Rappture::ChoiceEntry $w $_owner $path 913 bind $w <<Value>> [itcl::code $this _controlChanged $name] 914 } 915 filechoice { 916 Rappture::FileChoiceEntry $w $_owner $path 917 bind $w <<Value>> [itcl::code $this _controlChanged $name] 918 } 919 filelist { 920 Rappture::FileListEntry $w $_owner $path 921 bind $w <<Value>> [itcl::code $this _controlChanged $name] 922 } 923 group { 924 Rappture::GroupEntry $w $_owner $path 925 } 926 loader { 927 Rappture::Loader $w $_owner $path -tool [$_owner tool] 928 bind $w <<Value>> [itcl::code $this _controlChanged $name] 929 } 930 number { 931 Rappture::NumberEntry $w $_owner $path 932 bind $w <<Value>> [itcl::code $this _controlChanged $name] 933 } 934 integer { 935 Rappture::IntegerEntry $w $_owner $path 936 bind $w <<Value>> [itcl::code $this _controlChanged $name] 937 } 938 boolean { 939 Rappture::BooleanEntry $w $_owner $path 940 bind $w <<Value>> [itcl::code $this _controlChanged $name] 941 } 942 string { 943 Rappture::TextEntry $w $_owner $path 944 bind $w <<Value>> [itcl::code $this _controlChanged $name] 945 } 946 image { 947 Rappture::ImageEntry $w $_owner $path 948 } 949 separator { 950 # no widget to create 951 set _name2info($name-value) "--" 952 } 953 note { 954 Rappture::Note $w $_owner $path 955 } 956 periodicelement { 957 Rappture::PeriodicElementEntry $w $_owner $path 958 bind $w <<Value>> [itcl::code $this _controlChanged $name] 959 } 960 default { 961 error "don't know how to add control type \"$type\"" 962 } 963 } 964 965 # 966 # If this element has an <enable> expression, then register its 967 # controlling widget here. 968 # 969 set notify [string trim [$_owner xml get $path.about.notify]] 970 971 set disablestyle [string trim [$_owner xml get $path.about.disablestyle]] 972 if { $disablestyle != "" } { 973 set _name2info($name-disablestyle) $disablestyle 974 } 975 # 976 # If this element has an <enable> expression, then register 977 # its controlling widget here. 978 # 979 set enable [string trim [$_owner xml get $path.about.enable]] 980 if {"" == $enable} { 981 set enable yes 982 } 983 if {![string is boolean $enable]} { 984 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/]+)?} 985 set rest $enable 986 set enable "" 987 set deps "" 988 while {1} { 989 if {[regexp -indices $re $rest match]} { 990 foreach {s0 s1} $match break 991 992 if {[string index $rest [expr {$s0-1}]] == "\"" 993 && [string index $rest [expr {$s1+1}]] == "\""} { 994 # string in ""'s? then leave it alone 995 append enable [string range $rest 0 $s1] 996 set rest [string range $rest [expr {$s1+1}] end] 997 } else { 998 # 999 # This is a symbol which should be substituted 1000 # it can be either: 1001 # input.foo.bar 1002 # input.foo.bar:units 1003 # 1004 set cpath [string range $rest $s0 $s1] 1005 set parts [split $cpath :] 1006 set ccpath [lindex $parts 0] 1007 set units [lindex $parts 1] 1008 1009 # make sure we have the standard path notation 1010 set stdpath [$_owner regularize $ccpath] 1011 if {"" == $stdpath} { 1012 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." 1013 set stdpath $ccpath 1014 } 1015 # substitute [_controlValue ...] call in place of path 1016 append enable [string range $rest 0 [expr {$s0-1}]] 1017 append enable [format {[_controlValue %s %s]} $stdpath $units] 1018 lappend deps $stdpath 1019 set rest [string range $rest [expr {$s1+1}] end] 1020 } 1021 } else { 1022 append enable $rest 1023 break 1024 } 1025 } 1026 1027 foreach cpath $deps { 1028 $_owner dependenciesfor $cpath $path 1029 } 1030 } 1031 set _name2info($name-enable) $enable 1032 1033 $_owner widgetfor $path $w 1034 1035 if {[lsearch {control group separator note} $type] < 0} { 1036 # make a label for this control 1037 set label [$w label] 1038 if {"" != $label} { 1039 set _name2info($name-label) $_frame.l$name 1040 set font [option get $itk_component(hull) labelFont Font] 1041 label $_name2info($name-label) -text [_formatLabel $label] \ 1042 -font $font 1043 } 1044 1045 # register the tooltip for this control 1046 set tip [$w tooltip] 1047 if {"" != $tip} { 1048 Rappture::Tooltip::for $w $tip 1049 1050 # add the tooltip to the label too, if there is one 1051 if {$_name2info($name-label) != ""} { 1052 Rappture::Tooltip::for $_name2info($name-label) $tip 1053 } 1054 } 1055 } 1056 1057 # insert the new control onto the known list 1058 set _controls [linsert $_controls $pos $name] 1059 _monitor $name on 1060 1061 # now that we have a new control, we should fix the layout 1062 after idle [itcl::code $this LayoutControls] 1063 ControlChanged $name 1064 return $name 1065 } 1066 1067 # ---------------------------------------------------------------------- 1068 # USAGE: ControlChanged <name> 1069 # 1070 # Invoked automatically whenever the value for a control changes. 1071 # Sends a notification along to the tool controlling this panel. 1072 # ---------------------------------------------------------------------- 1073 itcl::body Rappture::DrawingEntry::ControlChanged {name} { 1074 set path $_name2info($name-path) 1075 # 1076 # Let the owner know that this control changed. 1077 # 1078 if {"" != $_owner} { 1079 $_owner changed $path 1080 } 1081 } 1082 1083 # ---------------------------------------------------------------------- 1084 # USAGE: LayoutControls 1085 # 1086 # Used internally to fix the layout of controls whenever controls 1087 # are added or deleted, or when the control arrangement changes. 1088 # There are a lot of heuristics here trying to achieve a "good" 1089 # arrangement of controls. 1090 # ---------------------------------------------------------------------- 1091 itcl::body Rappture::Controls::LayoutControls {} { 1092 # 1093 # Clear any existing layout 1094 # 1095 foreach name $_controls { 1096 foreach elem {label value} { 1097 set w $_name2info($name-$elem) 1098 if {$w != "" && [winfo exists $w]} { 1099 grid forget $w 1100 } 1101 } 1102 } 1103 grid forget $_frame.empty 1104 1105 # 1106 # Decide which widgets should be shown and which should be hidden. 1107 # 1108 set hidden "" 1109 set showing "" 1110 foreach name $_controls { 1111 set show 1 1112 set cond $_name2info($name-enable) 1113 if {[string is boolean $cond] && !$cond} { 1114 # hard-coded "off" -- ignore completely 1115 } elseif {[catch {expr $cond} show] == 0} { 1116 set type $_name2info($name-type) 1117 set disablestyle $_name2info($name-disablestyle) 1118 set lwidget $_name2info($name-label) 1119 set vwidget $_name2info($name-value) 1120 if {[lsearch -exact {group image structure} $type] >= 0 || 1121 $disablestyle == "hide" } { 1122 if {$show ne "" && $show} { 1123 lappend showing $name 1124 } else { 1125 lappend hidden $name 1126 } 1127 } else { 1128 # show other objects, but enable/disable them 1129 lappend showing $name 1130 if {$show ne "" && $show} { 1131 if {[winfo exists $vwidget]} { 1132 $vwidget configure -state normal 1133 } 1134 if {[winfo exists $lwidget]} { 1135 $lwidget configure -foreground \ 1136 [lindex [$lwidget configure -foreground] 3] 1137 } 1138 } else { 1139 if {[winfo exists $vwidget]} { 1140 $vwidget configure -state disabled 1141 } 1142 if {[winfo exists $lwidget]} { 1143 $lwidget configure -foreground gray 1144 } 1145 } 1146 } 1147 } else { 1148 bgerror "Error in <enable> expression for \"$_name2info($name-path)\":\n $show" 1149 } 1150 } 1151 1152 # store the showing tabs in the object so it can be used in _changeTabs 1153 set _showing $showing 1154 1155 # 1156 # SCHEME: hlabels 1157 # simple "Label: Value" layout 1158 # 1159 #pack forget $_tabs 1160 grid propagate $_frame on 1161 grid columnconfigure $_frame 0 -weight 0 1162 grid rowconfigure $_frame 0 -weight 0 1163 1164 set expand 0 ;# most controls float to top 1165 set row 0 1166 foreach name $showing { 1167 set wl $_name2info($name-label) 1168 if {$wl != "" && [winfo exists $wl]} { 1169 grid $wl -row $row -column 0 -sticky e 1170 } 1171 1172 set wv $_name2info($name-value) 1173 if {$wv != "" && [winfo exists $wv]} { 1174 if {$wl != ""} { 1175 grid $wv -row $row -column 1 -sticky ew 1176 } else { 1177 grid $wv -row $row -column 0 -columnspan 2 -sticky ew 1178 } 1179 1180 grid rowconfigure $_frame $row -weight 0 1181 1182 switch -- [winfo class $wv] { 1183 TextEntry { 1184 if {[regexp {[0-9]+x[0-9]+} [$wv size]]} { 1185 grid $wl -sticky n -pady 4 1186 grid $wv -sticky nsew 1187 grid rowconfigure $_frame $row -weight 1 1188 grid columnconfigure $_frame 1 -weight 1 1189 set expand 1 1190 } 1191 } 1192 GroupEntry { 1193 $wv configure -heading yes 1194 1195 # 1196 # Scan through all children in this group 1197 # and see if any demand more space. If the 1198 # group contains a structure or a note, then 1199 # make sure that the group itself is set to 1200 # expand/fill. 1201 # 1202 set queue [winfo children $wv] 1203 set expandgroup 0 1204 while {[llength $queue] > 0} { 1205 set w [lindex $queue 0] 1206 set queue [lrange $queue 1 end] 1207 set c [winfo class $w] 1208 if {[lsearch {DeviceEditor Note} $c] >= 0} { 1209 set expandgroup 1 1210 break 1211 } 1212 eval lappend queue [winfo children $w] 1213 } 1214 if {$expandgroup} { 1215 set expand 1 1216 grid $wv -sticky nsew 1217 grid rowconfigure $_frame $row -weight 1 1218 } 1219 } 1220 Note { 1221 grid $wv -sticky nsew 1222 grid rowconfigure $_frame $row -weight 1 1223 set expand 1 1224 } 1225 } 1226 grid columnconfigure $_frame 1 -weight 1 1227 } elseif {$wv == "--"} { 1228 grid rowconfigure $_frame $row -minsize 10 1229 } 1230 1231 incr row 1232 grid rowconfigure $_frame $row -minsize $itk_option(-padding) 1233 incr row 1234 } 1235 grid $_frame.empty -row $row 1236 1237 # 1238 # If there are any hidden items, then make the bottom of 1239 # this form fill up any extra space, so the form floats 1240 # to the top. Otherwise, it will jitter around as the 1241 # hidden items come and go. 1242 # 1243 if {[llength $hidden] > 0 && !$expand} { 1244 grid rowconfigure $_frame 99 -weight 1 1245 } else { 1246 grid rowconfigure $_frame 99 -weight 0 1247 } 1248 }
Note: See TracChangeset
for help on using the changeset viewer.