Ignore:
Timestamp:
Jul 19, 2005, 1:15:04 AM (19 years ago)
Author:
mmc
Message:

Fixed the rendering of groups, and groups within groups.
If groups are mixed in with other elements, then they are
drawn with a gray outline/heading, with the title taken
from the <group><about><label>. However, if a group
contains only other groups, then it is treated as a tabbed
notebook, and each group within is put on a separate page.

WARNING: There are many bad interactions between the
blt::tabset, the Rappture::Scroller, and the Rappture::Pager.
Pages shake violently when all are in play. The only way I
could get them to settle down was by putting the tabs above
the pages they control. Have to revisit this some time to
make it look better...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/controls.tcl

    r23 r26  
    1111# ======================================================================
    1212package require Itk
     13package require BLT
    1314
    1415option add *Controls.padding 4 widgetDefault
     
    3132    protected method _controlChanged {path}
    3233    protected method _formatLabel {str}
     34    protected method _changeTabs {}
    3335
    3436    private variable _owner ""       ;# controls belong to this owner
     37    private variable _tabs ""        ;# optional tabset for groups
     38    private variable _frame ""       ;# pack controls into this frame
    3539    private variable _counter 0      ;# counter for control names
    3640    private variable _dispatcher ""  ;# dispatcher for !events
     
    5155
    5256    set _owner $owner
     57
     58    Rappture::Scroller $itk_interior.sc -xscrollmode none -yscrollmode auto
     59    pack $itk_interior.sc -expand yes -fill both
     60    set f [$itk_interior.sc contents frame]
     61
     62    set _tabs [blt::tabset $f.tabs -borderwidth 0 -relief flat \
     63        -side top -tearoff 0 -highlightthickness 0 \
     64        -selectbackground $itk_option(-background) \
     65        -selectcommand [itcl::code $this _changeTabs]]
     66
     67    set _frame [frame $f.inner]
     68    pack $_frame -expand yes -fill both
    5369
    5470    eval itk_initialize $args
     
    7894    set _name2info($name-path) $path
    7995    set _name2info($name-label) ""
    80     set _name2info($name-value) [set w $itk_interior.v$name]
     96    set _name2info($name-value) [set w $_frame.v$name]
    8197
    8298    set type [$_owner xml element -as type $path]
     
    126142        set label [$w label]
    127143        if {"" != $label} {
    128             set _name2info($name-label) $itk_interior.l$name
     144            set _name2info($name-label) $_frame.l$name
    129145            set font [option get $itk_component(hull) labelFont Font]
    130146            label $_name2info($name-label) -text [_formatLabel $label] \
     
    257273        }
    258274    }
     275    if {[$_tabs size] > 0} {
     276        $_tabs delete 0 end
     277    }
    259278
    260279    #
    261     # Lay out the widgets in a simple "Label: Value" scheme...
     280    # Decide on a layout scheme:
     281    #   tabs ...... best if all elements within are groups
     282    #   hlabels ... horizontal labels (label: value)
    262283    #
    263     set row 0
    264     foreach name $_controls {
    265         set wl $_name2info($name-label)
    266         if {$wl != "" && [winfo exists $wl]} {
    267             grid $wl -row $row -column 0 -sticky e
    268         }
    269 
    270         set wv $_name2info($name-value)
    271         if {$wv != "" && [winfo exists $wv]} {
    272             grid $wv -row $row -column 1 -sticky ew
    273 
    274             set frame [winfo parent $wv]
    275             grid rowconfigure $frame $row -weight 0
    276             grid rowconfigure $frame $row -weight 0
    277 
    278             switch -- [winfo class $wv] {
    279                 TextEntry {
    280                     if {[regexp {[0-9]+x[0-9]+} [$wv size]]} {
    281                         grid $wl -sticky n -pady 4
    282                         grid $wv -sticky nsew
    283                         grid rowconfigure $frame $row -weight 1
    284                         grid columnconfigure $frame 1 -weight 1
     284    if {[llength $_controls] >= 2} {
     285        # assume tabs for multiple groups
     286        set scheme tabs
     287        foreach name $_controls {
     288            set w $_name2info($name-value)
     289
     290            if {[winfo class $w] != "GroupEntry"} {
     291                # something other than a group? then fall back on hlabels
     292                set scheme hlabels
     293                break
     294            }
     295        }
     296    } else {
     297        set scheme hlabels
     298    }
     299
     300    switch -- $scheme {
     301      tabs {
     302        #
     303        # SCHEME: tabs
     304        # put a series of groups into a tabbed notebook
     305        #
     306
     307        # use inner frame within tabs to show current group
     308        pack $_tabs -before $_frame -fill x
     309
     310        set gn 1
     311        foreach name $_controls {
     312            set wv $_name2info($name-value)
     313            $wv configure -heading no
     314
     315            set label [$wv component heading cget -text]
     316            if {"" == $label} {
     317                set label "Group #$gn"
     318            }
     319            set _name2info($name-label) $label
     320
     321            $_tabs insert end $label \
     322                -activebackground $itk_option(-background)
     323
     324            incr gn
     325        }
     326
     327        # compute the overall size
     328        # BE CAREFUL: do this after setting "-heading no" above
     329        set maxw 0
     330        set maxh 0
     331        update idletasks
     332        foreach name $_controls {
     333            set w [winfo reqwidth $wv]
     334            if {$w > $maxw} { set maxw $w }
     335            set h [winfo reqheight $wv]
     336            if {$h > $maxh} { set maxh $h }
     337        }
     338        $_frame configure -width $maxw -height $maxh
     339
     340        grid propagate $_frame off
     341        grid columnconfigure $_frame 0 -weight 1
     342        grid rowconfigure $_frame 0 -weight 1
     343
     344        $_tabs select 0; _changeTabs
     345      }
     346
     347      hlabels {
     348        #
     349        # SCHEME: hlabels
     350        # simple "Label: Value" layout
     351        #
     352        pack forget $_tabs
     353        grid propagate $_frame on
     354        grid columnconfigure $_frame 0 -weight 0
     355        grid rowconfigure $_frame 0 -weight 0
     356
     357        set row 0
     358        foreach name $_controls {
     359            set wl $_name2info($name-label)
     360            if {$wl != "" && [winfo exists $wl]} {
     361                grid $wl -row $row -column 0 -sticky e
     362            }
     363
     364            set wv $_name2info($name-value)
     365            if {$wv != "" && [winfo exists $wv]} {
     366                if {$wl != ""} {
     367                    grid $wv -row $row -column 1 -sticky ew
     368                } else {
     369                    grid $wv -row $row -column 0 -columnspan 2 -sticky ew
     370                }
     371
     372                set frame [winfo parent $wv]
     373                grid rowconfigure $frame $row -weight 0
     374                grid rowconfigure $frame $row -weight 0
     375
     376                switch -- [winfo class $wv] {
     377                    TextEntry {
     378                        if {[regexp {[0-9]+x[0-9]+} [$wv size]]} {
     379                            grid $wl -sticky n -pady 4
     380                            grid $wv -sticky nsew
     381                            grid rowconfigure $frame $row -weight 1
     382                            grid columnconfigure $frame 1 -weight 1
     383                        }
     384                    }
     385                    GroupEntry {
     386                        $wv configure -heading yes
    285387                    }
    286388                }
    287             }
    288             grid columnconfigure $frame 1 -weight 1
    289         }
    290 
    291 
    292         incr row
    293         grid rowconfigure [winfo parent $w] $row -minsize $itk_option(-padding)
    294         incr row
     389                grid columnconfigure $frame 1 -weight 1
     390            }
     391
     392
     393            incr row
     394            grid rowconfigure [winfo parent $w] $row \
     395                -minsize $itk_option(-padding)
     396            incr row
     397        }
     398      }
    295399    }
    296400}
     
    325429
    326430# ----------------------------------------------------------------------
     431# USAGE: _changeTabs
     432#
     433# Used internally to change tabs when the user clicks on a tab
     434# in the "tabs" layout mode.  This mode is used when the widget
     435# contains nothing but groups, as a compact way of representing
     436# the groups.
     437# ----------------------------------------------------------------------
     438itcl::body Rappture::Controls::_changeTabs {} {
     439    set i [$_tabs index select]
     440    set name [lindex $_controls $i]
     441    if {"" != $name} {
     442        foreach w [grid slaves $_frame] {
     443            grid forget $w
     444        }
     445
     446        set wv $_name2info($name-value)
     447        grid $wv -row 0 -column 0 -sticky new
     448    }
     449}
     450
     451# ----------------------------------------------------------------------
    327452# OPTION: -padding
    328453# ----------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.