Changeset d7768ed in tol for tolbase/lib/byswidget/blistboxplus
- Timestamp:
- Nov 12, 2008, 6:24:56 PM (18 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- e5c8751
- Parents:
- db6cf9c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tolbase/lib/byswidget/blistboxplus/blistboxplus.tcl
rdb6cf9c rd7768ed 541 541 # open file to read 542 542 if { ![ catch { set fd [open $filNam r] } msgerr] } { 543 while { [gets $fd line ] >= 0} { 543 while { [gets $fd line ] >= 0} { 544 Tolcon_Trace "adding $line" 544 545 $self add $line 545 546 } … … 551 552 } 552 553 553 554 554 #/////////////////////////////////////////////////////////////////////////// 555 555 method _SortByColumn { col } { … … 560 560 # 561 561 #/////////////////////////////////////////////////////////////////////////// 562 $self _QuickSort $col 0 [expr [$self size]-1] 563 } 564 565 566 #/////////////////////////////////////////////////////////////////////////// 567 method _QuickSort { col left right } { 568 # 569 # PURPOSE: 570 # function quicksort(a, left, right) 571 # if right > left 572 # select a pivot value a[pivotIndex] 573 # pivotNewIndex := partition(a, left, right, pivotIndex) 574 # quicksort(a, left, pivotNewIndex-1) 575 # quicksort(a, pivotNewIndex+1, right) 576 # 577 #/////////////////////////////////////////////////////////////////////////// 578 if {$right > $left} { 579 set pivotIndex [expr (($left + $right) / 2)] 580 set pivotNewIndex [$self _Partition $col $left $right $pivotIndex] 581 $self _QuickSort $col $left [expr $pivotNewIndex-1] 582 $self _QuickSort $col [expr $pivotNewIndex+1] $right 583 } 584 } 585 586 587 #/////////////////////////////////////////////////////////////////////////// 588 method _Partition { col left right pivotIndex } { 589 # 590 # PURPOSE: 591 # function partition(a, left, right, pivotIndex) 592 # pivotValue := a[pivotIndex] 593 # swap(a[pivotIndex], a[right]) // Move pivot to end 594 # storeIndex := left 595 # for i from left to right 596 # if a[i] <= pivotValue 597 # swap(a[storeIndex], a[i]) 598 # storeIndex := storeIndex + 1 599 # swap(a[right], a[storeIndex]) // Move pivot to its final place 600 # return storeIndex 601 # 602 #/////////////////////////////////////////////////////////////////////////// 603 set pivotValue [$self get [lindex [$self get] $pivotIndex] $col] 604 $self _Swap $pivotIndex $right 605 set storeIndex $left 606 for { set i $left } { $i < $right } { incr i } { 607 if { [$self get [lindex [$self get] $i] $col] <= $pivotValue } { 608 $self _Swap $storeIndex $i 609 incr storeIndex 610 } 611 } 612 $self _Swap $right $storeIndex 613 return $storeIndex 614 } 615 616 617 #/////////////////////////////////////////////////////////////////////////// 618 method _Swap { index1 index2 } { 619 # 620 # PURPOSE: 621 # 622 #/////////////////////////////////////////////////////////////////////////// 623 if { $index1 < $index2 } { 624 set lst [$self get] 625 $self move [lindex $lst $index1] after [lindex $lst $index2] 626 set lst [$self get] 627 $self move [lindex $lst [expr $index2-1]] before [lindex $lst $index1] 628 } elseif { $index1 > $index2 } { 629 set lst [$self get] 630 $self move [lindex $lst $index1] before [lindex $lst $index2] 631 set lst [$self get] 632 $self move [lindex $lst [expr $index2+1]] after [lindex $lst $index1] 633 } 562 563 set numofel [$self size] 564 set lst [list] 565 set fulllst [$self get] 566 567 foreach i $fulllst { 568 lappend lst [$self get $i ] 569 } 570 # lst: contains a list of values 571 set coln 0 572 set cols [$self cget -cols] 573 set hidcols [$self cget -hiddencols] 574 for { set j 0 } { $j < [llength $cols] } { incr j } { 575 if {[lindex $cols $j] eq $col} { 576 set coln $j 577 } 578 } 579 # coln: contains the index of the column to be ordered 580 set lst [lsort -index $coln $lst] 581 $self clear 582 for { set i 0 } { $i < $numofel } { incr i } { 583 set el [lindex $lst $i ] 584 $self insert end $el 585 } 586 634 587 } 635 588 … … 922 875 923 876 set result {} 924 877 878 if { "$cols" eq "" } { 879 set cols [$self column names] 880 } 881 925 882 foreach id $ids { 926 883 … … 928 885 929 886 set data [$_listbox entry cget $id -data] 930 if { "$cols" eq "" } {931 set cols [$self column names]932 }933 887 934 888 foreach col $cols { … … 1279 1233 -icons [list [Bitmap::get $icon] [Bitmap::get $icon]] 1280 1234 } 1281 1235 1282 1236 # delegacion de metodos y opciones 1283 1237 delegate method * to _listbox … … 1378 1332 } 1379 1333 } 1334
Note: See TracChangeset
for help on using the changeset viewer.
