📄 labeledframe.itk
字号:
## Labeledframe# ----------------------------------------------------------------------# Implements a hull frame with a grooved relief, a label, and a# frame childsite.## The frame childsite can be filled with any widget via a derived class# or though the use of the childsite method. This class was designed# to be a general purpose base class for supporting the combination of# a labeled frame and a childsite. The options include the ability to# position the label at configurable locations within the grooved relief# of the hull frame, and control the display of the label.## To following demonstrates the different values which the "-labelpos"# option may be set to and the resulting layout of the label when# one executes the following command with "-labeltext" set to "LABEL":## example:# labeledframe .w -labeltext LABEL -labelpos <ne,n,nw,se,s,sw,en,e,es,wn,s,ws>## ne n nw se s sw## *LABEL**** **LABEL** ****LABEL* ********** ********* **********# * * * * * * * * * * * * # * * * * * * * * * * * * # * * * * * * * * * * * *# ********** ********* ********** *LABEL**** **LABEL** ****LABEL*## en e es wn s ws## ********** ********* ********* ********* ********* **********# * * * * * * * * * * * *# L * * * * * * L * * * *# A * L * * * * A * L * L# B * A * L * * B * A * A# E * B * A * * E * B * B# L * E * B * * L * E * E# * * L * E * * * * L * L# * * * * L * * * * * * *# ********** ********** ********* ********** ********* **********## ----------------------------------------------------------------------# AUTHOR: John A. Tucker EMAIL: jatucker@spd.dsccc.com## ======================================================================# Copyright (c) 1997 DSC Technologies Corporation# ======================================================================# Permission to use, copy, modify, distribute and license this software # and its documentation for any purpose, and without fee or written # agreement with DSC, is hereby granted, provided that the above copyright # notice appears in all copies and that both the copyright notice and # warranty disclaimer below appear in supporting documentation, and that # the names of DSC Technologies Corporation or DSC Communications # Corporation not be used in advertising or publicity pertaining to the # software without specific, written prior permission.# # DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL # DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS # SOFTWARE.# ======================================================================## Default resources.#option add *Labeledframe.labelMargin 10 widgetDefaultoption add *Labeledframe.labelFont \ "-Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*" widgetDefaultoption add *Labeledframe.labelPos n widgetDefaultoption add *Labeledframe.labelBorderWidth 2 widgetDefaultoption add *Labeledframe.labelRelief groove widgetDefault## Usual options.#itk::usual Labeledframe { keep -background -cursor -labelfont -foreground -labelrelief -labelborderwidth}class iwidgets::Labeledframe { inherit itk::Widget itk_option define -ipadx iPadX IPad 0 itk_option define -ipady iPadY IPad 0 itk_option define -labelmargin labelMargin LabelMargin 10 itk_option define -labelpos labelPos LabelPos n itk_option define -labeltext labelText LabelText "" constructor {args} {} destructor {} # # Public methods # public method childsite {} public method clientHandlesConfigure {{yes 1}} # # Protected methods # protected { method _positionLabel {{when later}} method _collapseMargin {} method _setMarginThickness {value} method smt {value} { _setMarginThickness $value } } # # Private methods/data # private { proc _initTable {} variable _reposition "" ;# non-null => _positionLabel pending variable dontUpdate 0 common _LAYOUT_TABLE }}## Provide a lowercased access method for the Labeledframe class.# proc ::iwidgets::labeledframe {pathName args} { uplevel ::iwidgets::Labeledframe $pathName $args}# -----------------------------------------------------------------------------# CONSTRUCTOR# -----------------------------------------------------------------------------body iwidgets::Labeledframe::constructor { args } { # # Create a window with the same name as this object # itk_component add labelFrame { frame $itk_interior.lf \ -relief groove \ -class [namespace tail [info class]] } { keep -background -cursor rename -relief -labelrelief labelRelief LabelRelief rename -borderwidth -labelborderwidth labelBorderWidth LabelBorderWidth rename -highlightbackground -background background Background rename -highlightcolor -background background Background } # # Create the childsite frame window # _______ # |_____| # |_|X|_| # |_____| # itk_component add childsite { frame $itk_component(labelFrame).childsite -highlightthickness 0 -bd 0 } # # Create the label to be positioned within the grooved relief # of the labelFrame frame. # itk_component add label { label $itk_component(labelFrame).label -highlightthickness 0 -bd 0 } { usual rename -bitmap -labelbitmap labelBitmap Bitmap rename -font -labelfont labelFont Font rename -image -labelimage labelImage Image #rename -text -labeltext labelText Text rename -textvariable -labelvariable labelVariable Variable ignore -highlightthickness -highlightcolor -text } grid $itk_component(childsite) -row 1 -column 1 -sticky nsew grid columnconfigure $itk_component(labelFrame) 1 -weight 1 grid rowconfigure $itk_component(labelFrame) 1 -weight 1 lappend after_script [code $this _positionLabel] bind $itk_component(label) <Configure> +[code $this _positionLabel] pack $itk_component(labelFrame) -fill both -expand 1 # # Initialize the class array of layout configuration options. Since # this is a one time only thing. # _initTable eval itk_initialize $args # # When idle, position the label. # _positionLabel}# -----------------------------------------------------------------------------# DESTRUCTOR# -----------------------------------------------------------------------------body iwidgets::Labeledframe::destructor {} { debug "In Labeledframe destructor for $this, reposition is $_reposition" if {$_reposition != ""} { debug "Canceling reposition $_reposition for $this" after cancel $_reposition set _reposition DESTRUCTOR }}# -----------------------------------------------------------------------------# OPTIONS# -----------------------------------------------------------------------------# ------------------------------------------------------------------# OPTION: -ipadx## Specifies the width of the horizontal gap from the border to the# the child site.# ------------------------------------------------------------------configbody iwidgets::Labeledframe::ipadx { grid configure $itk_component(childsite) -padx $itk_option(-ipadx) _positionLabel}# ------------------------------------------------------------------# OPTION: -ipady## Specifies the width of the vertical gap from the border to the# the child site.# ------------------------------------------------------------------configbody iwidgets::Labeledframe::ipady { grid configure $itk_component(childsite) -pady $itk_option(-ipady) _positionLabel}# -----------------------------------------------------------------------------# OPTION: -labelmargin## Set the margin of the most adjacent side of the label to the labelFrame# relief.# ----------------------------------------------------------------------------configbody iwidgets::Labeledframe::labelmargin { _positionLabel}# -----------------------------------------------------------------------------# OPTION: -labelpos## Set the position of the label within the relief of the labelFrame frame# widget.# ----------------------------------------------------------------------------configbody iwidgets::Labeledframe::labelpos {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -