📄 preferences.tcl
字号:
} #Triggered when the -enabled option is changed onconfigure -enabled { val } { set options(-enabled) $val $preferenceitem configure -enabled $val #Now tell all the children to enable themshelves set num 0 foreach item $items { $item configure -enabled $val } } #Create the label frame and icon, and tell all children items to draw themshelves method draw { path } { #Store the path for later usage set itemPath $path #Create and pack the labelframe set f [labelframe $path.f -text $options(-text) -font splainf] pack $path.f -side top -fill x #If there is an icon, draw it if { $options(-icon) != "" } { frame $f.f label $f.icon -image [::skin::loadPixmap $options(-icon)] pack $f.icon -side left -padx 5 -pady 5 pack $f.f -side left -fill x -expand true set f $f.f } #Now tell all the children to draw themshelves, and pack them set num 0 foreach item $items { set f2 $f.f$num frame $f2 $item draw $f2 pack $f2 -side top -expand $options(-expand) -fill $options(-fill) incr num } } #Tell all children to store themselves method store {} { foreach item $items { $item store } }}#A text entry item. Child of PreferenceItem#Usage:# OPTIONS# -text The text to be shown next to the text entry# -width The width of the text entry# -onchange A command that is called everytime the text entry changes to validate the input# -enabled Enables or disabled the text entry# METHODS::snit::type TextEntry { #Delegate to PrferenceItem!! delegate method * to preferenceitem delegate option * to preferenceitem #Enable or disable the item option -enabled -default true #The widget path variable itemPath "" constructor {args} { install preferenceitem using PreferenceItem %AUTO% $self configurelist $args } destructor { #Destroy the PreferenceItem instance $preferenceitem destroy #Destroy widgets destroy $itemPath.l destroy $itemPath.t } ######################### #Static options (creation time) ######################### #Command to be triggered when the item changes option -onchange -readonly yes -default "" #Text for the item label option -text -readonly yes -default "" #With of the textfield option -width -readonly yes -default "" ######################### #Dinamic options ######################### #Triggered when the -enabled option is changed onconfigure -enabled { val } { set options(-enabled) $val $preferenceitem configure -enabled $val if {[winfo exists $itemPath.t]} { if { $val } { $itemPath.t configure -state normal } else { $itemPath.t configure -state disabled } } } #Draw the text box in the given path method draw { path } { set itemPath $path #Draw an input box #Composed by a label... and... label $path.l -text $options(-text) -font sboldf if { $options(-enabled) } { set state normal } else { set state disabled } if { $options(-onchange) != "" } { set validatecommand [list $options(-onchange) $self %s %S] } else { set validatecommand "" } #...a text entry (can have defined width or not) if { [string is integer -strict $options(-width)] } { entry $path.t -width $options(-width) -background white -state $state -textvariable [$self valueVar] \ -validate all -validatecommand $validatecommand pack $path.t -side right -expand false -padx 5 -pady 3 pack $path.l -side right -expand false -padx 5 -pady 3 } else { entry $path.t -background white -state $state -textvariable [$self valueVar] \ -validate all -validatecommand $validatecommand pack $path.t -side right -expand true -fill x -padx 5 -pady 3 pack $path.l -side right -expand false -padx 5 -pady 3 } } }#A check box item. Child of PreferenceItem#Usage:# OPTIONS# -text The text to be shown next to the check button# -onchange A command that is called everytime the check button value changes# -enabled Enables or disabled the checkbutton# -onvalue The value that the item will take when the checkbutton is checked. Defaults to 1# -offvalue The value that the item will take when the checkbutton is not checked. Defaults to 0# METHODS::snit::type CheckBox { #Delegate to PrferenceItem!! delegate method * to preferenceitem delegate option * to preferenceitem #Enable or disable the item option -enabled -default true #The widget path variable itemPath "" constructor {args} { install preferenceitem using PreferenceItem %AUTO% $self configurelist $args } destructor { #Destroy the PreferenceItem instance $preferenceitem destroy #Destroy widgets destroy $itemPath.c } ######################### #Static options (creation time) ######################### #Command to be triggered when the item changes option -onchange -readonly yes -default "" #Text for the item label option -text -readonly yes -default "" #ON/OFF values option -onvalue -readonly yes -default 1 option -offvalue -readonly yes -default 0 ######################### #Dynamic options ######################### #Triggered when the -enabled option is changed onconfigure -enabled { val } { set options(-enabled) $val $preferenceitem configure -enabled $val if {[winfo exists $itemPath.c]} { if { $val } { $itemPath.c configure -state normal } else { $itemPath.c configure -state disabled } } } #Draw the text box in the given path method draw { path } { set itemPath $path #Draw an input box if { $options(-enabled) } { set state normal } else { set state disabled } if { $options(-onchange) != "" } { set changecommand [list $options(-onchange) $self %s %S] } else { set changecommand "" } #...a checkbutton entry checkbutton $path.c -text $options(-text) -font sboldf -state $state -variable [$self valueVar] \ -command $changecommand -onvalue $options(-onvalue) -offvalue $options(-offvalue) pack $path.c -side right -expand false -padx 5 -pady 3 } }#A group of radio buttons. Child of PreferenceItem#Usage:# OPTIONS# -texts A list with one text for every checkbutton# -values A list of values corresponding to every selection. Defaults to 0, 1, 2...# -onchange A command that is called everytime the radio button value changes# -enabled Enables or disabled the radio buttons# METHODS::snit::type RadioGroup { #Delegate to PrferenceItem!! delegate method * to preferenceitem delegate option * to preferenceitem #Enable or disable the item option -enabled -default true #The widget path variable itemPath "" constructor {args} { install preferenceitem using PreferenceItem %AUTO% $self configurelist $args } destructor { #Destroy the PreferenceItem instance $preferenceitem destroy #Destroy widgets destroy $itemPath.f } ######################### #Static options (creation time) ######################### #Command to be triggered when the item changes option -onchange -readonly yes -default "" #Text for the item label option -texts -readonly yes -default [list] option -values -readonly yes -default [list] ######################### #Dynamic options ######################### #Triggered when the -enabled option is changed onconfigure -enabled { val } { set options(-enabled) $val $preferenceitem configure -enabled $val if {[winfo exists $itemPath.f]} { foreach child [winfo children $itemPath.f] { if { $val } { $child configure -state normal } else { $child configure -state disabled } } } } #Draw the text box in the given path method draw { path } { set itemPath $path #Draw an input box if { $options(-enabled) } { set state normal } else { set state disabled } if { $options(-onchange) != "" } { set changecommand [list $options(-onchange) $self %s %S] } else { set changecommand "" } frame $path.f set i 0 foreach text $options(-texts) { radiobutton $path.f.rb$i -text $text -font sboldf -state $state -variable [$self valueVar] \ -command $changecommand -value [lindex $options(-values) $i] pack $path.f.rb$i -side top -anchor nw incr i } pack $path.f -side left -expand false -padx 5 -pady 3 } }#A command button. Child of PreferenceItem#Usage:# OPTIONS# -text The text to be shown in the button# -buttoncommand# The command that will be launched when the button is pressed. When this happens, the current item value will be appended as# a parameter to this command. The return value of the command is then stored as new item value# -enabled Enables or disabled the checkbutton# METHODS::snit::type CommandButton { #Delegate to PrferenceItem!! delegate method * to preferenceitem delegate option * to preferenceitem #The variable where the items stores its data option -buttoncommand -readonly yes -default "" #Enable or disable the item option -enabled -default true #The widget path variable itemPath "" constructor {args} { install preferenceitem using PreferenceItem %AUTO% $self configurelist $args } destructor { #Destroy the PreferenceItem instance $preferenceitem destroy #Destroy widgets destroy $itemPath.b } ######################### #Static options (creation time) ######################### #Text for the item label option -text -readonly yes -default "" option -align -readonly yes -default center ######################### #Dynamic options ######################### #Triggered when the -enabled option is changed onconfigure -enabled { val } { set options(-enabled) $val
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -