Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Monks:

As an aide to learning Perl and wxPerl, I ported 45 of the C++ examples from the "wxBook" -"Cross-Platform GUI Programming with wxWidgets" by Smart, Hock, & Csomar. I apologise for the delay in getting these examples posted, but Life Happens.

I hope this is useful to the community.

James

Update: More wxPerl Examples now on Github

wxPerl Digest - A Compilation of wxPerl Ports of the C++ Examples from the wxBook

---------------------------------------------------------------------------------

Ported and compiled by James M. Lynes, Jr. April - May 2011.

Introduction

------------

While I have many years in real-time control system software development, I am new to Ubuntu, Perl, and wxPerl. It is probably best to not try to learn all of these at the same time, but that's where I am at.

I purchased a copy of "The wxBook" - "Cross-Platform GUI Programming with wxWidgets" by Smart, Hock, & Csomar. After two complete read-throughs, I downloaded a copy of wxIndustrialControls(Appendix E - www.koansoftware.com) and began a port of their LCD Display program. I soon realized that I did not understand enough about the relationship between C++ and wxPerl to complete this port.

To get past this learning curve I decided to port the C++ examples from the wxBook to wxPerl. Over 45 examples have been ported so far. More ports are planned. Each port was kept as close to the C++ example code as possible. However, changes were made where required by differences in wxPerl syntax or implementation. Also, code was added where necessary to provide screen output of the example topic.

The examples were coded to be clear to someone new to wxPerl(like myself) and it is not my desire to trade clarity for efficiency. I believe in coding for the next guy that has to maintain my code - KISS. Almost all programs deal with a single topic unlike some of the other examples available on-line. The single topic implementation should be easier for a beginner to grasp. I think this style would have shortened my learning process. An exception is CppTrial-pg086.pl which consists of 20 short Static and Non-Static Control examples. Most of these are 3-4 lines long and don't need to be discussed individually.

As much as possible the setup code was kept the same from example to example. The specific example code was isolated to a subroutine in the bottom half of the program. These example code subroutines were called directly and via OnPaint and OnMotion events as necessary to generate screen output of the example results. You will notice that the setup code did evolve somewhat as the porting progressed. An example of the learning curve in action!

Lessons Learned

---------------

The 2300+ page wx.pdf manual is hard to use on my relatively slow Thinkpad R31. The search feature is so slow as to be unusable. So, page through the index to find your topic, add 28 to the page number, then jump directly to that page.

Not all features in wxwidgets are implemented in wxPerl. Look for wxPerl specific notes in wx.pdf. A digest of all of these notes would be useful.

wxwidgets features that use "wxArraySomething" will instead use a wxPerl list - @list or a list reference \@list or array syntax x,y.

use Wx qw(:everything) doesn't really load all modules- like the Grid, HTML and Clipboard modules. Substantial time can be spent locating the module that exports the function that you need. It would be nice to have a directory of all the modules and their exporters, as well as all constant definitions.

Case matters! C++ wxFunction() becomes wxPerl Wx::Function->new(). wx is not Wx. WxFunction is not Wx::Function. Typos will cause module loading errors.

The PADRE debugger locks up from time to time. Save your work often.

Porting Environment

-------------------

All porting was done using Ubuntu 10.10 and the PADRE IDE. This digest is regenerated by a Perl script at the completion of a new port or modification to a support file like this introduction(intro.txt).

The .png files used in these examples are not provided in this digest. Pick your own and modify the path/file names as needed.

RESOURCES

---------

These resources were found to be useful in porting the wxBook examples. Many thanks to their authors.

"Cross-Platform GUI Programming with wxWidgets" Smart, Hock, & Csomar - The "wxBook"

"Learning Perl" - Schwartz, Phoenix, & d Foy

"Perl Cookbook" - Christiansen & Torkington

perldoc (perldoc perltoc) - On-line Man Pages

"wxWidgets 2.8.10: A Portable C++ and Python GUI Toolkit" Smart, Roebling, Zeitlin, Dunn et. al. - PDF Format (Wx.pdf)

"wxWidgets 2.8.7: A Portable C++ and Python GUI Toolkit" Smart, Roebling, Zeitlin, Dunn et. al. - HTML Format

Numerous Demo and Example Programs by Mattia Barbon

Tutorials from the Perl Monks: Three by Boo Radley and A Simple Socket Server Using "inetd": Samizdat

Tutorials from the wxPerl Wiki: C++ Docs for Perl Programmers, WxPerl Tablet (i.e. The Cheat-sheet), Download with Progress Bar, Memory DC, Mini Image Demo, Tiled Background Image, wxPerl GUI for a Twitter Script

The PADRE IDE and Included Sample Programs

www.perlmonks.org

wxperl.sourceforge.net

wiki.wxperl.info

www.wxwidgets.org

www.perl.org

search.cpan.org

And others that were read, but the references were not recorded....

James M. Lynes, Jr. - Kissimmee, Florida May 2011

----------------------------------------------------------------------------------------------------

Index of Example Files from : Cross Platform GUI Programming with wxWidgets by: Smart, Hock, and Csomor - The "wxBook" Ported to wxPerl by: James M. Lynes, Jr., File Updated: Tue May 24 14:00:58 2011

----------------------------------------------------------------------------------------------------

1. CppTrial-pg019.pl : # C++ Example from pg 19 - Create a basic frame with menus and status bar

2. CppTrial-pg065.pl : # C++ Example from pg 65 - MDI Child Frame Example

