├── AngularMeter.pl ├── CppTrial-pg019.pl ├── CppTrial-pg065.pl ├── CppTrial-pg073.pl ├── CppTrial-pg077.pl ├── CppTrial-pg081.pl ├── CppTrial-pg086.pl ├── CppTrial-pg124.pl ├── CppTrial-pg133.pl ├── CppTrial-pg135.pl ├── CppTrial-pg150.pl ├── CppTrial-pg151.pl ├── CppTrial-pg152.pl ├── CppTrial-pg154.pl ├── CppTrial-pg155.pl ├── CppTrial-pg156.pl ├── CppTrial-pg157.pl ├── CppTrial-pg158.pl ├── CppTrial-pg159A.pl ├── CppTrial-pg159B.pl ├── CppTrial-pg195.pl ├── CppTrial-pg196.pl ├── CppTrial-pg197.pl ├── CppTrial-pg199.pl ├── CppTrial-pg201.pl ├── CppTrial-pg202.pl ├── CppTrial-pg207A.pl ├── CppTrial-pg207B.pl ├── CppTrial-pg209.pl ├── CppTrial-pg210.pl ├── CppTrial-pg211.pl ├── CppTrial-pg215.pl ├── CppTrial-pg218.pl ├── CppTrial-pg221.pl ├── CppTrial-pg224.pl ├── CppTrial-pg225.pl ├── CppTrial-pg226.pl ├── CppTrial-pg227.pl ├── CppTrial-pg228A.pl ├── CppTrial-pg228B.pl ├── CppTrial-pg245.pl ├── CppTrial-pg283.pl ├── CppTrial-pg293.pl ├── CppTrial-pg294.pl ├── CppTrial-pg340.pl ├── CppTrial-pg347.pl ├── FILE-INDEX.txt ├── LCDdisplay.pl ├── LM3.pl ├── LinearMeter.pl ├── LinearMeter3.pm ├── README.txt ├── ScreenCapture.pl ├── WxScreenCapture.pm ├── copy.xpm ├── cut.xpm ├── logo.png ├── padre_logo_64x64.png ├── pg342.html ├── print.xpm ├── test2.bmp ├── tips.txt └── wxWizard.pl /AngularMeter.pl: -------------------------------------------------------------------------------- 1 | #! /home/pete/CitrusPerl/perl/bin/perl 2 | # 3 | # AngularMeter.pl 4 | # This script draws a simulated round panel meter. 5 | # 6 | # 7 | # Written in wxPerl. Tested on Citrus Perl 5.16 with wxWidgets 2.8.x. 8 | # Ported by: James M. Lynes. Jr. 9 | # Last Modified Date: January 20, 2013 10 | # 11 | # Adapted from AngularMeter.cpp by Marco Cavallini 12 | # based in part(mostly) on the work of 13 | # the KWIC project (http://www.koansoftware.com/kwic/index.htm). 14 | # Referenced on pg 596 of the "Wx Book" - 15 | # "Cross-Platform GUI Programming with wxWidgets", Smart, Hock, & Csomor 16 | # 17 | # Added limit checking with green/red zones - Normal/Hi-limit 18 | # could reverse colors to alarm on a low limit if needed. 19 | # Added animation - ***Needle follows left/right mouse movement*** 20 | # Added Meter identification label 21 | # Could add mouse click event to capture value at that point 22 | # and use the meter as an input device. 23 | # 24 | use 5.010; 25 | use strict; 26 | use warnings; 27 | use Wx qw(:everything :allclasses); 28 | use Wx::Event qw( EVT_PAINT EVT_SIZE EVT_MOTION); 29 | use Math::Trig; 30 | # 31 | # Configuration Data ------------------------------------------------------------------ 32 | # 33 | my $MeterWidth = 350; # Define the meter size 34 | my $MeterHeight = $MeterWidth; # Must be square to look right 35 | 36 | my $ScaledVal = 0; 37 | my $RealVal = 0; 38 | 39 | my $Tick = 9; # Number of tic marks 40 | my $Sec = 2; # Number of sections - green/red 41 | 42 | my $RangeStart = 0; # Define Meter Span - Min 43 | my $RangeEnd = 100; # - Max 44 | my $AlarmLimit = 65; # Alarm Limit 45 | my $AngleStart = -20; # East is 0 degrees, + is CCW 46 | my $AngleEnd = 200; 47 | 48 | my @SectorColours = (wxGREEN, wxRED); # Only using two sections 49 | my $BackColour = wxLIGHT_GREY; 50 | my $NeedleColour = wxBLACK; 51 | my $BorderColour = wxBLUE; 52 | 53 | my $PI = 4.0*atan(1.0); 54 | my $Font = Wx::Font->new(10, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL); 55 | my $DrawCurrent = 1; # Turn on/off value displayed as text 56 | my $Label = "Process Temperature - degC"; # Label Meter at bottom of display 57 | my $ramp = 25; # Initial value/needle position 58 | my $lastpos = 0; # Last mouse position 59 | # 60 | # Main Application ----------------------------------------------------------------------- 61 | # 62 | my $app = Wx::SimpleApp->new; 63 | my $frame = Wx::Frame->new(undef, -1, "Simulated Round Panel Meter", 64 | wxDefaultPosition, [$MeterWidth, $MeterHeight]); 65 | SetValue($ramp); # Initial value/needle position 66 | EVT_PAINT( $frame, \&onPaint ); 67 | EVT_SIZE( $frame, \&onSize ); 68 | EVT_MOTION( $frame, \&onMotion ); 69 | $frame->Show; 70 | $app->MainLoop; 71 | # 72 | # Dismiss a size event 73 | # 74 | sub onSize{ 75 | my($self, $event) = @_; 76 | $event->Skip(); 77 | } 78 | sub onMotion { # Change the setpoint value and redraw 79 | my($self, $event) = @_; 80 | my $x = $event->GetPosition->x; # Current mouse position 81 | if($x > $lastpos) {$ramp += 1; $lastpos = $x} # Mouse right, increment needle 82 | if($x < $lastpos) {$ramp -= 1; $lastpos = $x} # Mouse left, decrement needle 83 | if($ramp >= $RangeEnd) {$ramp = $RangeEnd;} # Clamp to max range 84 | if($ramp <= $RangeStart) {$ramp = $RangeStart;} # Clamp to min range 85 | SetValue($ramp); 86 | $self->Refresh; 87 | $self->Update; 88 | } 89 | # 90 | # Paint the simulated LCD Display ---------------------------------------------------------- 91 | # 92 | sub onPaint { 93 | my($self, $event) = @_; 94 | my $dc = Wx::PaintDC->new($self); 95 | my( $w, $h) = $dc->GetSizeWH(); 96 | my $memdc = Wx::MemoryDC->new(); 97 | $memdc->SelectObject(Wx::Bitmap->new($MeterWidth, $MeterHeight)); 98 | my $brush = Wx::Brush->new($BackColour, wxSOLID); 99 | $memdc->SetBackground($brush); 100 | $memdc->SetBrush($brush); 101 | $memdc->Clear(); 102 | my $pen = Wx::Pen->new($BorderColour, 2, wxSOLID); 103 | $memdc->SetPen($pen); 104 | $memdc->DrawRectangle(0, 0, $w, $h); 105 | DrawSectors($memdc); 106 | if($Tick > 0) {DrawTicks($memdc);} 107 | DrawNeedle($memdc); 108 | if($DrawCurrent) { # Display current value as text 109 | my $valuetext = sprintf("%d", $RealVal); 110 | my @te = $memdc->GetTextExtent($valuetext); 111 | my $x = ($w-$te[0])/2; 112 | $memdc->SetFont($Font); 113 | $memdc->DrawText($valuetext, $x, ($h/2)+20); 114 | } 115 | DrawLabel($memdc); 116 | $dc->Blit(0, 0, $w, $h, $memdc, 0, 0); 117 | } 118 | sub DrawNeedle { 119 | my($dc) = @_; 120 | my($w, $h) = $dc->GetSizeWH(); 121 | my $pen = Wx::Pen->new($NeedleColour, 1, wxSOLID); 122 | $dc->SetPen($pen); 123 | my $brush = Wx::Brush->new($NeedleColour, wxSOLID); 124 | $dc->SetBrush($brush); 125 | my $val = ($ScaledVal + $AngleStart) * $PI/180; 126 | my $dyi = sin($val-90)*2; 127 | my $dxi = cos($val-90)*2; 128 | my @points; 129 | $points[0] = Wx::Point->new($w/2-$dxi, $h/2-$dyi); 130 | $dxi = cos($val) * ($h/2-4); 131 | $dyi = sin($val) * ($h/2-4); 132 | $points[2] = Wx::Point->new($w/2-$dxi, $h/2-$dyi); 133 | $dxi = cos($val+90)*2; 134 | $dyi = sin($val+90)*2; 135 | $points[4] = Wx::Point->new($w/2-$dxi, $h/2-$dyi); 136 | $points[5] = $points[0]; 137 | $val = ($ScaledVal + $AngleStart + 1) * $PI/180; 138 | $dxi = cos($val) * ($h/2-10); 139 | $dyi = sin($val) * ($h/2-10); 140 | $points[3] = Wx::Point->new($w/2-$dxi, $h/2-$dyi); 141 | $val = ($ScaledVal + $AngleStart - 1) * $PI/180; 142 | $dxi = cos($val) * ($h/2-10); 143 | $dyi = sin($val) * ($h/2-10); 144 | $points[1] = Wx::Point->new($w/2-$dxi, $h/2-$dyi); 145 | $dc->DrawPolygon(\@points, 0, 0, wxODDEVEN_RULE); 146 | $brush = Wx::Brush->new(wxWHITE, wxSOLID); # Draw white dot at base of needle 147 | $dc->SetBrush($brush); 148 | $dc->DrawCircle($w/2, $h/2, 4); 149 | } 150 | sub DrawSectors { 151 | my($dc) = @_; 152 | my($w, $h) = $dc->GetSizeWH(); 153 | my $pen = Wx::Pen->new(wxBLACK, 1, wxSOLID); 154 | $dc->SetPen($pen); 155 | my $starc = $AngleStart; 156 | my $endarc = $starc + (($AngleEnd - $AngleStart) * ($AlarmLimit/$RangeEnd)); 157 | my $ctr = 0; 158 | while($ctr < $Sec) { 159 | my $brush = Wx::Brush->new($SectorColours[$ctr], wxSOLID); 160 | $dc->SetBrush($brush); 161 | $dc->DrawEllipticArc(0, 0, $w, $h, 180-$endarc, 180-$starc); 162 | $starc = $endarc; 163 | $endarc = $AngleEnd; 164 | $ctr++; 165 | } 166 | my $val = $AngleStart * $PI / 180; 167 | my $dx = cos($val) * $h/2; 168 | my $dy = sin($val) * $h/2; 169 | $dc->DrawLine($w/2, $h/2, $w/2-$dx, $h/2-$dy); 170 | $val = $AngleEnd * $PI / 180; 171 | $dx = cos($val) * $h/2; 172 | $dy = sin($val) * $h/2; 173 | $dc->DrawLine($w/2, $h/2, $w/2-$dx, $h/2-$dy); 174 | } 175 | sub DrawTicks { 176 | my($dc) = @_; 177 | my($w, $h) = $dc->GetSizeWH(); 178 | my $interval = ($AngleEnd - $AngleStart) / ($Tick +1); 179 | my $valint = $interval + $AngleStart; 180 | my $ctr = 0; 181 | while($ctr < $Tick) { 182 | my $val = $valint * $PI/180; 183 | my $dx = cos($val) * $h/2; 184 | my $dy = sin($val) * $h/2; 185 | my $tx = cos($val) * (($h/2)-10); 186 | my $ty = sin($val) * (($h/2)-10); 187 | $dc->DrawLine($w/2-$tx, $h/2-$ty, $w/2-$dx, $h/2-$dy); 188 | my $DeltaRange = $RangeEnd - $RangeStart; 189 | my $DeltaAngle = $AngleEnd - $AngleStart; 190 | my $Coeff = $DeltaAngle / $DeltaRange; 191 | my $rightval = (($valint - $AngleStart) / $Coeff) + $RangeStart; 192 | my $string = sprintf("%d", $rightval+.5); 193 | my($tew, $teh, $dct, $ext) = $dc->GetTextExtent($string); 194 | $val = ($valint - 4) * $PI/180; 195 | $tx = cos($val) * (($h/2)-12); 196 | $ty = sin($val) * (($h/2)-12); 197 | $dc->SetFont($Font); 198 | $dc->DrawRotatedText($string, $w/2-$tx, $h/2-$ty, 90-$valint); 199 | $valint = $valint + $interval; 200 | $ctr++; 201 | } 202 | } 203 | sub SetValue { # Scale the value for display 204 | my($Value) = @_; 205 | my $DeltaRange = $RangeEnd - $RangeStart; 206 | my $RangeZero = $DeltaRange - $RangeStart; 207 | my $DeltaAngle = $AngleEnd - $AngleStart; 208 | my $Coeff = $DeltaAngle / $DeltaRange; 209 | $ScaledVal = ($Value - $RangeStart) * $Coeff; 210 | $RealVal = $Value; 211 | } 212 | sub DrawLabel { # Draw a label at bottom of meter 213 | my($dc) = @_; 214 | my($w, $h) = $dc->GetSizeWH(); 215 | my @te = $dc->GetTextExtent($Label); 216 | my $x = ($w-$te[0])/2; 217 | $dc->DrawText($Label, $x, $h-25); 218 | } 219 | -------------------------------------------------------------------------------- /CppTrial-pg019.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg019.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 19 - Create a basic frame with menus and status bar 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/23/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | 12 | use Wx qw(:everything); 13 | use Wx::Event qw(EVT_MOTION); 14 | 15 | # create the WxApplication 16 | my $app = Wx::SimpleApp->new; 17 | my $frame = Wx::Frame->new(undef, -1, 18 | 'CppTrial-pg19.pl', 19 | wxDefaultPosition, wxDefaultSize); 20 | $frame->Show; 21 | 22 | # Example specific code 23 | my $cutIcon = Wx::Icon->new( "cut.xpm", wxBITMAP_TYPE_XPM, -1, -1); 24 | $frame->SetIcon($cutIcon); 25 | 26 | my $fileMenu = Wx::Menu->new(); 27 | my $helpMenu = Wx::Menu->new(); 28 | 29 | $fileMenu->Append(wxID_EXIT, "E&xit\tAlt-X", "Quit This Program"); 30 | $helpMenu->Append(wxID_ABOUT, "&About...\tF1", "Show About Dialog"); 31 | 32 | my $menuBar = Wx::MenuBar->new(); 33 | $menuBar->Append($fileMenu, "&File"); 34 | $menuBar->Append($helpMenu, "&Help"); 35 | 36 | $frame->SetMenuBar($menuBar); 37 | 38 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 39 | $frame->SetStatusBar($statusBar); 40 | $statusBar->SetStatusText("Welcome to wxWidgets!", 0); 41 | $app->MainLoop; 42 | -------------------------------------------------------------------------------- /CppTrial-pg065.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg065.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 65 - MDI Child Frame Example 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/23/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | 12 | use Wx qw(:everything); 13 | use Wx::MDI; 14 | 15 | # create the WxApplication 16 | my $app = Wx::SimpleApp->new; 17 | my $frame = Wx::Frame->new( undef, -1, 18 | 'CppTrial-pg065.pl', 19 | wxDefaultPosition, wxDefaultSize ); 20 | mdiChildFrame($frame); 21 | $frame->Show; 22 | $app->MainLoop; 23 | 24 | # Example specific code 25 | sub mdiChildFrame { 26 | my ( $self ) = @_; 27 | 28 | my $ID_MYFRAME = 1; 29 | my $ID_MYCHILD1 = 2; 30 | my $ID_MYCHILD2 = 3; 31 | my $ID_MYCHILD3 = 4; 32 | my $ID_MYCHILD4 = 5; 33 | 34 | my $parentFrame = Wx::MDIParentFrame->new($self, $ID_MYFRAME, "MDI Parent Window"); 35 | 36 | my $childFrame1 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD1, "Child 1"); 37 | my $childFrame2 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD2, "Child 2"); 38 | my $childFrame3 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD3, "Child 3"); 39 | my $childFrame4 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD4, "Child 4"); 40 | 41 | $childFrame1->Show(1); 42 | $childFrame2->Show(1); 43 | $childFrame3->Show(1); 44 | $childFrame4->Show(1); 45 | $parentFrame->Show(1); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /CppTrial-pg073.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg073.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 73 - Notebook Example 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/23/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | 13 | # create the WxApplication 14 | my $app = Wx::SimpleApp->new; 15 | my $frame = Wx::Frame->new(undef, -1, 16 | 'CppTrial-pg073.pl', 17 | wxDefaultPosition, wxDefaultSize); 18 | Wx::InitAllImageHandlers(); 19 | Notebook($frame); 20 | $frame->Show; 21 | $app->MainLoop; 22 | 23 | #Example specific code 24 | sub Notebook { 25 | my ( $self ) = @_; 26 | 27 | my $noteBook = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize); 28 | 29 | my $imageList = Wx::ImageList->new(16, 16, 1, 3); 30 | 31 | my $cutxpm = Wx::Bitmap->new( "cut.xpm", wxBITMAP_TYPE_XPM ); 32 | my $copyxpm = Wx::Bitmap->new( "copy.xpm", wxBITMAP_TYPE_XPM ); 33 | my $printxpm = Wx::Bitmap->new( "print.xpm", wxBITMAP_TYPE_XPM ); 34 | 35 | $imageList->Add($cutxpm); 36 | $imageList->Add($copyxpm); 37 | $imageList->Add($printxpm); 38 | 39 | $noteBook->SetImageList($imageList); 40 | 41 | my $window1 = Wx::Panel->new($noteBook, wxID_ANY); 42 | my $window2 = Wx::Panel->new($noteBook, wxID_ANY); 43 | my $window3 = Wx::Panel->new($noteBook, wxID_ANY); 44 | 45 | $noteBook->AddPage($window1, "Tab One", 1, 0); 46 | $noteBook->AddPage($window2, "Tab Two", 0, 1); 47 | $noteBook->AddPage($window3, "Tab Three", 0, 2); 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /CppTrial-pg077.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg077.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 77 - Scrolled Window Example 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modfied 9/23/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | 13 | # create the WxApplication 14 | my $app = Wx::SimpleApp->new; 15 | my $frame = Wx::Frame->new(undef, -1, 16 | 'CppTrial-pg077.pl', 17 | wxDefaultPosition, wxDefaultSize); 18 | scrolledWindow($frame); 19 | $frame->Show; 20 | $app->MainLoop; 21 | 22 | # Example specific code 23 | sub scrolledWindow { 24 | my ( $self ) = @_; 25 | 26 | my $scrolledWindow = Wx::ScrolledWindow->new($self, wxID_ANY, 27 | Wx::Point->new(0, 0), Wx::Size->new(400, 400), 28 | wxVSCROLL | wxHSCROLL); 29 | 30 | my $pixelsPerUnitX = 10; 31 | my $pixelsPerUnitY = 10; 32 | my $noUnitsX = 1000; 33 | my $noUnitsY = 1000; 34 | 35 | $scrolledWindow->SetScrollbars($pixelsPerUnitX, $pixelsPerUnitY, 36 | $noUnitsX, $noUnitsY); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /CppTrial-pg081.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg081.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 81 - Splitter Window Example 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/23/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg081.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | SplitterWindow($frame); 20 | $frame->Show; 21 | $app->MainLoop; 22 | 23 | # Example specific code 24 | sub SplitterWindow { 25 | my ( $self ) = @_; 26 | 27 | my $splitterWindow = Wx::SplitterWindow->new($self, -1, 28 | Wx::Point->new(0, 0), Wx::Size->new(400, 400), 29 | wxSP_3D); 30 | 31 | my $leftWindow = Wx::ScrolledWindow->new($splitterWindow); 32 | $leftWindow->SetScrollbars(20, 20, 50, 50); 33 | $leftWindow->SetBackgroundColour(wxRED); 34 | $leftWindow->Show(1); 35 | 36 | my $rightWindow = Wx::ScrolledWindow->new($splitterWindow); 37 | $rightWindow->SetScrollbars(20, 20, 50, 50); 38 | $rightWindow->SetBackgroundColour(wxCYAN); 39 | $rightWindow->Show(0); # Right Window is Hidden 40 | 41 | $splitterWindow->Initialize($leftWindow); 42 | } 43 | -------------------------------------------------------------------------------- /CppTrial-pg086.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg086.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 86 - 20 Assorted Static & Non-Static Controls Examples 6 | # Several small examples combined into one source file covers pg86 - pg116 7 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/23/2012 8 | 9 | use 5.010; 10 | use strict; 11 | use warnings; 12 | use Wx qw(:everything); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg086.pl', 18 | wxDefaultPosition, Wx::Size->new(500,700)); 19 | assortedControls($frame); 20 | $frame->Show; 21 | $app->MainLoop; 22 | 23 | # Example specific code 24 | sub assortedControls { 25 | my ( $self ) = @_; 26 | 27 | # Create a panel to place all of the controls on 28 | my $panel= Wx::Panel->new($self, wxID_ANY, wxDefaultPosition, wxDefaultSize); 29 | 30 | # pg86----- Plain Button 31 | my $button = Wx::Button->new($panel, wxID_OK, "Ok", 32 | Wx::Point->new(10, 10), wxDefaultSize); 33 | 34 | # pg89----- Bitmap Button 35 | my $bmp1 = Wx::Bitmap->new("print.xpm", wxBITMAP_TYPE_XPM); 36 | my $picButton = Wx::BitmapButton->new($panel, wxID_OK, $bmp1, 37 | Wx::Point->new(150, 10), wxDefaultSize, wxBU_AUTODRAW); 38 | 39 | # pg91----- Choice Control 40 | my $ID_CHOICEBOX = 1; 41 | my @strings1 = ("One", "Two", "Three", "Four", "Five"); 42 | my $choice = Wx::Choice->new($panel, $ID_CHOICEBOX, 43 | Wx::Point->new(250, 10), wxDefaultSize, \@strings1); 44 | 45 | # pg92----- ComboBox Control 46 | my $ID_COMBOBOX = 2; 47 | my @strings2 = ("Apple", "Orange", "Pear", "Grapefruit"); 48 | my $combo = Wx::ComboBox->new($panel, $ID_COMBOBOX, "Apple", 49 | Wx::Point->new(10,50), wxDefaultSize, \@strings2, wxCB_DROPDOWN); 50 | 51 | # pg94----- CheckBox Control 52 | my $ID_CHECKBOX = 3; 53 | my $checkBox = Wx::CheckBox->new($panel, $ID_CHECKBOX, "&Check Me", 54 | Wx::Point->new(10,200), wxDefaultSize); 55 | $checkBox->SetValue(1); 56 | 57 | # pg95----- ListBox Control 58 | my $ID_LISTBOX = 4; 59 | my @strings3 = ("First String", "Second String", "Third String", 60 | "Fourth String", "Fifth String", "Sixth String"); 61 | my $listbox = Wx::ListBox->new($panel, $ID_LISTBOX, 62 | Wx::Point->new(200,200), Wx::Size->new(180,80), 63 | \@strings3, wxLB_SINGLE); 64 | 65 | # pg96----- CheckListBox Control 66 | my $ID_CHECKLISTBOX = 5; 67 | my @strings4 = ("1st String", "2nd String", "3rd String", 68 | "4th String", "5th String", "6th String"); 69 | my $checklistbox = Wx::CheckListBox->new($panel, $ID_CHECKLISTBOX, 70 | Wx::Point->new(200,300), Wx::Size->new(180,80), 71 | \@strings4, wxLB_SINGLE); 72 | 73 | # pg99----- RadioBox Control 74 | my $ID_RADIOBOX = 6; 75 | my @strings5 = ("&One", "&Two", "T&hree", "&Four", "F&ive","&Six"); 76 | my $radiobox = Wx::RadioBox->new($panel, $ID_RADIOBOX, "RadioBox", 77 | Wx::Point->new(10,300), wxDefaultSize, \@strings5, 78 | 3, wxRA_SPECIFY_COLS); 79 | 80 | # pg101---- Radio Button Control (Spacing forced for display purposes - Sizers want to use whole window) 81 | my $ID_RADIOBUTTON1 = 7; 82 | my $ID_RADIOBUTTON2 = 8; 83 | my $radioButton1 = Wx::RadioButton->new($panel, $ID_RADIOBUTTON1, 84 | "&Male", Wx::Point->new(10,400), wxDefaultSize, wxRB_GROUP); 85 | $radioButton1->SetValue(1); 86 | my $radioButton2 = Wx::RadioButton->new($panel, $ID_RADIOBUTTON2, 87 | "&Female", Wx::Point->new(75,400)); 88 | my $topSizer = Wx::BoxSizer->new(wxHORIZONTAL); 89 | my $boxSizer = Wx::BoxSizer->new(wxHORIZONTAL); 90 | $boxSizer->Add($radioButton1, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 91 | $boxSizer->Add($radioButton2, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 92 | # $topSizer->Add($boxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 93 | # $self->SetSizer($topSizer); 94 | 95 | # pg102---- ScrollBar Control 96 | my $ID_SCROLLBAR = 9; 97 | my $scrollbar = Wx::ScrollBar->new($panel, $ID_SCROLLBAR, 98 | Wx::Point->new(10,450), Wx::Size->new(200,20), wxSB_HORIZONTAL); 99 | 100 | # pg103---- Spin Button Control 101 | my $ID_SPINBUTTON = 10; 102 | my $spinbutton = Wx::SpinButton->new($panel, $ID_SPINBUTTON, 103 | Wx::Point->new(330,400), wxDefaultSize, wxSP_VERTICAL); 104 | 105 | # pg105---- Spin Control 106 | my $ID_SPINCONTROL = 11; 107 | my $spincontrol = Wx::SpinCtrl->new($panel, $ID_SPINCONTROL, "5", 108 | Wx::Point->new(250,450), wxDefaultSize, 109 | wxSP_ARROW_KEYS, 0, 100, 5); 110 | 111 | # pg106---- Slider Control 112 | my $ID_SLIDERCONTROL = 12; 113 | my $slidercontrol = Wx::Slider->new($panel, $ID_SLIDERCONTROL, 16, 0, 40, 114 | Wx::Point->new(10,500), Wx::Size->new(200, -1), 115 | wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS); 116 | 117 | # pg108---- Text Control (w/pg109 also) 118 | my $ID_TEXTCONTROL = 13; 119 | my $textcontrol = Wx::TextCtrl->new($panel, $ID_TEXTCONTROL, "", 120 | Wx::Point->new(250,500), Wx::Size->new(240, 100), 121 | wxTE_MULTILINE); 122 | $textcontrol->SetDefaultStyle(Wx::TextAttr->new(wxRED)); 123 | $textcontrol->AppendText("Red Text\n"); 124 | $textcontrol->SetDefaultStyle(Wx::TextAttr->new(wxNullColour, wxLIGHT_GREY)); 125 | $textcontrol->AppendText("Red on Gray Text\n"); 126 | $textcontrol->SetDefaultStyle(Wx::TextAttr->new(wxBLUE)); 127 | $textcontrol->AppendText("Blue on Gray Text\n"); 128 | 129 | # pg111---- Toggle Button 130 | my $ID_TOGGLEBUTTON = 14; 131 | my $togglebutton = Wx::ToggleButton->new($panel, $ID_TOGGLEBUTTON, "&Toggle Button", 132 | Wx::Point->new(10,550), wxDefaultSize); 133 | $togglebutton->SetValue(1); 134 | 135 | # pg112---- Guage Control 136 | my $ID_GAUGE = 15; 137 | my $gauge = Wx::Gauge->new($panel, $ID_GAUGE, 200, 138 | Wx::Point->new(10,600), wxDefaultSize, wxGA_HORIZONTAL); 139 | $gauge->SetValue(50); 140 | 141 | # pg113---- Static Text Control 142 | my $ID_STATICTEXT = 16; 143 | my $statictext = Wx::StaticText->new($panel, $ID_STATICTEXT, 144 | "This is my &static text label", 145 | Wx::Point->new(250,600), wxDefaultSize, wxALIGN_LEFT); 146 | 147 | # pg114---- Static Bitmap Control 148 | my $ID_STATICBITMAP = 17; 149 | my $bmp2 = Wx::Bitmap->new("print.xpm", wxBITMAP_TYPE_XPM); 150 | my $staticbitmap = Wx::StaticBitmap->new($panel, $ID_STATICBITMAP, $bmp2, 151 | Wx::Point->new(175, 600), wxDefaultSize); 152 | 153 | # pg115---- Static Line Control 154 | my $ID_STATICLINE = 18; 155 | my $staticline = Wx::StaticLine->new($panel, $ID_STATICLINE, 156 | Wx::Point->new(10, 650), Wx::Size->new(450,-1), 157 | wxLI_HORIZONTAL); 158 | 159 | # pg116---- Static Box Control 160 | my $ID_STATICBOX = 19; 161 | my $staticbox = Wx::StaticBox->new($panel, $ID_STATICBOX, 162 | "&Static Box", 163 | Wx::Point->new(350, 10), Wx::Size->new(100, 100)); 164 | } 165 | -------------------------------------------------------------------------------- /CppTrial-pg124.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg124.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 124 - Tool Bar Example 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/23/2012 7 | 8 | use 5.010; 9 | 10 | use strict; 11 | use warnings; 12 | use Wx qw(:everything); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg124.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | Wx::InitAllImageHandlers(); 20 | ToolBar($frame); 21 | $frame->Show; 22 | $app->MainLoop; 23 | 24 | # Example specific code 25 | sub ToolBar { 26 | my ( $self ) = @_; 27 | 28 | my $toolBar = Wx::ToolBar->new($self, -1, 29 | wxDefaultPosition, wxDefaultSize, 30 | wxTB_HORIZONTAL | wxNO_BORDER); 31 | 32 | my $cutxpm = Wx::Bitmap->new( "cut.xpm", wxBITMAP_TYPE_XPM ); 33 | my $copyxpm = Wx::Bitmap->new( "copy.xpm", wxBITMAP_TYPE_XPM ); 34 | my $printxpm = Wx::Bitmap->new( "print.xpm", wxBITMAP_TYPE_XPM ); 35 | 36 | $toolBar->AddTool(wxID_CUT, $cutxpm, "cut"); 37 | $toolBar->AddTool(wxID_COPY, $copyxpm, "Copy"); 38 | $toolBar->AddTool(wxID_PRINT, $printxpm, "Print"); 39 | $toolBar->AddSeparator(); 40 | my $ID_COMBOBOX = 1; 41 | my $comboBox = Wx::ComboBox->new($toolBar, $ID_COMBOBOX); 42 | $toolBar->AddControl($comboBox); 43 | $toolBar->Realize(); 44 | $self->SetToolBar($toolBar); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /CppTrial-pg133.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg133.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 133 - Drawing on Windows with wxClientDC 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/23/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_MOTION); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg133.pl', 18 | wxDefaultPosition, wxDefaultSize,); 19 | EVT_MOTION($frame,\&OnMotion); 20 | $frame->Show; 21 | $app->MainLoop; 22 | 23 | # Example specific code 24 | sub OnMotion { 25 | my ( $self, $event) = @_; 26 | if($event->Dragging) { # True if mouse button pressed & mouse moving 27 | my $dc = Wx::ClientDC->new($self); 28 | my $pen = Wx::Pen->new(wxRED,1,wxSOLID); 29 | $dc->SetPen($pen); 30 | $dc->DrawPoint($event->GetPosition->x,$event->GetPosition->y); 31 | $dc->SetPen(wxNullPen); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CppTrial-pg135.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg135.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/23/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_PAINT); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg135.pl', 18 | wxDefaultPosition, wxDefaultSize,); 19 | EVT_PAINT($frame,\&OnPaint); 20 | $frame->Show; 21 | $app->MainLoop; 22 | 23 | # Example specific code 24 | sub OnPaint { 25 | my ( $self, $event) = @_; 26 | 27 | my $dc = Wx::PaintDC->new($self); 28 | 29 | my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); 30 | $dc->SetPen($pen); 31 | my $brush=Wx::Brush->new(wxRED,wxSOLID); 32 | $dc->SetBrush($brush); 33 | 34 | my $sz=$self->GetClientSize(); 35 | my $szx=$sz->x; 36 | my $szy=$sz->y; 37 | 38 | my $w=100; 39 | my $h=50; 40 | my $x=($szx - $w)/2; 41 | my $y=($szy - $h)/2; 42 | 43 | $dc->DrawRectangle($x,$y,$w,$h); # Centered on the window, try resizing... 44 | } 45 | 46 | -------------------------------------------------------------------------------- /CppTrial-pg150.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg150.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 150 - Drawing Text - Extends pg 135 example 6 | # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 7 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/23/2012 8 | 9 | use 5.010; 10 | use strict; 11 | use warnings; 12 | use Wx qw(:everything); 13 | use Wx::Event qw(EVT_PAINT); 14 | 15 | # create the WxApplication 16 | my $app = Wx::SimpleApp->new; 17 | my $frame = Wx::Frame->new(undef, -1, 18 | 'CppTrial-pg150.pl', 19 | wxDefaultPosition, wxDefaultSize); 20 | EVT_PAINT($frame,\&OnPaint); 21 | $frame->Show; 22 | $app->MainLoop; 23 | 24 | # Example specific code 25 | sub OnPaint { 26 | my ( $self, $event) = @_; 27 | 28 | my $dc = Wx::PaintDC->new($self); 29 | 30 | my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); 31 | $dc->SetPen($pen); 32 | my $brush=Wx::Brush->new(wxRED,wxSOLID); 33 | $dc->SetBrush($brush); 34 | 35 | my $sz=$self->GetClientSize(); 36 | my $szx=$sz->x; 37 | my $szy=$sz->y; 38 | 39 | my $w=100; 40 | my $h=50; 41 | my $x=($szx - $w)/2; 42 | my $y=($szy - $h)/2; 43 | 44 | $dc->DrawRectangle($x,$y,$w,$h); # Centered in frame 45 | my $pt=Wx::Point->new(160,275); 46 | CppDrawText($dc, "Test Text", $pt); # Text at fixed position 47 | } 48 | 49 | sub CppDrawText { 50 | my ( $dc, $text, $pt) = @_; 51 | 52 | my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxNORMAL); 53 | $dc->SetFont($font); 54 | $dc->SetBackgroundMode(wxTRANSPARENT); 55 | $dc->SetTextForeground(wxBLACK); 56 | $dc->SetTextBackground(wxWHITE); 57 | $dc->DrawText($text,$pt->x, $pt->y); 58 | return; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /CppTrial-pg151.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg151.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 151 - Drawing Text Rotated - Extends pg 150 & 135 examples 6 | # C++ Example from pg 150 - Drawing Text - Extends pg 135 example 7 | # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 8 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/23/2012 9 | 10 | use 5.010; 11 | use strict; 12 | use warnings; 13 | use Wx qw(:everything); 14 | use Wx::Event qw(EVT_PAINT); 15 | 16 | # create the WxApplication 17 | my $app = Wx::SimpleApp->new; 18 | my $frame = Wx::Frame->new(undef, -1, 19 | 'CppTrial-pg151.pl', 20 | wxDefaultPosition, wxDefaultSize); 21 | EVT_PAINT($frame,\&OnPaint); 22 | $frame->Show; 23 | $app->MainLoop; 24 | 25 | # Example specific code 26 | sub OnPaint { 27 | my ( $self, $event) = @_; 28 | 29 | my $dc = Wx::PaintDC->new($self); 30 | 31 | my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); 32 | $dc->SetPen($pen); 33 | my $brush=Wx::Brush->new(wxRED,wxSOLID); 34 | $dc->SetBrush($brush); 35 | 36 | my $sz=$self->GetClientSize(); 37 | my $szx=$sz->x; 38 | my $szy=$sz->y; 39 | 40 | my $w=100; 41 | my $h=50; 42 | my $x=($szx - $w)/2; 43 | my $y=($szy - $h)/2; 44 | 45 | $dc->DrawRectangle($x,$y,$w,$h); # Centered on frame 46 | my $pt1=Wx::Point->new(160,275); 47 | CppDrawText($dc, "Test Text", $pt1); # Fixed position 48 | my $pt2=Wx::Point->new(200,375); 49 | CppDrawRotatedText($dc, "Test Text", $pt2); # Fixed position 50 | } 51 | 52 | sub CppDrawText { 53 | my ( $dc, $text, $pt) = @_; 54 | 55 | my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxBOLD); 56 | $dc->SetFont($font); 57 | $dc->SetBackgroundMode(wxTRANSPARENT); 58 | $dc->SetTextForeground(wxBLACK); 59 | $dc->SetTextBackground(wxWHITE); 60 | $dc->DrawText($text,$pt->x, $pt->y); 61 | return; 62 | 63 | } 64 | 65 | sub CppDrawRotatedText { 66 | my ( $dc, $text, $pt) = @_; 67 | 68 | my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxNORMAL); 69 | $dc->SetFont($font); 70 | $dc->SetBackgroundMode(wxTRANSPARENT); 71 | $dc->SetTextForeground(wxGREEN); 72 | $dc->SetTextBackground(wxWHITE); 73 | for (my $angle=0; $angle<360; $angle +=45) { 74 | $dc->DrawRotatedText($text,$pt->x, $pt->y, $angle); 75 | } 76 | return; 77 | 78 | } 79 | -------------------------------------------------------------------------------- /CppTrial-pg152.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg152.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 152 - Centering Text - Extends pg 151, 150, & 135 examples 6 | # C++ Example from pg 151 - Drawing Text Rotated - Extends pg 150, & 135 examples 7 | # C++ Example from pg 150 - Drawing Text - Extends pg 135 example 8 | # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 9 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 10 | 11 | use 5.010; 12 | use strict; 13 | use warnings; 14 | use Wx qw(:everything); 15 | use Wx::Event qw(EVT_PAINT); 16 | 17 | # create the WxApplication 18 | my $app = Wx::SimpleApp->new; 19 | my $frame = Wx::Frame->new(undef, -1, 20 | 'CppTrial-pg152.pl', 21 | wxDefaultPosition, wxDefaultSize); 22 | EVT_PAINT($frame,\&OnPaint); 23 | $frame->Show; 24 | $app->MainLoop; 25 | 26 | # Example specific code 27 | sub OnPaint { 28 | my ( $self, $event) = @_; 29 | 30 | my $dc = Wx::PaintDC->new($self); 31 | 32 | my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); 33 | $dc->SetPen($pen); 34 | my $brush=Wx::Brush->new(wxRED,wxSOLID); 35 | $dc->SetBrush($brush); 36 | 37 | my $sz=$self->GetClientSize(); 38 | my $szx=$sz->x; 39 | my $szy=$sz->y; 40 | 41 | my $w=100; 42 | my $h=50; 43 | my $x=($szx - $w)/2; 44 | my $y=($szy - $h)/2; 45 | 46 | $dc->DrawRectangle($x,$y,$w,$h); # Centered on frame 47 | 48 | my $pt1=Wx::Point->new(160,275); # Fixed position 49 | CppDrawText($dc, "Test Text", $pt1); 50 | 51 | my $pt2=Wx::Point->new(200,375); # Fixed position 52 | CppDrawRotatedText($dc, "Test Text", $pt2); 53 | 54 | my $pt3=Wx::Point->new(0,50); # Centered on frame 55 | CppDrawCenteredText("Centered Text", $dc, $pt3, $self); 56 | } 57 | 58 | sub CppDrawText { 59 | my ( $dc, $text, $pt) = @_; 60 | 61 | my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxBOLD); 62 | $dc->SetFont($font); 63 | $dc->SetBackgroundMode(wxTRANSPARENT); 64 | $dc->SetTextForeground(wxBLACK); 65 | $dc->SetTextBackground(wxWHITE); 66 | $dc->DrawText($text,$pt->x, $pt->y); 67 | return; 68 | 69 | } 70 | 71 | sub CppDrawRotatedText { 72 | my ( $dc, $text, $pt) = @_; 73 | 74 | my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxNORMAL); 75 | $dc->SetFont($font); 76 | $dc->SetBackgroundMode(wxTRANSPARENT); 77 | $dc->SetTextForeground(wxGREEN); 78 | $dc->SetTextBackground(wxWHITE); 79 | for (my $angle=0; $angle<360; $angle +=45) { 80 | $dc->DrawRotatedText($text,$pt->x, $pt->y, $angle); 81 | } 82 | return; 83 | 84 | } 85 | 86 | sub CppDrawCenteredText { 87 | my ( $text, $dc, $pt, $self) = @_; 88 | 89 | my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxBOLD); 90 | $dc->SetFont($font); 91 | $dc->SetBackgroundMode(wxTRANSPARENT); 92 | $dc->SetTextForeground(wxBLUE); 93 | $dc->SetTextBackground(wxWHITE); 94 | 95 | my $sz=$self->GetClientSize(); 96 | 97 | my @te=$dc->GetTextExtent($text); 98 | my $x=($sz->x - $te[0])/2; 99 | my $y=$pt->y; 100 | $dc->DrawText($text, $x, $y); 101 | return; 102 | 103 | } 104 | -------------------------------------------------------------------------------- /CppTrial-pg154.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg154.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 154 - Drawing multiple lines - Extends pg 135 example 6 | # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 7 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 8 | 9 | use 5.010; 10 | use strict; 11 | use warnings; 12 | use Wx qw(:everything); 13 | use Wx::Event qw(EVT_PAINT); 14 | 15 | # create the WxApplication 16 | my $app = Wx::SimpleApp->new; 17 | my $frame = Wx::Frame->new(undef, -1, 18 | 'CppTrial-pg154.pl', 19 | wxDefaultPosition, wxDefaultSize); 20 | EVT_PAINT($frame,\&OnPaint); 21 | $frame->Show; 22 | $app->MainLoop; 23 | 24 | # Example specific code 25 | sub OnPaint { 26 | my ( $self, $event) = @_; 27 | 28 | my $dc = Wx::PaintDC->new($self); 29 | 30 | my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); 31 | $dc->SetPen($pen); 32 | my $brush=Wx::Brush->new(wxRED,wxSOLID); 33 | $dc->SetBrush($brush); 34 | 35 | my @points; 36 | my $x=0; 37 | my $y=0; 38 | 39 | for my $i(0..9) { 40 | 41 | my $pt1=Wx::Point->new($x,$y); 42 | my $pt2=Wx::Point->new($x+100,$y); 43 | push(@points, $pt1, $pt2); 44 | 45 | # print "$i-> $x, $y / ", $x+100, ",", $y, "\n"; 46 | $dc->DrawLine($pt1->x, $pt1->y, $pt2->x, $pt2->y); 47 | 48 | $x=$x + 10; 49 | $y=$y + 20; 50 | } 51 | 52 | # print "@points\n"; 53 | 54 | my $offsetx = 100; 55 | my $offsety = 250; 56 | $dc->DrawLines(\@points, $offsetx, $offsety); 57 | } 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /CppTrial-pg155.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg155.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 155 - Drawing polygons - Extends pg 154 example 6 | # C++ Example from pg 154 - Drawing single & multiple lines - Extends pg 135 example 7 | # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 8 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 9 | 10 | use 5.010; 11 | use strict; 12 | use warnings; 13 | use Wx qw(:everything); 14 | use Wx::Event qw(EVT_PAINT); 15 | 16 | # create the WxApplication 17 | my $app = Wx::SimpleApp->new; 18 | my $frame = Wx::Frame->new(undef, -1, 19 | 'CppTrial-pg155.pl', 20 | wxDefaultPosition, wxDefaultSize); 21 | EVT_PAINT($frame,\&OnPaint); 22 | $frame->Show; 23 | $app->MainLoop; 24 | 25 | # Example specific code 26 | sub OnPaint { 27 | my ( $self, $event) = @_; 28 | 29 | my $dc = Wx::PaintDC->new($self); 30 | 31 | my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); 32 | $dc->SetPen($pen); 33 | my $brush=Wx::Brush->new(wxRED,wxCROSSDIAG_HATCH); 34 | $dc->SetBrush($brush); 35 | 36 | my @points; 37 | 38 | my $pt0=Wx::Point->new(100, 60); 39 | my $pt1=Wx::Point->new(60, 150); 40 | my $pt2=Wx::Point->new(160,100); 41 | my $pt3=Wx::Point->new(40, 100); 42 | my $pt4=Wx::Point->new(140, 150); 43 | 44 | push(@points, $pt0, $pt1, $pt2, $pt3, $pt4); 45 | 46 | # print "@points\n"; 47 | 48 | $dc->DrawPolygon(\@points, 0, 30); 49 | } 50 | -------------------------------------------------------------------------------- /CppTrial-pg156.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg156.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 156 - Drawing Splines - Extends pg 155 example 6 | # C++ Example from pg 155 - Drawing polygons - Extends pg 154 example 7 | # C++ Example from pg 154 - Drawing single & multiple lines - Extends pg 135 example 8 | # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 9 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 10 | 11 | use 5.010; 12 | use strict; 13 | use warnings; 14 | use Wx qw(:everything); 15 | use Wx::Event qw(EVT_PAINT); 16 | 17 | # create the WxApplication 18 | my $app = Wx::SimpleApp->new; 19 | my $frame = Wx::Frame->new(undef, -1, 20 | 'CppTrial-pg156.pl', 21 | wxDefaultPosition, wxDefaultSize); 22 | EVT_PAINT($frame,\&OnPaint); 23 | $frame->Show; 24 | $app->MainLoop; 25 | 26 | # Example specific code 27 | sub OnPaint { 28 | my ( $self, $event) = @_; 29 | 30 | my $dc = Wx::PaintDC->new($self); 31 | 32 | my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); 33 | $dc->SetPen($pen); 34 | my $brush=Wx::Brush->new(wxRED,wxCROSSDIAG_HATCH); 35 | $dc->SetBrush($brush); 36 | 37 | my @pts; 38 | my $pts0=Wx::Point->new(10, 100); 39 | my $pts1=Wx::Point->new(200, 200); 40 | my $pts2=Wx::Point->new(50, 230); 41 | push(@pts, $pts0, $pts1, $pts2); 42 | $dc->DrawSpline(\@pts); 43 | 44 | my @points; 45 | my $pt0=Wx::Point->new(100, 60); 46 | my $pt1=Wx::Point->new(60, 150); 47 | my $pt2=Wx::Point->new(160,100); 48 | my $pt3=Wx::Point->new(40, 100); 49 | my $pt4=Wx::Point->new(140, 150); 50 | push(@points, $pt0, $pt1, $pt2, $pt3, $pt4); 51 | $dc->DrawSpline(\@points); 52 | } 53 | -------------------------------------------------------------------------------- /CppTrial-pg157.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg157.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 157 - Drawing Bitmaps - Extends pg 150 example 6 | # C++ Example from pg 150 - Drawing Text - Extends pg 135 example 7 | # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 8 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 9 | 10 | use 5.010; 11 | use strict; 12 | use warnings; 13 | use Wx qw(:everything); 14 | use Wx::Event qw(EVT_PAINT); 15 | 16 | # create the WxApplication 17 | my $app = Wx::SimpleApp->new; 18 | Wx::InitAllImageHandlers(); 19 | my $frame = Wx::Frame->new(undef, -1, 20 | 'CppTrial-pg157.pl', 21 | wxDefaultPosition, wxDefaultSize); 22 | EVT_PAINT($frame,\&OnPaint); 23 | $frame->Show; 24 | $app->MainLoop; 25 | 26 | # Example specific code 27 | sub OnPaint { 28 | my ( $self, $event) = @_; 29 | 30 | my $dc = Wx::PaintDC->new($self); 31 | 32 | my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); 33 | $dc->SetPen($pen); 34 | my $brush=Wx::Brush->new(wxRED,wxSOLID); 35 | $dc->SetBrush($brush); 36 | 37 | my $font = Wx::Font->new(10, wxFONTFAMILY_ROMAN, wxNORMAL, wxNORMAL); 38 | $dc->SetFont($font); 39 | $dc->SetBackgroundMode(wxTRANSPARENT); 40 | $dc->SetTextForeground(wxBLACK); 41 | $dc->SetTextBackground(wxWHITE); 42 | 43 | my $msg = "Some text will appear mixed in the image's shadow..."; 44 | my $bmp = Wx::Bitmap->new("padre_logo_64x64.png", wxBITMAP_TYPE_PNG); 45 | 46 | my $y = 75; 47 | for (0..9) { 48 | $y += $dc->GetCharHeight() +5; 49 | $dc->DrawText($msg, 10, $y); 50 | } 51 | 52 | $dc->DrawBitmap($bmp, 150, 175, 1); 53 | return; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /CppTrial-pg158.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg158.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 158 - Copy(Tile) Bitmaps Between Device Contexts - Extends pg 157 example 6 | # C++ Example from pg 157 - Drawing Bitmaps - Extends pg 150 example 7 | # C++ Example from pg 150 - Drawing Text - Extends pg 135 example 8 | # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 9 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 10 | 11 | use 5.010; 12 | use strict; 13 | use warnings; 14 | use Wx qw(:everything); 15 | use Wx::Event qw(EVT_PAINT); 16 | 17 | # create the WxApplication 18 | my $app = Wx::SimpleApp->new; 19 | Wx::InitAllImageHandlers(); 20 | my $frame = Wx::Frame->new(undef, -1, 21 | 'CppTrial-pg158.pl', 22 | wxDefaultPosition, wxDefaultSize); 23 | EVT_PAINT($frame,\&OnPaint); 24 | $frame->Show; 25 | $app->MainLoop; 26 | 27 | # Example specific code 28 | sub OnPaint { 29 | my ( $self, $event) = @_; 30 | 31 | my $dcPaint = Wx::PaintDC->new($self); #OnPaint Event Requires a PaintDC 32 | my $dcSource = Wx::MemoryDC->new(); 33 | my $dcDest = Wx::MemoryDC->new(); 34 | 35 | my $destWidth = 350; 36 | my $destHeight = 400; 37 | my $bmpDest = Wx::Bitmap->new($destWidth, $destHeight); 38 | my $bmpSource = Wx::Bitmap->new("padre_logo_64x64.png", wxBITMAP_TYPE_PNG); 39 | my $sourceWidth = $bmpSource->GetWidth(); 40 | my $sourceHeight = $bmpSource->GetHeight(); 41 | $dcDest->SelectObject($bmpDest); 42 | $dcDest->SetBackground(wxWHITE_BRUSH); 43 | $dcDest->Clear(); 44 | $dcSource->SelectObject($bmpSource); 45 | 46 | 47 | for (my $i = 0; $i < $destWidth; $i += $sourceWidth) 48 | { 49 | for (my $j = 0; $j < $destHeight; $j += $sourceHeight) 50 | { 51 | $dcDest->Blit($i, $j, $sourceWidth, $sourceHeight, $dcSource, 0, 0, wxCOPY, 1); 52 | } 53 | } 54 | 55 | $dcPaint->Blit(0,0,$destWidth,$destHeight,$dcDest,0,0,wxCOPY,1); #Copy to PaintDC for display 56 | 57 | $dcDest->SelectObject(wxNullBitmap); 58 | $dcSource->SelectObject(wxNullBitmap); 59 | 60 | 61 | return; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /CppTrial-pg159A.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg159A.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 159A - Filling arbitrary areas - Extends pg 135 example 6 | # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 7 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 8 | 9 | use 5.010; 10 | use strict; 11 | use warnings; 12 | use Wx qw(:everything); 13 | use Wx::Event qw(EVT_PAINT); 14 | 15 | # create the WxApplication 16 | my $app = Wx::SimpleApp->new; 17 | my $frame = Wx::Frame->new(undef, -1, 18 | 'CppTrial-pg159A.pl', 19 | wxDefaultPosition, wxDefaultSize); 20 | EVT_PAINT($frame,\&OnPaint); 21 | $frame->Show; 22 | $app->MainLoop; 23 | 24 | # Example Specific code 25 | sub OnPaint { 26 | my ( $self, $event) = @_; 27 | 28 | my $dc = Wx::PaintDC->new($self); 29 | 30 | my $pen = Wx::Pen->new(wxRED,5,wxSOLID); 31 | $dc->SetPen($pen); 32 | my $brush=Wx::Brush->new(wxGREEN,wxSOLID); 33 | $dc->SetBrush($brush); 34 | 35 | $dc->DrawRectangle(0, 0, 400, 450); 36 | $dc->DrawRectangle(20, 20, 100, 100); 37 | $dc->DrawRectangle(200, 200, 100, 100); 38 | $dc->DrawRectangle(20, 300, 100, 100); # 4 Rects filled green 39 | 40 | # wxFLOOD_SURFACE - Fill area of given color 41 | $dc->SetBrush(wxBLACK_BRUSH); 42 | $dc->FloodFill(250, 250, wxGREEN, wxFLOOD_SURFACE); # Center Rect filled black 43 | 44 | # wxFLOOD_BORDER - Fill area within given color border 45 | $dc->SetBrush(wxCYAN_BRUSH); 46 | $dc->FloodFill(100, 350, wxRED, wxFLOOD_BORDER); # Bottom Rect filled cyan 47 | 48 | $dc->SetBrush(wxBLUE_BRUSH); 49 | $dc->FloodFill(6, 6, wxRED, wxFLOOD_BORDER); # Large Rect filled blue 50 | 51 | } 52 | -------------------------------------------------------------------------------- /CppTrial-pg159B.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg159B.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 159B - Logical Functions - Extends pg 135 example 6 | # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 7 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 8 | 9 | use 5.010; 10 | use strict; 11 | use warnings; 12 | use Wx qw(:everything); 13 | use Wx::Event qw(:everything); 14 | 15 | # create the WxApplication 16 | my $app = Wx::SimpleApp->new; 17 | my $frame = Wx::Frame->new(undef, -1, 18 | 'CppTrial-pg159B.pl', 19 | wxDefaultPosition, wxDefaultSize); 20 | EVT_MOTION($frame,\&OnMotion,); 21 | $frame->Show; 22 | $app->MainLoop; 23 | 24 | # Example specific code 25 | sub OnMotion { 26 | my ( $self, $event) = @_; 27 | 28 | my $dc = Wx::PaintDC->new($self); 29 | 30 | my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); 31 | $dc->SetPen($pen); 32 | my $brush=Wx::Brush->new(wxRED,wxSOLID); 33 | $dc->SetBrush($brush); 34 | 35 | $dc->SetLogicalFunction(wxINVERT); # Invert Pixels 36 | $dc->DrawCircle(200, 200, 50); # Circle appears and erases as mouse moves 37 | 38 | } 39 | -------------------------------------------------------------------------------- /CppTrial-pg195.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg195.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 195 - Sizers -Dialog with streatching text control 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | 13 | # create the WxApplication 14 | my $app = Wx::SimpleApp->new; 15 | my $dialog = Wx::Dialog->new(undef, -1, "Sizer Dialog Example", 16 | wxDefaultPosition, wxDefaultSize, 17 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); 18 | mydialog($dialog); 19 | $dialog->Show; 20 | $app->MainLoop; 21 | 22 | # Example specific code 23 | sub mydialog { 24 | my ($dialog)= @_; 25 | 26 | # Create two Sizers 27 | 28 | my $topSizer = Wx::BoxSizer->new(wxVERTICAL); 29 | my $buttonSizer = Wx::BoxSizer->new(wxHORIZONTAL); 30 | 31 | # Create a Text Control, and OK and CANCEL Buttons 32 | 33 | my $textCtrl = Wx::TextCtrl->new($dialog, wxID_ANY, "Stretching Text Control...", 34 | wxDefaultPosition, Wx::Size->new(100, 60), wxTE_MULTILINE); 35 | my $buttOk = Wx::Button->new($dialog, wxID_OK, "OK"); 36 | my $buttCancel = Wx::Button->new($dialog, wxID_CANCEL, "Cancel"); 37 | 38 | # Associate Text Control and buttons with Sizers 39 | 40 | $topSizer->Add($textCtrl, 1, wxEXPAND, wxALL, 10); 41 | $buttonSizer->Add($buttOk, 0, wxALL, 10); 42 | $buttonSizer->Add($buttCancel, 0, wxALL, 10); 43 | 44 | # Associate Button Sizer with TopSizer 45 | 46 | $topSizer->Add($buttonSizer, 0, wxALIGN_CENTER); 47 | 48 | $dialog->SetSizer($topSizer); 49 | $topSizer->Fit($dialog); 50 | $topSizer->SetSizeHints($dialog); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /CppTrial-pg196.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg196.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 196 - Sizers -Dialog with static box sizer and check box 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | 13 | # create the WxApplication 14 | my $app = Wx::SimpleApp->new; 15 | my $dialog = Wx::Dialog->new(undef, -1, "Static Box Sizer Dialog Example", 16 | wxDefaultPosition, wxDefaultSize, 17 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); 18 | mydialog($dialog); 19 | $dialog->Show; 20 | $app->MainLoop; 21 | 22 | # Example specific code 23 | sub mydialog { 24 | my ($dialog)= @_; 25 | 26 | # Create two Sizers and a Static Box 27 | 28 | my $topLevel = Wx::BoxSizer->new(wxVERTICAL); 29 | my $staticBox = Wx::StaticBox->new($dialog, wxID_ANY, "General Settings"); 30 | my $staticSizer = Wx::StaticBoxSizer->new($staticBox, wxVERTICAL); 31 | 32 | # Create a Check Box 33 | 34 | my $checkBox = Wx::CheckBox->new($dialog, -1, "&Show Splash Screen", 35 | wxDefaultPosition, wxDefaultSize); 36 | 37 | # Associate Check Box Control with Sizers 38 | 39 | $topLevel->Add($staticSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); 40 | $staticSizer->Add($checkBox, 0, wxALIGN_LEFT | wxALL, 5); 41 | 42 | # Associate Button Sizer with TopSizer 43 | 44 | $dialog->SetSizer($topLevel); 45 | $topLevel->Fit($dialog); 46 | $topLevel->SetSizeHints($dialog); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /CppTrial-pg197.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg197.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 197 - Sizers -Dialog with grid sizer 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | 13 | # create the WxApplication 14 | my $app = Wx::SimpleApp->new; 15 | my $dialog = Wx::Dialog->new(undef, -1, "Grid Sizer Dialog Example", 16 | wxDefaultPosition, wxDefaultSize, 17 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); 18 | mydialog($dialog); 19 | $dialog->Show; 20 | $app->MainLoop; 21 | 22 | # Example specific code 23 | sub mydialog { 24 | my ($dialog)= @_; 25 | 26 | # Create a Grid Sizers 27 | 28 | my $gridSizer = Wx::GridSizer->new(2, 3, 0, 0); 29 | $dialog->SetSizer($gridSizer); 30 | 31 | # Create Buttons and add to GridSizer 32 | 33 | my $button1 = Wx::Button->new($dialog , -1, "One"); 34 | $gridSizer->Add($button1, 0, wxALIGN_CENTER_HORIZONTAL | 35 | wxALIGN_CENTER_VERTICAL | wxALL,5); 36 | 37 | my $button2 = Wx::Button->new($dialog , -1, "Two (the second button)"); 38 | $gridSizer->Add($button2, 0, wxALIGN_CENTER_HORIZONTAL | 39 | wxALIGN_CENTER_VERTICAL | wxALL,5); 40 | 41 | my $button3 = Wx::Button->new($dialog , -1, "Three"); 42 | $gridSizer->Add($button3, 0, wxALIGN_CENTER_HORIZONTAL | 43 | wxALIGN_CENTER_VERTICAL | wxALL,5); 44 | 45 | my $button4 = Wx::Button->new($dialog , -1, "Four"); 46 | $gridSizer->Add($button4, 0, wxALIGN_CENTER_HORIZONTAL | 47 | wxALIGN_CENTER_VERTICAL | wxALL,5); 48 | 49 | my $button5 = Wx::Button->new($dialog , -1, "Five"); 50 | $gridSizer->Add($button5, 0, wxALIGN_CENTER_HORIZONTAL | 51 | wxALIGN_CENTER_VERTICAL | wxALL,5); 52 | 53 | my $button6 = Wx::Button->new($dialog , -1, "Six"); 54 | $gridSizer->Add($button6, 0, wxALIGN_CENTER_HORIZONTAL | 55 | wxALIGN_CENTER_VERTICAL | wxALL,5); 56 | 57 | $gridSizer->Fit($dialog); 58 | $gridSizer->SetSizeHints($dialog); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /CppTrial-pg199.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg199.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 199 - Sizers -Dialog with flex grid sizer 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | 13 | # create the WxApplication 14 | my $app = Wx::SimpleApp->new; 15 | my $dialog = Wx::Dialog->new(undef, -1, "Flex Grid Sizer Dialog Example", 16 | wxDefaultPosition, wxDefaultSize, 17 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); 18 | mydialog($dialog); 19 | $dialog->Show; 20 | $app->MainLoop; 21 | 22 | # Example specific code 23 | sub mydialog { 24 | my ($dialog)= @_; 25 | 26 | # Create a Grid Sizers make column 0 growable 27 | 28 | my $flexGridSizer = Wx::FlexGridSizer->new(2, 3, 0, 0); 29 | $dialog->SetSizer($flexGridSizer); 30 | $flexGridSizer->AddGrowableCol(0); 31 | 32 | # Create Buttons and add to FlexGridSizer 33 | 34 | my $button1 = Wx::Button->new($dialog , -1, "One"); 35 | $flexGridSizer->Add($button1, 0, wxALIGN_CENTER_HORIZONTAL | 36 | wxALIGN_CENTER_VERTICAL | wxALL,5); 37 | 38 | my $button2 = Wx::Button->new($dialog , -1, "Two (the second button)"); 39 | $flexGridSizer->Add($button2, 0, wxALIGN_CENTER_HORIZONTAL | 40 | wxALIGN_CENTER_VERTICAL | wxALL,5); 41 | 42 | my $button3 = Wx::Button->new($dialog , -1, "Three"); 43 | $flexGridSizer->Add($button3, 0, wxALIGN_CENTER_HORIZONTAL | 44 | wxALIGN_CENTER_VERTICAL | wxALL,5); 45 | 46 | my $button4 = Wx::Button->new($dialog , -1, "Four"); 47 | $flexGridSizer->Add($button4, 0, wxALIGN_CENTER_HORIZONTAL | 48 | wxALIGN_CENTER_VERTICAL | wxALL,5); 49 | 50 | my $button5 = Wx::Button->new($dialog , -1, "Five"); 51 | $flexGridSizer->Add($button5, 0, wxALIGN_CENTER_HORIZONTAL | 52 | wxALIGN_CENTER_VERTICAL | wxALL,5); 53 | 54 | my $button6 = Wx::Button->new($dialog , -1, "Six"); 55 | $flexGridSizer->Add($button6, 0, wxALIGN_CENTER_HORIZONTAL | 56 | wxALIGN_CENTER_VERTICAL | wxALL,5); 57 | 58 | $flexGridSizer->Fit($dialog); 59 | $flexGridSizer->SetSizeHints($dialog); 60 | 61 | } 62 | -------------------------------------------------------------------------------- /CppTrial-pg201.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg201.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 201 - Sizers -Dialog with grid bag sizer 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | 13 | # create the WxApplication 14 | my $app = Wx::SimpleApp->new; 15 | my $dialog = Wx::Dialog->new(undef, -1, "Grid Bag Sizer Dialog Example", 16 | wxDefaultPosition, wxDefaultSize, 17 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); 18 | mydialog($dialog); 19 | $dialog->Show; 20 | $app->MainLoop; 21 | 22 | # Example specific code 23 | sub mydialog { 24 | my ($dialog)= @_; 25 | 26 | # Create a Grid Bag Sizers make column 2 and row 3 growable 27 | 28 | my $gridBagSizer = Wx::GridBagSizer->new(); 29 | $dialog->SetSizer($gridBagSizer); 30 | 31 | 32 | # Create Buttons and add to GridBagSizer 33 | 34 | my $b1 = Wx::Button->new($dialog , -1, "One (0,0)"); 35 | $gridBagSizer->Add($b1, Wx::GBPosition->new(0, 0)); 36 | 37 | my $b2 = Wx::Button->new($dialog , -1, "Two (2, 2)"); 38 | $gridBagSizer->Add($b2, Wx::GBPosition->new(2, 2), Wx::GBSpan->new(1, 2), wxGROW); 39 | 40 | my $b3 = Wx::Button->new($dialog , -1, "Three (3, 2)"); 41 | $gridBagSizer->Add($b3, Wx::GBPosition->new(3, 2)); 42 | 43 | my $b4 = Wx::Button->new($dialog , -1, "Four (3, 3)"); 44 | $gridBagSizer->Add($b4, Wx::GBPosition->new(3, 3)); 45 | 46 | $gridBagSizer->AddGrowableRow(3); 47 | $gridBagSizer->AddGrowableCol(2); 48 | 49 | $gridBagSizer->Fit($dialog); 50 | $gridBagSizer->SetSizeHints($dialog); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /CppTrial-pg202.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg202.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 202 - Sizers -Dialog with Standard Dialog Button Sizer 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | 13 | # create the WxApplication 14 | my $app = Wx::SimpleApp->new; 15 | my $dialog = Wx::Dialog->new(undef, -1, "Standard Dialog Button Sizer Example", 16 | wxDefaultPosition, wxDefaultSize, 17 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); 18 | mydialog($dialog); 19 | $dialog->Show; 20 | $app->MainLoop; 21 | 22 | # Example specific code 23 | sub mydialog { 24 | my ($dialog)= @_; 25 | 26 | # Create Sizer 27 | 28 | my $topSizer = Wx::BoxSizer->new(wxVERTICAL); 29 | $dialog->SetSizer($topSizer); 30 | 31 | # Create an OK, CANCEL, and HELP Buttons 32 | 33 | my $buttOk = Wx::Button->new($dialog, wxID_OK, "OK"); 34 | my $buttCancel = Wx::Button->new($dialog, wxID_CANCEL, "Cancel"); 35 | my $buttHelp = Wx::Button->new($dialog, wxID_HELP, "Help"); 36 | 37 | # Associate buttons with Sizers 38 | 39 | my $buttonSizer = Wx::StdDialogButtonSizer->new(); 40 | $topSizer->Add($buttonSizer, 0, wxEXPAND | wxALL, 10); 41 | 42 | $buttonSizer->AddButton($buttOk); 43 | $buttonSizer->AddButton($buttCancel); 44 | $buttonSizer->AddButton($buttHelp); 45 | 46 | $buttonSizer->Realize(); 47 | } 48 | -------------------------------------------------------------------------------- /CppTrial-pg207A.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg207A.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 207(A) - Message Dialog Dialog 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_PAINT); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg207A.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (200, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | myStdDialogs($frame); 29 | 30 | $frame->Show; 31 | $app->MainLoop; 32 | 33 | # Example specific code 34 | sub myStdDialogs { 35 | my ( $self ) = @_; 36 | 37 | my $stdDialog = Wx::MessageDialog->new($self, "Message Box Caption", 38 | "Message Box Text", wxNO_DEFAULT | wxYES_NO | 39 | wxCANCEL | wxICON_INFORMATION); 40 | 41 | my $selection = $stdDialog->ShowModal(); 42 | 43 | given ($selection) { 44 | when ([wxID_YES]) {$self->Wx::LogStatus ("You pressed: \"Yes\" ")} 45 | when ([wxID_NO]) {$self->Wx::LogStatus ("You pressed: \"No\" ")} 46 | when ([wxID_CANCEL]) {$self->Wx::LogStatus ("You pressed: \"Cancel\" ")} 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /CppTrial-pg207B.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg207B.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 207(B) - Message Box Dialog 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_PAINT); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg207B.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (200, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | myStdDialogs($frame); 29 | 30 | $frame->Show; 31 | $app->MainLoop; 32 | 33 | # Example Specific code 34 | sub myStdDialogs { 35 | my ( $self ) = @_; 36 | 37 | my $stdDialog = Wx::MessageBox("Message Box Text", 38 | "Message Box Caption", wxNO_DEFAULT | wxOK | wxYES_NO | 39 | wxCANCEL | wxICON_INFORMATION, $self); 40 | 41 | # Note: Wx::MessageBox returns different button IDs from Wx::MessageDialog - pg207A 42 | 43 | given ($stdDialog) { 44 | when ([wxYES]) {$self->Wx::LogStatus ("You pressed: \"Yes\" ")} 45 | when ([wxNO]) {$self->Wx::LogStatus ("You pressed: \"No\" ")} 46 | when ([wxCANCEL]) {$self->Wx::LogStatus ("You pressed: \"Cancel\" ")} 47 | when ([wxOK]) {$self->Wx::LogStatus ("You pressed: \"Ok\" ")}; 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CppTrial-pg209.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg209.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 209 - Progress Dialog 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_PAINT); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg209.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (250, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | myStdDialogs($frame); 29 | 30 | $frame->Show; 31 | $app->MainLoop; 32 | 33 | # Example specific code 34 | sub myStdDialogs { 35 | my ( $self ) = @_; 36 | 37 | my $continue = 1; 38 | my $max = 10; 39 | 40 | my $myProgressDialog = Wx::ProgressDialog->new("Progress Dialog Example", 41 | "An Information Message", $max, $self, 42 | wxPD_CAN_ABORT | 43 | wxPD_APP_MODAL | 44 | wxPD_ELAPSED_TIME | 45 | wxPD_ESTIMATED_TIME | 46 | wxPD_REMAINING_TIME); 47 | 48 | for ( my $i = 0; $i <= $max; $i++) { 49 | Wx::Sleep(1); 50 | 51 | if ($i == $max) { 52 | $continue = $myProgressDialog->Update($i, "That's all, folks!"); 53 | } 54 | elsif ($i == $max/2) { 55 | $continue = $myProgressDialog->Update($i, "Only a half left (very long message)!"); 56 | } 57 | else { 58 | $continue = $myProgressDialog->Update($i); 59 | } 60 | 61 | if (! $continue) { 62 | if ( Wx::MessageBox("Do you really want to cancel?", 63 | "Progress Dialog Question", wxYES_NO | 64 | wxICON_QUESTION, $self) == wxYES ) { 65 | last; 66 | } 67 | else { 68 | $self->Wx::LogStatus ("Progress Dialog Resumed"); 69 | $myProgressDialog->Resume(); 70 | } 71 | } 72 | } 73 | 74 | if (! $continue) { 75 | $self->Wx::LogStatus ("Progress Dialog Aborted!"); 76 | } 77 | else { 78 | $self->Wx::LogStatus ("Countdown from %d Finished", $max); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /CppTrial-pg210.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg210.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 210 - Busy Info Box 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_MOTION); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg210.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (250, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | # &myStdDialogs($frame); 29 | EVT_MOTION($frame, \&myStdDialogs); 30 | 31 | $frame->Show; 32 | $app->MainLoop; 33 | 34 | # Example specific code 35 | sub myStdDialogs { 36 | my ( $self, $event ) = @_; 37 | 38 | $self->Wx::LogStatus ("Display Busy Info Box"); 39 | 40 | Wx::Window::Disable($self); 41 | 42 | my $info = Wx::BusyInfo->new("Counting, please wait..."); #bug - not displaying text in box 43 | 44 | Wx::Sleep(1); 45 | 46 | Wx::Window::Enable($self); 47 | $self->Wx::LogStatus ("Removed Busy Info Box"); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /CppTrial-pg211.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg211.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 211 - Application Tips Dialog 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_MOTION); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg211.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (250, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | myStdDialogs($frame); 29 | 30 | $frame->Show; 31 | $app->MainLoop; 32 | 33 | # Example specific code 34 | sub myStdDialogs { 35 | my ( $self) = @_; 36 | 37 | # Display an Application Tip Dialog Box 38 | # Tips are stored in the file "tips.txt", one tip per line 39 | # Randomly select the first tip to be displayed 40 | # Return a flag that can be used to control display of tips in the future 41 | 42 | my $index = int( rand(9) ); 43 | my $tipProvider = Wx::CreateFileTipProvider("tips.txt", $index); 44 | my $showAtStartup = Wx::ShowTip($self, $tipProvider, 1); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /CppTrial-pg215.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg215.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 215 - File Dialog 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_MOTION); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg215.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (250, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | myStdDialogs($frame); 29 | 30 | $frame->Show; 31 | $app->MainLoop; 32 | 33 | # Example specific code 34 | sub myStdDialogs { 35 | my ( $self ) = @_; 36 | 37 | my $caption = "Choose A File"; 38 | my $wildcard = "*.*"; 39 | my $defaultDir = "~/Projects/perlprojects/wx.proj"; 40 | my $defaultFilename = ""; 41 | 42 | my $fileDialog = Wx::FileDialog->new($self, $caption, $defaultDir, 43 | $defaultFilename, $wildcard, wxOPEN); 44 | 45 | my $fileDialogStatus = $fileDialog->ShowModal(); 46 | 47 | my $selecteddir = $fileDialog->GetDirectory(); 48 | my $selectedfile = $fileDialog->GetFilename(); 49 | # print $selecteddir, "\n", $selectedfile, "\n"; 50 | 51 | if ( $fileDialogStatus == wxID_OK ) {$self->Wx::LogStatus ("You pressed: \"Open\" ")}; 52 | if ( $fileDialogStatus == wxID_CANCEL ) {$self->Wx::LogStatus ("You pressed: \"Cancel\" ")}; 53 | } 54 | -------------------------------------------------------------------------------- /CppTrial-pg218.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg218.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 218 - Directory Dialog 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_MOTION); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg218.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (250, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | myStdDialogs($frame); 29 | 30 | $frame->Show; 31 | $app->MainLoop; 32 | 33 | 34 | # Example specific code 35 | sub myStdDialogs { 36 | my ( $self ) = @_; 37 | 38 | my $caption = "Choose A Directory"; 39 | my $defaultPath = "/"; 40 | 41 | my $dirDialog = Wx::DirDialog->new($self, $caption, $defaultPath, 42 | wxDD_NEW_DIR_BUTTON); 43 | 44 | my $dirDialogStatus = $dirDialog->ShowModal(); 45 | 46 | my $selecteddir = $dirDialog->GetPath(); 47 | # print $selecteddir, "\n"; 48 | 49 | if ( $dirDialogStatus == wxID_OK ) {$self->Wx::LogStatus ("You pressed: \"Open\" ")}; 50 | if ( $dirDialogStatus == wxID_CANCEL ) {$self->Wx::LogStatus ("You pressed: \"Cancel\" ")}; 51 | } 52 | -------------------------------------------------------------------------------- /CppTrial-pg221.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg221.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 221 - Color Selection Dialog 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_MOTION); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg221.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (250, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | myStdDialogs($frame); 29 | 30 | $frame->Show; 31 | $app->MainLoop; 32 | 33 | # Example specific code 34 | sub myStdDialogs { 35 | my ( $self ) = @_; 36 | 37 | my $colourDialog = Wx::ColourDialog->new($self); 38 | 39 | my $colorDialogStatus = $colourDialog->ShowModal(); 40 | 41 | my $colourdata = $colourDialog->GetColourData(); 42 | my $selectedColour = $colourdata->GetColour(); 43 | $self->SetBackgroundColour($selectedColour); 44 | $self->Refresh(); 45 | 46 | if ( $colorDialogStatus == wxID_OK ) {$self->Wx::LogStatus ("You pressed: \"Ok\" ")}; 47 | if ( $colorDialogStatus == wxID_CANCEL ) {$self->Wx::LogStatus ("You pressed: \"Cancel\" ")}; 48 | } 49 | -------------------------------------------------------------------------------- /CppTrial-pg224.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg224.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 224 - Font Selection Dialog 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_PAINT); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg224.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (250, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | EVT_PAINT($frame, \&myStdDialogs); 29 | 30 | $frame->Show; 31 | $app->MainLoop; 32 | 33 | # Example specific code 34 | sub myStdDialogs { 35 | my ( $self, $event ) = @_; 36 | 37 | my $font = Wx::Font->new(18, wxFONTFAMILY_ROMAN, wxNORMAL, wxNORMAL); 38 | 39 | my $fontData = Wx::FontData->new(); 40 | $fontData->SetInitialFont($font); 41 | $fontData->SetColour(wxGREEN); 42 | 43 | my $fontDialog = Wx::FontDialog->new($self, $fontData); 44 | 45 | my $fontDialogStatus = $fontDialog->ShowModal(); 46 | 47 | $fontData = $fontDialog->GetFontData(); 48 | my $selectedfont = $fontData->GetChosenFont(); 49 | my $selectedcolour = $fontData->GetColour(); 50 | # 51 | # Code added to provide something to display, drag dialog off of frame to see text displayed 52 | # 53 | my $dc = Wx::PaintDC->new($self); 54 | my $pt=Wx::Point->new(100,200); 55 | $dc->SetFont($selectedfont); 56 | $dc->SetBackgroundMode(wxTRANSPARENT); 57 | $dc->SetTextForeground($selectedcolour); 58 | $dc->SetTextBackground(wxWHITE); 59 | $dc->DrawText("Font Selection Sample",$pt->x, $pt->y); 60 | $self->Refresh(); 61 | 62 | # 63 | # Loop until Cancel is Selected 64 | # 65 | if ( $fontDialogStatus == wxID_CANCEL ) {die "Font Selection Terminated"}; 66 | } 67 | -------------------------------------------------------------------------------- /CppTrial-pg225.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg225.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 225 - Single Choice Dialog 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_PAINT); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg225.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | #Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (250, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | myStdDialogs($frame); 29 | 30 | $frame->Show; 31 | $app->MainLoop; 32 | 33 | # Example specific code 34 | sub myStdDialogs { 35 | my ( $self ) = @_; 36 | 37 | my @choices = ("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"); 38 | 39 | my $singleChoiceDialog = Wx::SingleChoiceDialog->new($self, 40 | "This is a small sample\nA single-choice convenience dialog", 41 | "Please select a value", \@choices); 42 | 43 | $singleChoiceDialog->SetSelection(2); 44 | 45 | if( $singleChoiceDialog->ShowModal() == wxID_OK) { 46 | Wx::MessageBox($singleChoiceDialog->GetStringSelection(), 47 | "Got String", wxOK | wxICON_INFORMATION, $self); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /CppTrial-pg226.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg226.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 226 - Multiple Choice Dialog 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_PAINT); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg226.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (250, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | myStdDialogs($frame); 29 | 30 | $frame->Show; 31 | $app->MainLoop; 32 | 33 | # Example specific code 34 | sub myStdDialogs { 35 | my ( $self ) = @_; 36 | 37 | my @choices = ("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"); 38 | 39 | my $multiChoiceDialog = Wx::MultiChoiceDialog->new($self, 40 | "A Multi-choice convenience dialog", 41 | "Please select several values", \@choices); 42 | 43 | if( $multiChoiceDialog->ShowModal() == wxID_OK) { 44 | my @selections = $multiChoiceDialog->GetSelections(); # Returns list of index numbers 45 | my $count = $#selections +1; # Index into @choices for text 46 | my $msg = ""; 47 | foreach my $selection (@selections) { 48 | $msg .= $selection . " : " . $choices[$selection] . "\n"; 49 | } 50 | Wx::MessageBox($msg, "Selections", wxOK | wxICON_INFORMATION, $self); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /CppTrial-pg227.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg227.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 227 - Number Entry Dialog (**Alternate Implementation - GetNumberFromUser**) 6 | # Could not get NumberEntryDialog, TextEntryDialog, or PasswordEntryDialog to load 7 | # Instead used GetNumberFromUser Function 8 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 9 | 10 | use 5.010; 11 | use strict; 12 | use warnings; 13 | use Wx qw(:everything); 14 | use Wx::Event qw(EVT_PAINT); 15 | 16 | # create the WxApplication 17 | my $app = Wx::SimpleApp->new; 18 | my $frame = Wx::Frame->new(undef, -1, 19 | 'CppTrial-pg227.pl', 20 | wxDefaultPosition, wxDefaultSize); 21 | 22 | # Use status bar to indicate button pushes 23 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 24 | $frame->SetStatusBar($statusBar); 25 | my @widths = (250, 100, -1); 26 | $statusBar->SetFieldsCount($#widths+1); 27 | $statusBar->SetStatusWidths(@widths); 28 | $statusBar->SetStatusText("Ready", 0); 29 | 30 | myStdDialogs($frame); 31 | 32 | $frame->Show; 33 | $app->MainLoop; 34 | 35 | # Example specific code 36 | sub myStdDialogs { 37 | my ( $self ) = @_; 38 | 39 | # 40 | # Not sure where the initial value of 20 is comming from.... 41 | # 42 | my $getNumberFromUser = Wx::GetNumberFromUser( # Appears to not support min/max bounds 43 | "Number Entry Dialog Example", 44 | "Enter A Number:", 45 | "Number Entry", 50, wxOK | wxCANCEL, $self); 46 | # 47 | # Returns -1 upon Cancel 48 | # 49 | Wx::MessageBox("$getNumberFromUser", "Entered Number:", wxOK | wxICON_INFORMATION, $self); 50 | } 51 | -------------------------------------------------------------------------------- /CppTrial-pg228A.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg228A.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 228 - Text Entry Dialog (**Alternate Implementation - GetTextFromUser**) 6 | # Could not get NumberEntryDialog, TextEntryDialog, or PasswordEntryDialog to load 7 | # Instead used GetTextFromUser Function 8 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 9 | 10 | use 5.010; 11 | use strict; 12 | use warnings; 13 | use Wx qw(:everything); 14 | use Wx::Event qw(EVT_PAINT); 15 | 16 | # create the WxApplication 17 | my $app = Wx::SimpleApp->new; 18 | my $frame = Wx::Frame->new(undef, -1, 19 | 'CppTrial-pg228A.pl', 20 | wxDefaultPosition, wxDefaultSize); 21 | 22 | # Use status bar to indicate button presses 23 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 24 | $frame->SetStatusBar($statusBar); 25 | my @widths = (250, 100, -1); 26 | $statusBar->SetFieldsCount($#widths+1); 27 | $statusBar->SetStatusWidths(@widths); 28 | $statusBar->SetStatusText("Ready", 0); 29 | 30 | myStdDialogs($frame); 31 | 32 | $frame->Show; 33 | $app->MainLoop; 34 | 35 | # Example specific code 36 | sub myStdDialogs { 37 | my ( $self ) = @_; 38 | 39 | # 40 | # Not sure where the initial value of 20 is comming from.... 41 | # 42 | my $getTextFromUser = Wx::GetTextFromUser( 43 | "This is some text, actually a lot of text\nEven two rows of text", 44 | "Enter a String: ", wxOK | wxCANCEL, $self); 45 | # 46 | # Returns empty string upon Cancel 47 | # 48 | Wx::MessageBox("$getTextFromUser", "Entered String", wxOK | wxICON_INFORMATION, $self); 49 | } 50 | -------------------------------------------------------------------------------- /CppTrial-pg228B.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg228B.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 228 - Password Entry Dialog (**Alternate Implementation - GetPasswordFromUser**) 6 | # Could not get NumberEntryDialog, TextEntryDialog, or PasswordEntryDialog to load 7 | # Instead used GetPasswordFromUser Function 8 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 9 | 10 | use 5.010; 11 | use strict; 12 | use warnings; 13 | use Wx qw(:everything); 14 | use Wx::Event qw(EVT_PAINT); 15 | 16 | # create the WxApplication 17 | my $app = Wx::SimpleApp->new; 18 | my $frame = Wx::Frame->new(undef, -1, 19 | 'CppTrial-pg228B.pl', 20 | wxDefaultPosition, wxDefaultSize); 21 | 22 | # Use status bar to indicate button presses 23 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 24 | $frame->SetStatusBar($statusBar); 25 | my @widths = (250, 100, -1); 26 | $statusBar->SetFieldsCount($#widths+1); 27 | $statusBar->SetStatusWidths(@widths); 28 | $statusBar->SetStatusText("Ready", 0); 29 | 30 | myStdDialogs($frame); 31 | 32 | $frame->Show; 33 | $app->MainLoop; 34 | 35 | # Example specific code 36 | sub myStdDialogs { 37 | my ( $self ) = @_; 38 | 39 | # 40 | # Not sure where the initial value of 20 is comming from.... 41 | # 42 | my $getPasswordFromUser = Wx::GetPasswordFromUser( 43 | "This is some text, actually a lot of text\nEven two rows of text", 44 | "Enter a Password: ", wxOK | wxCANCEL, $self); 45 | # 46 | # Returns empty string upon Cancel 47 | # 48 | Wx::MessageBox("$getPasswordFromUser", "Entered Password:", wxOK | wxICON_INFORMATION, $self); 49 | } 50 | -------------------------------------------------------------------------------- /CppTrial-pg245.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg245.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 245 - Personal Records Dialog 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | 13 | # create the WxApplication 14 | my $app = Wx::SimpleApp->new; 15 | my $dialog = Wx::Dialog->new(undef, -1, "Personal Records Dialog Example", 16 | wxDefaultPosition, wxDefaultSize, 17 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); 18 | 19 | mydialog($dialog); 20 | 21 | $dialog->Show; 22 | $app->MainLoop; 23 | 24 | # Example specific code 25 | sub mydialog { 26 | my ($dialog)= @_; 27 | 28 | my ($ID_NAME, $ID_AGE, $ID_SEX, $ID_VOTE, $ID_RESET, $ID_OK, $ID_CANCEL, $ID_HELP) = (1..8); 29 | my ($wxEmptyString, $true) = ("", 1); 30 | 31 | my $topSizer = Wx::BoxSizer->new(wxVERTICAL); 32 | $dialog->SetSizer($topSizer); 33 | 34 | my $boxSizer = Wx::BoxSizer->new(wxVERTICAL); 35 | $topSizer->Add($boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); 36 | 37 | my $desc = Wx::StaticText->new($dialog, wxID_STATIC, 38 | "Please enter your name, age, and sex, and specify whether you wish to\nvote in a general election.", 39 | wxDefaultPosition, wxDefaultSize, 0); 40 | $boxSizer->Add($desc, 0, wxALIGN_LEFT | wxALL, 5); 41 | 42 | my $nameCtrl = Wx::TextCtrl->new($dialog, $ID_NAME, "Maylee", 43 | wxDefaultPosition, wxDefaultSize, 0); 44 | $boxSizer->Add($nameCtrl, 0, wxGROW | wxALL, 5); 45 | 46 | my $ageSexVoteBox = Wx::BoxSizer->new(wxHORIZONTAL); 47 | $boxSizer->Add($ageSexVoteBox, 0, wxGROW | wxALL, 5); 48 | 49 | my $ageLabel = Wx::StaticText->new($dialog, wxID_STATIC, "&Age:", wxDefaultPosition, wxDefaultSize, 0); 50 | $ageSexVoteBox->Add($ageLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 51 | 52 | my $ageSpin = Wx::SpinCtrl->new($dialog, $ID_AGE, $wxEmptyString, wxDefaultPosition, 53 | Wx::Size->new(60, -1), wxSP_ARROW_KEYS, 0, 120, 50); 54 | $ageSexVoteBox->Add($ageSpin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 55 | 56 | my $sexLabel = Wx::StaticText->new($dialog, wxID_STATIC, "&Sex:", wxDefaultPosition, wxDefaultSize, 0); 57 | $ageSexVoteBox->Add($sexLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 58 | 59 | my @sexStrings = ("Male", "Female"); 60 | my $sexChoice = Wx::Choice->new($dialog, $ID_SEX, wxDefaultPosition, 61 | Wx::Size->new(85,-1), \@sexStrings); 62 | $sexChoice->SetStringSelection("Female"); 63 | $ageSexVoteBox->Add($sexChoice, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 64 | 65 | $ageSexVoteBox->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5); # Spacer Box 66 | 67 | my $voteCheckBox = Wx::CheckBox->new($dialog, $ID_VOTE, "&Vote", 68 | wxDefaultPosition, wxDefaultSize, 0); 69 | $voteCheckBox->SetValue($true); 70 | $ageSexVoteBox->Add($voteCheckBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 71 | 72 | my $line = Wx::StaticLine->new($dialog, wxID_STATIC, wxDefaultPosition, 73 | wxDefaultSize, wxLI_HORIZONTAL); 74 | $boxSizer->Add($line, 0, wxGROW | wxALL, 5); 75 | 76 | my $okCancelBox = Wx::BoxSizer->new(wxHORIZONTAL); 77 | $boxSizer->Add($okCancelBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 78 | 79 | my $reset = Wx::Button->new($dialog, $ID_RESET, "&Reset", 80 | wxDefaultPosition, wxDefaultSize, 0); 81 | $okCancelBox->Add($reset, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 82 | 83 | my $ok = Wx::Button->new($dialog, $ID_OK, "&Ok", 84 | wxDefaultPosition, wxDefaultSize, 0); 85 | $ok->SetDefault(); 86 | $okCancelBox->Add($ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 87 | 88 | my $cancel = Wx::Button->new($dialog, $ID_CANCEL, "&Cancel", 89 | wxDefaultPosition, wxDefaultSize, 0); 90 | $okCancelBox->Add($cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 91 | 92 | my $help = Wx::Button->new($dialog, $ID_HELP, "&Help", 93 | wxDefaultPosition, wxDefaultSize, 0); 94 | $okCancelBox->Add($help, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); 95 | 96 | $topSizer->Fit($dialog); 97 | $topSizer->SetSizeHints($dialog); # Return values not processed in this example 98 | } 99 | -------------------------------------------------------------------------------- /CppTrial-pg283.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg283.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 283 - Drawing a masked image 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/24/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_PAINT); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg283.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | EVT_PAINT($frame,\&OnPaint); 20 | $frame->Show; 21 | $app->MainLoop; 22 | 23 | # Example specific code 24 | sub OnPaint { 25 | my ( $self, $event) = @_; 26 | 27 | my $memdc = Wx::MemoryDC->new(); 28 | 29 | my $bitMap = Wx::Bitmap->new(400,400); 30 | $memdc->SelectObject($bitMap); 31 | 32 | my $brush1 = Wx::Brush->new(wxBLUE, wxSOLID); 33 | $memdc->SetBackground($brush1); 34 | $memdc->Clear(); # Fill DC with background brush color 35 | 36 | my $pen1 = Wx::Pen->new(wxRED,1,wxSOLID); 37 | $memdc->SetPen($pen1); 38 | my $brush2 = Wx::Brush->new(wxRED,wxSOLID); 39 | $memdc->SetBrush($brush2); 40 | $memdc->DrawRectangle(50, 50, 200, 200); # Red rectangle on blue background 41 | 42 | 43 | my $image = $bitMap->ConvertToImage(); 44 | $image->SetMaskColour(255, 0, 0); 45 | $image->SetMask(1); 46 | 47 | # my $dispBitMap = Wx::Bitmap->new($image, -1); # Constructor not supported by wxPerl 48 | # $dc->DrawBitmap($dispBitMap, 0, 0, 1); # Can't display $image 49 | # 50 | # Code added for display purposes - many book examples are only fragments 51 | # 52 | my $bmp = Wx::Bitmap->new("test2.bmp", wxBITMAP_TYPE_BMP); 53 | $bmp->SetMask(Wx::Mask->new($bmp, wxBLUE)); 54 | # Wx:StaticBitMap->new($memdc, -1, $bmp, [300,120]); 55 | 56 | my $dcPaint = Wx::PaintDC->new($self); 57 | $dcPaint->Blit(0, 0, 400, 400, $memdc, 0, 0, wxCOPY, 1); 58 | 59 | $memdc->SelectObject(wxNullBitmap); 60 | 61 | } 62 | -------------------------------------------------------------------------------- /CppTrial-pg293.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg293.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 293 - Writing Text to the Clipboard 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg293.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 22 | $frame->SetStatusBar($statusBar); 23 | my @widths = (200, 100, -1); 24 | $statusBar->SetFieldsCount($#widths+1); 25 | $statusBar->SetStatusWidths(@widths); 26 | $statusBar->SetStatusText("Ready", 0); 27 | 28 | myStdDialogs($frame); 29 | 30 | $frame->Show; 31 | $app->MainLoop; 32 | 33 | # Example specific code 34 | sub myStdDialogs { 35 | my ( $self ) = @_; 36 | 37 | use Wx::DND; # Loads all of the Clipboard 38 | # and Drag and Drop packages 39 | # Like - Wx::DataObjectSimple 40 | 41 | my $textDataObject1 = Wx::TextDataObject->new("Save this string to the clipboard"); 42 | 43 | wxTheClipboard->Open; 44 | wxTheClipboard->SetData( $textDataObject1 ); 45 | wxTheClipboard->Close; 46 | 47 | wxTheClipboard->Open; 48 | my $text; 49 | if( wxTheClipboard->IsSupported( wxDF_TEXT ) ) { 50 | my $textDataObject2 = Wx::TextDataObject->new; 51 | my $ok = wxTheClipboard->GetData( $textDataObject2 ); 52 | if( $ok ) { 53 | $self->Wx::LogStatus( "Pasted and Retrieved text" ); 54 | $text = $textDataObject2->GetText; 55 | } 56 | else { 57 | $self->Wx::LogStatus( "Error pasting and Retrieving text" ); 58 | $text = ''; 59 | } 60 | } 61 | Wx::MessageBox($text); 62 | } 63 | -------------------------------------------------------------------------------- /CppTrial-pg294.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg294.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 294 - Writing a bitmap/image to the Clipboard 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_PAINT); 13 | 14 | # create the WxApplication 15 | my $app = Wx::SimpleApp->new; 16 | my $frame = Wx::Frame->new(undef, -1, 17 | 'CppTrial-pg294.pl', 18 | wxDefaultPosition, wxDefaultSize); 19 | 20 | # Use status bar to indicate button presses 21 | Wx::InitAllImageHandlers(); 22 | my $statusBar = Wx::StatusBar->new($frame, wxID_ANY, wxST_SIZEGRIP); 23 | $frame->SetStatusBar($statusBar); 24 | my @widths = (200, 100, -1); 25 | $statusBar->SetFieldsCount($#widths+1); 26 | $statusBar->SetStatusWidths(@widths); 27 | $statusBar->SetStatusText("Ready", 0); 28 | 29 | EVT_PAINT($frame, \&myStdDialogs); 30 | 31 | $frame->Show; 32 | $app->MainLoop; 33 | 34 | # Example specific code 35 | sub myStdDialogs { 36 | my ( $self, $event ) = @_; 37 | 38 | use Wx::DND; # Loads all of the Clipboard 39 | # and Drag and Drop packages 40 | # Like - Wx::DataObjectSimple 41 | 42 | my $bmp = Wx::Bitmap->new("logo.png", wxBITMAP_TYPE_PNG); 43 | my $bmpObject1 = Wx::BitmapDataObject->new($bmp); 44 | 45 | wxTheClipboard->Open; 46 | wxTheClipboard->SetData( $bmpObject1 ); # Put the bitmap object on the clipboard 47 | wxTheClipboard->Close; 48 | 49 | wxTheClipboard->Open; 50 | my $bitmap = wxNullBitmap; 51 | if( wxTheClipboard->IsSupported( wxDF_BITMAP ) ) { 52 | my $bmpObject2 = Wx::BitmapDataObject->new($bitmap); 53 | my $ok = wxTheClipboard->GetData( $bmpObject2 ); # Get the bitmap object from the clipboard 54 | if( $ok ) { 55 | $self->Wx::LogStatus("Pasted and Retrieved bitmap" ); 56 | $bitmap = $bmpObject2->GetBitmap(); 57 | } 58 | else { 59 | $self->Wx::LogStatus("Error pasting bitmap" ); 60 | $bitmap = wxNullBitmap; 61 | } 62 | wxTheClipboard->Close; 63 | } 64 | # 65 | # Use a paint event to get the bitmap to draw on screen 66 | # 67 | my $dc = Wx::PaintDC->new($self); 68 | my $pen = Wx::Pen->new(wxBLACK, 1, wxSOLID); 69 | $dc->SetPen($pen); 70 | my $brush=Wx::Brush->new(wxRED, wxSOLID); 71 | $dc->SetBrush($brush); 72 | $dc->DrawBitmap($bitmap, 30, 100, 1); 73 | } 74 | -------------------------------------------------------------------------------- /CppTrial-pg340.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg340.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 340 - HTML Window - Displays an HTML file 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_PAINT); 13 | use Wx::Html; # Html package not loaded by "use Wx qw(:everything)" 14 | # Html pulls in all of the HTML modules 15 | # create the WxApplication 16 | my $app = Wx::SimpleApp->new; 17 | my $dialog = Wx::Dialog->new(undef, -1, 18 | 'CppTrial-pg340.pl', 19 | wxDefaultPosition, wxDefaultSize, 20 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); 21 | Wx::InitAllImageHandlers(); 22 | myStdDialogs($dialog); 23 | $app->MainLoop; 24 | 25 | # Example specific code 26 | sub myStdDialogs { 27 | my ( $self ) = @_; 28 | 29 | my $topSizer = Wx::BoxSizer->new(wxVERTICAL); 30 | 31 | my $html = Wx::HtmlWindow->new($self, wxID_ANY, wxDefaultPosition, 32 | Wx::Size->new(600,400), wxHW_SCROLLBAR_NEVER); 33 | 34 | $html->SetBorders(5); 35 | $html->LoadPage("pg342.html"); 36 | # 37 | # GetInternalRepresentation() not supported under wxPerl 38 | # 39 | $topSizer->Add($html, 1, wxALL, 10); 40 | 41 | my $staticLine = Wx::StaticLine->new($self, wxID_ANY); 42 | $topSizer->Add($staticLine, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); 43 | 44 | my $button = Wx::Button->new($self, wxID_OK, "Ok"); 45 | $button->SetDefault(); 46 | $topSizer->Add($button, 0, wxALL | wxALIGN_RIGHT, 15); 47 | 48 | $self->SetSizer($topSizer); 49 | $topSizer->Fit($self); 50 | $self->ShowModal(); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /CppTrial-pg347.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # CppTrial-pg347.pl 4 | # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomor 5 | # C++ Example from pg 347 - Simple Grid Example 6 | # Ported to wxPerl by James M. Lynes Jr. - Last Modified 9/25/2012 7 | 8 | use 5.010; 9 | use strict; 10 | use warnings; 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_PAINT); 13 | use Wx::Grid; # Package not loaded by "use Wx qw(:everything)" 14 | 15 | # create the WxApplication 16 | my $app = Wx::SimpleApp->new; 17 | my $dialog = Wx::Dialog->new(undef, -1, 18 | 'CppTrial-pg347.pl', 19 | wxDefaultPosition, wxDefaultSize, 20 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); 21 | Wx::InitAllImageHandlers(); 22 | myStdDialogs($dialog); 23 | $dialog->Show; 24 | $app->MainLoop; 25 | 26 | # Example specific code 27 | sub myStdDialogs { 28 | my ( $self ) = @_; 29 | 30 | my $grid = Wx::Grid->new($self, wxID_ANY, wxDefaultPosition, 31 | Wx::Size->new(400,300)); 32 | 33 | $grid->CreateGrid(8, 10); # 8 rows by 10 columns 34 | $grid->SetRowSize(0, 60); # row size in pixels 35 | $grid->SetColSize(0, 120); # column size in pixels 36 | 37 | $grid->SetCellValue(0, 0, "wxGrid is Good"); # A1 38 | 39 | $grid->SetCellValue(0, 3, "This is Read-only"); # D1 40 | $grid->SetReadOnly(0, 3); 41 | 42 | $grid->SetCellValue(3, 3, "Green on Grey"); # D4 43 | $grid->SetCellTextColour(3, 3, wxGREEN); 44 | $grid->SetCellBackgroundColour(3, 3, wxLIGHT_GREY); 45 | 46 | $grid->SetColFormatFloat(5, 6, 2); 47 | $grid->SetCellValue(0, 5, "3.1415"); # F1 48 | 49 | $grid->Fit(); 50 | $self->SetClientSize($grid->GetSize); 51 | } 52 | -------------------------------------------------------------------------------- /FILE-INDEX.txt: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------------------------------------------- 2 | 3 | Index of Example Files from : Cross Platform GUI Programming with wxWidgets 4 | by: Smart, Hock, and Csomor - The "wxBook" 5 | Ported to wxPerl by: James M. Lynes, Jr., September 26,2012 6 | ---------------------------------------------------------------------------------------------------- 7 | 8 | 1. CppTrial-pg019.pl : # C++ Example from pg 19 - Create a basic frame with menus and status bar 9 | 2. CppTrial-pg065.pl : # C++ Example from pg 65 - MDI Child Frame Example 10 | 3. CppTrial-pg073.pl : # C++ Example from pg 73 - Notebook Example 11 | 4. CppTrial-pg077.pl : # C++ Example from pg 77 - Scrolled Window Example 12 | 5. CppTrial-pg081.pl : # C++ Example from pg 81 - Splitter Window Example 13 | 6. CppTrial-pg086.pl : # C++ Example from pg 86 - 20 Assorted Static & Non-Static Controls Examples 14 | 7. CppTrial-pg124.pl : # C++ Example from pg 124 - Tool Bar Example 15 | 8. CppTrial-pg133.pl : # C++ Example from pg 133 - Drawing on Windows with wxClientDC 16 | 9. CppTrial-pg135.pl : # C++ Example from pg 135 - Drawing on Windows with wxPaintDC 17 | 10. CppTrial-pg150.pl : # C++ Example from pg 150 - Drawing Text - Extends pg 135 example 18 | 11. CppTrial-pg151.pl : # C++ Example from pg 151 - Drawing Text Rotated - Extends pg 150 & 135 examples 19 | 12. CppTrial-pg152.pl : # C++ Example from pg 152 - Centering Text - Extends pg 151, 150, & 135 examples 20 | 13. CppTrial-pg154.pl : # C++ Example from pg 154 - Drawing multiple lines - Extends pg 135 example 21 | 14. CppTrial-pg155.pl : # C++ Example from pg 155 - Drawing polygons - Extends pg 154 example 22 | 15. CppTrial-pg156.pl : # C++ Example from pg 156 - Drawing Splines - Extends pg 155 example 23 | 16. CppTrial-pg157.pl : # C++ Example from pg 157 - Drawing Bitmaps - Extends pg 150 example 24 | 17. CppTrial-pg158.pl : # C++ Example from pg 158 - Copy(Tile) Bitmaps Between Device Contexts - Extends pg 157 example 25 | 18. CppTrial-pg159A.pl : # C++ Example from pg 159A - Filling arbitrary areas - Extends pg 135 example 26 | 19. CppTrial-pg159B.pl : # C++ Example from pg 159B - Logical Functions - Extends pg 135 example 27 | 20. CppTrial-pg195.pl : # C++ Example from pg 195 - Sizers -Dialog with streatching text control 28 | 21. CppTrial-pg196.pl : # C++ Example from pg 196 - Sizers -Dialog with static box sizer and check box 29 | 22. CppTrial-pg197.pl : # C++ Example from pg 197 - Sizers -Dialog with grid sizer 30 | 23. CppTrial-pg199.pl : # C++ Example from pg 199 - Sizers -Dialog with flex grid sizer 31 | 24. CppTrial-pg201.pl : # C++ Example from pg 201 - Sizers -Dialog with grid bag sizer 32 | 25. CppTrial-pg202.pl : # C++ Example from pg 202 - Sizers -Dialog with Standard Dialog Button Sizer 33 | 26. CppTrial-pg207A.pl : # C++ Example from pg 207(A) - Message Dialog Dialog 34 | 27. CppTrial-pg207B.pl : # C++ Example from pg 207(B) - Message Box Dialog 35 | 28. CppTrial-pg209.pl : # C++ Example from pg 209 - Progress Dialog 36 | 29. CppTrial-pg210.pl : # C++ Example from pg 210 - Busy Info Box 37 | 30. CppTrial-pg211.pl : # C++ Example from pg 211 - Application Tips Dialog 38 | 31. CppTrial-pg215.pl : # C++ Example from pg 215 - File Dialog 39 | 32. CppTrial-pg218.pl : # C++ Example from pg 218 - Directory Dialog 40 | 33. CppTrial-pg221.pl : # C++ Example from pg 221 - Color Selection Dialog 41 | 34. CppTrial-pg224.pl : # C++ Example from pg 224 - Font Selection Dialog 42 | 35. CppTrial-pg225.pl : # C++ Example from pg 225 - Single Choice Dialog 43 | 36. CppTrial-pg226.pl : # C++ Example from pg 226 - Multiple Choice Dialog 44 | 37. CppTrial-pg227.pl : # C++ Example from pg 227 - Number Entry Dialog (**Alt Implementation - GetNumberFromUser**) 45 | 38. CppTrial-pg228A.pl : # C++ Example from pg 228 - Text Entry Dialog (**Alt Implementation - GetTextFromUser**) 46 | 39. CppTrial-pg228B.pl : # C++ Example from pg 228 - Password Entry Dialog (**Alt Implementation - GetPasswordFromUser**) 47 | 40. CppTrial-pg245.pl : # C++ Example from pg 245 - Personal Records Dialog 48 | 41. CppTrial-pg283.pl : # C++ Example from pg 283 - Drawing a masked image 49 | 42. CppTrial-pg293.pl : # C++ Example from pg 293 - Writing Text to the Clipboard 50 | 43. CppTrial-pg294.pl : # C++ Example from pg 294 - Writing a bitmap/image to the Clipboard 51 | 44. CppTrial-pg340.pl : # C++ Example from pg 340 - HTML Window - Displays an HTML file 52 | 45. CppTrial-pg347.pl : # C++ Example from pg 347 - Simple Grid Example 53 | 54 | Additional Example programs and modules 55 | --------------------------------------- 56 | ScreenCapture.pl - Captures the screen to a file 57 | WxScreenCapture.pm - Screen capture program above in module form 58 | wxWizard.pl - Example of a simple wizard(simple version of pg333) 59 | LCDdisplay.pl - Example of a simulated 7 segment LCD display 60 | AngularMeter.pl - Example of simulated round panel meter 61 | LinearMeter.pl - Example of a simulated linear panel meter - verticle or horizontal configuration 62 | LinearMeter3.pm - Module version of Linear Panel Meter 63 | LM3.pl - Simulated Process Control Screen using LinearMeter3.pm 64 | 65 | Additional support files used by the example code 66 | ------------------------------------------------- 67 | cut.xpm 68 | copy.xpm 69 | print.xpm 70 | tips.txt 71 | logo.png 72 | padre_logo_64x64.png 73 | pg342.html 74 | test2.bmp 75 | 76 | Documentation Files 77 | ------------------- 78 | README.txt 79 | FILE-INDEX.txt 80 | 81 | 82 | -------------------------------------------------------------------------------- /LCDdisplay.pl: -------------------------------------------------------------------------------- 1 | #! /home/pete/CitrusPerl/perl/bin/perl 2 | # 3 | # LCDdisplay.pl 4 | # This script draws a simulated seven segment LCD Display. 5 | # Segments are drawn as 4 or 6 sided polygons 6 | # The colon(:) is drawn as 2 ellipses and takes up a character space 7 | # The decimal(.) is drawn as 1 ellipse and does not take a character space 8 | # A leading decimal(.) must be prefaced by a 0 as 0.1234 9 | # For demo purposes the value to be displayed is stored in %wxGlobals{mValue} 10 | # 11 | # Written in wxPerl. Tested on Citrus Perl 5.16 with wxWidgets 2.8.x. 12 | # Ported by: James M. Lynes. Jr. 13 | # Last Modified Date: January 19, 2013 14 | # 15 | # Adapted from LCDWindow.cpp by Marco Cavallini 16 | # based in part(mostly) on the work of 17 | # the KWIC project (http://www.koansoftware.com/kwic/index.htm). 18 | # Referenced on pg 596 of the "Wx Book" - 19 | # "Cross-Platform GUI Programming with wxWidgets", Smart, Hock, & Csomor 20 | # 21 | # 22 | use 5.010; # Using Given/When 23 | use strict; 24 | use warnings; 25 | use Wx qw(:everything :allclasses); 26 | use Wx::Event qw( EVT_PAINT EVT_SIZE ); 27 | 28 | my %wxGlobals = ( # Configuration Data 29 | mSegmentLen => 40, 30 | mSegmentWidth => 10, 31 | mSpace => 5, 32 | mNumberDigits => 6, # width of mValue including . or : 33 | mValue => "12.045", # Default string to be displayed 34 | LCD_Number_Segments => 8, # Segment 7 is the decimal point 35 | mLightColour => sub{Wx::Colour->new(0, 255, 0)}, # Bright green 36 | mGrayColour => sub{Wx::Colour->new(0, 64, 0)}, # Dim green 37 | mDefaultColour => sub{Wx::Colour->new(0, 0, 0)}, # Black 38 | ); 39 | 40 | my %wxDigitData = ( # Actual string to be displayed 41 | value => "", 42 | decimal => 0, # 1=true turns on the decimal point for digit 43 | ); 44 | 45 | my %ctbl = ( # Map character to segments - 46 | 0 => 0x3F, # Not defined in the 7-segment "abcdefg" format 47 | 1 => 0x14, 48 | 2 => 0x6D, # ***0*** Bit Numbers -654 3210 49 | 3 => 0x75, # * * 50 | 4 => 0x56, # 1 2 51 | 5 => 0x73, # * * 52 | 6 => 0x7B, # ***6*** 53 | 7 => 0x15, # * * 54 | 8 => 0x7F, # 3 4 55 | 9 => 0x77, # * * 56 | A => 0x5F, # ***5*** 7 57 | B => 0x7A, 58 | C => 0x2B, 59 | D => 0x7C, 60 | E => 0x6B, 61 | F => 0x4B, 62 | '-' => 0x40, 63 | '_' => 0x20, 64 | '^' => 0x47, # code for degree symbol 65 | '=' => 0x61, # code for undefined symbol 66 | ' ' => 0x00, # code for a space 67 | ); # Other options could be added 68 | 69 | # 70 | # Main Application ----------------------------------------------------------------------- 71 | # 72 | my $app = Wx::SimpleApp->new; 73 | my $frame = Wx::Frame->new(undef, -1, "Simulated 7-segment LCD Display", 74 | wxDefaultPosition, [400,150]); 75 | $frame->SetBackgroundColour($wxGlobals{mDefaultColour}->()); 76 | EVT_PAINT( $frame, \&onPaint ); 77 | EVT_SIZE( $frame, \&onSize ); 78 | $frame->Show; 79 | $app->MainLoop; 80 | # 81 | # Dismiss a size event 82 | # 83 | sub onSize{ 84 | my($self, $event) = @_; 85 | $event->Skip(); 86 | } 87 | # 88 | # Paint the simulated LCD Display ---------------------------------------------------------- 89 | # 90 | sub onPaint{ 91 | my($self, $event) = @_; 92 | my $disp = Wx::PaintDC->new($self); # Create paint device context 93 | my( $dw, $dh) = $disp->GetSizeWH(); # Calculate display scaling 94 | my $bw = GetBitmapWidth(); 95 | my $bh = GetBitmapHeight(); 96 | my $xs = $dw/$bw; 97 | my $ys = $dh/$bh; 98 | my $as = $xs > $ys ? $ys : $xs; 99 | $disp->SetUserScale($as, $as); 100 | $disp->SetDeviceOrigin((($dw-$bw*$as)/2), (($dh-$bh*$as)/2)); 101 | DoDrawing($disp); # Paint the display 102 | } 103 | sub DoDrawing{ 104 | my($dc) = @_; 105 | my @cbuf = reverse(split(//,$wxGlobals{mValue})); # Process one character at a time 106 | my $cbuflen = @cbuf; 107 | if($cbuflen > $wxGlobals{mNumberDigits}) { # Truncate string to max display width 108 | $cbuflen = $wxGlobals{mNumberDigits}; 109 | } 110 | my $ctr = 0; 111 | my $seg = 0; 112 | while($ctr < $cbuflen) { 113 | if($cbuf[$ctr] ne '.') { # Skip decimal point, not drawn as a character 114 | $wxDigitData{value} = $cbuf[$ctr]; 115 | $wxDigitData{decimal} = 0; 116 | if($cbuf[$ctr-1] eq '.') {$wxDigitData{decimal} = 1;} # Turn on decimal point for this digit 117 | DrawDigit($dc, $seg); 118 | $seg++; 119 | } 120 | $ctr++ 121 | } 122 | } 123 | sub DrawDigit{ 124 | my($dc, $digit) = @_; 125 | my $value = $wxDigitData{value}; 126 | my $dec = Decode($value); 127 | if($value eq ':') { # Draw a colon(:) 128 | DrawTwoDots($dc, $digit); 129 | } 130 | else{ 131 | my $ctr = 0; 132 | while($ctr < $wxGlobals{LCD_Number_Segments}-1) { 133 | DrawSegment($dc, $digit, $ctr, ($dec>>$ctr)&1); 134 | $ctr++; 135 | } 136 | DrawSegment($dc, $digit, 7, $wxDigitData{decimal}); # Draw the decimal point 137 | } 138 | } 139 | sub DrawTwoDots{ # Draws a colon(:) 140 | my($dc, $digit) = @_; 141 | my $sl = $wxGlobals{mSegmentLen}; 142 | my $sw = $wxGlobals{mSegmentWidth}; 143 | my $sp = $wxGlobals{mSpace}; 144 | my $x = DigitX($digit); 145 | my $y = DigitY($digit); 146 | $x += ($sl/2)-$sw; 147 | $y += ($sl/2)-$sw; 148 | my $brushOn = Wx::Brush->new($wxGlobals{mLightColour}->(), wxSOLID); 149 | $dc->SetBrush($brushOn); 150 | $dc->SetPen(Wx::Pen->new($frame->GetBackgroundColour(), 1, wxSOLID)); 151 | $dc->DrawEllipse($x, $y, $sw*2, $sw*2); 152 | $y += $sl; 153 | $dc->DrawEllipse($x, $y, $sw*2, $sw*2); 154 | } 155 | sub DrawSegment{ 156 | my($dc, $digit, $segment, $state) = @_; 157 | my $sl = $wxGlobals{mSegmentLen}; 158 | my $sw = $wxGlobals{mSegmentWidth}; 159 | my $x = DigitX($digit); 160 | my $y = DigitY($digit); 161 | my $brushOn = Wx::Brush->new($wxGlobals{mLightColour}->(), wxSOLID); 162 | my $brushOff = Wx::Brush->new($wxGlobals{mGrayColour}->(), wxSOLID); 163 | if($state) { # bit set for On segment 164 | $dc->SetBrush($brushOn); # Bright color for On segment 165 | } 166 | else { # bit cleared for Off segment 167 | $dc->SetBrush($brushOff); # Dim color for Off segment 168 | } 169 | $dc->SetPen(Wx::Pen->new($frame->GetBackgroundColour(), 1, wxSOLID)); 170 | my @points; # Verticies for 4 sided segments 171 | my @p6; # Verticies for the 6 sided segment 172 | given($segment) { 173 | when(0) { 174 | $points[0] = Wx::Point->new($x, $y); 175 | $points[1] = Wx::Point->new($x+$sl, $y); 176 | $points[2] = Wx::Point->new($x+$sl-$sw, $y+$sw); 177 | $points[3] = Wx::Point->new($x+$sw, $y+$sw); 178 | } 179 | when(1) { 180 | $points[0] = Wx::Point->new($x, $y); 181 | $points[1] = Wx::Point->new($x, $y+$sl); 182 | $points[2] = Wx::Point->new($x+$sw, $y+$sl-$sw/2); 183 | $points[3] = Wx::Point->new($x+$sw, $y+$sw); 184 | } 185 | when(2) { 186 | $x += $sl-$sw; 187 | $points[0] = Wx::Point->new($x,$y+$sw); 188 | $points[1] = Wx::Point->new($x+$sw, $y); 189 | $points[2] = Wx::Point->new($x+$sw, $y+$sl); 190 | $points[3] = Wx::Point->new($x, $y+$sl-$sw/2); 191 | } 192 | when(3) { 193 | $y += $sl; 194 | $points[0] = Wx::Point->new($x, $y); 195 | $points[1] = Wx::Point->new($x, $y+$sl); 196 | $points[2] = Wx::Point->new($x+$sw, $y+$sl-$sw); 197 | $points[3] = Wx::Point->new($x+$sw, $y+$sw-$sw/2); 198 | } 199 | when(4) { 200 | $x += $sl-$sw; 201 | $y += $sl; 202 | $points[0] = Wx::Point->new($x, $y+$sw/2); 203 | $points[1] = Wx::Point->new($x+$sw, $y); 204 | $points[2] = Wx::Point->new($x+$sw, $y+$sl); 205 | $points[3] = Wx::Point->new($x, $y+$sl-$sw); 206 | } 207 | when(5) { 208 | $y += 2*$sl-$sw; 209 | $points[0] = Wx::Point->new($x+$sw, $y); 210 | $points[1] = Wx::Point->new($x+$sl-$sw, $y); 211 | $points[2] = Wx::Point->new($x+$sl, $y+$sw); 212 | $points[3] = Wx::Point->new($x, $y+$sw); 213 | } 214 | when(6) { 215 | $y += $sl-$sw/2; 216 | $p6[0] = Wx::Point->new($x, $y+$sw/2); 217 | $p6[1] = Wx::Point->new($x+$sw, $y); 218 | $p6[2] = Wx::Point->new($x+$sl-$sw, $y); 219 | $p6[3] = Wx::Point->new($x+$sl, $y+$sw/2); 220 | $p6[4] = Wx::Point->new($x+$sl-$sw, $y+$sw); 221 | $p6[5] = Wx::Point->new($x+$sw, $y+$sw); 222 | } 223 | default {} 224 | } 225 | if($segment < 6) { # Draw the 4 sided segments(0-5) 226 | $dc->DrawPolygon(\@points, 0, 0); 227 | } 228 | elsif($segment == 6) { # Draw the 6 sided segment(6) 229 | $dc->DrawPolygon(\@p6, 0, 0); 230 | } 231 | else { # Draw the decimal point(7) 232 | $y += 2*$sl; 233 | $x += $sl; 234 | $dc->DrawEllipse($x+1, $y-$sw, $sw, $sw); 235 | } 236 | } 237 | sub Decode { $ctbl{$_[0]} // $ctbl{'='}} # Table lookup 238 | # for character translation 239 | 240 | # 241 | # Support subs ---------------------------------------------------------------------------- 242 | # 243 | sub GetDigitWidth{ 244 | return $wxGlobals{mSegmentLen} + $wxGlobals{mSegmentWidth} + $wxGlobals{mSpace}; 245 | } 246 | sub GetDigitHeight{ 247 | return ($wxGlobals{mSegmentLen}*2) + ($wxGlobals{mSpace}*2); 248 | } 249 | sub GetBitmapWidth{ 250 | return ($wxGlobals{mNumberDigits}*GetDigitWidth()) + $wxGlobals{mSpace}; 251 | } 252 | sub GetBitmapHeight{ 253 | return GetDigitHeight(); 254 | } 255 | sub DigitX{ 256 | my($digit) = @_; 257 | return GetBitmapWidth()-(($digit+1)*GetDigitWidth()); 258 | } 259 | sub DigitY{ 260 | my($digit) = @_; 261 | return $wxGlobals{mSpace}; 262 | } 263 | sub SetNumberDigits{ 264 | my $ndigits = @_; 265 | $wxGlobals{mNumberDigits} = $ndigits; 266 | } 267 | sub SetValue{ 268 | my $value = @_; 269 | $wxGlobals{mValue} = $value; 270 | } 271 | sub GetValue{ 272 | return $wxGlobals{mValue}; 273 | } 274 | sub GetNumberDigits{ 275 | return $wxGlobals{mNumberDigits}; 276 | } 277 | sub SetLightColour{ 278 | my($ref) = @_; 279 | $wxGlobals{mLightColour} = $ref; 280 | } 281 | sub SetGrayColour{ 282 | my($ref) = @_; 283 | $wxGlobals{mGrayColour} = $ref; 284 | } 285 | sub GetLightColour{ 286 | return $wxGlobals{mLightColour}; 287 | } 288 | sub GetGrayColour{ 289 | return $wxGlobals{mGrayColour}; 290 | } 291 | sub GetDigitsNeeded{ 292 | my($string) = @_; 293 | $string =~ s/\.//g; 294 | return strlen($string); 295 | } 296 | -------------------------------------------------------------------------------- /LM3.pl: -------------------------------------------------------------------------------- 1 | #! /home/pete/CitrusPerl/perl/bin/perl 2 | 3 | # LM3.pl - wxPerl Process Control Example 4 | # uses the LinearMeter3.pm modular meter 5 | # 6 | # Last modified by James M. Lynes, Jr - January 30,2013 7 | # 8 | # Draws and animates 8 Linear Meters, uses LinearMeter3.pm 9 | # Meters change green/red to indicate limit violations 10 | # Creates a 1 second timer to update the animation 11 | # Left click selects/deselects the meter and sets the border to yellow/blue 12 | # Right click on a selected meter pops a limit change dialog 13 | # Right click on a deselected meter pops an error messsage box 14 | # Multiple meters may be selected at the same time - may want to limit 15 | # this in the future. 16 | # 17 | # The panel is created 40 units longer than the meter to allow space 18 | # for drawing the meter label 19 | # 20 | 21 | package main; 22 | use strict; 23 | use warnings; 24 | my $app = App->new(); 25 | $app->MainLoop; 26 | 27 | package App; 28 | use strict; 29 | use warnings; 30 | use base 'Wx::App'; 31 | sub OnInit { 32 | my $frame = Frame->new(); 33 | $frame->Show(1); 34 | } 35 | 36 | package Frame; 37 | use strict; 38 | use warnings; 39 | use Wx qw(:everything); 40 | use base qw(Wx::Frame); 41 | use LinearMeter3; 42 | use Data::Dumper; 43 | use Wx::Event qw(EVT_PAINT EVT_TIMER EVT_LEFT_DOWN EVT_RIGHT_DOWN); 44 | 45 | sub new { 46 | my ($self) = @_; 47 | my($meters, $width, $height) = (8, 100, 550); 48 | $self = $self->SUPER::new(undef, -1, "wxPerl Process Control Example", wxDefaultPosition, 49 | [(($meters)+1)*10+20 + (($meters)*$width),($height+90)]); 50 | my $font = Wx::Font->new(12, wxFONTFAMILY_SWISS, wxNORMAL, wxBOLD); 51 | $self->SetFont($font); 52 | Wx::StaticText->new($self, -1, "Boiler 1", [190, 15], wxDefaultSize, wxALIGN_LEFT); 53 | Wx::StaticText->new($self, -1, "Boiler 2", [650, 15], wxDefaultSize, wxALIGN_LEFT); 54 | 55 | # Create 8 panels to hold 8 meters - single row layout 56 | $self->{MP1} = Wx::Panel->new($self, wxID_ANY, [10 ,40], [$width, $height+40]); 57 | $self->{MP2} = Wx::Panel->new($self, wxID_ANY, [($width*1)+20 ,40], [$width, $height+40]); 58 | $self->{MP3} = Wx::Panel->new($self, wxID_ANY, [($width*2)+30 ,40], [$width, $height+40]); 59 | $self->{MP4} = Wx::Panel->new($self, wxID_ANY, [($width*3)+40 ,40], [$width, $height+40]); 60 | $self->{MP5} = Wx::Panel->new($self, wxID_ANY, [($width*4)+70 ,40], [$width, $height+40]); 61 | $self->{MP6} = Wx::Panel->new($self, wxID_ANY, [($width*5)+80 ,40], [$width, $height+40]); 62 | $self->{MP7} = Wx::Panel->new($self, wxID_ANY, [($width*6)+90 ,40], [$width, $height+40]); 63 | $self->{MP8} = Wx::Panel->new($self, wxID_ANY, [($width*7)+100 ,40], [$width, $height+40]); 64 | 65 | # Create 8 meter objects - Override some default values 66 | $self->{LM1} = LinearMeter->new(); 67 | $self->{LM1}->InitialValue(73); 68 | $self->{LM1}->Limit(76); 69 | $self->{LM1}->Label("Temp 1"); 70 | $self->{LM1}->MeterHeight($height); 71 | $self->{LM1}->MeterWidth($width); 72 | $self->{LM2} = LinearMeter->new(); 73 | $self->{LM2}->InitialValue(28); 74 | $self->{LM2}->Limit(31); 75 | $self->{LM2}->Label("Flow 1"); 76 | $self->{LM2}->MeterHeight($height); 77 | $self->{LM2}->MeterWidth($width); 78 | $self->{LM3} = LinearMeter->new(); 79 | $self->{LM3}->InitialValue(42); 80 | $self->{LM3}->Limit(46); 81 | $self->{LM3}->Label("Pressure 1"); 82 | $self->{LM3}->MeterHeight($height); 83 | $self->{LM3}->MeterWidth($width); 84 | $self->{LM4} = LinearMeter->new(); 85 | $self->{LM4}->InitialValue(62); 86 | $self->{LM4}->Limit(66); 87 | $self->{LM4}->Label("Level 1"); 88 | $self->{LM4}->MeterHeight($height); 89 | $self->{LM4}->MeterWidth($width); 90 | $self->{LM5} = LinearMeter->new(); 91 | $self->{LM5}->InitialValue(24); 92 | $self->{LM5}->Limit(28); 93 | $self->{LM5}->Label("Temp 2"); 94 | $self->{LM5}->MeterHeight($height); 95 | $self->{LM5}->MeterWidth($width); 96 | $self->{LM6} = LinearMeter->new(); 97 | $self->{LM6}->InitialValue(63); 98 | $self->{LM6}->Limit(66); 99 | $self->{LM6}->Label("Flow 2"); 100 | $self->{LM6}->MeterHeight($height); 101 | $self->{LM6}->MeterWidth($width); 102 | $self->{LM7} = LinearMeter->new(); 103 | $self->{LM7}->InitialValue(33); 104 | $self->{LM7}->Limit(37); 105 | $self->{LM7}->Label("Pressure 2"); 106 | $self->{LM7}->MeterHeight($height); 107 | $self->{LM7}->MeterWidth($width); 108 | $self->{LM8} = LinearMeter->new(); 109 | $self->{LM8}->InitialValue(81); 110 | $self->{LM8}->Limit(85); 111 | $self->{LM8}->Label("Level 2"); 112 | $self->{LM8}->MeterHeight($height); 113 | $self->{LM8}->MeterWidth($width); 114 | # 115 | # Set up Event Handlers ------------------------------------------------------- 116 | # 117 | # Timer 118 | my $timer = Wx::Timer->new( $self ); 119 | $timer->Start( 1000 ); # 1 second period 120 | EVT_TIMER($self, -1, \&onTimer); 121 | # Paint 122 | EVT_PAINT($self, \&onPaint); 123 | # Mouse 124 | EVT_LEFT_DOWN($self->{MP1}, sub{$self->_evt_left_down( $self->{LM1}, @_);}); 125 | EVT_LEFT_DOWN($self->{MP2}, sub{$self->_evt_left_down( $self->{LM2}, @_);}); 126 | EVT_LEFT_DOWN($self->{MP3}, sub{$self->_evt_left_down( $self->{LM3}, @_);}); 127 | EVT_LEFT_DOWN($self->{MP4}, sub{$self->_evt_left_down( $self->{LM4}, @_);}); 128 | EVT_LEFT_DOWN($self->{MP5}, sub{$self->_evt_left_down( $self->{LM5}, @_);}); 129 | EVT_LEFT_DOWN($self->{MP6}, sub{$self->_evt_left_down( $self->{LM6}, @_);}); 130 | EVT_LEFT_DOWN($self->{MP7}, sub{$self->_evt_left_down( $self->{LM7}, @_);}); 131 | EVT_LEFT_DOWN($self->{MP8}, sub{$self->_evt_left_down( $self->{LM8}, @_);}); 132 | 133 | EVT_RIGHT_DOWN($self->{MP1}, sub{$self->_evt_right_down( $self->{LM1}, @_);}); 134 | EVT_RIGHT_DOWN($self->{MP2}, sub{$self->_evt_right_down( $self->{LM2}, @_);}); 135 | EVT_RIGHT_DOWN($self->{MP3}, sub{$self->_evt_right_down( $self->{LM3}, @_);}); 136 | EVT_RIGHT_DOWN($self->{MP4}, sub{$self->_evt_right_down( $self->{LM4}, @_);}); 137 | EVT_RIGHT_DOWN($self->{MP5}, sub{$self->_evt_right_down( $self->{LM5}, @_);}); 138 | EVT_RIGHT_DOWN($self->{MP6}, sub{$self->_evt_right_down( $self->{LM6}, @_);}); 139 | EVT_RIGHT_DOWN($self->{MP7}, sub{$self->_evt_right_down( $self->{LM7}, @_);}); 140 | EVT_RIGHT_DOWN($self->{MP8}, sub{$self->_evt_right_down( $self->{LM8}, @_);}); 141 | return $self; 142 | } 143 | 1; 144 | # 145 | # Right Mouse Pressed Event - Change the Selected Meter's Limit ----------------- 146 | # 147 | sub _evt_right_down { 148 | my($frame, $meter, $panel, $event) = @_; 149 | if($meter->Selected()) { 150 | my $label = $meter->Label(); 151 | my $dialog = Wx::TextEntryDialog->new( $frame, 152 | "Select a New Limit", "Change the $label Alarm Limit", 153 | $meter->Limit()); 154 | if($dialog->ShowModal == wxID_CANCEL) { 155 | $meter->BorderColour(wxBLUE); 156 | $meter->Selected(0); 157 | return; 158 | }; 159 | $meter->Limit($dialog->GetValue()); 160 | $meter->BorderColour(wxBLUE); 161 | $meter->Selected(0); 162 | } 163 | else { 164 | my $msg = Wx::MessageBox("No Meter Selected\nLeft Click a Meter to Select", 165 | "Meter Limit Entry Error", wxICON_ERROR, $frame); 166 | } 167 | $event->Skip(1); 168 | } 169 | # 170 | # Left Mouse Pressed Event - Selects a Meter - Selection will Toggle ----------- 171 | # 172 | sub _evt_left_down { 173 | my($frame, $meter, $panel, $event) = @_; 174 | if($meter->Selected()) { 175 | $meter->BorderColour(wxBLUE); 176 | $meter->Selected(0); 177 | } 178 | else { 179 | $meter->BorderColour(Wx::Colour->new("yellow")); 180 | $meter->Selected(1); 181 | } 182 | $event->Skip(1); 183 | } 184 | 185 | # Simple version of Event Handler Closure 186 | # More complex version fits better for this application 187 | # EVT_LEFT_DOWN($self->{MP1}, sub{ 188 | # my($panel, $event) = @_; 189 | # $self->{LM1}->BordorColour(Wx::Colour->new("yellow")); 190 | # $event->Skip(1); 191 | # }); 192 | 193 | # 194 | # 1 second timer to simulate meter movement --------------------------------- 195 | # 196 | sub onTimer { 197 | my($self, $event) = @_; 198 | # Randomize for each meter 199 | # for a more natural look 200 | my $dir = (rand 10) < 5 ? -1 : 1; 201 | my $inc = (rand 1) * $dir; 202 | $self->{LM1}->InitialValue($self->{LM1}->InitialValue() + $inc); 203 | LinearMeter->Draw($self->{MP1}, $self->{LM1}); 204 | 205 | $dir = (rand 10) < 5 ? -1 : 1; 206 | $inc = (rand 1) * $dir; 207 | $self->{LM2}->InitialValue($self->{LM2}->InitialValue() + $inc); 208 | LinearMeter->Draw($self->{MP2}, $self->{LM2}); 209 | 210 | $dir = (rand 10) < 5 ? -1 : 1; 211 | $inc = (rand 1) * $dir; 212 | $self->{LM3}->InitialValue($self->{LM3}->InitialValue() + $inc); 213 | LinearMeter->Draw($self->{MP3}, $self->{LM3}); 214 | 215 | $dir = (rand 10) < 5 ? -1 : 1; 216 | $inc = (rand 1) * $dir; 217 | $self->{LM4}->InitialValue($self->{LM4}->InitialValue() + $inc); 218 | LinearMeter->Draw($self->{MP4}, $self->{LM4}); 219 | 220 | $dir = (rand 10) < 5 ? -1 : 1; 221 | $inc = (rand 1) * $dir; 222 | $self->{LM5}->InitialValue($self->{LM5}->InitialValue() + $inc); 223 | LinearMeter->Draw($self->{MP5}, $self->{LM5}); 224 | 225 | $dir = (rand 10) < 5 ? -1 : 1; 226 | $inc = (rand 1) * $dir; 227 | $self->{LM6}->InitialValue($self->{LM6}->InitialValue() + $inc); 228 | LinearMeter->Draw($self->{MP6}, $self->{LM6}); 229 | 230 | $dir = (rand 10) < 5 ? -1 : 1; 231 | $inc = (rand 1) * $dir; 232 | $self->{LM7}->InitialValue($self->{LM7}->InitialValue() + $inc); 233 | LinearMeter->Draw($self->{MP7}, $self->{LM7}); 234 | 235 | $dir = (rand 10) < 5 ? -1 : 1; 236 | $inc = (rand 1) * $dir; 237 | $self->{LM8}->InitialValue($self->{LM8}->InitialValue() + $inc); 238 | LinearMeter->Draw($self->{MP8}, $self->{LM8}); 239 | } 240 | # 241 | # Paint the Meters --------------------------------------------------------------------- 242 | # 243 | sub onPaint { 244 | my($self, $event) = @_; 245 | # Draw the 8 meters 246 | LinearMeter->Draw($self->{MP1}, $self->{LM1}); 247 | LinearMeter->Draw($self->{MP2}, $self->{LM2}); 248 | LinearMeter->Draw($self->{MP3}, $self->{LM3}); 249 | LinearMeter->Draw($self->{MP4}, $self->{LM4}); 250 | LinearMeter->Draw($self->{MP5}, $self->{LM5}); 251 | LinearMeter->Draw($self->{MP6}, $self->{LM6}); 252 | LinearMeter->Draw($self->{MP7}, $self->{LM7}); 253 | LinearMeter->Draw($self->{MP8}, $self->{LM8}); 254 | } 255 | 256 | -------------------------------------------------------------------------------- /LinearMeter.pl: -------------------------------------------------------------------------------- 1 | #! /home/pete/CitrusPerl/perl/bin/perl 2 | # 3 | # LinearMeter.pl 4 | # This script draws a simulated linear panel meter. 5 | # Meter can be configured to be verticle or horizontal 6 | # 7 | # Move mouse up/down to change the displayed value on verticle meter 8 | # (or left/right if reconfigured for horizontal meter) 9 | # 10 | # Written in wxPerl. Tested on Citrus Perl 5.16 with wxWidgets 2.8.x. 11 | # Ported by: James M. Lynes. Jr. 12 | # Last Modified Date: January 21, 2013 13 | # 14 | # Adapted from LinearMeter.cpp by Marco Cavallini 15 | # based in part(mostly) on the work of 16 | # the KWIC project (http://www.koansoftware.com/kwic/index.htm). 17 | # Referenced on pg 596 of the "Wx Book" - 18 | # "Cross-Platform GUI Programming with wxWidgets", Smart, Hock, & Csomor 19 | # 20 | # Added high-limit/alarm processing- red/green color change 21 | # Added animation 22 | # Added label display at bottom of meter 23 | # Set an initial value, high-limit, and tic array 24 | # 25 | # 26 | use 5.010; 27 | use strict; 28 | use warnings; 29 | use Wx qw(:everything :allclasses); 30 | use Wx::Event qw( EVT_PAINT EVT_ERASE_BACKGROUND EVT_MOTION ); 31 | # 32 | # Configuration Data ------------------------------------------------------------------ 33 | # 34 | my $MeterHeight = 400; # Swap these for horizontal display 35 | my $MeterWidth = 100; 36 | my $ActiveBar = wxGREEN; 37 | my $PassiveBar = wxWHITE; 38 | my $ValueColour = wxBLACK; 39 | my $BorderColour = wxBLUE; 40 | my $LimitColour = wxBLACK; 41 | my $AlarmLimitColour = wxRED; 42 | my $TagsColour = wxBLACK; 43 | 44 | my $ScaledValue = 0; 45 | my $RealVal = 0; 46 | my $Limit = 75; # High-Limit setpoint 47 | my @TagsVal; 48 | my $TagsNum = 0; 49 | my $StartTag = 0; 50 | my $NumTags = 10; 51 | my $IncTag = 10; 52 | my $Max = 100; # Span 53 | my $Min = 0; 54 | my $ramp = 45; # Initial value displayed 55 | my $lastpos = 0; # Last mouse position 56 | 57 | my $DirHorizFlag = 0; # 0-Verticle, 1-Horizontal 58 | my $ShowCurrent = 1; 59 | my $ShowLimits = 0; 60 | my $ShowLabel = 1; 61 | my $Font = Wx::Font->new(10, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL); 62 | my $Label = "Temp degC"; 63 | # 64 | # Main Application ----------------------------------------------------------------------- 65 | # 66 | my $app = Wx::SimpleApp->new; 67 | my $frame = Wx::Frame->new(undef, -1, "", 68 | [600,200], [$MeterWidth, $MeterHeight]); 69 | EVT_PAINT( $frame, \&onPaint ); 70 | EVT_ERASE_BACKGROUND( $frame, \&onEraseBackground ); 71 | EVT_MOTION( $frame, \&onMotion ); 72 | $frame->Show; 73 | $app->MainLoop; 74 | # 75 | # Dismiss an erase background event ----------------------------------------------------- 76 | # 77 | sub onEraseBackground { 78 | my($self, $event) = @_; 79 | $event->Skip(); 80 | } 81 | # 82 | # Paint the simulated LCD Display ---------------------------------------------------------- 83 | # 84 | sub onPaint { 85 | my($self, $event) = @_; 86 | my $dc = Wx::PaintDC->new($self); 87 | my $memdc = Wx::MemoryDC->new(); 88 | $memdc->SelectObject(Wx::Bitmap->new($MeterWidth, $MeterHeight)); 89 | my($w, $h) = $memdc->GetSizeWH(); 90 | my $brush = Wx::Brush->new($PassiveBar, wxSOLID); 91 | $memdc->SetBackground($brush); 92 | $memdc->Clear(); 93 | SetUp($memdc); # Set the initial value and tic marks 94 | my $pen = Wx::Pen->new($BorderColour, 2, wxSOLID); 95 | $memdc->SetPen($pen); 96 | $memdc->DrawRectangle(0, 0, $w, $h); 97 | $pen = Wx::Pen->new($BorderColour, 2, wxSOLID); 98 | $memdc->SetPen($pen); 99 | $brush = Wx::Brush->new($ActiveBar, wxSOLID); 100 | if($RealVal > $Limit) {$brush = Wx::Brush->new($AlarmLimitColour, wxSOLID)} 101 | $memdc->SetBrush($brush); 102 | my $yPoint; 103 | my $rectHeight; 104 | if($DirHorizFlag) { # Horizontal Orientation 105 | $memdc->DrawRectangle(1, 1, $ScaledValue, $h-2); 106 | } 107 | else { # Verticle Orientation 108 | $yPoint = $h - $ScaledValue; 109 | if($ScaledValue == 0) { 110 | $rectHeight = $ScaledValue; 111 | } 112 | else { 113 | if($RealVal == $Max) { 114 | $rectHeight = $ScaledValue; 115 | $yPoint -= 1; 116 | } 117 | else { 118 | $rectHeight = $ScaledValue - 1; 119 | } 120 | $memdc->DrawRectangle(1, $yPoint, $w-2, $rectHeight); 121 | } 122 | } 123 | if($ShowCurrent) {DrawCurrent($memdc)} 124 | if($ShowLimits) {DrawLimits($memdc)} 125 | if($TagsNum > 0) {DrawTags($memdc)} 126 | if($ShowLabel) {DrawLabel($memdc)} 127 | $dc->Blit(0, 0, $w, $h, $memdc, 0, 0); 128 | } 129 | sub onMotion { # Change the setpoint value and redraw 130 | my($self, $event) = @_; 131 | my $y = $event->GetPosition->y; # Current mouse position, swap to (x) for horz 132 | if($y > $lastpos) {$ramp -= 1; $lastpos = $y} # Mouse down, decrement needle, swap (x/+=)for horz 133 | if($y < $lastpos) {$ramp += 1; $lastpos = $y} # Mouse up, increment needle, swap(x/-=) for horz 134 | if($ramp >= $Max) {$ramp = $Max;} # Clamp to max range 135 | if($ramp <= $Min) {$ramp = $Min;} # Clamp to min range 136 | $self->Refresh; 137 | $self->Update; 138 | } 139 | sub SetUp { # Set and update the displayed value 140 | my($dc) = @_; 141 | SetValue($dc, $ramp); 142 | if($TagsNum == 0) { # Build tic marks 1st time through 143 | for($StartTag..$NumTags) { # Quick and dirty 144 | AddTag($_ * $IncTag); 145 | } 146 | } 147 | } 148 | sub DrawCurrent { # Draw the current value as text 149 | my($dc) = @_; 150 | my($w, $h) = $dc->GetSizeWH(); 151 | my $valuetext = sprintf("%d", $RealVal); 152 | my ($tw, $th) = $dc->GetTextExtent($valuetext); 153 | $dc->SetTextForeground($ValueColour); 154 | $dc->DrawText($valuetext, $w/2-$tw/2, $h/2-$th/2); 155 | } 156 | sub DrawLimits { # Draw Min and Max as text 157 | my($dc) = @_; 158 | my($w, $h) = $dc->GetSizeWH(); 159 | $dc->SetFont($Font); 160 | $dc->SetTextForeground($LimitColour); 161 | if($DirHorizFlag) { 162 | my $valuetext = sprintf("%d", $Min); 163 | my ($tw, $th) = $dc->GetTextExtent($valuetext); 164 | $dc->DrawText($valuetext, 5, $h/2-$th/2); 165 | $valuetext = sprintf("%d", $Max); 166 | ($tw, $th) = $dc->GetTextExtent($valuetext); 167 | $dc->DrawText($valuetext, $w-$tw-5, $h/2-$th/2); 168 | } 169 | else { 170 | my $valuetext = sprintf("%d", $Min); 171 | my ($tw, $th) = $dc->GetTextExtent($valuetext); 172 | $dc->DrawText($valuetext, $w/2-$tw/2, $h-$th-5); 173 | $valuetext = sprintf("%d", $Max); 174 | ($tw, $th) = $dc->GetTextExtent($valuetext); 175 | $dc->DrawText($valuetext, $w/2-$tw/2, 5); 176 | } 177 | } 178 | sub DrawTags { # Draw tic marks and labels 179 | my($dc, $Value) = @_; 180 | my($w, $h) = $dc->GetSizeWH(); 181 | my $tcoeff; 182 | if($DirHorizFlag) { 183 | $tcoeff = ($w-2)/($Max-$Min); 184 | } 185 | else { 186 | $tcoeff = ($h-2)/($Max-$Min); 187 | } 188 | my $pen = Wx::Pen->new($TagsColour, 1, wxSOLID); 189 | $dc->SetPen($pen); 190 | my $brush = Wx::Brush->new($TagsColour, wxSOLID); 191 | $dc->SetBrush($brush); 192 | $dc->SetTextForeground($TagsColour); 193 | my $tag = 0; 194 | while($tag < $TagsNum) { 195 | my $scalval = ($TagsVal[$tag]-$Min) * $tcoeff; 196 | my $textvalue = sprintf("%d", $TagsVal[$tag]); 197 | if($DirHorizFlag) { 198 | $dc->DrawLine($scalval+1, $h-2, $scalval+1, $h-10); 199 | my($tw, $th) = $dc->GetTextExtent($textvalue); 200 | $dc->DrawText($textvalue, $scalval+1-($tw/2), $h-10-$th); 201 | } 202 | else { 203 | $dc->DrawLine($w-2, $h-$scalval+1, $w-10, $h-$scalval); 204 | my($tw, $th) = $dc->GetTextExtent($textvalue); 205 | $dc->DrawText($textvalue, $w-10-$tw, $h-$scalval-($th/2)); 206 | } 207 | $tag++; 208 | } 209 | } 210 | sub AddTag { # Add a tic mark to array 211 | my($val) = @_; 212 | push(@TagsVal, $val); 213 | $TagsNum = @TagsVal; 214 | } 215 | sub SetValue { # Scale the value for display 216 | my($dc, $Value) = @_; 217 | my($w, $h) = $dc->GetSizeWH(); 218 | my $coeff; 219 | if($DirHorizFlag) { 220 | $coeff = ($w-2)/($Max-$Min); 221 | } 222 | else { 223 | $coeff = ($h-2)/($Max-$Min); 224 | } 225 | $ScaledValue = (($Value-$Min) * $coeff); 226 | $RealVal = $Value; 227 | } 228 | sub DrawLabel { # Draw a label at bottom of meter 229 | my($dc) = @_; 230 | my($w, $h) = $dc->GetSizeWH(); 231 | my @te = $dc->GetTextExtent($Label); 232 | my $x = ($w-$te[0])/2; 233 | $dc->DrawText($Label, $x, $h-20); 234 | } 235 | -------------------------------------------------------------------------------- /LinearMeter3.pm: -------------------------------------------------------------------------------- 1 | # LinearMeter3.pm - Linear Meter Object 2 | # 3 | # Last modified by James M. Lynes, Jr - January 30,2013 4 | # 5 | # Creates a Linear Panel Meter 6 | # Can be drawn vertical or horizontal 7 | # Modified LinearMeter.pl into an object that can be used to create multiple meters 8 | # Adapted from LinearMeter.cpp by Marco Cavallini 9 | # based in part(mostly) on the work of 10 | # the KWIC project (http://www.koansoftware.com/kwic/index.htm). 11 | # Referenced on pg 596 of the "Wx Book" - 12 | # "Cross-Platform GUI Programming with wxWidgets", Smart, Hock, & Csomor 13 | # 14 | # Added high-limit/alarm processing- red/green color change 15 | # Added label display between the bottom of the meter and the bottom of the panel 16 | # Set an initial value, high-limit, and tic array 17 | # Added DrawLimitBar to draw a tic mark at the current limit value 18 | # Deleted drawing the 1st and last tags to reduce crowding of the display 19 | # Added a "Selected" flag 20 | # Driver program implements mouse events for limit modification 21 | # and timer event to drive the animation. 22 | # 23 | # To-Do: Rework meter so that a wider border can be drawn. PANEL(BORDER(METER)) 24 | # Currently the border draws on top of the meter space. 25 | 26 | package LinearMeter; 27 | use strict; 28 | use warnings; 29 | use Wx qw(:everything); 30 | use Data::Dumper; 31 | # 32 | # Define the meter object hash ------------------------------------------------ 33 | # 34 | sub new { 35 | my $self = {}; 36 | $self->{METERHEIGHT} = 300; # Swap these for horizontal display 37 | $self->{METERWIDTH} = 100; 38 | $self->{ACTIVEBAR} = wxGREEN; 39 | $self->{PASSIVEBAR} = wxWHITE; 40 | $self->{VALUECOLOUR} = wxBLACK; 41 | $self->{BORDERCOLOUR} = wxBLUE; 42 | $self->{LIMITCOLOUR} = wxBLACK; 43 | $self->{ALARMLIMITCOLOUR} = wxRED; 44 | $self->{TAGSCOLOUR} = wxBLACK; 45 | $self->{SCALEDVALUE} = 0; 46 | $self->{REALVAL} = 0; 47 | $self->{LIMIT} = 75; # High-Limit setpoint 48 | $self->{TAGSVAL} = []; 49 | $self->{TAGSNUM} = 0; 50 | $self->{STARTTAG} = 0; 51 | $self->{NUMTAGS} = 10; 52 | $self->{INCTAG} = 10; 53 | $self->{MAX} = 100; # Span 54 | $self->{MIN} = 0; 55 | $self->{INITIALVALUE} = 0; # Initial value displayed 56 | $self->{LASTPOS} = 0; # Last mouse position 57 | $self->{DIRHORIZFLAG} = 0; # 0-Verticle, 1-Horizontal 58 | $self->{SHOWCURRENT} = 1; 59 | $self->{SHOWLIMITS} = 1; 60 | $self->{SHOWLABEL} = 1; 61 | $self->{FONT} = Wx::Font->new(8, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL); 62 | $self->{LABEL} = ""; 63 | $self->{SELECTED} = 0; 64 | bless($self); 65 | return $self; 66 | } 67 | # 68 | # Draw the Linear Meter ---------------------------------------------------------- 69 | # 70 | sub Draw { 71 | my($class, $panel, $Meter) = @_; 72 | my $dc = Wx::PaintDC->new($panel); 73 | my $memdc = Wx::MemoryDC->new(); 74 | $memdc->SelectObject(Wx::Bitmap->new($Meter->MeterWidth(), $Meter->MeterHeight())); 75 | my($w, $h) = $memdc->GetSizeWH(); 76 | my $brush = Wx::Brush->new($Meter->PassiveBar(), wxSOLID); 77 | $memdc->SetBackground($brush); 78 | $memdc->Clear(); 79 | SetUp($memdc, $Meter); # Set the initial value and tic marks 80 | my $pen = Wx::Pen->new($Meter->BorderColour(), 3, wxSOLID); 81 | $memdc->SetPen($pen); 82 | $memdc->DrawRectangle(0, 0, $w, $h); 83 | $pen = Wx::Pen->new($Meter->BorderColour(), 3, wxSOLID); 84 | $memdc->SetPen($pen); 85 | $brush = Wx::Brush->new($Meter->ActiveBar(), wxSOLID); 86 | if($Meter->RealVal() > $Meter->Limit()) {$brush = Wx::Brush->new($Meter->AlarmLimitColour(), wxSOLID)} 87 | $memdc->SetBrush($brush); 88 | my $yPoint; 89 | my $rectHeight; 90 | if($Meter->DirHorizFlag()) { # Horizontal Orientation 91 | $memdc->DrawRectangle(1, 1, $Meter->ScaledValue(), $h-2); 92 | } 93 | else { # Verticle Orientation 94 | $yPoint = $h - $Meter->ScaledValue(); 95 | if($Meter->ScaledValue() == 0) { 96 | $rectHeight = $Meter->ScaledValue(); 97 | } 98 | else { 99 | if($Meter->RealVal() == $Meter->Max()) { 100 | $rectHeight = $Meter->ScaledValue(); 101 | $yPoint -= 1; 102 | } 103 | else { 104 | $rectHeight = $Meter->ScaledValue() - 1; 105 | } 106 | $memdc->DrawRectangle(1, $yPoint, $w-2, $rectHeight); 107 | } 108 | } 109 | if($Meter->ShowCurrent()) {DrawCurrent($memdc, $Meter)} 110 | if($Meter->ShowLimits()) {DrawLimits($memdc, $Meter)} 111 | if($Meter->TagsNum() > 0) {DrawTags($memdc, $Meter)} 112 | $dc->Blit(0, 0, $w, $h, $memdc, 0, 0); # Keep blit above DrawLabel call 113 | if($Meter->ShowLabel()) {DrawLabel($dc, $Meter)} # <---- 114 | } 115 | sub SetUp { # Set and update the displayed value 116 | my($dc, $Meter) = @_; 117 | SetValue($dc, $Meter->InitialValue(), $Meter); 118 | 119 | if($Meter->TagsNum() == 0) { # Build tic marks 1st time through 120 | for($Meter->StartTag()..$Meter->NumTags()) { # Quick and dirty 121 | AddTag($_ * $Meter->IncTag(), $Meter); 122 | } 123 | } 124 | } 125 | sub DrawCurrent { # Draw the current value as text 126 | my($dc, $Meter) = @_; 127 | my($w, $h) = $dc->GetSizeWH(); 128 | my $valuetext = sprintf("%d", $Meter->RealVal()); 129 | my ($tw, $th) = $dc->GetTextExtent($valuetext); 130 | $dc->SetTextForeground($Meter->ValueColour()); 131 | $dc->SetFont($Meter->Font()); 132 | $dc->DrawText($valuetext, $w/2-$tw/2, $h/2-$th/2); 133 | } 134 | sub DrawLimits { # Draw Min and Max as text 135 | my($dc, $Meter) = @_; 136 | my($w, $h) = $dc->GetSizeWH(); 137 | $dc->SetFont($Meter->Font()); 138 | $dc->SetTextForeground($Meter->LimitColour()); 139 | if($Meter->DirHorizFlag()) { 140 | my $valuetext = sprintf("%d", $Meter->Min()); 141 | my ($tw, $th) = $dc->GetTextExtent($valuetext); 142 | $dc->DrawText($valuetext, 5, $h/2-$th/2); 143 | $valuetext = sprintf("%d", $Meter->Max()); 144 | ($tw, $th) = $dc->GetTextExtent($valuetext); 145 | $dc->DrawText($valuetext, $w-$tw-5, $h/2-$th/2); 146 | } 147 | else { 148 | my $valuetext = sprintf("%d", $Meter->Min()); 149 | my ($tw, $th) = $dc->GetTextExtent($valuetext); 150 | $dc->DrawText($valuetext, $w/2-$tw/2, $h-$th-5); 151 | $valuetext = sprintf("%d", $Meter->Max()); 152 | ($tw, $th) = $dc->GetTextExtent($valuetext); 153 | $dc->DrawText($valuetext, $w/2-$tw/2, 5); 154 | } 155 | } 156 | sub DrawTags { # Draw tic marks and labels 157 | my($dc, $Meter) = @_; 158 | my($w, $h) = $dc->GetSizeWH(); 159 | my $tcoeff; 160 | if($Meter->DirHorizFlag()) { 161 | $tcoeff = ($w-2)/($Meter->Max()-$Meter->Min()); 162 | } 163 | else { 164 | $tcoeff = ($h-2)/($Meter->Max()-$Meter->Min()); 165 | } 166 | my $pen = Wx::Pen->new($Meter->TagsColour(), 1, wxSOLID); 167 | $dc->SetPen($pen); 168 | my $brush = Wx::Brush->new($Meter->TagsColour(), wxSOLID); 169 | $dc->SetBrush($brush); 170 | $dc->SetTextForeground($Meter->TagsColour()); 171 | my $tag = 1; 172 | while($tag < ($Meter->TagsNum()-1)) { 173 | my $scalval = (${$Meter->TagsVal()}[$tag]-$Meter->Min()) * $tcoeff; 174 | my $textvalue = sprintf("%d", ${$Meter->TagsVal()}[$tag]); 175 | if($Meter->DirHorizFlag()) { 176 | $dc->DrawLine($scalval+1, $h-2, $scalval+1, $h-10); 177 | my($tw, $th) = $dc->GetTextExtent($textvalue); 178 | $dc->DrawText($textvalue, $scalval+1-($tw/2), $h-10-$th); 179 | } 180 | else { 181 | $dc->DrawLine($w-2, $h-$scalval-1, $w-10, $h-$scalval-1); 182 | my($tw, $th) = $dc->GetTextExtent($textvalue); 183 | $dc->DrawText($textvalue, $w-10-$tw, $h-$scalval-($th/2)); 184 | } 185 | $tag++; 186 | } 187 | DrawLimitBar($dc, $Meter); 188 | } 189 | sub DrawLimitBar { # Draw small bar at limit setting 190 | my($dc, $Meter) = @_; 191 | my($w, $h) = $dc->GetSizeWH(); 192 | my $tcoeff; 193 | if($Meter->DirHorizFlag()) { 194 | $tcoeff = ($w-2)/($Meter->Max()-$Meter->Min()); 195 | } 196 | else { 197 | $tcoeff = ($h-2)/($Meter->Max()-$Meter->Min()); 198 | } 199 | 200 | my $pen = Wx::Pen->new(Wx::Colour->new("orange"), 3, wxSOLID); 201 | $dc->SetPen($pen); 202 | my $brush = Wx::Brush->new($Meter->TagsColour(), wxSOLID); 203 | $dc->SetBrush($brush); 204 | $dc->SetTextForeground($Meter->TagsColour()); 205 | 206 | my $scalval = ($Meter->Limit()-$Meter->Min()) * $tcoeff; 207 | if($Meter->DirHorizFlag()) { 208 | $dc->DrawLine($scalval+1, $h-2, $scalval+1, $h-20); 209 | } 210 | else { 211 | $dc->DrawLine($w-2, $h-$scalval, $w-20, $h-$scalval); 212 | } 213 | } 214 | sub AddTag { # Add a tic mark to array 215 | my($val, $Meter) = @_; 216 | push(@{$Meter->TagsVal()}, $val); 217 | $Meter->TagsNum($#{$Meter->TagsVal()}+1); 218 | } 219 | sub SetValue { # Scale the value for display 220 | my($dc, $Value, $Meter) = @_; 221 | my($w, $h) = $dc->GetSizeWH(); 222 | my $coeff; 223 | if($Meter->DirHorizFlag()) { 224 | $coeff = ($w-2)/($Meter->Max()-$Meter->Min()); 225 | } 226 | else { 227 | $coeff = ($h-2)/($Meter->Max()-$Meter->Min()); 228 | } 229 | $Meter->ScaledValue(($Value-$Meter->Min()) * $coeff); 230 | $Meter->RealVal($Value); 231 | } 232 | sub DrawLabel { # Draw a label at bottom of meter 233 | my($dc, $Meter) = @_; 234 | my $memdc = Wx::MemoryDC->new(); 235 | $memdc->SelectObject(Wx::Bitmap->new($Meter->MeterWidth(), 40)); 236 | my($w, $h) = $memdc->GetSizeWH(); 237 | my $brush = Wx::Brush->new(wxLIGHT_GREY, wxSOLID); 238 | $memdc->SetBackground($brush); 239 | my $pen = Wx::Pen->new($Meter->TagsColour(), 1, wxSOLID); 240 | $memdc->SetPen($pen); 241 | $memdc->SetTextForeground($Meter->TagsColour()); 242 | $memdc->SetFont($Meter->Font()); 243 | $memdc->Clear(); 244 | my @te = $memdc->GetTextExtent($Meter->Label()); 245 | my $x = (($w-$te[0])/2)-5; 246 | $memdc->DrawText($Meter->Label(), $x, 5); 247 | $dc->Blit(0, $Meter->MeterHeight(), $w, $Meter->MeterHeight()+40, $memdc, 0, 0); 248 | } 249 | # 250 | # Object Accessors - Hand coded method --------------------------------------------- 251 | # Replace with Class::Accessor in the future 252 | # 253 | sub MeterHeight { 254 | my $self = shift; 255 | if(@_) { $self->{METERHEIGHT} = shift } 256 | return $self->{METERHEIGHT}; 257 | } 258 | sub MeterWidth { 259 | my $self = shift; 260 | if(@_) { $self->{METERWIDTH} = shift } 261 | return $self->{METERWIDTH}; 262 | } 263 | sub ActiveBar { 264 | my $self = shift; 265 | if(@_) { $self->{ACTIVEBAR} = shift } 266 | return $self->{ACTIVEBAR}; 267 | } 268 | sub PassiveBar { 269 | my $self = shift; 270 | if(@_) { $self->{PASSIVEBAR} = shift } 271 | return $self->{PASSIVEBAR}; 272 | } 273 | sub ValueColour { 274 | my $self = shift; 275 | if(@_) { $self->{VALUECOLOUR} = shift } 276 | return $self->{VALUECOLOUR}; 277 | } 278 | sub BorderColour { 279 | my $self = shift; 280 | if(@_) { $self->{BORDERCOLOUR} = shift } 281 | return $self->{BORDERCOLOUR}; 282 | } 283 | sub LimitColour { 284 | my $self = shift; 285 | if(@_) { $self->{LIMITCOLOUR} = shift } 286 | return $self->{LIMITCOLOUR}; 287 | } 288 | sub AlarmLimitColour { 289 | my $self = shift; 290 | if(@_) { $self->{ALARMLIMITCOLOUR} = shift } 291 | return $self->{ALARMLIMITCOLOUR}; 292 | } 293 | sub TagsColour { 294 | my $self = shift; 295 | if(@_) { $self->{TAGSCOLOUR} = shift } 296 | return $self->{TAGSCOLOUR}; 297 | } 298 | sub ScaledValue { 299 | my $self = shift; 300 | if(@_) { $self->{SCALEDVALUE} = shift } 301 | return $self->{SCALEDVALUE}; 302 | } 303 | sub RealVal { 304 | my $self = shift; 305 | if(@_) { $self->{REALVAL} = shift } 306 | return $self->{REALVAL}; 307 | } 308 | sub Limit { 309 | my $self = shift; 310 | if(@_) { $self->{LIMIT} = shift } 311 | return $self->{LIMIT}; 312 | } 313 | sub TagsVal { 314 | my $self = shift; 315 | if(@_) { $self->{TAGSVAL} = @_ } 316 | return $self->{TAGSVAL}; 317 | } 318 | sub TagsNum { 319 | my $self = shift; 320 | if(@_) { $self->{TAGSNUM} = shift } 321 | return $self->{TAGSNUM}; 322 | } 323 | sub StartTag { 324 | my $self = shift; 325 | if(@_) { $self->{STARTTAG} = shift } 326 | return $self->{STARTTAG}; 327 | } 328 | sub NumTags { 329 | my $self = shift; 330 | if(@_) { $self->{NUMTAGS} = shift } 331 | return $self->{NUMTAGS}; 332 | } 333 | sub IncTag { 334 | my $self = shift; 335 | if(@_) { $self->{INCTAG} = shift } 336 | return $self->{INCTAG}; 337 | } 338 | sub Max { 339 | my $self = shift; 340 | if(@_) { $self->{MAX} = shift } 341 | return $self->{MAX}; 342 | } 343 | sub Min { 344 | my $self = shift; 345 | if(@_) { $self->{MIN} = shift } 346 | return $self->{MIN}; 347 | } 348 | sub InitialValue { 349 | my $self = shift; 350 | if(@_) { $self->{INITIALVALUE} = shift } 351 | return $self->{INITIALVALUE}; 352 | } 353 | sub lastpos { 354 | my $self = shift; 355 | if(@_) { $self->{LASTPOS} = shift } 356 | return $self->{LASTPOS}; 357 | } 358 | sub DirHorizFlag { 359 | my $self = shift; 360 | if(@_) { $self->{DIRHORIZFLAG} = shift } 361 | return $self->{DIRHORIZFLAG}; 362 | } 363 | sub ShowCurrent { 364 | my $self = shift; 365 | if(@_) { $self->{SHOWCURRENT} = shift } 366 | return $self->{SHOWCURRENT}; 367 | } 368 | sub ShowLimits { 369 | my $self = shift; 370 | if(@_) { $self->{SHOWLIMITS} = shift } 371 | return $self->{SHOWLIMITS}; 372 | } 373 | sub ShowLabel { 374 | my $self = shift; 375 | if(@_) { $self->{SHOWLABEL} = shift } 376 | return $self->{SHOWLABEL}; 377 | } 378 | sub Font { 379 | my $self = shift; 380 | if(@_) { $self->{FONT} = shift } 381 | return $self->{FONT}; 382 | } 383 | sub Label { 384 | my $self = shift; 385 | if(@_) { $self->{LABEL} = shift } 386 | return $self->{LABEL}; 387 | } 388 | sub Selected { 389 | my $self = shift; 390 | if(@_) { $self->{SELECTED} = shift } 391 | return $self->{SELECTED}; 392 | } 393 | 1; 394 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | A Compilation of wxPerl Ports of the C++ Examples from "The wxBook" 2 | --------------------------------------------------------------------------------- 3 | Ported and compiled by James M. Lynes, Jr. April-May 2011 & August-September 2012. 4 | 5 | Major Modifications implemented in September 2012. Setup code for each example was 6 | greatly simplified using wx::SimpleApp as suggested by Mattia Barbon. 7 | 8 | Introduction 9 | ------------ 10 | While I have many years in real-time control system software development, I am new to 11 | Ubuntu, Perl, and wxPerl. It is probably best to not try to learn all of these at the 12 | same time, but that's where I am at. 13 | 14 | I purchased a copy of "The wxBook" - "Cross-Platform GUI Programming with wxWidgets" 15 | by Smart, Hock, & Csomar. After two complete read-throughs, I downloaded a copy of 16 | wxIndustrialControls(Appendix E - www.koansoftware.com) and began a port of their 17 | LCD Display program. I soon realized that I did not understand enough about the 18 | relationship between C++ and wxPerl to complete this port. 19 | 20 | To get past this learning curve I decided to port the C++ examples from the wxBook 21 | to wxPerl. Over 45 examples have been ported so far. Each port was kept as close 22 | to the C++ example code as possible. However, changes were made where required 23 | by differences in wxPerl syntax or implementation. Also, code 24 | was added where necessary to provide screen output of the example topic. 25 | 26 | The examples were coded to be clear to someone new to wxPerl(like myself) and it 27 | is not my desire to trade clarity for efficiency. I believe in coding for the next 28 | guy that has to maintain my code - KISS. Almost all programs deal with a single topic 29 | unlike some of the other examples available on-line. The single topic implementation 30 | should be easier for a beginner to grasp. I think this style would have shortened 31 | my learning process. An exception is CppTrial-pg086.pl which consists of 20 short 32 | Static and Non-Static Control examples. Most of these are 3-4 lines long and 33 | don't need to be discussed individually. 34 | 35 | As much as possible the setup code was kept the same from example to example. The 36 | specific example code was isolated to a subroutine in the bottom half of the 37 | program. These example code subroutines were called directly and via OnPaint and 38 | OnMotion events as necessary to generate screen output of the example results. 39 | You will notice that the setup code did evolve somewhat as the porting 40 | progressed(and has since evolved more). An example of the learning curve in action! 41 | 42 | 43 | Lessons Learned 44 | --------------- 45 | The 2300+ page wx.pdf manual is hard to use on my relatively slow Thinkpad R31. The 46 | search feature is so slow as to be unusable. So, page through the index to find your 47 | topic, add 28(+/-) to the page number, then jump directly to that page. 48 | 49 | Not all features in wxwidgets are implemented in wxPerl. Look for wxPerl specific 50 | notes in wx.pdf. A digest of all of these notes would be useful. 51 | 52 | wxwidgets features that use "wxArraySomething" will instead use a wxPerl list - @list 53 | or a list reference \@list or array syntax [x,y]. 54 | 55 | use Wx qw(:everything) doesn't really load all modules- like the Grid, HTML and Clipboard 56 | modules. Substantial time can be spent locating the module that exports the function 57 | that you need. It would be nice to have an index of all the modules and their 58 | exporters, as well as all constant definitions. Any input on this topic would be welcome. 59 | 60 | Case matters! C++ wxFunction() becomes wxPerl Wx::Function->new(). wx is not Wx. 61 | WxFunction is not Wx::Function. Typos will cause module loading errors. 62 | 63 | The PADRE debugger locks up from time to time. Save your work often. 64 | 65 | 66 | Porting Environment 67 | ------------------- 68 | All porting was done using Ubuntu 10.10, Perl 5.10.1, and the PADRE IDE. Modifications 69 | were done with gedit. 70 | 71 | 72 | RESOURCES 73 | --------- 74 | These resources were found to be useful in porting the wxBook examples. Many thanks 75 | to their authors. 76 | 77 | "Cross-Platform GUI Programming with wxWidgets" Smart, Hock, & Csomar - The "wxBook" 78 | (Buy this book! It's well worth the cost) 79 | 80 | "Learning Perl" - Schwartz, Phoenix, & d Foy 81 | 82 | "Programming Perl" - Christiansen, d Foy, Wall, & Orwant 83 | 84 | "Perl Cookbook" - Christiansen & Torkington 85 | 86 | perldoc (perldoc perltoc) - On-line Man Pages 87 | 88 | "wxWidgets 2.8.10: A Portable C++ and Python GUI Toolkit" 89 | Smart, Roebling, Zeitlin, Dunn et. al. - PDF Format (Wx.pdf) 90 | 91 | "wxWidgets 2.8.7: A Portable C++ and Python GUI Toolkit" 92 | Smart, Roebling, Zeitlin, Dunn et. al. - HTML Format(many files) 93 | 94 | Numerous Demo and Example Programs by Mattia Barbon - (Sourceforge.net) 95 | 96 | Tutorials from the Perl Monks ( 97 | www.perlmonks.org) 98 | Three by Boo Radley 99 | A Simple Socket Server Using "inetd" - Samizdat 100 | 101 | Tutorials from the wxPerl Wiki: 102 | C++ Docs for Perl Programmers 103 | WxPerl Tablet (i.e. The Cheat-sheet) 104 | Download with Progress Bar 105 | Memory DC 106 | Mini Image Demo 107 | Tiled Background Image 108 | wxPerl GUI for a Twitter Script 109 | 110 | The PADRE IDE and Included Sample Programs 111 | 112 | www.perlmonks.org 113 | 114 | wxperl.sourceforge.net 115 | 116 | wiki.wxperl.info 117 | 118 | www.wxwidgets.org 119 | 120 | www.perl.org 121 | 122 | www.nntp.perl.org/group/perl.wxperl.users/2012/ 123 | 124 | search.cpan.org 125 | 126 | And others that were read, but the references were not recorded.... 127 | 128 | Original version uploaded to www.perlmonks.org August 2012 - two large files. 129 | (This) github initial version uploaded September 2012 - separate files. 130 | 131 | I hope you find this information useful. 132 | 133 | James M. Lynes, Jr. - Lakeland, Florida September 2012 134 | 135 | 136 | -------------------------------------------------------------------------------- /ScreenCapture.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | # 3 | # Capture Screen to a file. Written in wxPerl. Tested on Citrus Perl 5.16 and wxWidgets 2.8.x. 4 | # 5 | # This script draws and captures a sample graphic. 6 | # Take_Screenshot needs to be generalized into a module 7 | # that can be used by any application. 8 | # 9 | # To capture the complete sample graphic, the frame size had to be set to the screen size 10 | # of [1024x768]. Using wxDefaultSize caused the screen to paint in two passes 11 | # and the capture to clip. 12 | # 13 | # Reference: GetScreenShot C++ code page 139 of "The wxBook" - 14 | # Cross-Platform GUI Programming with wxWidgets - 15 | # Smart, Hock, and Csomor 16 | # 17 | # Original author: "PodMaster" from Perl Monks-2003 (no idea of real identity-not active for 6+ years) 18 | # 19 | # Modified by: James M. Lynes. Jr. 20 | # Last Modified Date: October 21, 2012 21 | # 22 | # 23 | use strict; 24 | use warnings; 25 | use Wx qw(:everything); 26 | use Wx::Event qw( EVT_PAINT ); 27 | # 28 | # Main Application 29 | # 30 | my $app = Wx::SimpleApp->new; 31 | my $frame = Wx::Frame->new(undef, -1, "Screen Capture Example", [0,0], [1024,768] , wxDEFAULT_FRAME_STYLE); 32 | EVT_PAINT( $frame, \&onPaint); 33 | my $file = file_entry_dialog_standard($frame); 34 | $frame->Show; 35 | take_screenshot($frame, $file); 36 | $app->MainLoop; 37 | # 38 | # Generate a sample graphic screen to capture 39 | # 40 | sub onPaint{ 41 | my($self,$event)=@_; 42 | my $screen = Wx::PaintDC->new($self); 43 | $screen->SetBackgroundMode( wxTRANSPARENT ); 44 | $screen->SetFont(Wx::Font->new( 12, wxFONTFAMILY_ROMAN, wxNORMAL, wxBOLD)); 45 | 46 | for(0..17){ 47 | my $c = $_ * 15; 48 | 49 | $screen->SetTextForeground( Wx::Colour->newRGB(0,0,$c)); 50 | $screen->DrawRotatedText("wxPerl",100 ,100 ,$c); 51 | } 52 | $screen->DrawRotatedText("wxPerl and PodMaster",000 ,400 ,0); 53 | $screen->DrawRotatedText("are messing up your screen",000 ,450 ,0); 54 | 55 | for(0..17){ 56 | my $c = $_ * 15; 57 | 58 | $screen->SetTextForeground( Wx::Colour->newRGB(0,$c,0)); 59 | $screen->DrawRotatedText("wxPerl",200 ,200 ,$c); 60 | } 61 | $screen->DrawRotatedText("wxPerl and PodMaster",100 ,500 ,0); 62 | $screen->DrawRotatedText("are messing up your screen",100 ,550 ,0); 63 | 64 | for(0..17){ 65 | my $c = $_ * 15; 66 | 67 | $screen->SetTextForeground( Wx::Colour->newRGB($c,0,0)); 68 | $screen->DrawRotatedText("wxPerl",300 ,300 ,$c); 69 | } 70 | $screen->DrawRotatedText("wxPerl and PodMaster",200 ,600 ,0); 71 | $screen->DrawRotatedText("are messing up your screen",200 ,650 ,0); 72 | } 73 | # 74 | # Copy the screen to the output file-similar to wxBook pg 139 example. 75 | # 76 | sub take_screenshot { 77 | my($self, $file ) = @_; 78 | $self->Refresh; # without Refresh and Update 79 | $self->Update; # the underlying window is captured 80 | my $screen = Wx::ScreenDC->new(); 81 | my( $x, $y) = $screen->GetSizeWH(); 82 | my $bitmap = Wx::Bitmap->new($x,$y,-1); 83 | my $memory = Wx::MemoryDC->new(); 84 | $memory->SelectObject( $bitmap ); 85 | $memory->Blit(0,0,$x,$y, $screen, 0, 0); # copy the screen to the bitmap 86 | $bitmap->SaveFile( $file , wxBITMAP_TYPE_BMP ) ; # copy the bitmap to the output file 87 | } 88 | # 89 | # Ask for the output filename - simple text entry dialog 90 | # 91 | sub file_entry_dialog_simple { 92 | my( $self ) = @_; 93 | my $textvalue = "capture.bmp"; 94 | my $dialog = Wx::TextEntryDialog->new 95 | ( $self, "Enter the Screen Capture output filename\n(Cancel will use the default filename shown below)\n", 96 | "Screen Capture Output File Entry", 97 | $textvalue, wxOK | wxCANCEL ); 98 | if( $dialog->ShowModal == wxID_OK ) { 99 | $textvalue = $dialog->GetValue; 100 | } 101 | $dialog->Destroy; 102 | return $textvalue; 103 | } 104 | # 105 | # Ask for the output filename - standard file dialog 106 | # 107 | sub file_entry_dialog_standard { 108 | my ( $self ) = @_; 109 | my $caption = "Choose a Screen Capture Output Filename"; 110 | my $wildcard = "*.bmp"; 111 | my $defaultDir = "."; 112 | my $defaultFilename = "capture.bmp"; 113 | my $filevalue = $defaultFilename; 114 | my $fileDialog = Wx::FileDialog->new($self, $caption, $defaultDir, 115 | $defaultFilename, $wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); 116 | if ($fileDialog->ShowModal() == wxID_OK ) { 117 | $filevalue = $fileDialog->GetPath(); 118 | } 119 | $fileDialog->Destroy; 120 | return $filevalue; 121 | } 122 | -------------------------------------------------------------------------------- /WxScreenCapture.pm: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | package WxScreenCapture; 5 | use parent qw(Exporter); 6 | 7 | our @EXPORT = qw(take_screenshot file_entry_dialog_simple file_entry_dialog_standard); 8 | 9 | use Wx qw(:everything); 10 | use Wx::Event qw( EVT_PAINT ); 11 | 12 | =head2 13 | # 14 | # Copy the screen to the output file-similar to wxBook pg 139 example. 15 | # 16 | =cut 17 | sub take_screenshot { 18 | my($self, $file ) = @_; 19 | $self->Refresh; # without Refresh and Update 20 | $self->Update; # the underlying window is captured 21 | my $screen = Wx::ScreenDC->new(); 22 | my( $x, $y) = $screen->GetSizeWH(); 23 | my $bitmap = Wx::Bitmap->new($x,$y,-1); 24 | my $memory = Wx::MemoryDC->new(); 25 | $memory->SelectObject( $bitmap ); 26 | $memory->Blit(0,0,$x,$y, $screen, 0, 0); # copy the screen to the bitmap 27 | $bitmap->SaveFile( $file , wxBITMAP_TYPE_BMP ) ; # copy the bitmap to the output file 28 | } 29 | 30 | =head2 31 | # 32 | # Ask for the output filename - simple text entry dialog 33 | # 34 | =cut 35 | sub file_entry_dialog_simple { 36 | my( $self ) = @_; 37 | my $textvalue = "capture.bmp"; 38 | my $dialog = Wx::TextEntryDialog->new 39 | ( $self, "Enter the Screen Capture output filename\n(Cancel will use the default filename shown below)\n", 40 | "Screen Capture Output File Entry", 41 | $textvalue, wxOK | wxCANCEL ); 42 | if( $dialog->ShowModal == wxID_OK ) { 43 | $textvalue = $dialog->GetValue; 44 | } 45 | $dialog->Destroy; 46 | return $textvalue; 47 | } 48 | 49 | =head2 50 | # 51 | # Ask for the output filename - standard file dialog 52 | # 53 | =cut 54 | sub file_entry_dialog_standard { 55 | my ( $self ) = @_; 56 | my $caption = "Choose a Screen Capture Output Filename"; 57 | my $wildcard = "*.bmp"; 58 | my $defaultDir = "."; 59 | my $defaultFilename = "capture.bmp"; 60 | my $filevalue = $defaultFilename; 61 | my $fileDialog = Wx::FileDialog->new($self, $caption, $defaultDir, 62 | $defaultFilename, $wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); 63 | if ($fileDialog->ShowModal() == wxID_OK ) { 64 | $filevalue = $fileDialog->GetPath(); 65 | } 66 | $fileDialog->Destroy; 67 | return $filevalue; 68 | } 69 | 1; 70 | __END__ 71 | 72 | =head1 NAME 73 | 74 | WxScreenCapture.pm 75 | 76 | =head1 SYNOPSIS 77 | 78 | Module to capture a screen to a file. Written in wxPerl. 79 | 80 | =head1 DESCRIPTION 81 | 82 | This module exports three subroutines: take_screenshot, file_entry_dialog_simple, and file_entry_dialog_standard. take_screenshot uses Wx::ScreenDC and Wx::MemoryDC device contexts and a Wx::Bitmap. Blit copies the ScreenDC to the MemoryDC Bitmap which is then copied to an output file. file_entry_dialog_simple provides a text_entry_dialog for requesting the capture filename. file_entry_dialog_standard provides the full directory/file entry screen for requesting the capture pathname. 83 | 84 | If the frame you wish to capture is smaller than the full screen, the background windows will also be captured. 85 | 86 | =head1 USAGE 87 | 88 | use Wx qw(:everything); 89 | 90 | use Wx::Event qw( EVT_PAINT ); 91 | 92 | use WxScreenCapture; 93 | 94 | my $app = Wx::SimpleApp->new; 95 | 96 | my $frame = Wx::Frame->new(undef, -1, "Screen Capture Module Example", [0,0], [1024,768] , wxDEFAULT_FRAME_STYLE); 97 | 98 | EVT_PAINT( $frame, \&onPaint); 99 | 100 | my $file = file_entry_dialog_standard($frame); 101 | 102 | $frame->Show; 103 | 104 | take_screenshot($frame, $file); 105 | 106 | $app->MainLoop; 107 | 108 | sub onPaint{} #paint the screen to be captured here. 109 | 110 | =head1 AUTHOR 111 | 112 | James M. Lynes, Jr. 113 | 114 | Lakeland, Florida USA October 21,2012. 115 | 116 | Original author: "PodMaster" from Perl Monks-2003 (no idea of real identity-not active for 6+ years) 117 | 118 | =head1 BUGS/FEATURES 119 | 120 | To capture the complete sample graphic(not included in this module definition), the frame size 121 | had to be set to the screen size of [1024x768]. Using wxDefaultSize caused the screen to paint in two passes 122 | and the capture to clip. If the frame is not defined large enough, parts of underlying 123 | windows will also be captured. 124 | 125 | =head1 SEE ALSO 126 | 127 | "The wxBook" - Cross-Platform GUI Programming with wxWidgets - 128 | Smart, Hock, and Csomor 129 | 130 | The wxWidgets documentation L 131 | 132 | The Citrus Perl Distribution L 133 | 134 | =head1 LICENSE 135 | 136 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. 137 | 138 | =cut 139 | 140 | -------------------------------------------------------------------------------- /copy.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *copy_xpm[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "16 15 4 1", 5 | " c None", 6 | ". c Black", 7 | "X c Gray100", 8 | "o c #000080", 9 | /* pixels */ 10 | " ", 11 | " ...... ", 12 | " .XXXX.. ", 13 | " .XXXX.X. ", 14 | " .X..X.oooooo ", 15 | " .XXXXXoXXXXoo ", 16 | " .X....oXXXXoXo ", 17 | " .XXXXXoX..Xoooo", 18 | " .X....oXXXXXXXo", 19 | " .XXXXXoX.....Xo", 20 | " ......oXXXXXXXo", 21 | " oX.....Xo", 22 | " oXXXXXXXo", 23 | " ooooooooo", 24 | " " 25 | }; 26 | -------------------------------------------------------------------------------- /cut.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *cut_xpm[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "16 15 3 1", 5 | " c None", 6 | ". c Black", 7 | "X c #000080", 8 | /* pixels */ 9 | " ", 10 | " . . ", 11 | " . . ", 12 | " . . ", 13 | " .. .. ", 14 | " . . ", 15 | " ... ", 16 | " . ", 17 | " X.X ", 18 | " X XXX ", 19 | " XXX X X ", 20 | " X X X X ", 21 | " X X X X ", 22 | " X X XX ", 23 | " XX " 24 | }; 25 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmlynesjr/wxPerl-wxBook-Examples/ce9040f233ae0b2800511bd6a5671ef79cab440b/logo.png -------------------------------------------------------------------------------- /padre_logo_64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmlynesjr/wxPerl-wxBook-Examples/ce9040f233ae0b2800511bd6a5671ef79cab440b/padre_logo_64x64.png -------------------------------------------------------------------------------- /pg342.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | 31 | 32 |
6 |
7 |
wxHTML Library Sample 0.2.0
8 |
9 |
10 |
14 | Copyright (c) 1999 Vaclav Slavic

