Dr. Mu has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a user's manual for a Perl/Tk program (Win32). My usual approach to illustrating such a manual would be to do screen captures of the program in action, then cut out individual controls or groups of controls in Corel PhotoPaint to paste into the text near their explanations. But this hand-cutting gets very tedious, to say the least.

I was thinking that, since Tk provides all the tools needed to determine each widget's extents on the screen, it would be an easy matter to include a subroutine to selectively capture individual widgets or groups of widgets and write them out as, say, BMP files, thus eliminating all the hand cutting. It would be easy, that is, if there was a way to read arbitrary pixels from the screen. And that's where I'm stuck. Tk doesn't seem to provide such a facility (unless I'm overlooking something really obvious). I'd prefer not going through the Windows API if there's a Perl module with this capability built-in. But a search of CPAN didn't turn up anything promising.

An alternative, of course, would be to reparent the desired controls, in turn, in a separate top-level window, capturing each with Corel Capture. But packed widgets are so plastic, they might not look the same removed thus from their normal context.

Any ideas?

Replies are listed 'Best First'.
(tye)Re: Reading screen pixels
by tye (Sage) on Nov 18, 2000 at 07:18 UTC

    Tk::WinPhoto takes a photograph of a window but requires X and so doesn't work under Win32. So you could download and install Linux and continue your work using X Windows... (well, I'd find that fun)

    You could capture an image of the full window and then use $widget->GetGeometry() to automate cropping subimages out of that using some image manipulation package like Image::Magick.

            - tye (but my friends call me "Tye")
      Yes, that's it! Hot key #1 captures the entire window using Corel Capture. Hot key #2 triggers a Perl subroutine that recursively traverses the widget hierarchy, starting from the toplevel, and writes each widget's geometry to a file. Then, with another script, I can import the captured image as a Tk::Photo and snip pieces out of it based on the geometry file. As a bonus, this part is being done without potentially disturbing a running program. Hmmm ... a nicely interactive app could be made from this, depending on the effort put into it...

      Thanks!
Re: Reading screen pixels
by strredwolf (Chaplain) on Nov 18, 2000 at 08:20 UTC
    Use the canvas widget and create more widgets inside them. When they're set perfectly, have the canvas "print" to a Postscrpt file. Tada, virtual screen capture! Tcl/Tk natively can do it; Perl I'm not too sure. Check the Tk module for a postscript command.

    --
    $Stalag99{"URL"}="http://stalag99.keenspace.com";