Changeset 3763
- Timestamp:
- Jul 9, 2013, 4:45:00 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3/gui/scripts/controls.tcl
r3669 r3763 428 428 } 429 429 grid rowconfigure $_frame 99 -weight 0 430 430 431 431 for {set c 0} {$c < $cmax} {incr c} { 432 432 grid columnconfigure $_frame $c -weight 0 -minsize 0 433 433 } 434 434 435 435 foreach name $_controls { 436 436 foreach elem {label value} { … … 442 442 } 443 443 grid forget $_frame.empty 444 444 445 445 if {[$_tabs size] > 0} { 446 446 $_tabs delete 0 end 447 447 } 448 448 449 449 # 450 450 # Decide which widgets should be shown and which should be hidden. … … 455 455 set show 1 456 456 set cond $_name2info($name-enable) 457 if {[catch {expr $cond} show] == 0} { 457 if {[string is boolean $cond] && !$cond} { 458 # hard-coded "off" -- ignore completely 459 460 # When the "enable" of a control is hardcoded "off", "0", etc., it 461 # means to hide the control. This is used by bandstrlab to add 462 # invisible parameters to a structure. The value of the parameter 463 # is used by other widgets with enable statements. 464 465 # The proper method for doing this is to add a 466 # <disablestyle>hide<disablestyle> 467 # tag to the about section of the control. 468 469 } elseif {[catch {expr $cond} show] == 0} { 458 470 set type $_name2info($name-type) 459 471 set disablestyle $_name2info($name-disablestyle) 460 472 set lwidget $_name2info($name-label) 461 473 set vwidget $_name2info($name-value) 462 474 if {[lsearch -exact {group image structure} $type] >= 0 || 463 475 $disablestyle == "hide" } { 464 476 if {$show ne "" && $show} { 465 477 lappend showing $name … … 487 499 } 488 500 } 489 501 490 502 # store the showing tabs in the object so it can be used in _changeTabs 491 503 set _showing $showing 492 504 493 505 # 494 506 # Decide on a layout scheme: … … 515 527 } 516 528 } 517 529 518 530 # if the layout is "sentence:..." then create new parts 519 531 if {[string match {sentence:*} $itk_option(-layout)] 520 532 && [array size _sentenceparts] == 0} { 521 533 set n 0 522 534 set font [option get $itk_component(hull) labelFont Font] … … 525 537 foreach {s0 s1} $name break 526 538 set name [string range $str $s0 $s1] 527 539 528 540 # create a label for the string before the substitution 529 541 foreach {s0 s1} $match break … … 535 547 lappend _sentenceparts(fragments) $lname 536 548 } 537 549 538 550 # add the widget for the substitution part 539 551 set found "" … … 549 561 puts stderr "WARNING: name \"$name\" in sentence layout \"$itk_option(-layout)\" not recognized" 550 562 } 551 563 552 564 set str [string range $str [expr {$s1+1}] end] 553 565 } 554 566 555 567 # create a label for any trailing string 556 568 set str [string trim $str] … … 562 574 } 563 575 } 564 576 565 577 switch -glob -- $_scheme { 566 tabs { 567 # 568 # SCHEME: tabs 569 # put a series of groups into a tabbed notebook 570 # 571 572 # stop covering up the tabset and put the _frame inside the tabs 573 pack forget $_frame 574 $_tabs configure -width 0 -height 0 575 576 set gn 1 577 foreach name $showing { 578 set wv $_name2info($name-value) 579 $wv configure -heading no 580 set label [$wv component heading cget -text] 581 if {"" == $label} { 582 set label "Group #$gn" 583 } 584 set _name2info($name-label) $label 585 $_tabs insert end $name -text $label \ 586 -activebackground $itk_option(-background) \ 587 -window $_frame -fill both 588 incr gn 589 } 590 591 # compute the overall size 592 # BE CAREFUL: do this after setting "-heading no" above 593 $_dispatcher event -now !resize 594 595 grid columnconfigure $_frame 0 -weight 1 596 grid rowconfigure $_frame 0 -weight 1 597 598 $_tabs select 0; _changeTabs 599 } 600 601 vertical { 602 # 603 # SCHEME: vertical 604 # simple "Label: Value" layout 605 # 606 if {[$_tabs size] > 0} { 607 $_tabs delete 0 end 608 } 609 pack $_frame -expand yes -fill both 610 $_tabs configure -width [winfo reqwidth $_frame] \ 611 -height [winfo reqheight $_frame] 612 613 set expand 0 ;# most controls float to top 614 set row 0 615 foreach name $showing { 616 set wl $_name2info($name-label) 617 if {$wl != "" && [winfo exists $wl]} { 618 grid $wl -row $row -column 0 -sticky e 619 } 620 621 set wv $_name2info($name-value) 622 if {$wv ne "" && [winfo exists $wv]} { 623 if {$wl != ""} { 624 grid $wv -row $row -column 1 -sticky ew 625 } else { 626 grid $wv -row $row -column 0 -columnspan 2 -sticky ew 578 tabs { 579 # 580 # SCHEME: tabs 581 # put a series of groups into a tabbed notebook 582 # 583 584 # stop covering up the tabset and put the _frame inside the tabs 585 pack forget $_frame 586 $_tabs configure -width 0 -height 0 587 588 set gn 1 589 foreach name $showing { 590 set wv $_name2info($name-value) 591 $wv configure -heading no 592 set label [$wv component heading cget -text] 593 if {"" == $label} { 594 set label "Group #$gn" 627 595 } 628 629 grid rowconfigure $_frame $row -weight 0 630 631 switch -- [winfo class $wv] { 632 TextEntry { 633 if {[regexp {[0-9]+x[0-9]+} [$wv size]]} { 634 grid $wl -sticky ne -pady 4 596 set _name2info($name-label) $label 597 $_tabs insert end $name -text $label \ 598 -activebackground $itk_option(-background) \ 599 -window $_frame -fill both 600 incr gn 601 } 602 603 # compute the overall size 604 # BE CAREFUL: do this after setting "-heading no" above 605 $_dispatcher event -now !resize 606 607 grid columnconfigure $_frame 0 -weight 1 608 grid rowconfigure $_frame 0 -weight 1 609 610 $_tabs select 0; _changeTabs 611 } 612 613 vertical { 614 # 615 # SCHEME: vertical 616 # simple "Label: Value" layout 617 # 618 if {[$_tabs size] > 0} { 619 $_tabs delete 0 end 620 } 621 pack $_frame -expand yes -fill both 622 $_tabs configure -width [winfo reqwidth $_frame] \ 623 -height [winfo reqheight $_frame] 624 625 set expand 0 ;# most controls float to top 626 set row 0 627 foreach name $showing { 628 set wl $_name2info($name-label) 629 if {$wl != "" && [winfo exists $wl]} { 630 grid $wl -row $row -column 0 -sticky e 631 } 632 633 set wv $_name2info($name-value) 634 if {$wv ne "" && [winfo exists $wv]} { 635 if {$wl != ""} { 636 grid $wv -row $row -column 1 -sticky ew 637 } else { 638 grid $wv -row $row -column 0 -columnspan 2 -sticky ew 639 } 640 641 grid rowconfigure $_frame $row -weight 0 642 643 switch -- [winfo class $wv] { 644 TextEntry { 645 if {[regexp {[0-9]+x[0-9]+} [$wv size]]} { 646 grid $wl -sticky ne -pady 4 647 grid $wv -sticky nsew 648 grid rowconfigure $_frame $row -weight 1 649 grid columnconfigure $_frame 1 -weight 1 650 set expand 1 651 } 652 } 653 GroupEntry { 654 $wv configure -heading yes 655 656 # 657 # Scan through all children in this group 658 # and see if any demand more space. If the 659 # group contains a structure or a note, then 660 # make sure that the group itself is set to 661 # expand/fill. 662 # 663 set queue [winfo children $wv] 664 set expandgroup 0 665 while {[llength $queue] > 0} { 666 set w [lindex $queue 0] 667 set queue [lrange $queue 1 end] 668 set c [winfo class $w] 669 if {[lsearch {DeviceEditor Note} $c] >= 0} { 670 set expandgroup 1 671 break 672 } 673 eval lappend queue [winfo children $w] 674 } 675 if {$expandgroup} { 676 set expand 1 677 grid $wv -sticky nsew 678 grid rowconfigure $_frame $row -weight 1 679 } 680 } 681 Note { 635 682 grid $wv -sticky nsew 636 683 grid rowconfigure $_frame $row -weight 1 637 grid columnconfigure $_frame 1 -weight 1638 684 set expand 1 639 685 } 640 686 } 641 GroupEntry { 642 $wv configure -heading yes 643 644 # 645 # Scan through all children in this group 646 # and see if any demand more space. If the 647 # group contains a structure or a note, then 648 # make sure that the group itself is set to 649 # expand/fill. 650 # 651 set queue [winfo children $wv] 652 set expandgroup 0 653 while {[llength $queue] > 0} { 654 set w [lindex $queue 0] 655 set queue [lrange $queue 1 end] 656 set c [winfo class $w] 657 if {[lsearch {DeviceEditor Note} $c] >= 0} { 658 set expandgroup 1 659 break 660 } 661 eval lappend queue [winfo children $w] 662 } 663 if {$expandgroup} { 664 set expand 1 665 grid $wv -sticky nsew 666 grid rowconfigure $_frame $row -weight 1 667 } 668 } 669 Note { 670 grid $wv -sticky nsew 671 grid rowconfigure $_frame $row -weight 1 672 set expand 1 673 } 687 grid columnconfigure $_frame 1 -weight 1 674 688 } 675 grid columnconfigure $_frame 1 -weight 1 676 } 677 678 incr row 679 grid rowconfigure $_frame $row -minsize $itk_option(-padding) 680 incr row 681 } 682 grid $_frame.empty -row $row 683 684 # 685 # If there are any hidden items, then make the bottom of 686 # this form fill up any extra space, so the form floats 687 # to the top. Otherwise, it will jitter around as the 688 # hidden items come and go. 689 # 690 if {[llength $hidden] > 0 && !$expand} { 691 grid rowconfigure $_frame 99 -weight 1 692 } else { 693 grid rowconfigure $_frame 99 -weight 0 694 } 695 } 696 697 horizontal { 698 # 699 # SCHEME: horizontal 700 # lay out left to right 701 # 702 if {[$_tabs size] > 0} { 703 $_tabs delete 0 end 704 } 705 pack $_frame -expand yes -fill both 706 $_tabs configure -width [winfo reqwidth $_frame] \ 707 -height [winfo reqheight $_frame] 708 709 set col 0 710 set pad [expr {$itk_option(-padding)/2}] 711 foreach name $showing { 712 set wl $_name2info($name-label) 713 if {$wl != "" && [winfo exists $wl]} { 714 grid $wl -row 0 -column $col -sticky e -padx $pad 689 690 incr row 691 grid rowconfigure $_frame $row -minsize $itk_option(-padding) 692 incr row 693 } 694 grid $_frame.empty -row $row 695 696 # 697 # If there are any hidden items, then make the bottom of 698 # this form fill up any extra space, so the form floats 699 # to the top. Otherwise, it will jitter around as the 700 # hidden items come and go. 701 # 702 if {[llength $hidden] > 0 && !$expand} { 703 grid rowconfigure $_frame 99 -weight 1 704 } else { 705 grid rowconfigure $_frame 99 -weight 0 706 } 707 } 708 709 horizontal { 710 # 711 # SCHEME: horizontal 712 # lay out left to right 713 # 714 if {[$_tabs size] > 0} { 715 $_tabs delete 0 end 716 } 717 pack $_frame -expand yes -fill both 718 $_tabs configure -width [winfo reqwidth $_frame] \ 719 -height [winfo reqheight $_frame] 720 721 set col 0 722 set pad [expr {$itk_option(-padding)/2}] 723 foreach name $showing { 724 set wl $_name2info($name-label) 725 if {$wl != "" && [winfo exists $wl]} { 726 grid $wl -row 0 -column $col -sticky e -padx $pad 727 incr col 728 } 729 730 set wv $_name2info($name-value) 731 if {$wv != "" && [winfo exists $wv]} { 732 grid $wv -row 0 -column $col -sticky ew -padx $pad 733 grid columnconfigure $_frame $col -weight 0 734 incr col 735 } 736 } 737 } 738 739 sentence:* { 740 # 741 # SCHEME: sentence 742 # lay out left to right with sentence parts: "( [x] , [y] )" 743 # 744 if {[$_tabs size] > 0} { 745 $_tabs delete 0 end 746 } 747 pack $_frame -expand yes -fill both 748 $_tabs configure -width [winfo reqwidth $_frame] \ 749 -height [winfo reqheight $_frame] 750 751 set col 0 752 set pad [expr {$itk_option(-padding)/2}] 753 foreach widget $_sentenceparts(all) { 754 grid $widget -row 0 -column $col -padx $pad 715 755 incr col 716 756 } 717 718 set wv $_name2info($name-value) 719 if {$wv != "" && [winfo exists $wv]} { 720 grid $wv -row 0 -column $col -sticky ew -padx $pad 721 grid columnconfigure $_frame $col -weight 0 722 incr col 723 } 724 } 725 } 726 727 sentence:* { 728 # 729 # SCHEME: sentence 730 # lay out left to right with sentence parts: "( [x] , [y] )" 731 # 732 if {[$_tabs size] > 0} { 733 $_tabs delete 0 end 734 } 735 pack $_frame -expand yes -fill both 736 $_tabs configure -width [winfo reqwidth $_frame] \ 737 -height [winfo reqheight $_frame] 738 739 set col 0 740 set pad [expr {$itk_option(-padding)/2}] 741 foreach widget $_sentenceparts(all) { 742 grid $widget -row 0 -column $col -padx $pad 743 incr col 744 } 745 } 757 } 746 758 } 747 759 }
Note: See TracChangeset
for help on using the changeset viewer.