15 | 16 | 17 | 18 | 21 | 24 | 25 |
19 | Vaclav Slavik

20 |

22 | 23 |
26 | 27 | Licenced under wxWindows Library Licence, Version 3. 28 | 29 |
30 |

33 | 34 | 35 | -------------------------------------------------------------------------------- /print.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *print_xpm[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "16 15 5 1", 5 | " c None", 6 | ". c Black", 7 | "X c Gray100", 8 | "o c #808000", 9 | "O c Yellow", 10 | /* pixels */ 11 | " ", 12 | " ......... ", 13 | " .XXXXXXXX. ", 14 | " .X.....X. ", 15 | " .XXXXXXXX. ", 16 | " .X.....X.... ", 17 | " .XXXXXXXX. . .", 18 | " .......... . ..", 19 | ". . . .", 20 | "............. .", 21 | ". ooo . . ", 22 | ". OOO ... ", 23 | "............. . ", 24 | " . . . ", 25 | " ........... " 26 | }; 27 | -------------------------------------------------------------------------------- /test2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmlynesjr/wxPerl-wxBook-Examples/ce9040f233ae0b2800511bd6a5671ef79cab440b/test2.bmp -------------------------------------------------------------------------------- /tips.txt: -------------------------------------------------------------------------------- 1 | This is Application Tip #1... 2 | This is Application Tip #2... 3 | This is Application Tip #3... 4 | This is Application Tip #4... 5 | This is Application Tip #5... 6 | This is Application Tip #6... 7 | This is Application Tip #7... 8 | This is Application Tip #8... 9 | This is Application Tip #9... 10 | This is Application Tip #10... 11 | -------------------------------------------------------------------------------- /wxWizard.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # wxWizard.pl 4 | # Adapted from wxperl_demo.pl from the wxPerl distribution 5 | # James M. Lynes Jr. - Last Modified 1/6/2013 6 | 7 | use 5.010; 8 | use strict; 9 | use warnings; 10 | 11 | use Wx qw(:everything); 12 | use Wx::Event qw(EVT_WIZARD_PAGE_CHANGED EVT_BUTTON EVT_WIZARD_FINISHED EVT_WIZARD_CANCEL); 13 | 14 | # create the WxApplication 15 | 16 | my $app = Wx::SimpleApp->new; 17 | 18 | my $frame = Wx::Frame->new( undef, -1,'wxWizard.pl', wxDefaultPosition, wxDefaultSize ); 19 | 20 | my $panel = Wx::Panel->new($frame, -1, wxDefaultPosition, wxDefaultSize); 21 | Wx::StaticText->new($panel, -1, "WxWizard Sample Program", Wx::Point->new(100,100), 22 | Wx::Size->new(200,200), wxALIGN_CENTER); 23 | 24 | my $button = Wx::Button->new( $panel, -1, "Start Wizard", Wx::Point->new(150, 225), wxDefaultSize ); 25 | 26 | Wx::InitAllImageHandlers(); 27 | my $bmp = Wx::Bitmap->new("logo.png", wxBITMAP_TYPE_PNG); 28 | my $wizard = Wx::Wizard->new( $panel, -1, "Wizard Example", $bmp ); 29 | 30 | # first page 31 | my $page1 = Wx::WizardPageSimple->new( $wizard ); 32 | Wx::TextCtrl->new( $page1, -1, "First page", wxDefaultPosition, Wx::Size->new(200,25) ); 33 | 34 | # second page 35 | my $page2 = Wx::WizardPageSimple->new( $wizard ); 36 | Wx::TextCtrl->new( $page2, -1, "Second page", wxDefaultPosition, Wx::Size->new(200,25) ); 37 | 38 | # third page 39 | my $page3 = Wx::WizardPageSimple->new( $wizard ); 40 | Wx::TextCtrl->new( $page3, -1, "Third page", wxDefaultPosition, Wx::Size->new(200,25) ); 41 | 42 | # fourth page 43 | my $page4 = Wx::WizardPageSimple->new( $wizard ); 44 | Wx::TextCtrl->new( $page4, -1, "Fourth page", wxDefaultPosition, Wx::Size->new(200,25) ); 45 | 46 | Wx::WizardPageSimple::Chain( $page1, $page2 ); 47 | Wx::WizardPageSimple::Chain( $page2, $page3 ); 48 | Wx::WizardPageSimple::Chain( $page3, $page4 ); 49 | 50 | EVT_BUTTON( $panel, $button, sub {$wizard->RunWizard( $page1 ); } ); 51 | EVT_WIZARD_CANCEL( $panel, $wizard, sub {Wx::Wizard->Destroy();} ); 52 | EVT_WIZARD_FINISHED($panel, $wizard, sub { Wx::Wizard->Destroy(); } ); 53 | 54 | # Testing Messages comment out matching event above 55 | # EVT_WIZARD_FINISHED($panel, $wizard, sub { Wx::LogMessage( "Wizard Canceled" ); } ); 56 | # EVT_WIZARD_PAGE_CHANGED( $panel, $wizard, sub {Wx::LogMessage( "Wizard page changed" ); } ); 57 | # EVT_WIZARD_CANCEL( $panel, $wizard, sub {Wx::LogMessage( "Wizard Canceled" ); } ); 58 | 59 | $frame->Show; 60 | $app->MainLoop; 61 | --------------------------------------------------------------------------------