3. CppTrial-pg073.pl : # C++ Example from pg 73 - Notebook Example

4. CppTrial-pg077.pl : # C++ Example from pg 77 - Scrolled Window Example

5. CppTrial-pg081.pl : # C++ Example from pg 81 - Splitter Window Example

6. CppTrial-pg086.pl : # C++ Example from pg 86 - 20 Assorted Static & Non-Static Controls Examples

7. CppTrial-pg124.pl : # C++ Example from pg 124 - Tool Bar Example

8. CppTrial-pg133.pl : # C++ Example from pg 133 - Drawing on Windows with wxClientDC

9. CppTrial-pg135.pl : # C++ Example from pg 135 - Drawing on Windows with wxPaintDC

10. CppTrial-pg150.pl : # C++ Example from pg 150 - Drawing Text - Extends pg 135 example

11. CppTrial-pg151.pl : # C++ Example from pg 151 - Drawing Text Rotated - Extends pg 150 & 135 examples

12. CppTrial-pg152.pl : # C++ Example from pg 152 - Centering Text - Extends pg 151, 150, & 135 examples

13. CppTrial-pg154.pl : # C++ Example from pg 154 - Drawing multiple lines - Extends pg 135 example

14. CppTrial-pg155.pl : # C++ Example from pg 155 - Drawing polygons - Extends pg 154 example

15. CppTrial-pg156.pl : # C++ Example from pg 156 - Drawing Splines - Extends pg 155 example

16. CppTrial-pg157.pl : # C++ Example from pg 157 - Drawing Bitmaps - Extends pg 150 example

17. CppTrial-pg158.pl : # C++ Example from pg 158 - Copy(Tile) Bitmaps Between Device Contexts - Extends pg 157 example

18. CppTrial-pg159A.pl : # C++ Example from pg 159A - Filling arbitrary areas - Extends pg 135 example

19. CppTrial-pg159B.pl : # C++ Example from pg 159B - Logical Functions - Extends pg 135 example

20. CppTrial-pg195.pl : # C++ Example from pg 195 - Sizers -Dialog with streatching text control

21. CppTrial-pg196.pl : # C++ Example from pg 196 - Sizers -Dialog with static box sizer and check box

22. CppTrial-pg197.pl : # C++ Example from pg 197 - Sizers -Dialog with grid sizer

23. CppTrial-pg199.pl : # C++ Example from pg 199 - Sizers -Dialog with flex grid sizer

24. CppTrial-pg201.pl : # C++ Example from pg 201 - Sizers -Dialog with grid bag sizer

25. CppTrial-pg202.pl : # C++ Example from pg 202 - Sizers -Dialog with Standard Dialog Button Sizer

26. CppTrial-pg207A.pl : # C++ Example from pg 207(A) - Message Dialog Dialog

27. CppTrial-pg207B.pl : # C++ Example from pg 207(B) - Message Box Dialog

28. CppTrial-pg209.pl : # C++ Example from pg 209 - Progress Dialog

29. CppTrial-pg210.pl : # C++ Example from pg 210 - Busy Info Box

30. CppTrial-pg211.pl : # C++ Example from pg 211 - Application Tips Dialog

31. CppTrial-pg215.pl : # C++ Example from pg 215 - File Dialog

32. CppTrial-pg218.pl : # C++ Example from pg 218 - Directory Dialog

33. CppTrial-pg221.pl : # C++ Example from pg 221 - Color Selection Dialog

34. CppTrial-pg224.pl : # C++ Example from pg 224 - Font Selection Dialog

35. CppTrial-pg225.pl : # C++ Example from pg 225 - Single Choice Dialog

36. CppTrial-pg226.pl : # C++ Example from pg 226 - Multiple Choice Dialog

37. CppTrial-pg227.pl : # C++ Example from pg 227 - Number Entry Dialog (**Alternate Implementation - GetNumberFromUser**)

38. CppTrial-pg228A.pl : # C++ Example from pg 228 - Text Entry Dialog (**Alternate Implementation - GetTextFromUser**)

39. CppTrial-pg228B.pl : # C++ Example from pg 228 - Password Entry Dialog (**Alternate Implementation - GetPasswordFromUser**)

40. CppTrial-pg245.pl : # C++ Example from pg 245 - Personal Records Dialog

41. CppTrial-pg283.pl : # C++ Example from pg 283 - Drawing a masked image

42. CppTrial-pg293.pl : # C++ Example from pg 293 - Writing Text to the Clipboard

43. CppTrial-pg294.pl : # C++ Example from pg 294 - Writing a bitmap/image to the Clipboard

44. CppTrial-pg340.pl : # C++ Example from pg 340 - HTML Window - Displays an HTML file

45. CppTrial-pg347.pl : # C++ Example from pg 347 - Simple Grid Example

----------------------------------------------------------------------------------------------------

