Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Tsw: Made sure that tsw::toggleswitch and future ttk::toggleswitch widgets won't conflict. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | trunk |
Files: | files | file ages | folders |
SHA3-256: |
79bfeabd8f44b5685e4e805cd68ddb89 |
User & Date: | csaba 2025-07-29 13:55:12.287 |
Context
2025-07-29
| ||
13:55 | Tsw: Made sure that tsw::toggleswitch and future ttk::toggleswitch widgets won't conflict. Leaf check-in: 79bfeabd8f user: csaba tags: trunk | |
2025-07-28
| ||
13:17 | Tsw: Code cleanup. check-in: 0f25a87991 user: csaba tags: trunk | |
Changes
Changes to modules/tsw/scripts/toggleswitch.tcl.
︙ | ︙ | |||
61 62 63 64 65 66 67 | variable cmdOpts [list attrib cget configure hasattrib identify instate \ state style switchstate toggle unsetattrib] # # Array variable used in binding scripts for the widget class TswScale # variable stateArr | | > | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | variable cmdOpts [list attrib cget configure hasattrib identify instate \ state style switchstate toggle unsetattrib] # # Array variable used in binding scripts for the widget class TswScale # variable stateArr set stateArr(dragging) 0 set stateArr(moveState) idle ;# other values: moving, moved variable scaled4 if {[llength [info procs ::tk::ScaleNum]] == 0} { # # Make sure that the variable ::scaleutil::scalingPct is set # scaleutil::scalingPercentage [tk windowingsystem] |
︙ | ︙ | |||
93 94 95 96 97 98 99 | # # Creates the default bindings for the binding tags Toggleswitch, TswMain, # ToggleswitchKeyNav, and TswScale. #------------------------------------------------------------------------------ proc tsw::createBindings {} { bind Toggleswitch <KeyPress> continue bind Toggleswitch <FocusIn> { | | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | # # Creates the default bindings for the binding tags Toggleswitch, TswMain, # ToggleswitchKeyNav, and TswScale. #------------------------------------------------------------------------------ proc tsw::createBindings {} { bind Toggleswitch <KeyPress> continue bind Toggleswitch <FocusIn> { if {[focus -lastfor %W] eq "%W" && [winfo exists %W.scl]} { focus %W.scl } } bind Toggleswitch <Destroy> { tsw::onDestroy %W } bindtags . [linsert [bindtags .] 1 TswMain] foreach event {<<ThemeChanged>> <<LightAqua>> <<DarkAqua>>} { |
︙ | ︙ | |||
163 164 165 166 167 168 169 | # Create a namespace within the current one to hold the data of the widget # namespace eval ns$win { # # The following array holds various data for this widget # variable data | < | 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | # Create a namespace within the current one to hold the data of the widget # namespace eval ns$win { # # The following array holds various data for this widget # variable data # # The following array is used to hold arbitrary # attributes and their values for this widget # variable attribs } |
︙ | ︙ | |||
569 570 571 572 573 574 575 576 577 578 579 580 581 582 | # =================================== # #------------------------------------------------------------------------------ # tsw::onDestroy #------------------------------------------------------------------------------ proc tsw::onDestroy win { upvar ::tsw::ns${win}::data data if {$data(-variable) ne "" && [catch {upvar #0 $data(-variable) var}] == 0} { trace remove variable var {write unset} $data(varTraceCmd) } namespace delete ::tsw::ns$win | > > > > | 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | # =================================== # #------------------------------------------------------------------------------ # tsw::onDestroy #------------------------------------------------------------------------------ proc tsw::onDestroy win { if {![namespace exists ::tsw::ns$win]} { return "" ;# the widget was not created by the tsw::toggleswitch cmd } upvar ::tsw::ns${win}::data data if {$data(-variable) ne "" && [catch {upvar #0 $data(-variable) var}] == 0} { trace remove variable var {write unset} $data(varTraceCmd) } namespace delete ::tsw::ns$win |
︙ | ︙ | |||
608 609 610 611 612 613 614 | $w instate disabled { return "" } $w state pressed variable stateArr | | < < < < | | 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | $w instate disabled { return "" } $w state pressed variable stateArr array set stateArr [list dragging 0 moveState idle startX $x prevX $x \ prevElem [$w identify element $x $y]] } #------------------------------------------------------------------------------ # tsw::onB1Motion #------------------------------------------------------------------------------ proc tsw::onB1Motion {w x y} { if {[$w instate disabled] || [$w instate !pressed]} { return "" } variable theme variable stateArr if {$theme eq "aqua"} { if {$stateArr(moveState) eq "moving"} { return "" } set curElem [$w identify element $x $y] if {[string match "*.slider" $stateArr(prevElem)] && [string match "*.trough" $curElem]} { startToggling $w |
︙ | ︙ | |||
684 685 686 687 688 689 690 | set win [winfo parent $w] if {$stateArr(dragging)} { ::$win switchstate [expr {[$w get] > [$w cget -to]/2}] } elseif {[$w instate hover]} { variable theme if {$theme eq "aqua"} { | < | | 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 | set win [winfo parent $w] if {$stateArr(dragging)} { ::$win switchstate [expr {[$w get] > [$w cget -to]/2}] } elseif {[$w instate hover]} { variable theme if {$theme eq "aqua"} { if {$stateArr(moveState) eq "idle"} { startToggling $w } } else { ::$win toggle } } |
︙ | ︙ | |||
728 729 730 731 732 733 734 | # tsw::startMovingLeft #------------------------------------------------------------------------------ proc tsw::startMovingLeft w { if {[$w get] == [$w cget -from]} { return "" } | | | | 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | # tsw::startMovingLeft #------------------------------------------------------------------------------ proc tsw::startMovingLeft w { if {[$w get] == [$w cget -from]} { return "" } variable stateArr set stateArr(moveState) moving $w state !selected ;# will be undone before invoking switchstate moveLeft $w [$w cget -to] } #------------------------------------------------------------------------------ # tsw::moveLeft #------------------------------------------------------------------------------ |
︙ | ︙ | |||
752 753 754 755 756 757 758 | if {$val > [$w cget -from]} { after 10 [list tsw::moveLeft $w $val] } else { $w state selected ;# restores the original selected state set win [winfo parent $w] ::$win switchstate 0 | | | | | | 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | if {$val > [$w cget -from]} { after 10 [list tsw::moveLeft $w $val] } else { $w state selected ;# restores the original selected state set win [winfo parent $w] ::$win switchstate 0 variable stateArr set stateArr(moveState) moved } } #------------------------------------------------------------------------------ # tsw::startMovingRight #------------------------------------------------------------------------------ proc tsw::startMovingRight w { if {[$w get] == [$w cget -to]} { return "" } variable stateArr set stateArr(moveState) moving $w state selected ;# will be undone before invoking switchstate moveRight $w [$w cget -from] } #------------------------------------------------------------------------------ # tsw::moveRight #------------------------------------------------------------------------------ |
︙ | ︙ | |||
789 790 791 792 793 794 795 | if {$val < [$w cget -to]} { after 10 [list tsw::moveRight $w $val] } else { $w state !selected ;# restores the original !selected state set win [winfo parent $w] ::$win switchstate 1 | | | | 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | if {$val < [$w cget -to]} { after 10 [list tsw::moveRight $w $val] } else { $w state !selected ;# restores the original !selected state set win [winfo parent $w] ::$win switchstate 1 variable stateArr set stateArr(moveState) moved } } #------------------------------------------------------------------------------ # tsw::toggleSwitchState #------------------------------------------------------------------------------ proc tsw::toggleSwitchState w { |
︙ | ︙ |