• Tk app screenshot is all black

    From Luc@21:1/5 to All on Wed Dec 21 10:17:03 2022
    I want to screenshot a Tk app. I mean, I want the app to screenshoot itself.
    To take a selfie.

    I found code in the wiki that works very well. Except that it only works
    if the application's window has focus. If I Alt+Tab away from it while it's running, the resulting screenshot is just a pitch black screen.

    My best guess is nothing can be done because the window manager "unmaps"
    the window when I Alt+Tab away from it.

    Please tell me that I'm wrong and there is some ninja trick to overcome
    this limitation.

    Please?

    The stolen code:

    proc CaptureWindow {win {baseImg ""} {px 0} {py 0}} {
    package require Img
    # create the base image of win (the root of capturing process)
    if {$baseImg eq ""} {
    set baseImg [image create photo -format window -data $win]
    }
    # paste images of win's children on the base image
    foreach child [winfo children $win] {
    if {![winfo ismapped $child]} continue
    set childImg [image create photo -format window -data $child]
    regexp {\+(\d*)\+(\d*)} [winfo geometry $child] -> x y
    $baseImg copy $childImg -to [incr x $px] [incr y $py]
    image delete $childImg
    CaptureWindow $child $baseImg $x $y
    }
    return $baseImg
    }


    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Wed Dec 21 14:55:20 2022
    Hi Luc,

    I want to screenshot a Tk app.
    you are aware that you can take a screen shot of _any_ window by means
    of the 'Alt + Print' key combo?
    HTH
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to Helmut Giese on Wed Dec 21 12:18:38 2022
    On Wed, 21 Dec 2022 14:55:20 +0100, Helmut Giese wrote:

    Hi Luc,

    I want to screenshot a Tk app.
    you are aware that you can take a screen shot of _any_ window by means
    of the 'Alt + Print' key combo?


    Not good. I want the app to do it automatically at a certain point of
    its routine.

    And I want it to be able to do it even when the parent window doesn't have focus in the window manager.

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to hgiese@ratiosoft.com on Wed Dec 21 16:48:11 2022
    At Wed, 21 Dec 2022 14:55:20 +0100 Helmut Giese <hgiese@ratiosoft.com> wrote:


    Hi Luc,

    I want to screenshot a Tk app.
    you are aware that you can take a screen shot of _any_ window by means
    of the 'Alt + Print' key combo?

    That is dependent on the O/S and/or desktop system.

    HTH
    Helmut



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to Robert Heller on Wed Dec 21 13:54:23 2022
    On Wed, 21 Dec 2022 16:48:11 +0000, Robert Heller wrote:

    At Wed, 21 Dec 2022 14:55:20 +0100 Helmut Giese wrote:


    Hi Luc,

    I want to screenshot a Tk app.
    you are aware that you can take a screen shot of _any_ window by means
    of the 'Alt + Print' key combo?

    That is dependent on the O/S and/or desktop system.


    Hi, Helmut.

    It's Linux and Openbox.

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Luc on Wed Dec 21 17:40:17 2022
    Luc <no@no.no> wrote:
    On Wed, 21 Dec 2022 16:48:11 +0000, Robert Heller wrote:

    At Wed, 21 Dec 2022 14:55:20 +0100 Helmut Giese wrote:


    Hi Luc,

    I want to screenshot a Tk app.
    you are aware that you can take a screen shot of _any_ window by means
    of the 'Alt + Print' key combo?

    That is dependent on the O/S and/or desktop system.


    Hi, Helmut.

    It's Linux and Openbox.

    This is still very likely dependent upon how the Img package is
    obtaining the bitmap that is the window contents. And how successful
    Img is at that is itself also dependent upon window manager and/or
    desktop environment.

    Here, under X11 and Fvwm2, doing a 'snapshot' of a partially obscured
    Tk window using Img returns the visible parts as visible and the
    obscured parts as pure black. Which also means that if the window were
    fully obscured, the return would be all pure black.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to Rich on Wed Dec 21 13:23:07 2022
    On 12/21/2022 12:40 PM, Rich wrote:
    Luc <no@no.no> wrote:
    On Wed, 21 Dec 2022 16:48:11 +0000, Robert Heller wrote:

    Here, under X11 and Fvwm2, doing a 'snapshot' of a partially obscured
    Tk window using Img returns the visible parts as visible and the
    obscured parts as pure black. Which also means that if the window were
    fully obscured, the return would be all pure black.



    On Windows, the obscured part is not black but it captures the other
    window that is doing the obscuring. Looks weird.

    In any case, I am not sure if it was a post here or on the wiki but I
    recall seeing code that did something similar, except that it did
    differently, iirc pixel by pixel. It may have been part of the alited
    editor, if I am spelling it correctly. I would look into that as an alternative.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andreas Leitgeb@21:1/5 to Luc on Thu Dec 22 23:34:46 2022
    Luc <no@no.no> wrote:
    I want to screenshot a Tk app.
    Please tell me that I'm wrong and there is some ninja trick to overcome
    this limitation.
    I want the app to do it automatically at a certain point of
    its routine.
    And I want it to be able to do it even when the parent window doesn't have focus in the window manager.

    Talking about "ninja tricks"... does it need to run on the active
    desktop?

    I'm talking of either multiple Desktop-sessions (essentially multiple
    X or wayland servers running in parallel on different ttys.

    If you still need to have it available right there on the main desktop,
    you could start a nested X-session Xnest (in Package "xnest" on debian- systems, likely similar on other distributions) and start a WM and your application inside it.

    Chances are, that while your Xnest-root-window is obscured, minimized,
    and/or out of focus, the front applications running inside will still
    assume to have your full attention.

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