Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: More wxPerl Examples

by jmlynesjr (Friar)
on Aug 08, 2012 at 01:22 UTC ( #986109=note: print w/ replies, xml ) Need Help??


in reply to Re^2: More wxPerl Examples
in thread More wxPerl Examples

Monks:

As a temporary aide until I can get this information posted to gethub et. al., listed below is the code that was truncated from the original posting.

Thanks for your patience and suggestions.

James

#!/usr/bin/perl # CppTrial-pg207A.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 207(A) - Message Dialog Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/4/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg207B.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (200, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; use Switch; my $stdDialog = Wx::MessageDialog->new($self, "Message Box Caption +", "Message Box Text", wxNO_DEFAULT | wxYES_NO | wxCANCEL | wxICON_INFORMATION); my $selection = $stdDialog->ShowModal(); switch ($selection) { case wxID_YES {$self->Wx::LogStatus ("You pressed: + \"Yes\" ")} case wxID_NO {$self->Wx::LogStatus ("You pressed: +\"No\" ")} case wxID_CANCEL {$self->Wx::LogStatus ("You pressed: +\"Cancel\" ")} } } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg207B.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 207(B) - Message Box Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/4/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg207B.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (200, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; use Switch; my $stdDialog = Wx::MessageBox("Message Box Text", "Message Box Caption", wxNO_DEFAULT | wxOK | wxYES_NO | wxCANCEL | wxICON_INFORMATION, $self); # Note: Wx::MessageBox returns different button IDs from Wx::Messag +eDialog - pg207A switch ($stdDialog) { case wxYES {$self->Wx::LogStatus ("You pressed: \" +Yes\" ")} case wxNO {$self->Wx::LogStatus ("You pressed: \"N +o\" ")} case wxCANCEL {$self->Wx::LogStatus ("You pressed: + \"Cancel\" ")} case wxOK {$self->Wx::LogStatus ("You pressed: \"O +k\" ")}; } } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg209.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 209 - Progress Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/5/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg209.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; my $continue = 1; my $max = 10; my $myProgressDialog = Wx::ProgressDialog->new("Progress Dialog Ex +ample", "An Information Message", $max, $self, wxPD_CAN_ABORT | wxPD_APP_MODAL | wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME); for ( my $i = 0; $i <= $max; $i++) { Wx::Sleep(1); if ($i == $max) { $continue = $myProgressDialog->Update($i, "That's all, fol +ks!"); } elsif ($i == $max/2) { $continue = $myProgressDialog->Update($i, "Only a half lef +t (very long message)!"); } else { $continue = $myProgressDialog->Update($i); } if (! $continue) { if ( Wx::MessageBox("Do you really want to cancel?", "Progress Dialog Question", wxYES_NO | wxICON_QUESTION, $self) == wxYES ) { last; } else { $self->Wx::LogStatus ("Progress Dialog Resumed"); $myProgressDialog->Resume(); } } } if (! $continue) { $self->Wx::LogStatus ("Progress Dialog Aborted!"); } else { $self->Wx::LogStatus ("Countdown from %d Finished", $max); } } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg210.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 210 - Busy Info Box # Ported to wxPerl by James M. Lynes Jr. - 5/5/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_MOTION); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg210.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); # &myStdDialogs($self); EVT_MOTION($self, \&myStdDialogs); return $self; } sub myStdDialogs { my ( $self, $event ) = @_; $self->Wx::LogStatus ("Display Busy Info Box"); Wx::Window::Disable($self); my $info = Wx::BusyInfo->new("Counting, please wait..."); #bug +- not displaying text in box Wx::Sleep(1); Wx::Window::Enable($self); $self->Wx::LogStatus ("Removed Busy Info Box"); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg211.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 211 - Application Tips Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/8/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_MOTION); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg211.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self) = @_; # Display an Application Tip Dialog Box # Tips are stored in the file "tips.txt", one tip per line # Randomly select the first tip to be displayed # Return a flag that can be used to control display of tips in the +future my $index = int( rand(9) ); my $tipProvider = Wx::CreateFileTipProvider("tips.txt", $index); my $showAtStartup = Wx::ShowTip($self, $tipProvider, 1); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg215.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 215 - File Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/8/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_MOTION); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg215.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; my $caption = "Choose A File"; my $wildcard = "*.*"; my $defaultDir = "~/Projects/perlprojects/wx.proj"; my $defaultFilename = ""; my $fileDialog = Wx::FileDialog->new($self, $caption, $defaultDir, + $defaultFilename, $wildcard, wxOPEN); my $fileDialogStatus = $fileDialog->ShowModal(); my $selecteddir = $fileDialog->GetDirectory(); my $selectedfile = $fileDialog->GetFilename(); # print $selecteddir, "\n", $selectedfile, "\n"; if ( $fileDialogStatus == wxID_OK ) {$self->Wx::LogStatus ("You pr +essed: \"Open\" ")}; if ( $fileDialogStatus == wxID_CANCEL ) {$self->Wx::LogStatus ("Yo +u pressed: \"Cancel\" ")}; } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg218.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 218 - Directory Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/8/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_MOTION); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg218.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; my $caption = "Choose A Directory"; my $defaultPath = "/"; my $dirDialog = Wx::DirDialog->new($self, $caption, $defaultPath, + wxDD_NEW_DIR_BUTTON); my $dirDialogStatus = $dirDialog->ShowModal(); my $selecteddir = $dirDialog->GetPath(); # print $selecteddir, "\n"; if ( $dirDialogStatus == wxID_OK ) {$self->Wx::LogStatus ("You pre +ssed: \"Open\" ")}; if ( $dirDialogStatus == wxID_CANCEL ) {$self->Wx::LogStatus ("You + pressed: \"Cancel\" ")}; } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg221.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 221 - Color Selection Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/8/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_MOTION); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg221.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; my $colourDialog = Wx::ColourDialog->new($self); my $colorDialogStatus = $colourDialog->ShowModal(); my $colourdata = $colourDialog->GetColourData(); my $selectedColour = $colourdata->GetColour(); $self->SetBackgroundColour($selectedColour); $self->Refresh(); if ( $colorDialogStatus == wxID_OK ) {$self->Wx::LogStatus ("You p +ressed: \"Ok\" ")}; if ( $colorDialogStatus == wxID_CANCEL ) {$self->Wx::LogStatus ("Y +ou pressed: \"Cancel\" ")}; } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg224.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 224 - Font Selection Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/8/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg224.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); EVT_PAINT($self, \&myStdDialogs); return $self; } sub myStdDialogs { my ( $self, $event ) = @_; my $font = Wx::Font->new(18, wxFONTFAMILY_ROMAN, wxNORMAL, wxNORMA +L); my $fontData = Wx::FontData->new(); $fontData->SetInitialFont($font); $fontData->SetColour(wxGREEN); my $fontDialog = Wx::FontDialog->new($self, $fontData); my $fontDialogStatus = $fontDialog->ShowModal(); $fontData = $fontDialog->GetFontData(); my $selectedfont = $fontData->GetChosenFont(); my $selectedcolour = $fontData->GetColour(); # # Code added to provide something to display, drag dialog off of fr +ame to see text displayed # my $dc = Wx::PaintDC->new($self); my $pt=Wx::Point->new(100,200); $dc->SetFont($selectedfont); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground($selectedcolour); $dc->SetTextBackground(wxWHITE); $dc->DrawText("Font Selection Sample",$pt->x, $pt->y); $self->Refresh(); # # Loop until Cancel is Selected # if ( $fontDialogStatus == wxID_CANCEL ) {die "Font Selection Termi +nated"}; } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg225.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 225 - Single Choice Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/9/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg225.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; my @choices = ("One", "Two", "Three", "Four", "Five", "Six", "Seve +n", "Eight"); my $singleChoiceDialog = Wx::SingleChoiceDialog->new($self, "This is a small sample\nA single-choice convenience +dialog", "Please select a value", \@choices); $singleChoiceDialog->SetSelection(2); if( $singleChoiceDialog->ShowModal() == wxID_OK) { Wx::MessageBox($singleChoiceDialog->GetStringSelection(), "Got String", wxOK | wxICON_INFORMATION, $self); } } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg226.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 226 - Multiple Choice Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/9/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg226.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; my @choices = ("One", "Two", "Three", "Four", "Five", "Six", "Seve +n", "Eight"); my $multiChoiceDialog = Wx::MultiChoiceDialog->new($self, "A Multi-choice convenience dialog", "Please select several values", \@choices); if( $multiChoiceDialog->ShowModal() == wxID_OK) { my @selections = $multiChoiceDialog->GetSelections(); # + Returns list of index numbers my $count = $#selections +1; # Index into @ +choices for text my $msg = ""; foreach my $selection (@selections) { $msg .= $selection . " : " . $choices[$selection] . "\n"; } Wx::MessageBox($msg, "Selections", wxOK | wxICON_INFORMATION, +$self); } } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg227.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 227 - Number Entry Dialog (**Alternate Implement +ation - GetNumberFromUser**) # Could not get NumberEntryDialog, TextEntryDialog, or PasswordEntryDi +alog to load # Instead used GetNumberFromUser Function # Ported to wxPerl by James M. Lynes Jr. - 5/10/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg227.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; # # Not sure where the initial value of 20 is comming from.... # my $getNumberFromUser = Wx::GetNumberFromUser( # Appea +rs to not support min/max bounds "Number Entry Dialog Example", "Enter A Number:", "Number Entry", 50, wxOK | wxCANCEL, $self); # # Returns -1 upon Cancel # Wx::MessageBox("$getNumberFromUser", "Entered Number:", wxOK | wxI +CON_INFORMATION, $self); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg228A.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 228 - Text Entry Dialog (**Alternate Implementat +ion - GetTextFromUser**) # Could not get NumberEntryDialog, TextEntryDialog, or PasswordEntryDi +alog to load # Instead used GetTextFromUser Function # Ported to wxPerl by James M. Lynes Jr. - 5/10/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg228A.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; # # Not sure where the initial value of 20 is comming from.... # my $getTextFromUser = Wx::GetTextFromUser( "This is some text, actually a lot of text\nEven two +rows of text", "Enter a String: ", wxOK | wxCANCEL, $self); # # Returns empty string upon Cancel # Wx::MessageBox("$getTextFromUser", "Entered String", wxOK | wxICON +_INFORMATION, $self); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg228B.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 228 - Password Entry Dialog (**Alternate Impleme +ntation - GetPasswordFromUser**) # Could not get NumberEntryDialog, TextEntryDialog, or PasswordEntryDi +alog to load # Instead used GetPasswordFromUser Function # Ported to wxPerl by James M. Lynes Jr. - 5/10/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg228B.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (250, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; # # Not sure where the initial value of 20 is comming from.... # my $getPasswordFromUser = Wx::GetPasswordFromUser( "This is some text, actually a lot of text\nEven two +rows of text", "Enter a Password: ", wxOK | wxCANCEL, $self); # # Returns empty string upon Cancel # Wx::MessageBox("$getPasswordFromUser", "Entered Password:", wxOK | + wxICON_INFORMATION, $self); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg245.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 245 - Personal Records Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/13/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Personal Records Dialog E +xample", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; my ($ID_NAME, $ID_AGE, $ID_SEX, $ID_VOTE, $ID_RESET, $ID_OK, $ID_C +ANCEL, $ID_HELP) = (1..8); my ($wxEmptyString, $true) = ("", 1); my $topSizer = Wx::BoxSizer->new(wxVERTICAL); $dialog->SetSizer($topSizer); my $boxSizer = Wx::BoxSizer->new(wxVERTICAL); $topSizer->Add($boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5) +; my $desc = Wx::StaticText->new($dialog, wxID_STATIC, "Please enter your name, age, and sex, and specify +whether you wish to\nvote in a general election.", wxDefaultPosition, wxDefaultSize, 0); $boxSizer->Add($desc, 0, wxALIGN_LEFT | wxALL, 5); my $nameCtrl = Wx::TextCtrl->new($dialog, $ID_NAME, "Maylee", wxDefaultPosition, wxDefaultSize, 0); $boxSizer->Add($nameCtrl, 0, wxGROW | wxALL, 5); my $ageSexVoteBox = Wx::BoxSizer->new(wxHORIZONTAL); $boxSizer->Add($ageSexVoteBox, 0, wxGROW | wxALL, 5); my $ageLabel = Wx::StaticText->new($dialog, wxID_STATIC, "&Age:", +wxDefaultPosition, wxDefaultSize, 0); $ageSexVoteBox->Add($ageLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, + 5); my $ageSpin = Wx::SpinCtrl->new($dialog, $ID_AGE, $wxEmptyString, +wxDefaultPosition, Wx::Size->new(60, -1), wxSP_ARROW_KEYS, 0, 120, 50); $ageSexVoteBox->Add($ageSpin, 0, wxALIGN_CENTER_VERTICAL | wxALL, +5); my $sexLabel = Wx::StaticText->new($dialog, wxID_STATIC, "&Sex:", +wxDefaultPosition, wxDefaultSize, 0); $ageSexVoteBox->Add($sexLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, + 5); my @sexStrings = ("Male", "Female"); my $sexChoice = Wx::Choice->new($dialog, $ID_SEX, wxDefaultPositio +n, Wx::Size->new(85,-1), \@sexStrings); $sexChoice->SetStringSelection("Female"); $ageSexVoteBox->Add($sexChoice, 0, wxALIGN_CENTER_VERTICAL | wxALL +, 5); $ageSexVoteBox->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5); + # Spacer Box my $voteCheckBox = Wx::CheckBox->new($dialog, $ID_VOTE, "&Vote", wxDefaultPosition, wxDefaultSize, 0); $voteCheckBox->SetValue($true); $ageSexVoteBox->Add($voteCheckBox, 0, wxALIGN_CENTER_VERTICAL | wx +ALL, 5); my $line = Wx::StaticLine->new($dialog, wxID_STATIC, wxDefaultPosi +tion, wxDefaultSize, wxLI_HORIZONTAL); $boxSizer->Add($line, 0, wxGROW | wxALL, 5); my $okCancelBox = Wx::BoxSizer->new(wxHORIZONTAL); $boxSizer->Add($okCancelBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 +); my $reset = Wx::Button->new($dialog, $ID_RESET, "&Reset", wxDefaultPosition, wxDefaultSize, 0); $okCancelBox->Add($reset, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); my $ok = Wx::Button->new($dialog, $ID_OK, "&Ok", wxDefaultPosition, wxDefaultSize, 0); $ok->SetDefault(); $okCancelBox->Add($ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); my $cancel = Wx::Button->new($dialog, $ID_CANCEL, "&Cancel", wxDefaultPosition, wxDefaultSize, 0); $okCancelBox->Add($cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + my $help = Wx::Button->new($dialog, $ID_HELP, "&Help", wxDefaultPosition, wxDefaultSize, 0); $okCancelBox->Add($help, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); $topSizer->Fit($dialog); $topSizer->SetSizeHints($dialog); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg283.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 283 - Drawing a masked image # Ported to wxPerl by James M. Lynes Jr. - 5/12/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg283.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $memdc = Wx::MemoryDC->new(); my $bitMap = Wx::Bitmap->new(400,400); $memdc->SelectObject($bitMap); my $brush1 = Wx::Brush->new(wxBLUE, wxSOLID); $memdc->SetBackground($brush1); $memdc->Clear(); # Fill DC with background +brush color my $pen1 = Wx::Pen->new(wxRED,1,wxSOLID); $memdc->SetPen($pen1); my $brush2 = Wx::Brush->new(wxRED,wxSOLID); $memdc->SetBrush($brush2); $memdc->DrawRectangle(50, 50, 200, 200); # Red rectangl +e on blue background my $image = $bitMap->ConvertToImage(); $image->SetMaskColour(255, 0, 0); $image->SetMask(1); # my $dispBitMap = Wx::Bitmap->new($image, -1); # Constr +uctor not supported by wxPerl # $dc->DrawBitmap($dispBitMap, 0, 0, 1); # Can't dis +play $image # # Code added for display purposes - many book examples are only + fragments # my $bmp = Wx::Bitmap->new("test2.bmp", wxBITMAP_TYPE_BMP); $bmp->SetMask(Wx::Mask->new($bmp, wxBLUE)); Wx:StaticBitMap->new($memdc, -1, $bmp, [300,120]); my $dcPaint = Wx::PaintDC->new($self); $dcPaint->Blit(0, 0, 400, 400, $memdc, 0, 0, wxCOPY, 1); $memdc->SelectObject(wxNullBitmap); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg293.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 293 - Writing Text to the Clipboard # Ported to wxPerl by James M. Lynes Jr. - 5/16/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg293.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (200, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; use Wx::DND; # Loads all of the Clipboard # and Drag and Drop packages # Like - Wx::DataObjectSimple my $textDataObject1 = Wx::TextDataObject->new("Save this string to + the clipboard"); wxTheClipboard->Open; wxTheClipboard->SetData( $textDataObject1 ); wxTheClipboard->Close; wxTheClipboard->Open; my $text; if( wxTheClipboard->IsSupported( wxDF_TEXT ) ) { my $textDataObject2 = Wx::TextDataObject->new; my $ok = wxTheClipboard->GetData( $textDataObject2 ); if( $ok ) { $self->Wx::LogStatus( "Pasted and Retrieved text" ); $text = $textDataObject2->GetText; } else { $self->Wx::LogStatus( "Error pasting and Retrieving te +xt" ); $text = ''; } } Wx::MessageBox($text); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg294.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 294 - Writing a bitmap/image to the Clipboard # Ported to wxPerl by James M. Lynes Jr. - 5/17/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { Wx::InitAllImageHandlers(); my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg294.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (200, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); EVT_PAINT($self, \&myStdDialogs); return $self; } sub myStdDialogs { my ( $self, $event ) = @_; use Wx::DND; # Loads all of the Clipboard # and Drag and Drop packages # Like - Wx::DataObjectSimple my $bmp = Wx::Bitmap->new("logo.png", wxBITMAP_TYPE_PNG); my $bmpObject1 = Wx::BitmapDataObject->new($bmp); wxTheClipboard->Open; wxTheClipboard->SetData( $bmpObject1 ); # Put the bitma +p object on the clipboard wxTheClipboard->Close; wxTheClipboard->Open; my $bitmap = wxNullBitmap; if( wxTheClipboard->IsSupported( wxDF_BITMAP ) ) { my $bmpObject2 = Wx::BitmapDataObject->new($bitmap); my $ok = wxTheClipboard->GetData( $bmpObject2 ); # Get the bit +map object from the clipboard if( $ok ) { $self->Wx::LogStatus("Pasted and Retrieved bitmap" ); $bitmap = $bmpObject2->GetBitmap(); } else { $self->Wx::LogStatus("Error pasting bitmap" ); $bitmap = wxNullBitmap; } wxTheClipboard->Close; } # # Use a paint event to get the bitmap to draw on screen # my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK, 1, wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED, wxSOLID); $dc->SetBrush($brush); $dc->DrawBitmap($bitmap, 30, 100, 1); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg340.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 340 - HTML Window - Displays an HTML file # Ported to wxPerl by James M. Lynes Jr. - 5/10/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { Wx::InitAllImageHandlers(); my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); use Wx::Html; # Html package not loaded by "use Wx +qw(:everything)" # Html pulls in all of the HTML modules sub new { my ($class) = @_; my $self = Wx::Dialog->new( undef, -1, 'CppTrial-pg340.pl', wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; my $topSizer = Wx::BoxSizer->new(wxVERTICAL); my $html = Wx::HtmlWindow->new($self, wxID_ANY, wxDefaultPosition, + Wx::Size->new(600,400), wxHW_SCROLLBAR_NEVER); $html->SetBorders(5); $html->LoadPage("pg342.html"); # # GetInternalRepresentation() not supported under wxPerl # $topSizer->Add($html, 1, wxALL, 10); my $staticLine = Wx::StaticLine->new($self, wxID_ANY); $topSizer->Add($staticLine, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); my $button = Wx::Button->new($self, wxID_OK, "Ok"); $button->SetDefault(); $topSizer->Add($button, 0, wxALL | wxALIGN_RIGHT, 15); $self->SetSizer($topSizer); $topSizer->Fit($self); $self->ShowModal(); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg347.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 347 - Simple Grid Example # Ported to wxPerl by James M. Lynes Jr. - 5/11/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { Wx::InitAllImageHandlers(); my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); use Wx::Grid; # Package not loaded by "use +Wx qw(:everything)" sub new { my ($class) = @_; my $self = Wx::Dialog->new( undef, -1, 'CppTrial-pg347.pl', wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; my $grid = Wx::Grid->new($self, wxID_ANY, wxDefaultPosition, Wx::Size->new(400,300)); $grid->CreateGrid(8, 10); # 8 rows by 10 columns $grid->SetRowSize(0, 60); # row size in pixels $grid->SetColSize(0, 120); # column size in pixels $grid->SetCellValue(0, 0, "wxGrid is Good"); # A1 $grid->SetCellValue(0, 3, "This is Read-only"); # D1 $grid->SetReadOnly(0, 3); $grid->SetCellValue(3, 3, "Green on Grey"); # D4 $grid->SetCellTextColour(3, 3, wxGREEN); $grid->SetCellBackgroundColour(3, 3, wxLIGHT_GREY); $grid->SetColFormatFloat(5, 6, 2); $grid->SetCellValue(0, 5, "3.1415"); # F1 $grid->Fit(); $self->SetClientSize($grid->GetSize); } ---------------------------------------------------------------------- +------------------------------ This is Application Tip #1... This is Application Tip #2... This is Application Tip #3... This is Application Tip #4... This is Application Tip #5... This is Application Tip #6... This is Application Tip #7... This is Application Tip #8... This is Application Tip #9... This is Application Tip #10... ---------------------------------------------------------------------- +------------------------------ <html> <body bgcolor="#FFFFFF"> <table cellspacing=3 cellpadding=4 width="100%"> <tr> <td bgcolor="#101010"> <center> <font size=+2 color="#FFFFFF"><b><br>wxHTML Library Sample 0.2.0<b +r></b> </font> </center> </td> </tr> <tr> <td bgcolor="#73A183"> <b><font size=+1>Copyright (c) 1999 Vaclav Slavic</font></b><p> <font size=-1> <table cellpadding=0 cellspacing=0 width="100%"> <tr> <td width="65%"> Vaclav Slavik<p> </td> <td valign=top> <img src="logo.png"> </td> </tr> </table> <font size=1> Licenced under wxWindows Library Licence, Version 3. </font> </font> </td> </tr> </table> </body> </html> ---------------------------------------------------------------------- +------------------------------


Comment on Re^3: More wxPerl Examples
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986109]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2014-12-27 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls