📄 disjointlistbox.itk
字号:
## ::iwidgets::Disjointlistbox# ----------------------------------------------------------------------# Implements a widget which maintains a disjoint relationship between# the items displayed by two listboxes. The disjointlistbox is composed# of 2 Scrolledlistboxes, 2 Pushbuttons, and 2 labels.## The disjoint behavior of this widget exists between the two Listboxes,# That is, a given instance of a ::iwidgets::Disjointlistbox will never# exist which has Listbox widgets with items in common.## Users may transfer items between the two Listbox widgets using the# the two Pushbuttons.## The options include the ability to configure the "items" displayed by# either of the two Listboxes and to control the placement of the insertion# and removal buttons.## The following depicts the allowable "-buttonplacement" option values# and their associated layout:## "-buttonplacement" => center## --------------------------# |listbox| |listbox|# | |________| |# | (LHS) | button | (RHS) |# | |========| |# | | button | |# |_______|--------|_______|# | count | | count |# --------------------------## "-buttonplacement" => bottom## ---------------------# | listbox | listbox |# | (LHS) | (RHS) |# |_________|_________|# | button | button |# |---------|---------|# | count | count |# ---------------------## ----------------------------------------------------------------------# AUTHOR: John A. Tucker EMAIL: jatucker@spd.dsccc.com## ======================================================================## Default resources.#option add *Disjointlistbox.lhsLabelText Available widgetDefaultoption add *Disjointlistbox.rhsLabelText Current widgetDefaultoption add *Disjointlistbox.lhsButtonLabel {Insert >>} widgetDefaultoption add *Disjointlistbox.rhsButtonLabel {<< Remove} widgetDefaultoption add *Disjointlistbox.vscrollMode static widgetDefaultoption add *Disjointlistbox.hscrollMode static widgetDefaultoption add *Disjointlistbox.selectMode multiple widgetDefaultoption add *Disjointlistbox.labelPos nw widgetDefaultoption add *Disjointlistbox.buttonPlacement bottom widgetDefaultoption add *Disjointlistbox.lhsSortOption increasing widgetDefaultoption add *Disjointlistbox.rhsSortOption increasing widgetDefault## Usual options.#itk::usual Disjointlistbox { keep -background -textbackground -cursor \ -foreground -textfont -labelfont}# ----------------------------------------------------------------------# ::iwidgets::Disjointlistbox # ----------------------------------------------------------------------itcl::class ::iwidgets::Disjointlistbox { inherit itk::Widget # # options # itk_option define -buttonplacement buttonPlacement ButtonPlacement bottom itk_option define -lhsbuttonlabel lhsButtonLabel LabelText {Insert >>} itk_option define -rhsbuttonlabel rhsButtonLabel LabelText {<< Remove} itk_option define -lhssortoption lhsSortOption LhsSortOption increasing itk_option define -rhssortoption rhsSortOption RhsSortOption increasing constructor {args} {} # # PUBLIC # public { method clear {} method getlhs {{first 0} {last end}} method getrhs {{first 0} {last end}} method lhs {args} method insertlhs {items} method insertrhs {items} method setlhs {items} method setrhs {items} method rhs {args} } # # PROTECTED # protected { method insert {theListbox items} method listboxClick {clickSide otherSide} method listboxDblClick {clickSide otherSide} method remove {theListbox items} method showCount {} method transfer {} variable sourceListbox {} variable destinationListbox {} }}## Provide a lowercased access method for the ::iwidgets::Disjointlistbox class.# proc ::iwidgets::disjointlistbox {pathName args} { uplevel ::iwidgets::Disjointlistbox $pathName $args}# ------------------------------------------------------------------## Method: Constructor## Purpose: #itcl::body ::iwidgets::Disjointlistbox::constructor {args} { # # Create the left-most Listbox # itk_component add lhs { iwidgets::Scrolledlistbox $itk_interior.lhs \ -selectioncommand [itcl::code $this listboxClick lhs rhs] \ -dblclickcommand [itcl::code $this listboxDblClick lhs rhs] } { usual keep -selectmode -vscrollmode -hscrollmode rename -labeltext -lhslabeltext lhsLabelText LabelText } # # Create the right-most Listbox # itk_component add rhs { iwidgets::Scrolledlistbox $itk_interior.rhs \ -selectioncommand [itcl::code $this listboxClick rhs lhs] \ -dblclickcommand [itcl::code $this listboxDblClick rhs lhs] } { usual keep -selectmode -vscrollmode -hscrollmode rename -labeltext -rhslabeltext rhsLabelText LabelText } # # Create the left-most item count Label # itk_component add lhsCount { label $itk_interior.lhscount } { usual rename -font -labelfont labelFont Font } # # Create the right-most item count Label # itk_component add rhsCount { label $itk_interior.rhscount } { usual rename -font -labelfont labelFont Font } set sourceListbox $itk_component(lhs) set destinationListbox $itk_component(rhs) # # Bind the "showCount" method to the Map event of one of the labels # to keep the diplayed item count current. # bind $itk_component(lhsCount) <Map> [itcl::code $this showCount] grid $itk_component(lhs) -row 0 -column 0 -sticky nsew grid $itk_component(rhs) -row 0 -column 2 -sticky nsew grid rowconfigure $itk_interior 0 -weight 1 grid columnconfigure $itk_interior 0 -weight 1 grid columnconfigure $itk_interior 2 -weight 1 eval itk_initialize $args}# ------------------------------------------------------------------# Method: listboxClick## Purpose: Evaluate a single click make in the specified Listbox.#itcl::body ::iwidgets::Disjointlistbox::listboxClick {clickSide otherSide} { set button "button" $itk_component($clickSide$button) configure -state active $itk_component($otherSide$button) configure -state disabled set sourceListbox $clickSide set destinationListbox $otherSide}# ------------------------------------------------------------------# Method: listboxDblClick## Purpose: Evaluate a double click in the specified Listbox.#itcl::body ::iwidgets::Disjointlistbox::listboxDblClick {clickSide otherSide} { listboxClick $clickSide $otherSide transfer}# ------------------------------------------------------------------# Method: transfer## Purpose: Transfer source Listbox items to destination Listbox#itcl::body ::iwidgets::Disjointlistbox::transfer {} { if {[$sourceListbox selecteditemcount] == 0} { return } set selectedindices [lsort -integer -decreasing [$sourceListbox curselection]] set selecteditems [$sourceListbox getcurselection] foreach index $selectedindices { $sourceListbox delete $index } foreach item $selecteditems { $destinationListbox insert end $item } if {![string equal $itk_option(-${destinationListbox}sortoption) "none"]} { $destinationListbox sort $itk_option(-${destinationListbox}sortoption) } showCount}# ------------------------------------------------------------------# Method: getlhs## Purpose: Retrieve the items of the left Listbox widget#itcl::body ::iwidgets::Disjointlistbox::getlhs {{first 0} {last end}} { return [lhs get $first $last]}# ------------------------------------------------------------------# Method: getrhs#
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -