• Another Tablelist question

    From Alan Grunwald@nospam.nurdglaw@gmail.com to comp.lang.tcl on Fri Nov 15 19:20:14 2024
    From Newsgroup: comp.lang.tcl

    How do I tell the height occupied by a row (or a few rows) in a Tablelist?

    tl;dr

    I'm writing a GUI with a tablelist and a text widget displayed one above
    the other in a paned window. I'd like to position the sash
    programmatically so that the entire content of the tablelist is visible,
    with the remaining space in the paned window occupied by the text widget.

    I have observed that having the two widget heights in the ratio 1:3
    works about right, but I'd like to get it spot on if I can.

    All the rows in the tablelist are the same height, so if I knew that
    height I could easily work out how much space is required for the five
    or six rows that I've inserted. On the other hand, one might conceivably
    have rows of different heights, so something to get the height of the
    first few rows (or maybe even any set of adjacent rows) would be nice.

    Thanks again (in advance)

    Alan
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From greg@gregor.ebbing@gmx.de to comp.lang.tcl on Sat Nov 16 01:00:44 2024
    From Newsgroup: comp.lang.tcl

    Am 15.11.24 um 20:20 schrieb Alan Grunwald:
    How do I tell the height occupied by a row (or a few rows) in a Tablelist?

    tl;dr

    I'm writing a GUI with a tablelist and a text widget displayed one above
    the other in a paned window. I'd like to position the sash
    programmatically so that the entire content of the tablelist is visible, with the remaining space in the paned window occupied by the text widget.

    I have observed that having the two widget heights in the ratio 1:3
    works about right, but I'd like to get it spot on if I can.

    All the rows in the tablelist are the same height, so if I knew that
    height I could easily work out how much space is required for the five
    or six rows that I've inserted. On the other hand, one might conceivably have rows of different heights, so something to get the height of the
    first few rows (or maybe even any set of adjacent rows) would be nice.

    Thanks again (in advance)

    Alan

    Hello,

    I find your question interesting.
    My script does not correspond to your suggestion.
    Perhaps bbox can help you.

    Gregor

    package require Tk
    package require tablelist

    # Main window
    ttk::panedwindow .pw -orient vertical
    pack .pw -fill both -expand true

    # Tablelist
    tablelist::tablelist .pw.tl -columns {0 "Name" left 0 "Value" center}
    -height 5
    .pw add .pw.tl -weight 0

    # Text
    text .pw.text -wrap word -background white
    .pw add .pw.text -weight 1

    # Tablelist insert datas
    set data {
    {"Item 1" "10"}
    {"Item 2" "20"}
    {"Item 3" "30"}
    {"Item 4" "40"}
    {"Item 5" "50"}
    {"Item 6" "60"}
    {"Item 7" "70"}
    }
    foreach row $data {
    .pw.tl insert end $row
    }

    # https://www.nemethi.de/tablelist/tablelistWidget.html#bbox
    wm geometry . 400x300
    update idle
    set hwin [winfo height .pw]
    set hpw [.pw sash 0 $hwin]
    set adjust [expr {$hwin - $hpw}]

    update idle
    #https://www.nemethi.de/tablelist/tablelistWidget.html#row_indices
    #bottom instead of end, if the entire table is not visible
    set bottomboxlist [.pw.tl bbox bottom]
    set ybottombox [lindex $bottomboxlist 1]
    set hbottombox [lindex $bottomboxlist 3]

    set htl [.pw sash 0 [expr {$ybottombox + $hbottombox + $adjust }]]

    puts "$hwin : $hpw : $adjust : $htl : $bottomboxlist : $ybottombox : $hbottombox"
    #300 : 295 : 5 : 169 : 2 145 110 19 : 145 : 19
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Alan Grunwald@nospam.nurdglaw@gmail.com to comp.lang.tcl on Sat Nov 16 00:23:32 2024
    From Newsgroup: comp.lang.tcl

    On 16/11/2024 00:00, greg wrote:
    Am 15.11.24 um 20:20 schrieb Alan Grunwald:
    How do I tell the height occupied by a row (or a few rows) in a
    Tablelist?

    tl;dr

    I'm writing a GUI with a tablelist and a text widget displayed one
    above the other in a paned window. I'd like to position the sash
    programmatically so that the entire content of the tablelist is
    visible, with the remaining space in the paned window occupied by the
    text widget.

    I have observed that having the two widget heights in the ratio 1:3
    works about right, but I'd like to get it spot on if I can.

    All the rows in the tablelist are the same height, so if I knew that
    height I could easily work out how much space is required for the five
    or six rows that I've inserted. On the other hand, one might
    conceivably have rows of different heights, so something to get the
    height of the first few rows (or maybe even any set of adjacent rows)
    would be nice.

    Thanks again (in advance)

    Alan

    Hello,

    I find your question interesting.
    My script does not correspond to your suggestion.
    Perhaps bbox can help you.

    Gregor

    package require Tk
    package require tablelist

    # Main window
    ttk::panedwindow .pw -orient vertical
    pack .pw -fill both -expand true

    # Tablelist
    tablelist::tablelist .pw.tl -columns {0 "Name" left 0 "Value" center} -height 5
    .pw add .pw.tl -weight 0

    # Text
    text .pw.text -wrap word -background white
    .pw add .pw.text -weight 1

    # Tablelist insert datas
    set data {
      {"Item 1" "10"}
      {"Item 2" "20"}
      {"Item 3" "30"}
      {"Item 4" "40"}
      {"Item 5" "50"}
      {"Item 6" "60"}
      {"Item 7" "70"}
    }
    foreach row $data {
      .pw.tl insert end $row
    }

    # https://www.nemethi.de/tablelist/tablelistWidget.html#bbox
    wm geometry . 400x300
    update idle
    set hwin [winfo height .pw]
    set hpw [.pw sash 0 $hwin]
    set adjust [expr {$hwin - $hpw}]

    update idle #https://www.nemethi.de/tablelist/tablelistWidget.html#row_indices
    #bottom instead of end, if the entire table is not visible
    set bottomboxlist [.pw.tl bbox bottom]
    set ybottombox [lindex $bottomboxlist 1]
    set hbottombox [lindex $bottomboxlist 3]

    set htl [.pw sash 0 [expr {$ybottombox + $hbottombox + $adjust }]]

    puts "$hwin : $hpw : $adjust : $htl : $bottomboxlist : $ybottombox : $hbottombox"
    #300 : 295 : 5 : 169 : 2 145 110 19 : 145 : 19
    Thanks Gregor,

    That should do the trick! Too late to try it now, I'll have a go in the morning and follow-up here.

    Alan
    --- Synchronet 3.20a-Linux NewsLink 1.114