#!/usr/bin/perl # CppTrial-pg019.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 19 - Create a basic frame with menus and status +bar # Ported to wxPerl by James M. Lynes Jr. - 5/18/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_MOTION); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg19.pl', wxDefaultPosition, wxDefaultSize, ); my $cutIcon = Wx::Icon->new( "cut.xpm", wxBITMAP_TYPE_XPM, -1, -1) +; $self->SetIcon($cutIcon); my $fileMenu = Wx::Menu->new(); my $helpMenu = Wx::Menu->new(); $fileMenu->Append(wxID_EXIT, "E&xit\tAlt-X", "Quit This Program"); + $helpMenu->Append(wxID_ABOUT, "&About...\tF1", "Show About Dialog" +); my $menuBar = Wx::MenuBar->new(); $menuBar->Append($fileMenu, "&File"); $menuBar->Append($helpMenu, "&Help"); $self->SetMenuBar($menuBar); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); $statusBar->SetStatusText("Welcome to wxWidgets!", 0); return $self; } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg065.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 65 - MDI Child Frame Example # Ported to wxPerl by James M. Lynes Jr. - 5/23/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::MDI; sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg065.pl', wxDefaultPosition, wxDefaultSize); &mdiChildFrame($self); return $self; } sub mdiChildFrame { my ( $self ) = @_; my $ID_MYFRAME = 1; my $ID_MYCHILD1 = 2; my $ID_MYCHILD2 = 3; my $ID_MYCHILD3 = 4; my $ID_MYCHILD4 = 5; my $parentFrame = Wx::MDIParentFrame->new($self, $ID_MYFRAME, "MDI + Parent Window"); my $childFrame1 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD +1, "Child 1"); my $childFrame2 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD +2, "Child 2"); my $childFrame3 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD +3, "Child 3"); my $childFrame4 = Wx::MDIChildFrame->new($parentFrame, $ID_MYCHILD +4, "Child 4"); $childFrame1->Show(1); $childFrame2->Show(1); $childFrame3->Show(1); $childFrame4->Show(1); $parentFrame->Show(1); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg073.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 73 - Notebook Example # Ported to wxPerl by James M. Lynes Jr. - 4/11/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; #use Wx::Window; sub new { my ($class) = @_; Wx::InitAllImageHandlers(); my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg073.pl', wxDefaultPosition, wxDefaultSize); &Notebook($self); return $self; } sub Notebook { my ( $self ) = @_; my $noteBook = Wx::Notebook->new($self, -1, wxDefaultPosition, wxD +efaultSize); my $imageList = Wx::ImageList->new(16, 16, 1, 3); my $cutxpm = Wx::Bitmap->new( "cut.xpm", wxBITMAP_TYPE_XPM ); my $copyxpm = Wx::Bitmap->new( "copy.xpm", wxBITMAP_TYPE_XPM ); my $printxpm = Wx::Bitmap->new( "print.xpm", wxBITMAP_TYPE_XPM ); $imageList->Add($cutxpm); $imageList->Add($copyxpm); $imageList->Add($printxpm); $noteBook->SetImageList($imageList); my $window1 = Wx::Panel->new($noteBook, wxID_ANY); my $window2 = Wx::Panel->new($noteBook, wxID_ANY); my $window3 = Wx::Panel->new($noteBook, wxID_ANY); $noteBook->AddPage($window1, "Tab One", 1, 0); $noteBook->AddPage($window2, "Tab Two", 0, 1); $noteBook->AddPage($window3, "Tab Three", 0, 2); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg077.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 77 - Scrolled Window Example # Ported to wxPerl by James M. Lynes Jr. - 5/23/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg077.pl', wxDefaultPosition, wxDefaultSize); &scrolledWindow($self); return $self; } sub scrolledWindow { my ( $self ) = @_; my $scrolledWindow = Wx::ScrolledWindow->new($self, wxID_ANY, Wx::Point->new(0, 0), Wx::Size->new(400, 400), wxVSCROLL | wxHSCROLL); my $pixelsPerUnitX = 10; my $pixelsPerUnitY = 10; my $noUnitsX = 1000; my $noUnitsY = 1000; $scrolledWindow->SetScrollbars($pixelsPerUnitX, $pixelsPerUnitY, $noUnitsX, $noUnitsY); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg081.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 81 - Splitter Window Example # Ported to wxPerl by James M. Lynes Jr. - 4/11/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg081.pl', wxDefaultPosition, wxDefaultSize); &SplitterWindow($self); return $self; } sub SplitterWindow { my ( $self ) = @_; my $splitterWindow = Wx::SplitterWindow->new($self, -1, Wx::Point->new(0, 0), Wx::Size->new(400, 400), wxSP_3D); my $leftWindow = Wx::ScrolledWindow->new($splitterWindow); $leftWindow->SetScrollbars(20, 20, 50, 50); $leftWindow->SetBackgroundColour(wxRED); $leftWindow->Show(1); my $rightWindow = Wx::ScrolledWindow->new($splitterWindow); $rightWindow->SetScrollbars(20, 20, 50, 50); $rightWindow->SetBackgroundColour(wxCYAN); $rightWindow->Show(0); # Right Window is Hi +dden $splitterWindow->Initialize($leftWindow); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg086.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 86 - 20 Assorted Static & Non-Static Controls Ex +amples # Several small examples combined into one source file covers pg86 - p +g116 # Ported to wxPerl by James M. Lynes Jr. - 5/23/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg086.pl', wxDefaultPosition, Wx::Size->new(500,700)); &assortedControls($self); return $self; } sub assortedControls { my ( $self ) = @_; # Create a panel to place all of the controls on my $panel= Wx::Panel->new($self, wxID_ANY, wxDefaultPosition, wxDe +faultSize); # pg86----- Plain Button my $button = Wx::Button->new($panel, wxID_OK, "Ok", Wx::Point->new(10, 10), wxDefaultSize); # pg89----- Bitmap Button my $bmp1 = Wx::Bitmap->new("print.xpm", wxBITMAP_TYPE_XPM); my $picButton = Wx::BitmapButton->new($panel, wxID_OK, $bmp1, Wx::Point->new(150, 10), wxDefaultSize, wxBU_AUTODRAW); # pg91----- Choice Control my $ID_CHOICEBOX = 1; my @strings1 = ("One", "Two", "Three", "Four", "Five"); my $choice = Wx::Choice->new($panel, $ID_CHOICEBOX, Wx::Point->new(250, 10), wxDefaultSize, \@strings1); # pg92----- ComboBox Control my $ID_COMBOBOX = 2; my @strings2 = ("Apple", "Orange", "Pear", "Grapefruit"); my $combo = Wx::ComboBox->new($panel, $ID_COMBOBOX, "Apple", Wx::Point->new(10,50), wxDefaultSize, \@strings2, wxCB_DRO +PDOWN); # pg94----- CheckBox Control my $ID_CHECKBOX = 3; my $checkBox = Wx::CheckBox->new($panel, $ID_CHECKBOX, "&Check Me" +, Wx::Point->new(10,200), wxDefaultSize); $checkBox->SetValue(1); # pg95----- ListBox Control my $ID_LISTBOX = 4; my @strings3 = ("First String", "Second String", "Third String", "Fourth String", "Fifth String", "Sixth String"); my $listbox = Wx::ListBox->new($panel, $ID_LISTBOX, Wx::Point->new(200,200), Wx::Size->new(180,80), \@strings3, wxLB_SINGLE); # pg96----- CheckListBox Control my $ID_CHECKLISTBOX = 5; my @strings4 = ("1st String", "2nd String", "3rd String", "4th String", "5th String", "6th String"); my $checklistbox = Wx::CheckListBox->new($panel, $ID_CHECKLISTBOX, + Wx::Point->new(200,300), Wx::Size->new(180,80), \@strings4, wxLB_SINGLE); # pg99----- RadioBox Control my $ID_RADIOBOX = 6; my @strings5 = ("&One", "&Two", "T&hree", "&Four", "F&ive","&Six") +; my $radiobox = Wx::RadioBox->new($panel, $ID_RADIOBOX, "RadioBox", + Wx::Point->new(10,300), wxDefaultSize, \@strings5, 3, wxRA_SPECIFY_COLS); # pg101---- Radio Button Control (Spacing forced for display purposes +- Sizers want to use whole window) my $ID_RADIOBUTTON1 = 7; my $ID_RADIOBUTTON2 = 8; my $radioButton1 = Wx::RadioButton->new($panel, $ID_RADIOBUTTON1, "&Male", Wx::Point->new(10,400), wxDefaultSize, wxRB_GR +OUP); $radioButton1->SetValue(1); my $radioButton2 = Wx::RadioButton->new($panel, $ID_RADIOBUTTON2, "&Female", Wx::Point->new(75,400)); my $topSizer = Wx::BoxSizer->new(wxHORIZONTAL); my $boxSizer = Wx::BoxSizer->new(wxHORIZONTAL); $boxSizer->Add($radioButton1, 0, wxALIGN_CENTER_VERTICAL | wxALL, +5); $boxSizer->Add($radioButton2, 0, wxALIGN_CENTER_VERTICAL | wxALL, +5); # $topSizer->Add($boxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5) +; # $self->SetSizer($topSizer); # pg102---- ScrollBar Control my $ID_SCROLLBAR = 9; my $scrollbar = Wx::ScrollBar->new($panel, $ID_SCROLLBAR, Wx::Point->new(10,450), Wx::Size->new(200,20), wxSB_HORIZO +NTAL); # pg103---- Spin Button Control my $ID_SPINBUTTON = 10; my $spinbutton = Wx::SpinButton->new($panel, $ID_SPINBUTTON, Wx::Point->new(330,400), wxDefaultSize, wxSP_VERTICAL); # pg105---- Spin Control my $ID_SPINCONTROL = 11; my $spincontrol = Wx::SpinCtrl->new($panel, $ID_SPINCONTROL, "5", Wx::Point->new(250,450), wxDefaultSize, wxSP_ARROW_KEYS, 0, 100, 5); # pg106---- Slider Control my $ID_SLIDERCONTROL = 12; my $slidercontrol = Wx::Slider->new($panel, $ID_SLIDERCONTROL, 16, + 0, 40, Wx::Point->new(10,500), Wx::Size->new(200, -1), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS); # pg108---- Text Control (w/pg109 also) my $ID_TEXTCONTROL = 13; my $textcontrol = Wx::TextCtrl->new($panel, $ID_TEXTCONTROL, "", Wx::Point->new(250,500), Wx::Size->new(240, 100), wxTE_MULTILINE); $textcontrol->SetDefaultStyle(Wx::TextAttr->new(wxRED)); $textcontrol->AppendText("Red Text\n"); $textcontrol->SetDefaultStyle(Wx::TextAttr->new(wxNullColour, wxLI +GHT_GREY)); $textcontrol->AppendText("Red on Gray Text\n"); $textcontrol->SetDefaultStyle(Wx::TextAttr->new(wxBLUE)); $textcontrol->AppendText("Blue on Gray Text\n"); # pg111---- Toggle Button my $ID_TOGGLEBUTTON = 14; my $togglebutton = Wx::ToggleButton->new($panel, $ID_TOGGLEBUTTON, + "&Toggle Button", Wx::Point->new(10,550), wxDefaultSize); $togglebutton->SetValue(1); # pg112---- Guage Control my $ID_GAUGE = 15; my $gauge = Wx::Gauge->new($panel, $ID_GAUGE, 200, Wx::Point->new(10,600), wxDefaultSize, wxGA_HORIZONTAL); $gauge->SetValue(50); # pg113---- Static Text Control my $ID_STATICTEXT = 16; my $statictext = Wx::StaticText->new($panel, $ID_STATICTEXT, "This is my &static text label", Wx::Point->new(250,600), wxDefaultSize, wxALIGN_LEFT); + # pg114---- Static Bitmap Control my $ID_STATICBITMAP = 17; my $bmp2 = Wx::Bitmap->new("print.xpm", wxBITMAP_TYPE_XPM); my $staticbitmap = Wx::StaticBitmap->new($panel, $ID_STATICBITMAP, + $bmp2, Wx::Point->new(175, 600), wxDefaultSize); # pg115---- Static Line Control my $ID_STATICLINE = 18; my $staticline = Wx::StaticLine->new($panel, $ID_STATICLINE, Wx::Point->new(10, 650), Wx::Size->new(450,-1), wxLI_HORIZONTAL); # pg116---- Static Box Control my $ID_STATICBOX = 19; my $staticbox = Wx::StaticBox->new($panel, $ID_STATICBOX, "&Static Box", Wx::Point->new(350, 10), Wx::Size->new(100, 100)); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg124.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 124 - Tool Bar Example # Ported to wxPerl by James M. Lynes Jr. - 4/12/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; Wx::InitAllImageHandlers(); my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg124.pl', wxDefaultPosition, wxDefaultSize); &ToolBar($self); return $self; } sub ToolBar { my ( $self ) = @_; my $toolBar = Wx::ToolBar->new($self, -1, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL | wxNO_BORDER); my $cutxpm = Wx::Bitmap->new( "cut.xpm", wxBITMAP_TYPE_XPM ); my $copyxpm = Wx::Bitmap->new( "copy.xpm", wxBITMAP_TYPE_XPM ); my $printxpm = Wx::Bitmap->new( "print.xpm", wxBITMAP_TYPE_XPM ); $toolBar->AddTool(wxID_CUT, $cutxpm, "cut"); $toolBar->AddTool(wxID_COPY, $copyxpm, "Copy"); $toolBar->AddTool(wxID_PRINT, $printxpm, "Print"); $toolBar->AddSeparator(); my $ID_COMBOBOX = 1; my $comboBox = Wx::ComboBox->new($toolBar, $ID_COMBOBOX); $toolBar->AddControl($comboBox); $toolBar->Realize(); $self->SetToolBar($toolBar); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg133.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 133 - Drawing on Windows with wxClientDC # Ported to wxPerl by James M. Lynes Jr. - 4/10/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_MOTION); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg133.pl', wxDefaultPosition, wxDefaultSize, ); EVT_MOTION($self,\&OnMotion); return $self; } sub OnMotion { my ( $self, $event) = @_; if($event->Dragging) { # True if mouse button press +ed & mouse moving my $dc = Wx::ClientDC->new($self); my $pen = Wx::Pen->new(wxRED,1,wxSOLID); $dc->SetPen($pen); $dc->DrawPoint($event->GetPosition->x,$event->GetPosition->y); + $dc->SetPen(wxNullPen); } } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg135.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/18/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg135.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my $sz=$self->GetClientSize(); my $szx=$sz->x; my $szy=$sz->y; my $w=100; my $h=50; my $x=($szx - $w)/2; my $y=($szy - $h)/2; $dc->DrawRectangle($x,$y,$w,$h); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg150.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 150 - Drawing Text - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/21/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg150.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my $sz=$self->GetClientSize(); my $szx=$sz->x; my $szy=$sz->y; my $w=100; my $h=50; my $x=($szx - $w)/2; my $y=($szy - $h)/2; $dc->DrawRectangle($x,$y,$w,$h); my $pt=Wx::Point->new(160,275); CppDrawText($dc, "Test Text", $pt); } sub CppDrawText { my ( $dc, $text, $pt) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxN +ORMAL); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxBLACK); $dc->SetTextBackground(wxWHITE); $dc->DrawText($text,$pt->x, $pt->y); return; } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg151.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 151 - Drawing Text Rotated - Extends pg 150 & 13 +5 examples # C++ Example from pg 150 - Drawing Text - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/21/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg151.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my $sz=$self->GetClientSize(); my $szx=$sz->x; my $szy=$sz->y; my $w=100; my $h=50; my $x=($szx - $w)/2; my $y=($szy - $h)/2; $dc->DrawRectangle($x,$y,$w,$h); my $pt1=Wx::Point->new(160,275); CppDrawText($dc, "Test Text", $pt1); my $pt2=Wx::Point->new(200,375); CppDrawRotatedText($dc, "Test Text", $pt2); } sub CppDrawText { my ( $dc, $text, $pt) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxB +OLD); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxBLACK); $dc->SetTextBackground(wxWHITE); $dc->DrawText($text,$pt->x, $pt->y); return; } sub CppDrawRotatedText { my ( $dc, $text, $pt) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxN +ORMAL); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxGREEN); $dc->SetTextBackground(wxWHITE); for (my $angle=0; $angle<360; $angle +=45) { $dc->DrawRotatedText($text,$pt->x, $pt->y, $angle); } return; } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg152.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 152 - Centering Text - Extends pg 151, 150, & 13 +5 examples # C++ Example from pg 151 - Drawing Text Rotated - Extends pg 150, & 1 +35 examples # C++ Example from pg 150 - Drawing Text - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/21/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg152.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my $sz=$self->GetClientSize(); my $szx=$sz->x; my $szy=$sz->y; my $w=100; my $h=50; my $x=($szx - $w)/2; my $y=($szy - $h)/2; $dc->DrawRectangle($x,$y,$w,$h); my $pt1=Wx::Point->new(160,275); CppDrawText($dc, "Test Text", $pt1); my $pt2=Wx::Point->new(200,375); CppDrawRotatedText($dc, "Test Text", $pt2); my $pt3=Wx::Point->new(0,50); CppDrawCenteredText("Centered Text", $dc, $pt3, $self); } sub CppDrawText { my ( $dc, $text, $pt) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxB +OLD); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxBLACK); $dc->SetTextBackground(wxWHITE); $dc->DrawText($text,$pt->x, $pt->y); return; } sub CppDrawRotatedText { my ( $dc, $text, $pt) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxN +ORMAL); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxGREEN); $dc->SetTextBackground(wxWHITE); for (my $angle=0; $angle<360; $angle +=45) { $dc->DrawRotatedText($text,$pt->x, $pt->y, $angle); } return; } sub CppDrawCenteredText { my ( $text, $dc, $pt, $self) = @_; my $font = Wx::Font->new(12, wxFONTFAMILY_ROMAN, wxNORMAL, wxB +OLD); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxBLUE); $dc->SetTextBackground(wxWHITE); my $sz=$self->GetClientSize(); my @te=$dc->GetTextExtent($text); my $x=($sz->x - $te[0])/2; my $y=$pt->y; $dc->DrawText($text, $x, $y); return; } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg154.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 154 - Drawing multiple lines - Extends pg 135 ex +ample # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/25/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg154.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my @points; my $x=0; my $y=0; for my $i(0..9) { my $pt1=Wx::Point->new($x,$y); my $pt2=Wx::Point->new($x+100,$y); push(@points, $pt1, $pt2); # print "$i-> $x, $y / ", $x+100, ",", $y, "\n"; $dc->DrawLine($pt1->x, $pt1->y, $pt2->x, $pt2->y); $x=$x + 10; $y=$y + 20; } # print "@points\n"; my $offsetx = 100; my $offsety = 250; $dc->DrawLines(\@points, $offsetx, $offsety); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg155.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 155 - Drawing polygons - Extends pg 154 example # C++ Example from pg 154 - Drawing single & multiple lines - Extends +pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/25/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg155.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxCROSSDIAG_HATCH); $dc->SetBrush($brush); my @points; my $pt0=Wx::Point->new(100, 60); my $pt1=Wx::Point->new(60, 150); my $pt2=Wx::Point->new(160,100); my $pt3=Wx::Point->new(40, 100); my $pt4=Wx::Point->new(140, 150); push(@points, $pt0, $pt1, $pt2, $pt3, $pt4); print "@points\n"; $dc->DrawPolygon(\@points, 0, 30); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg156.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 156 - Drawing Splines - Extends pg 155 example # C++ Example from pg 155 - Drawing polygons - Extends pg 154 example # C++ Example from pg 154 - Drawing single & multiple lines - Extends +pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/26/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg156.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxCROSSDIAG_HATCH); $dc->SetBrush($brush); my @pts; my $pts0=Wx::Point->new(10, 100); my $pts1=Wx::Point->new(200, 200); my $pts2=Wx::Point->new(50, 230); push(@pts, $pts0, $pts1, $pts2); $dc->DrawSpline(\@pts); my @points; my $pt0=Wx::Point->new(100, 60); my $pt1=Wx::Point->new(60, 150); my $pt2=Wx::Point->new(160,100); my $pt3=Wx::Point->new(40, 100); my $pt4=Wx::Point->new(140, 150); push(@points, $pt0, $pt1, $pt2, $pt3, $pt4); $dc->DrawSpline(\@points); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg157.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 157 - Drawing Bitmaps - Extends pg 150 example # C++ Example from pg 150 - Drawing Text - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/26/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { Wx::InitAllImageHandlers(); my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg157.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); my $font = Wx::Font->new(10, wxFONTFAMILY_ROMAN, wxNORMAL, wxN +ORMAL); $dc->SetFont($font); $dc->SetBackgroundMode(wxTRANSPARENT); $dc->SetTextForeground(wxBLACK); $dc->SetTextBackground(wxWHITE); my $msg = "Some text will appear mixed in the image's shadow.. +."; my $bmp = Wx::Bitmap->new("padre_logo_64x64.png", wxBITMAP_TYP +E_PNG); my $y = 75; for (0..9) { $y += $dc->GetCharHeight() +5; $dc->DrawText($msg, 10, $y); } $dc->DrawBitmap($bmp, 150, 175, 1); return; } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg158.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 158 - Copy(Tile) Bitmaps Between Device Contexts + - Extends pg 157 example # C++ Example from pg 157 - Drawing Bitmaps - Extends pg 150 example # C++ Example from pg 150 - Drawing Text - Extends pg 135 example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/26/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { Wx::InitAllImageHandlers(); my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg158.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dcPaint = Wx::PaintDC->new($self); #OnPaint Event R +equires a PaintDC my $dcSource = Wx::MemoryDC->new(); my $dcDest = Wx::MemoryDC->new(); my $destWidth = 350; my $destHeight = 400; my $bmpDest = Wx::Bitmap->new($destWidth, $destHeight); my $bmpSource = Wx::Bitmap->new("padre_logo_64x64.png", wxBITM +AP_TYPE_PNG); my $sourceWidth = $bmpSource->GetWidth(); my $sourceHeight = $bmpSource->GetHeight(); $dcDest->SelectObject($bmpDest); $dcDest->SetBackground(wxWHITE_BRUSH); $dcDest->Clear(); $dcSource->SelectObject($bmpSource); for (my $i = 0; $i < $destWidth; $i += $sourceWidth) { for (my $j = 0; $j < $destHeight; $j += $sourceHeight) { $dcDest->Blit($i, $j, $sourceWidth, $sourceHeight, $dc +Source, 0, 0, wxCOPY, 1); } } $dcPaint->Blit(0,0,$destWidth,$destHeight,$dcDest,0,0,wxCOPY,1 +); #Copy to PaintDC for display $dcDest->SelectObject(wxNullBitmap); $dcSource->SelectObject(wxNullBitmap); return; } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg159A.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 159A - Filling arbitrary areas - Extends pg 135 +example # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/27/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg159A.pl', wxDefaultPosition, wxDefaultSize, ); EVT_PAINT($self,\&OnPaint); return $self; } sub OnPaint { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxRED,5,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxGREEN,wxSOLID); $dc->SetBrush($brush); $dc->DrawRectangle(0, 0, 400, 450); $dc->DrawRectangle(20, 20, 100, 100); $dc->DrawRectangle(200, 200, 100, 100); $dc->DrawRectangle(20, 300, 100, 100); # 4 Rects fi +lled green # wxFLOOD_SURFACE - Fill area of given color $dc->SetBrush(wxBLACK_BRUSH); $dc->FloodFill(250, 250, wxGREEN, wxFLOOD_SURFACE); # Center R +ect filled black # wxFLOOD_BORDER - Fill area within given color border + $dc->SetBrush(wxCYAN_BRUSH); $dc->FloodFill(100, 350, wxRED, wxFLOOD_BORDER); # Bottom R +ect filled cyan $dc->SetBrush(wxBLUE_BRUSH); $dc->FloodFill(6, 6, wxRED, wxFLOOD_BORDER); # Large Re +ct filled blue } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg159B.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 159B - Logical Functions - Extends pg 135 examp +le # C++ Example from pg 135 - Drawing on Windows with wxPaintDC # Ported to wxPerl by James M. Lynes Jr. - 4/27/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(:everything); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg159B.pl', wxDefaultPosition, wxDefaultSize, ); EVT_MOTION($self,\&OnMotion,); return $self; } sub OnMotion { my ( $self, $event) = @_; my $dc = Wx::PaintDC->new($self); my $pen = Wx::Pen->new(wxBLACK,1,wxSOLID); $dc->SetPen($pen); my $brush=Wx::Brush->new(wxRED,wxSOLID); $dc->SetBrush($brush); $dc->SetLogicalFunction(wxINVERT); # Invert Pixels $dc->DrawCircle(200, 200, 50); # Circle appears and era +ses as mouse moves } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg195.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 195 - Sizers -Dialog with streatching text contr +ol # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Sizer Dialog Example", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create two Sizers my $topSizer = Wx::BoxSizer->new(wxVERTICAL); my $buttonSizer = Wx::BoxSizer->new(wxHORIZONTAL); # Create a Text Control, and OK and CANCEL Buttons my $textCtrl = Wx::TextCtrl->new($dialog, wxID_ANY, "Stretching Te +xt Control...", wxDefaultPosition, Wx::Size->new(100, 60), wxTE_MULTILI +NE); my $buttOk = Wx::Button->new($dialog, wxID_OK, "OK"); my $buttCancel = Wx::Button->new($dialog, wxID_CANCEL, "Cancel"); # Associate Text Control and buttons with Sizers $topSizer->Add($textCtrl, 1, wxEXPAND, wxALL, 10); $buttonSizer->Add($buttOk, 0, wxALL, 10); $buttonSizer->Add($buttCancel, 0, wxALL, 10); # Associate Button Sizer with TopSizer $topSizer->Add($buttonSizer, 0, wxALIGN_CENTER); $dialog->SetSizer($topSizer); $topSizer->Fit($dialog); $topSizer->SetSizeHints($dialog); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg196.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 196 - Sizers -Dialog with static box sizer and c +heck box # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Static Box Sizer Dialog E +xample", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create two Sizers and a Static Box my $topLevel = Wx::BoxSizer->new(wxVERTICAL); my $staticBox = Wx::StaticBox->new($dialog, wxID_ANY, "General Set +tings"); my $staticSizer = Wx::StaticBoxSizer->new($staticBox, wxVERTICAL); + # Create a Check Box my $checkBox = Wx::CheckBox->new($dialog, -1, "&Show Splash Screen +", wxDefaultPosition, wxDefaultSize); # Associate Check Box Control with Sizers $topLevel->Add($staticSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, + 5); $staticSizer->Add($checkBox, 0, wxALIGN_LEFT | wxALL, 5); # Associate Button Sizer with TopSizer $dialog->SetSizer($topLevel); $topLevel->Fit($dialog); $topLevel->SetSizeHints($dialog); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg197.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 197 - Sizers -Dialog with grid sizer # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Grid Sizer Dialog Example +", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create a Grid Sizers my $gridSizer = Wx::GridSizer->new(2, 3, 0, 0); $dialog->SetSizer($gridSizer); # Create Buttons and add to GridSizer my $button1 = Wx::Button->new($dialog , -1, "One"); $gridSizer->Add($button1, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button2 = Wx::Button->new($dialog , -1, "Two (the second butt +on)"); $gridSizer->Add($button2, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button3 = Wx::Button->new($dialog , -1, "Three"); $gridSizer->Add($button3, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button4 = Wx::Button->new($dialog , -1, "Four"); $gridSizer->Add($button4, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button5 = Wx::Button->new($dialog , -1, "Five"); $gridSizer->Add($button5, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button6 = Wx::Button->new($dialog , -1, "Six"); $gridSizer->Add($button6, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); $gridSizer->Fit($dialog); $gridSizer->SetSizeHints($dialog); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg199.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 199 - Sizers -Dialog with flex grid sizer # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Flex Grid Sizer Dialog Ex +ample", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create a Grid Sizers make column 0 growable my $flexGridSizer = Wx::FlexGridSizer->new(2, 3, 0, 0); $dialog->SetSizer($flexGridSizer); $flexGridSizer->AddGrowableCol(0); # Create Buttons and add to FlexGridSizer my $button1 = Wx::Button->new($dialog , -1, "One"); $flexGridSizer->Add($button1, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button2 = Wx::Button->new($dialog , -1, "Two (the second butt +on)"); $flexGridSizer->Add($button2, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button3 = Wx::Button->new($dialog , -1, "Three"); $flexGridSizer->Add($button3, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button4 = Wx::Button->new($dialog , -1, "Four"); $flexGridSizer->Add($button4, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button5 = Wx::Button->new($dialog , -1, "Five"); $flexGridSizer->Add($button5, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); my $button6 = Wx::Button->new($dialog , -1, "Six"); $flexGridSizer->Add($button6, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL,5); $flexGridSizer->Fit($dialog); $flexGridSizer->SetSizeHints($dialog); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg201.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 201 - Sizers -Dialog with grid bag sizer # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Grid Bag Sizer Dialog Exa +mple", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create a Grid Bag Sizers make column 2 and row 3 growable my $gridBagSizer = Wx::GridBagSizer->new(); $dialog->SetSizer($gridBagSizer); # Create Buttons and add to GridBagSizer my $b1 = Wx::Button->new($dialog , -1, "One (0,0)"); $gridBagSizer->Add($b1, Wx::GBPosition->new(0, 0)); my $b2 = Wx::Button->new($dialog , -1, "Two (2, 2)"); $gridBagSizer->Add($b2, Wx::GBPosition->new(2, 2), Wx::GBSpan->new +(1, 2), wxGROW); my $b3 = Wx::Button->new($dialog , -1, "Three (3, 2)"); $gridBagSizer->Add($b3, Wx::GBPosition->new(3, 2)); my $b4 = Wx::Button->new($dialog , -1, "Four (3, 3)"); $gridBagSizer->Add($b4, Wx::GBPosition->new(3, 3)); $gridBagSizer->AddGrowableRow(3); $gridBagSizer->AddGrowableCol(2); $gridBagSizer->Fit($dialog); $gridBagSizer->SetSizeHints($dialog); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg202.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 202 - Sizers -Dialog with Standard Dialog Button + Sizer # Ported to wxPerl by James M. Lynes Jr. - 5/03/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $dialog = Wx::Dialog->new(undef, -1, "Standard Dialog Button Si +zer Example", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); mydialog($dialog); return $dialog; } sub mydialog { my ($dialog)= @_; # Create Sizer my $topSizer = Wx::BoxSizer->new(wxVERTICAL); $dialog->SetSizer($topSizer); # Create an OK, CANCEL, and HELP Buttons my $buttOk = Wx::Button->new($dialog, wxID_OK, "OK"); my $buttCancel = Wx::Button->new($dialog, wxID_CANCEL, "Cancel"); my $buttHelp = Wx::Button->new($dialog, wxID_HELP, "Help"); # Associate buttons with Sizers my $buttonSizer = Wx::StdDialogButtonSizer->new(); $topSizer->Add($buttonSizer, 0, wxEXPAND | wxALL, 10); $buttonSizer->AddButton($buttOk); $buttonSizer->AddButton($buttCancel); $buttonSizer->AddButton($buttHelp); $buttonSizer->Realize(); } ---------------------------------------------------------------------- +------------------------------ #!/usr/bin/perl # CppTrial-pg207A.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 207(A) - Message Dialog Dialog # Ported to wxPerl by James M. Lynes Jr. - 5/4/2011 package main; use 5.008; use strict; use warnings; $| = 1; # create the WxApplication my $app = Demo::App->new; $app->MainLoop; package Demo::App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); return 1; } package Demo::App::Frame; use strict; use warnings; use Wx qw(:everything); use base 'Wx::Frame'; use Wx::Event qw(EVT_PAINT); sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, 'CppTrial-pg207B.pl', wxDefaultPosition, wxDefaultSize, ); my $statusBar = Wx::StatusBar->new($self, wxID_ANY, wxST_SIZEGRIP) +; $self->SetStatusBar($statusBar); my @widths = (200, 100, -1); $statusBar->SetFieldsCount($#widths+1); $statusBar->SetStatusWidths(@widths); $statusBar->SetStatusText("Ready", 0); &myStdDialogs($self); return $self; } sub myStdDialogs { my ( $self ) = @_; use Switch;
(truncated due to size)

In reply to More wxPerl Examples by jmlynesjr

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (9)
As of 2024-03-28 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found