Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The Screen Capture wxPerl script is now in modular form. My first try at creating a (very simple) module and using POD.


Update-added to POD sections

Module wxScreenCapture
use strict; use warnings; package WxScreenCapture; use parent qw(Exporter); our @EXPORT = qw(take_screenshot file_entry_dialog_simple file_entry_d +ialog_standard); use Wx qw(:everything); use Wx::Event qw( EVT_PAINT ); =head2 # # Copy the screen to the output file-similar to wxBook pg 139 example. # =cut sub take_screenshot { my($self, $file ) = @_; $self->Refresh; # without Refresh and Updat +e $self->Update; # the underlying window is c +aptured my $screen = Wx::ScreenDC->new(); my( $x, $y) = $screen->GetSizeWH(); my $bitmap = Wx::Bitmap->new($x,$y,-1); my $memory = Wx::MemoryDC->new(); $memory->SelectObject( $bitmap ); $memory->Blit(0,0,$x,$y, $screen, 0, 0); # copy the scr +een to the bitmap $bitmap->SaveFile( $file , wxBITMAP_TYPE_BMP ) ; # copy the + bitmap to the output file } =head2 # # Ask for the output filename - simple text entry dialog # =cut sub file_entry_dialog_simple { my( $self ) = @_; my $textvalue = "capture.bmp"; my $dialog = Wx::TextEntryDialog->new ( $self, "Enter the Screen Capture output filename\n(Cancel will u +se the default filename shown below)\n", "Screen Capture Output File Entry", $textvalue, wxOK | wxCANCEL ); if( $dialog->ShowModal == wxID_OK ) { $textvalue = $dialog->GetValue; } $dialog->Destroy; return $textvalue; } =head2 # # Ask for the output filename - standard file dialog # =cut sub file_entry_dialog_standard { my ( $self ) = @_; my $caption = "Choose a Screen Capture Output Filename"; my $wildcard = "*.bmp"; my $defaultDir = "."; my $defaultFilename = "capture.bmp"; my $filevalue = $defaultFilename; my $fileDialog = Wx::FileDialog->new($self, $caption, $defaultDir, + $defaultFilename, $wildcard, wxFD_SAVE | wxFD_OVERWRITE_P +ROMPT); if ($fileDialog->ShowModal() == wxID_OK ) { $filevalue = $fileDialog->GetPath(); } $fileDialog->Destroy; return $filevalue; } 1; __END__ =head1 NAME =head1 SYNOPSIS Module to capture a screen to a file. Written in wxPerl. =head1 DESCRIPTION This module exports three subroutines: take_screenshot, file_entry_dia +log_simple, and file_entry_dialog_standard. take_screenshot uses Wx:: +ScreenDC and Wx::MemoryDC device contexts and a Wx::Bitmap. Blit copi +es the ScreenDC to the MemoryDC Bitmap which is then copied to an out +put file. file_entry_dialog_simple provides a text_entry_dialog for r +equesting the capture filename. file_entry_dialog_standard provides t +he full directory/file entry screen for requesting the capture pathna +me. If the frame you wish to capture is smaller than the full screen, the +background windows will also be captured. =head1 USAGE use Wx qw(:everything); use Wx::Event qw( EVT_PAINT ); use WxScreenCapture; my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new(undef, -1, "Screen Capture Module Example", + [0,0], [1024,768] , wxDEFAULT_FRAME_STYLE); EVT_PAINT( $frame, \&onPaint); my $file = file_entry_dialog_standard($frame); $frame->Show; take_screenshot($frame, $file); $app->MainLoop; sub onPaint{} #paint the screen to be captured here. =head1 AUTHOR James M. Lynes, Jr. <> Lakeland, Florida USA October 21,2012. Original author: "PodMaster" from Perl Monks-2003 (no idea of real ide +ntity-not active for 6+ years) =head1 BUGS/FEATURES To capture the complete sample graphic(not included in this module def +inition), the frame size had to be set to the screen size of [1024x768]. Using wxDefaultSize ca +used the screen to paint in two passes and the capture to clip. If the frame is not defined large enough, par +ts of underlying windows will also be captured. =head1 SEE ALSO "The wxBook" - Cross-Platform GUI Programming with wxWidgets - Smart, Hock, and Csomor The wxWidgets documentation L<> The Citrus Perl Distribution L<> =head1 LICENSE This program is free software; you can redistribute it and/or modify i +t under the same terms as Perl itself. =cut
Test Script
use strict; use warnings; use Wx qw(:everything); use Wx::Event qw( EVT_PAINT ); use WxScreenCapture; =head2 # # Main Application # =cut my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new(undef, -1, "Screen Capture Module Example", + [0,0], [1024,768] , wxDEFAULT_FRAME_STYLE); EVT_PAINT( $frame, \&onPaint); my $file = file_entry_dialog_standard($frame); $frame->Show; take_screenshot($frame, $file); $app->MainLoop; =head2 # # Generate a sample graphic screen to capture # =cut sub onPaint{ my($self,$event)=@_; my $screen = Wx::PaintDC->new($self); $screen->SetBackgroundMode( wxTRANSPARENT ); $screen->SetFont(Wx::Font->new( 12, wxFONTFAMILY_ROMAN, wxNORMAL, +wxBOLD)); for(0..17){ my $c = $_ * 15; $screen->SetTextForeground( Wx::Colour->newRGB(0,0,$c) +); $screen->DrawRotatedText("wxPerl",100 ,100 ,$c); } $screen->DrawRotatedText("wxPerl and PodMaster",000 ,4 +00 ,0); $screen->DrawRotatedText("are messing up your screen", +000 ,450 ,0); for(0..17){ my $c = $_ * 15; $screen->SetTextForeground( Wx::Colour->newRGB(0,$c,0) +); $screen->DrawRotatedText("wxPerl",200 ,200 ,$c); } $screen->DrawRotatedText("wxPerl and PodMaster",100 ,5 +00 ,0); $screen->DrawRotatedText("are messing up your screen", +100 ,550 ,0); for(0..17){ my $c = $_ * 15; $screen->SetTextForeground( Wx::Colour->newRGB($c,0,0) +); $screen->DrawRotatedText("wxPerl",300 ,300 ,$c); } $screen->DrawRotatedText("wxPerl and PodMaster",200 ,6 +00 ,0); $screen->DrawRotatedText("are messing up your screen", +200 ,650 ,0); }

In reply to Screen Capture Module via wxPerl by jmlynesjr

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [choroba]: just one of its angles, in fact
    [LanX]: <|--
    [choroba]: Reminds me of an old joke about an orchestra...
    erix imagines that in a true Lancs accent
    [choroba]: so a Czech orchestra rehearses a new piece by a German composer
    LanX LOL of the day ... the Turkish Anonymous Alcoholics stopped their "No to alcohol" campaign for political reasons ...
    LanX omg my browser is posting again on its own ...
    [LanX]: choroba: GREAT JOKE! xD

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (5)
    As of 2017-03-27 11:48 GMT
    Find Nodes?
      Voting Booth?
      Should Pluto Get Its Planethood Back?

      Results (319 votes). Check out past polls.