• Image in labels mess them all up

    From Luc@21:1/5 to All on Thu Jun 8 20:46:51 2023
    Would someone please like to take a look at this video and explain
    to me what is going on here? I swear I don't have a clue.


    https://0x0.st/HcTs.mp4


    I'm not posting the entire code because the video illustrates
    the problem very well and I believe the relevant part of the
    code is all there.

    Thanks in advance.

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From D Groth@21:1/5 to Luc on Fri Jun 9 00:04:08 2023
    Luc schrieb am Freitag, 9. Juni 2023 um 01:46:56 UTC+2:
    Would someone please like to take a look at this video and explain
    to me what is going on here? I swear I don't have a clue.


    https://0x0.st/HcTs.mp4


    I'm not posting the entire code because the video illustrates
    the problem very well and I believe the relevant part of the
    code is all there.

    Thanks in advance.

    --
    Luc


    Dear Luc,

    please post short code examples to show what your problem is. Nobody will click usually on dubious image or video links. Having the code in the group as well will help future readers of the message where the video or the image link is already
    pointing to 404...

    Best,
    Detlef

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to D Groth on Fri Jun 9 14:14:50 2023
    On 6/9/2023 3:04 AM, D Groth wrote:
    Dear Luc,

    please post short code examples to show what your problem is. Nobody will click usually on dubious image or video links. Having the code in the group as well will help future readers of the message where the video or the image link is already
    pointing to 404...


    True. The video format has also inadvertently made it more difficult for someone to offer assistance without resizing the video window, stopping
    it, writing everything from scratch, etc.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to Luc on Fri Jun 9 14:32:25 2023
    On 6/8/2023 7:46 PM, Luc wrote:

    I'm not posting the entire code because the video illustrates
    the problem very well and I believe the relevant part of the
    code is all there.

    Thanks in advance.


    I think your problem is in the other column labels expanding to fill the
    space from the name.

    Not all of the labels in your script need to be "-fill x". As fas as I
    can tell, only the first one, "name", needs to be that, and the rest
    should have a fixed size. You may also want to make sure that you
    configure "name" with "-expand 1" in addition to "-fill x".

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to D Groth on Fri Jun 9 18:06:54 2023
    On Fri, 9 Jun 2023 00:04:08 -0700 (PDT), D Groth wrote:

    Dear Luc,

    please post short code examples to show what your problem is. Nobody
    will click usually on dubious image or video links. Having the code in
    the group as well will help future readers of the message where the
    video or the image link is already pointing to 404...

    Best,
    Detlef


    Well, here is the code. But you don't have the SVG icon file.


    package require Tk
    load "/home/tcl/fm/libtksvg0.12.so"
    set file "/home/tcl/fm/icons/svg/folder_open3.svg"
    image create photo i1 -file $file -format {svg -scaletoheight 24}

    bind . <Escape> {exit}
    pack [frame .outerframe -bg #ffffff]
    pack [frame .outerframe.line0 -padx 0 -pady 0 -relief raised -bd 0 -bg #ffffff]

    set ::headings {
    line0 Name heading_name
    line0 Size heading_size
    line0 Modified heading_date
    line0 Permissions heading_perms
    line0 Owner heading_owner
    }
    foreach {line name col} $::headings {
    set w [button .outerframe.$line.$col -text $name -anchor w -relief raised -font {Arial 14} -width 10 -bd 1 -anchor center -padx 0 -pady 0]
    if {$col == "heading_name"} {.outerframe.$line.$col configure -width 50 -text "$name [subst -nocommands \\u25be]"}
    pack $w -side left -fill x
    }
    pack [frame .line1] [frame .line2] [frame .line3] [frame .line4]

    set ::data {
    line1 "File 1" name
    line1 "32.1 Mb" size
    line1 2023-05-05 date
    line1 755 perms
    line1 root:root owner

    line2 "File 2" name
    line2 "32.1 Mb" size
    line2 2023-05-05 date
    line2 755 perms
    line2 root:root owner

    line3 "File 3" name
    line3 "32.1 Mb" size
    line3 2023-05-05 date
    line3 755 perms
    line3 root:root owner

    line4 "File 4" name
    line4 "32.1 Mb" size
    line4 2023-05-05 date
    line4 755 perms
    line4 root:root owner
    }
    foreach {line name val} $::data {
    set w [label .$line.$val -text $name -anchor w -relief flat -font {Arial 14} -width 10 -fg #000000 -bg #ffffff -bd 2 -anchor center]
    if {$line == "line1"} {.$line.$val configure -bg #4A6984 -fg #ffffff}
    if {$val == "name"} {.$line.$val configure -width 50 -anchor w}
    pack $w -side left -fill x
    }


    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to All on Fri Jun 9 18:07:53 2023
    On Fri, 9 Jun 2023 14:32:25 -0400, saitology9 wrote:

    I think your problem is in the other column labels expanding to fill the space from the name.

    Not all of the labels in your script need to be "-fill x". As fas as I
    can tell, only the first one, "name", needs to be that, and the rest
    should have a fixed size. You may also want to make sure that you
    configure "name" with "-expand 1" in addition to "-fill x".


    Thank you for all the suggestions. But they didn't work. Nothing seems
    to have changed.

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerald Lester@21:1/5 to Luc on Fri Jun 9 17:07:08 2023
    On 6/9/23 16:06, Luc wrote:
    On Fri, 9 Jun 2023 00:04:08 -0700 (PDT), D Groth wrote:

    Dear Luc,

    please post short code examples to show what your problem is. Nobody
    will click usually on dubious image or video links. Having the code in
    the group as well will help future readers of the message where the
    video or the image link is already pointing to 404...

    Best,
    Detlef


    Well, here is the code. But you don't have the SVG icon file.


    package require Tk
    load "/home/tcl/fm/libtksvg0.12.so"
    set file "/home/tcl/fm/icons/svg/folder_open3.svg"
    image create photo i1 -file $file -format {svg -scaletoheight 24}

    bind . <Escape> {exit}
    pack [frame .outerframe -bg #ffffff]
    pack [frame .outerframe.line0 -padx 0 -pady 0 -relief raised -bd 0 -bg #ffffff]

    set ::headings {
    line0 Name heading_name
    line0 Size heading_size
    line0 Modified heading_date
    line0 Permissions heading_perms
    line0 Owner heading_owner
    }
    foreach {line name col} $::headings {
    set w [button .outerframe.$line.$col -text $name -anchor w -relief raised -font {Arial 14} -width 10 -bd 1 -anchor center -padx 0 -pady 0]
    if {$col == "heading_name"} {.outerframe.$line.$col configure -width 50 -text "$name [subst -nocommands \\u25be]"}
    pack $w -side left -fill x
    }
    pack [frame .line1] [frame .line2] [frame .line3] [frame .line4]

    set ::data {
    line1 "File 1" name
    line1 "32.1 Mb" size
    line1 2023-05-05 date
    line1 755 perms
    line1 root:root owner

    line2 "File 2" name
    line2 "32.1 Mb" size
    line2 2023-05-05 date
    line2 755 perms
    line2 root:root owner

    line3 "File 3" name
    line3 "32.1 Mb" size
    line3 2023-05-05 date
    line3 755 perms
    line3 root:root owner

    line4 "File 4" name
    line4 "32.1 Mb" size
    line4 2023-05-05 date
    line4 755 perms
    line4 root:root owner
    }
    foreach {line name val} $::data {
    set w [label .$line.$val -text $name -anchor w -relief flat -font {Arial 14} -width 10 -fg #000000 -bg #ffffff -bd 2 -anchor center]
    if {$line == "line1"} {.$line.$val configure -bg #4A6984 -fg #ffffff}
    if {$val == "name"} {.$line.$val configure -width 50 -anchor w}
    pack $w -side left -fill x
    }

    Use grid if you really want to roll your own table -- or better yet, use
    one of the "table" widgets.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to Luc on Fri Jun 9 20:05:12 2023
    On 6/9/2023 5:07 PM, Luc wrote:

    Thank you for all the suggestions. But they didn't work. Nothing seems
    to have changed.



    For buttons with text and images, you need to drastically increase the
    width, not totally sure why.

    If I increase the with to 650 as follows, everything lines up nicely
    again.

    if {$val == "name"} {$t.$line.$val configure -width 650 -anchor
    w -image i1 -compound left}


    Check out the image: https://0x0.st/HcSR.png


    By the way, there are several table type widgets available to you as
    packages. They might work better for you.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to [email protected] on Sat Jun 10 02:34:09 2023
    saitology9 <[email protected]> wrote:
    On 6/9/2023 5:07 PM, Luc wrote:

    Thank you for all the suggestions. But they didn't work. Nothing seems
    to have changed.

    For buttons with text and images, you need to drastically increase the
    width, not totally sure why.

    The /why/ is stated in the documentation:

    man n button:

    Command-Line Name:-width
    Database Name: width
    Database Class: Width

    Specifies a desired width for the button. If an image or
    bitmap is being displayed in the button then the value is
    in screen units (i.e. any of the forms acceptable to
    Tk_GetPixels). For a text button (no image or with
    -compound none) then the width specifies how much space
    in characters to allocate for the text label. ...

    man n label:

    Command-Line Name:-width
    Database Name: width
    Database Class: Width

    Specifies a desired width for the label. If an image or
    bitmap is being displayed in the label then the value is
    in screen units (i.e. any of the forms acceptable to
    Tk_GetPixels); for text it is in characters. ...

    Note the part about "if an image or bitmap" and the resulting change in
    default measurement units for "-width" when an image is present vs.
    when text only is present.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to All on Sat Jun 10 13:32:10 2023
    On Fri, 9 Jun 2023 20:05:12 -0400, saitology9 wrote:

    For buttons with text and images, you need to drastically increase the
    width, not totally sure why.
    If I increase the with to 650 as follows, everything lines up nicely
    again.


    Yes, I noticed that, except that I had to use 550 to make it look
    correct. But Rich has solved that mystery.


    Check out the image: https://0x0.st/HcSR.png

    Your heading buttons look very tall. Are you on Windows?


    By the way, there are several table type widgets available to you as packages. They might work better for you.


    They might work, but not better for me. I think they are quite
    complicated, and I am going to have to manage the code once the
    application is out. I have to keep the code manageable within my
    abilities. For example, I've tried to make drag and drop work with
    those and I failed. I have to be realistic.


    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to Rich on Sat Jun 10 13:44:22 2023
    On Sat, 10 Jun 2023 02:34:09 -0000 (UTC), Rich wrote:

    The /why/ is stated in the documentation:

    man n button:

    man n label:


    You are right again, of course.

    Still confusing though because while the width measure/metric is
    automatically changed to pixels, height seems to be still measured
    in text characters.

    I don't always understand Tk.


    So looks like I am going to have to measure the icon's width which
    will be variable because I'm using SVG and the label's text width
    with [font metrics] and do some math.

    Whether it will work to be seen. I'll let you know.


    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to Gerald Lester on Sat Jun 10 13:35:34 2023
    On Fri, 9 Jun 2023 17:07:08 -0500, Gerald Lester wrote:

    Use grid if you really want to roll your own table -- or better yet, use
    one of the "table" widgets.


    The nice thing about [pack] is that I can [pack forget] a bunch of
    widgets and not lose their configuration when I [pack] them again.
    That is pretty valuable in an application with multiple tabs
    (and an Undo Close Tab feature). Sadly, [grid] cannot do that.

    The "table" widgets are too complicated for my taste. I will have
    better control of the application without them.

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Luc on Sat Jun 10 18:07:36 2023
    Luc <[email protected]d> wrote:
    On Sat, 10 Jun 2023 02:34:09 -0000 (UTC), Rich wrote:

    The /why/ is stated in the documentation:

    man n button:

    man n label:


    You are right again, of course.

    Still confusing though because while the width measure/metric is automatically changed to pixels, height seems to be still measured
    in text characters.

    The same "change" to a different unit is documented to occur for
    -height as well:

    Command-Line Name:-height
    Database Name: height
    Database Class: Height

    Specifies a desired height for the button. If an image
    or bitmap is being displayed in the button then the value
    is in screen units (i.e. any of the forms acceptable to
    Tk_GetPixels); for text it is in lines of text.

    So unless you are seeing something different (possible) the addition of
    an image to a button or label causes both -width and -height to be
    "pixel based" measurements instead of "size of underlying font based" measurements.

    So looks like I am going to have to measure the icon's width which
    will be variable because I'm using SVG

    How so? Are you dynamically changing the size of the icon?

    and the label's text width with [font metrics] and do some math.

    The [font measure ...] command is also useful here (at least for
    -width values).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andreas Leitgeb@21:1/5 to Luc on Sat Jun 10 18:02:19 2023
    Luc <[email protected]d> wrote:
    The nice thing about [pack] is that I can [pack forget] a bunch of
    widgets and not lose their configuration when I [pack] them again.
    That is pretty valuable in an application with multiple tabs
    (and an Undo Close Tab feature). Sadly, [grid] cannot do that.

    grid also does have a subcommand "forget".

    A few experiments seem to imply, that [pack forget] forgets
    everything specific to the widget, same as [grid forget], so
    I don't yet understand the preference for pack.

    Could you expand on that a bit more?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to Andreas Leitgeb on Sat Jun 10 17:11:37 2023
    On Sat, 10 Jun 2023 18:02:19 -0000 (UTC), Andreas Leitgeb wrote:

    grid also does have a subcommand "forget".

    A few experiments seem to imply, that [pack forget] forgets
    everything specific to the widget, same as [grid forget], so
    I don't yet understand the preference for pack.

    Could you expand on that a bit more?

    **************************

    Of course.

    I may have been half right and half wrong.

    Yes, grid also does have a subcommand "forget," but my copy of
    the documentation (may be outdated) says:

    pack forget slave ?slave ...?
    Removes each of the slaves from the packing order for its master
    and unmaps their windows. The slaves will no longer be managed
    by the packer.


    No mention of configuration, but I've been testing my application
    using pack with tabs that contain multiple widgets that are
    repeatedly "forgotten" and "remembered" and nothing is lost.


    Documentation again:

    grid forget slave ?slave ...?
    Removes each of the slaves from grid for its master and unmaps
    their windows. The slaves will no longer be managed by the grid
    geometry manager. The configuration options for that window are
    forgotten, so that if the slave is managed once more by the grid
    geometry manager, the initial default settings are used.


    This time, we see very specific language saying that widget
    configuration *will* be lost. Will it though? I haven't tried.
    I am (obviously) very used to using pack. I guess I will have
    to test.


    And there is this, which I hadn't noticed before:

    grid remove slave ?slave ...?
    Removes each of the slaves from grid for its master and unmaps
    their windows. The slaves will no longer be managed by the grid
    geometry manager. However, the configuration options for that
    window are remembered, so that if the slave is managed once more
    by the grid geometry manager, the previous values are retained.


    Oh. Sounds like just what the doctor orderded. Again, I will
    have to try.


    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to Rich on Sat Jun 10 17:25:14 2023
    On Sat, 10 Jun 2023 18:07:36 -0000 (UTC), Rich wrote:

    So unless you are seeing something different (possible) the addition of
    an image to a button or label causes both -width and -height to be
    "pixel based" measurements instead of "size of underlying font based" >measurements.


    Yes, I am seeing something different. When I insert the image and
    change height from 1 to 2, it gets too tall, obviously twice as tall
    as before the change. At 3, it begins to look ridiculous. It is
    obviously not using pixels, but font height.


    So looks like I am going to have to measure the icon's width which
    will be variable because I'm using SVG

    How so? Are you dynamically changing the size of the icon?


    Not yet. But I will.

    My initial plan was to provide multiple sets of icons. I have 16,
    20, 24, 32, 48, 64 and 128px icon sets. I never liked that, but
    what else could I do? Well, then I discovered SVG support for Tk.
    That is a game changer. Now the user can press + and - keys at will
    and choose arbitrary icon sizes. I am not looking back.

    Or maybe I am. I've already seen it's rather difficult to make the
    entire file list scale along with the icons. The text size would
    have to follow suit somehow, or maybe I should leave it to the user
    to realize that they can only go so far with the resizing.

    As they say on TV, to be continued...


    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to Luc on Sat Jun 10 15:21:55 2023
    On 6/10/2023 1:25 PM, Luc wrote:
    On Sat, 10 Jun 2023 18:07:36 -0000 (UTC), Rich wrote:

    So unless you are seeing something different (possible) the addition of
    an image to a button or label causes both -width and -height to be
    "pixel based" measurements instead of "size of underlying font based"
    measurements.


    Yes, I am seeing something different. When I insert the image and
    change height from 1 to 2, it gets too tall, obviously twice as tall
    as before the change. At 3, it begins to look ridiculous. It is
    obviously not using pixels, but font height.


    So looks like I am going to have to measure the icon's width which
    will be variable because I'm using SVG

    How so? Are you dynamically changing the size of the icon?


    Not yet. But I will.

    My initial plan was to provide multiple sets of icons. I have 16,
    20, 24, 32, 48, 64 and 128px icon sets. I never liked that, but
    what else could I do? Well, then I discovered SVG support for Tk.
    That is a game changer. Now the user can press + and - keys at will
    and choose arbitrary icon sizes. I am not looking back.

    Or maybe I am. I've already seen it's rather difficult to make the
    entire file list scale along with the icons. The text size would
    have to follow suit somehow, or maybe I should leave it to the user
    to realize that they can only go so far with the resizing.

    As they say on TV, to be continued...



    It sounds like you've found your grid vs. pack solution, but for future reference, both have a [grid info window] or [pack info window] to retrieve
    the current settings such that they could be restored using pack/grid configure.

    I mostly use those for debugging, however.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Luc on Sun Jun 11 02:29:47 2023
    Luc <[email protected]d> wrote:
    On Sat, 10 Jun 2023 18:07:36 -0000 (UTC), Rich wrote:

    So unless you are seeing something different (possible) the addition of
    an image to a button or label causes both -width and -height to be
    "pixel based" measurements instead of "size of underlying font based" >>measurements.


    Yes, I am seeing something different. When I insert the image and
    change height from 1 to 2, it gets too tall, obviously twice as tall
    as before the change. At 3, it begins to look ridiculous. It is
    obviously not using pixels, but font height.

    That is very interesting. I do not see the effect you see.

    Code (this uses an image that is supplied as part of Tk itself):

    $ rlwrap wish
    % label .l -text Hello -image ::tk::icons::information -compound left
    .l
    % pack .l
    % .l cget -height
    0
    % .l configure -height 1
    % .l configure -height 2
    % .l configure -height 3
    % button .b -text Hello -image ::tk::icons::information -compound left
    .b
    % pack .b
    % .b cget -height
    0
    % .b configure -height 1
    % .b configure -height 2
    % .b configure -height 3
    %

    And screenshots of the result of running the above commands are here
    (all shots in one image):

    https://0x0.st/Hcpi.png

    I see what is documented to happen given what is written in the
    manpages.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)