Hello ,
I'm currently working with the tablelist widget in Tcl/Tk and have a
question about column widths. I would like to save the original column
widths and later determine if a column whose original width was 0 was
resized interactively by the user. With
pathName columnwidth columnIndex ?-requested|-stretched|-total?
I can't manage it.
The aim is to save the status of the table and, after inserting
individual rows, the view, sorting, selection, etc. to restore.
a example table:
package require tablelist
proc cmd {tbl} {
puts "[$tbl columnwidth 0]"
puts "[$tbl columnwidth 0 -stretched]"
puts "[$tbl columnwidth 0 -total]"
puts [join [.tbl configure] \n]
puts [join [.tbl columnconfigure 0] \n]
}
tablelist::tablelist .tbl -columns {0 "ID" right 10 "Name" left 0
"Class" center}
pack .tbl -fill both -expand true
.tbl insert end {1 Herbert 3a}
.tbl insert end {2 Anna 7d}
.tbl insert end {3 Anna 7c}
button .btn -text "cmd" -command [list cmd .tbl]
pack .btn -side top
mfg
Gregot
Hello ,
I'm currently working with the tablelist widget in Tcl/Tk and have a
question about column widths. I would like to save the original column
widths and later determine if a column whose original width was 0 was
resized interactively by the user. With
pathName columnwidth columnIndex ?-requested|-stretched|-total?
I can't manage it.
The aim is to save the status of the table and, after inserting
individual rows, the view, sorting, selection, etc. to restore.
a example table:
package require tablelist
proc cmd {tbl} {
puts "[$tbl columnwidth 0]"
puts "[$tbl columnwidth 0 -stretched]"
puts "[$tbl columnwidth 0 -total]"
puts [join [.tbl configure] \n]
puts [join [.tbl columnconfigure 0] \n]
}
tablelist::tablelist .tbl -columns {0 "ID" right 10 "Name" left 0
"Class" center}
pack .tbl -fill both -expand true
.tbl insert end {1 Herbert 3a}
.tbl insert end {2 Anna 7d}
.tbl insert end {3 Anna 7c}
button .btn -text "cmd" -command [list cmd .tbl]
pack .btn -side top
mfg
Gregot
Am 16.05.24 um 23:13 schrieb greg:
Hello ,
I'm currently working with the tablelist widget in Tcl/Tk and have a
question about column widths. I would like to save the original column
widths and later determine if a column whose original width was 0 was
resized interactively by the user. With
pathName columnwidth columnIndex ?-requested|-stretched|-total?
I can't manage it.
The aim is to save the status of the table and, after inserting
individual rows, the view, sorting, selection, etc. to restore.
a example table:
package require tablelist
proc cmd {tbl} {
puts "[$tbl columnwidth 0]"
puts "[$tbl columnwidth 0 -stretched]"
puts "[$tbl columnwidth 0 -total]"
puts [join [.tbl configure] \n]
puts [join [.tbl columnconfigure 0] \n]
}
tablelist::tablelist .tbl -columns {0 "ID" right 10 "Name" left 0
"Class" center}
pack .tbl -fill both -expand true
.tbl insert end {1 Herbert 3a}
.tbl insert end {2 Anna 7d}
.tbl insert end {3 Anna 7c}
button .btn -text "cmd" -command [list cmd .tbl]
pack .btn -side top
mfg
Gregot
And how do I sort the table by knumber or getkeys?
mfg
Gregor
Am 16.05.24 um 23:13 schrieb greg:
Hello ,
I'm currently working with the tablelist widget in Tcl/Tk and have a
question about column widths. I would like to save the original column
widths and later determine if a column whose original width was 0 was
resized interactively by the user. With
pathName columnwidth columnIndex ?-requested|-stretched|-total?
I can't manage it.
The aim is to save the status of the table and, after inserting
individual rows, the view, sorting, selection, etc. to restore.
a example table:
package require tablelist
proc cmd {tbl} {
puts "[$tbl columnwidth 0]"
puts "[$tbl columnwidth 0 -stretched]"
puts "[$tbl columnwidth 0 -total]"
puts [join [.tbl configure] \n]
puts [join [.tbl columnconfigure 0] \n]
}
tablelist::tablelist .tbl -columns {0 "ID" right 10 "Name" left 0
"Class" center}
pack .tbl -fill both -expand true
.tbl insert end {1 Herbert 3a}
.tbl insert end {2 Anna 7d}
.tbl insert end {3 Anna 7c}
button .btn -text "cmd" -command [list cmd .tbl]
pack .btn -side top
mfg
Gregot
And how do I sort the table by knumber or getkeys?
mfg
Gregor
# the procs
proc save_tablelist_status {tbl} {
set statusDict [dict create]
# Save sorting information
if {[string length [$tbl sortorder]] > 0} {
dict set statusDict -sortOrder [$tbl sortorder]
dict set statusDict -sortColumn [$tbl sortcolumn]
}
# Save selections
set selectedIDs [list]
foreach row [$tbl curselection] {
lappend selectedIDs k[$tbl getkeys $row]
}
dict set statusDict -selectedRows $selectedIDs
# Save scroll position
lassign [$tbl xview] x1 x2
lassign [$tbl yview] y1 y2
dict set statusDict -xview $x1
dict set statusDict -yview $y1
# Save visible rows and columns
set firstVisibleRow [$tbl index @0,0]
set lastVisibleRow [$tbl index @0,[winfo height $tbl]]
dict set statusDict -visibleRows "$firstVisibleRow $lastVisibleRow"
set firstVisibleColumn [$tbl columnindex @0,0]
set lastVisibleColumn [$tbl columnindex @0,[winfo width $tbl]]
dict set statusDict -visibleColumns "$firstVisibleColumn $lastVisibleColumn"
# Save column widths
set columnWidths [list]
set columnCount [$tbl columncount]
for {set i 0} {$i < $columnCount} {incr i} {
lappend columnWidths [$tbl columnwidth $i -requested]
}
dict set statusDict -columnWidths $columnWidths
puts "save: $statusDict"
return $statusDict
}
proc restore_tablelist_status {tbl statusDict} {
# Restore sorting information
if {[dict exists $statusDict -sortColumn] && [dict get $statusDict -sortColumn] != -1} {
$tbl sortbycolumn [dict get $statusDict -sortColumn] -[dict get $statusDict -sortOrder]
}
# Restore selections
if {[dict exists $statusDict -selectedRows]} {
foreach row [dict get $statusDict -selectedRows] {
$tbl selection set $row
}
}
# Restore scroll position
if {[dict exists $statusDict -xview] && [dict exists $statusDict
-yview]} {
$tbl xview moveto [dict get $statusDict -xview]
$tbl yview moveto [dict get $statusDict -yview]
}
# Restore visible rows and columns
if {[dict exists $statusDict -visibleRows]} {
set firstVisibleRow [lindex [dict get $statusDict -visibleRows] 0]
set lastVisibleRow [lindex [dict get $statusDict -visibleRows] 1]
$tbl see $firstVisibleRow
$tbl see $lastVisibleRow
}
if {[dict exists $statusDict -visibleColumns]} {
set firstVisibleColumn [lindex [dict get $statusDict
-visibleColumns] 0]
set lastVisibleColumn [lindex [dict get $statusDict
-visibleColumns] 1]
$tbl seecolumn $firstVisibleColumn
$tbl seecolumn $lastVisibleColumn
}
# Restore column widths
if {[dict exists $statusDict -columnWidths]} {
set columnWidths [dict get $statusDict -columnWidths]
set columnCount [$tbl columncount]
for {set i 0} {$i < $columnCount} {incr i} {
$tbl columnconfigure $i -width -[lindex $columnWidths $i]
}
}
}
Am 16.05.24 um 23:13 schrieb greg:
Hello ,
I'm currently working with the tablelist widget in Tcl/Tk and have a
question about column widths. I would like to save the original column
widths and later determine if a column whose original width was 0 was
resized interactively by the user. With
pathName columnwidth columnIndex ?-requested|-stretched|-total?
...
mfg
Gregot
Hi Greg,
The columnwidth subcommand returns the current width in pixels of the column. Example:
# Save the width of column 2
set colWidth [.tbl columnwidth 2]
...
# Restore the width of column 2
.tbl columnconfigure 2 -width -$colWidth
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 497 |
Nodes: | 16 (2 / 14) |
Uptime: | 68:33:16 |
Calls: | 9,766 |
Calls today: | 7 |
Files: | 13,747 |
Messages: | 6,186,073 |