📄 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.borderWidth 2 widgetDefaultoption add *Labeledframe.relief groove widgetDefault## Usual options.#itk::usual Labeledframe { keep -background -cursor -labelfont -foreground}itcl::class iwidgets::Labeledframe { inherit itk::Archetype 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 constructor {args} {} destructor {} # # Public methods # public method childsite {} # # 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 itk_hull "" common _LAYOUT_TABLE }}## Provide a lowercased access method for the Labeledframe class.# proc ::iwidgets::labeledframe {pathName args} { uplevel ::iwidgets::Labeledframe $pathName $args}# -----------------------------------------------------------------------------# CONSTRUCTOR# -----------------------------------------------------------------------------itcl::body iwidgets::Labeledframe::constructor { args } { # # Create a window with the same name as this object # set itk_hull [namespace tail $this] set itk_interior $itk_hull itk_component add hull { frame $itk_hull \ -relief groove \ -class [namespace tail [info class]] } { keep -background -cursor -relief -borderwidth rename -highlightbackground -background background Background rename -highlightcolor -background background Background } bind itk-delete-$itk_hull <Destroy> "itcl::delete object $this" set tags [bindtags $itk_hull] bindtags $itk_hull [linsert $tags 0 itk-delete-$itk_hull] # # Create the childsite frame window # _______ # |_____| # |_|X|_| # |_____| # itk_component add childsite { frame $itk_interior.childsite -highlightthickness 0 -bd 0 } # # Create the label to be positioned within the grooved relief # of the hull frame. # itk_component add label { label $itk_interior.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 } grid $itk_component(childsite) -row 1 -column 1 -sticky nsew grid columnconfigure $itk_interior 1 -weight 1 grid rowconfigure $itk_interior 1 -weight 1 bind $itk_component(label) <Configure> +[itcl::code $this _positionLabel] # # 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# -----------------------------------------------------------------------------itcl::body iwidgets::Labeledframe::destructor {} { if {$_reposition != ""} { after cancel $_reposition } if {[winfo exists $itk_hull]} { set tags [bindtags $itk_hull] set i [lsearch $tags itk-delete-$itk_hull] if {$i >= 0} { bindtags $itk_hull [lreplace $tags $i $i] } destroy $itk_hull }}# -----------------------------------------------------------------------------# OPTIONS# -----------------------------------------------------------------------------# ------------------------------------------------------------------# OPTION: -ipadx## Specifies the width of the horizontal gap from the border to the# the child site.# ------------------------------------------------------------------itcl::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.# ------------------------------------------------------------------itcl::configbody iwidgets::Labeledframe::ipady { grid configure $itk_component(childsite) -pady $itk_option(-ipady) _positionLabel}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -