📄 panedwindow.itk
字号:
# ------------------------------------------------------------------# OPTION: -sashindent## Specifies the placement of the sash along the panes. A positive# value causes the sash to be offset from the near (left/top) side# of the pane, and a negative value causes the sash to be offset from# the far (right/bottom) side. If the offset is greater than the # width, then the sash is placed flush against the side. # ------------------------------------------------------------------itcl::configbody iwidgets::Panedwindow::sashindent { set pixels [winfo pixels $itk_component(hull) \ $itk_option(-sashindent)] set itk_option(-sashindent) $pixels if {$_initialized} { for {set i 1} {$i < [llength $_activePanes]} {incr i} { _placeSash $i } }}# ------------------------------------------------------------------# METHODS# ------------------------------------------------------------------# ------------------------------------------------------------------# METHOD: index index## Searches the panes in the paned window for the one with the # requested tag, numerical index, or keyword "end". Returns the pane's # numerical index if found, otherwise error.# ------------------------------------------------------------------ itcl::body iwidgets::Panedwindow::index {index} { if {[llength $_panes] > 0} { if {[regexp {(^[0-9]+$)} $index]} { if {$index < [llength $_panes]} { return $index } else { error "Panedwindow index \"$index\" is out of range" } } elseif {$index == "end"} { return [expr {[llength $_panes] - 1}] } else { if {[set idx [lsearch $_panes $index]] != -1} { return $idx } error "bad Panedwindow index \"$index\": must be number, end,\ or pattern" } } else { error "Panedwindow \"$itk_component(hull)\" has no panes" }}# ------------------------------------------------------------------# METHOD: childsite ?index?## Given an index return the specifc childsite path name. Invoked # without an index return a list of all the child site panes. The # list is ordered from the near side (left/top).# ------------------------------------------------------------------itcl::body iwidgets::Panedwindow::childsite {args} { if {! $_initialized} { set _initialized 1 reset } if {[llength $args] == 0} { set children {} foreach pane $_panes { lappend children [$itk_component($pane) childSite] } return $children } else { set index [index [lindex $args 0]] return [$itk_component([lindex $_panes $index]) childSite] }}# ------------------------------------------------------------------# METHOD: fraction percentage percentage ?percentage ...?## Sets the visible percentage of the panes. Specifies a list of# percentages which are applied to the currently visible panes from # the near side (left/top). The number of percentages must be equal # to the current number of visible (mapped) panes and add up to 100.# ------------------------------------------------------------------itcl::body iwidgets::Panedwindow::fraction {args} { #set args [linsert $args 0 $percentage1 $percentage2] if {[llength $args] == [llength $_activePanes]} { set sum 0 for {set i 0} {$i < [llength $args]} {incr i} { set sum [expr {$sum + [lindex $args $i]}] } if {$sum == 100} { set perc 0.0 for {set i 0} {$i < [llength $_activePanes]} {incr i} { set _frac($i) $perc set perc [expr {$perc + [expr {[lindex $args $i] / 100.0}]}] } set _frac($i) 1.0 if {[winfo ismapped $itk_component(hull)]} { _placePanes } } else { error "bad fraction arguments \"$args\": they should add\ up to 100" } } elseif {[llength $args] == 0} { for {set i 0; set j 1} {$j < [llength $_activePanes]} {incr i; incr j} { lappend _ret [expr {round(($_frac($j) - $_frac($i))*100)}] } lappend _ret [eval expr {100 - ([join $_ret +])}] return $_ret } else { error "wrong # args: should be \"$itk_component(hull)\ fraction percentage percentage ?percentage ...?\",\ where the number of percentages is\ [llength $_activePanes] and equal 100 or \"$itk_component(hull) fraction\" which will return a list of the current percentages" }}# ------------------------------------------------------------------# METHOD: add tag ?option value option value ...?## Add a new pane to the paned window to the far (right/bottom) side.# The method takes additional options which are passed on to the # pane constructor. These include -margin, and -minimum. The path # of the pane is returned.# ------------------------------------------------------------------itcl::body iwidgets::Panedwindow::add {tag args} { # # Create panes. # itk_component add $tag { eval iwidgets::Pane $itk_interior.pane[incr _unique] $args } { keep -background -cursor } lappend _panes $tag lappend _activePanes $tag reset return $itk_component($tag)}# ------------------------------------------------------------------# METHOD: insert index tag ?option value option value ...?## Insert the specified pane in the paned window just before the one # given by index. Any additional options which are passed on to the # pane constructor. These include -margin, -minimum. The path of # the pane is returned.# ------------------------------------------------------------------itcl::body iwidgets::Panedwindow::insert {index tag args} { # # Create panes. # itk_component add $tag { eval iwidgets::Pane $itk_interior.pane[incr _unique] $args } { keep -background -cursor } set index [index $index] set _panes [linsert $_panes $index $tag] lappend _activePanes $tag reset return $itk_component($tag)}# ------------------------------------------------------------------# METHOD: delete index## Delete the specified pane.# ------------------------------------------------------------------itcl::body iwidgets::Panedwindow::delete {index} { set index [index $index] set tag [lindex $_panes $index] destroy $itk_component($tag) set _panes [lreplace $_panes $index $index] reset}# ------------------------------------------------------------------# METHOD: hide index## Remove the specified pane from the paned window. # ------------------------------------------------------------------itcl::body iwidgets::Panedwindow::hide {index} { set index [index $index] set tag [lindex $_panes $index] if {[set idx [lsearch -exact $_activePanes $tag]] != -1} { set _activePanes [lreplace $_activePanes $idx $idx] } reset} # ------------------------------------------------------------------# METHOD: show index## Display the specified pane in the paned window.# ------------------------------------------------------------------itcl::body iwidgets::Panedwindow::show {index} { set index [index $index] set tag [lindex $_panes $index] if {[lsearch -exact $_activePanes $tag] == -1} { lappend _activePanes $tag } reset} # ------------------------------------------------------------------# METHOD: paneconfigure index ?option? ?value option value ...?## Configure a specified pane. This method allows configuration of# panes from the Panedwindow level. The options may have any of the # values accepted by the add method.# ------------------------------------------------------------------itcl::body iwidgets::Panedwindow::paneconfigure {index args} { set index [index $index] set tag [lindex $_panes $index] return [uplevel $itk_component($tag) configure $args]}# ------------------------------------------------------------------# METHOD: reset## Redisplay the panes based on the default percentages of the panes.# ------------------------------------------------------------------itcl::body iwidgets::Panedwindow::reset {} { if {$_initialized && [llength $_panes]} { _setActivePanes _setFracArray _makeSashes _placePanes }}# ------------------------------------------------------------------# PROTECTED METHOD: _pwConfigureEventHandler## Performs operations necessary following a configure event. This# includes placing the panes.# ------------------------------------------------------------------itcl::body iwidgets::Panedwindow::_pwConfigureEventHandler {width height} { set _width $width set _height $height if {$_initialized} { _placePanes } else { set _initialized 1 reset }}# ------------------------------------------------------------------# PROTECTED METHOD: _startGrip where num## Starts the sash drag and drop operation. At the start of the drag# operation all the information is known as for the upper and lower# limits for sash movement. The calculation is made at this time and# stored in protected variables for later access during the drag# handling routines.# ------------------------------------------------------------------itcl::body iwidgets::Panedwindow::_startGrip {where num} { if {$itk_option(-orient) == "horizontal"} { set _dimension $_height } else { set _dimension $_width } set _minsashmoved $num set _maxsashmoved $num set totMinHeight 0 set cnt [llength $_activePanes] set _sashloc(0) 0 set _pixels($cnt) [expr {int($_dimension)}] for {set i 0} {$i < $cnt} {incr i} { set _pixels($i) [expr {int($_frac($i) * $_dimension)}] set margaft [$itk_component([lindex $_activePanes $i]) cget -margin]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -