Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: WxPerl Next button

by jmlynesjr (Pilgrim)
on Jan 05, 2013 at 14:20 UTC ( #1011789=note: print w/ replies, xml ) Need Help??


in reply to WxPerl Next button

After reviewing and running your code, and having read a zillion of theses posts now, I knew that a more learned Monk would suggest using one of the CPAN XML parsers. Thanks stefbz. I have not gotten into XML at all yet.

I do think that you should be using a dialog(modal) rather than individual controls. I would start with the wxSingleChoiceDialog and use it to get my application logic correct. Build and popup the dialog, extract your answer, destroy the popup, then repeat for all of your questions. Then if you still want a different look and feel you could implement a custom dialog like the wxSingleChoiceDialog, but using radio boxes instead of a list. See CppTrial-pg225.pl for the wxSingleChoiceDialog example and CppTrial-pg245.pl for the PersonalRecordDialog custom dialog example.

The next more complicated option would be to create a wxWizard. Unfortunately I haven't yet implemented the wxWizard example from the "wxBook" in my github examples.

See also the wxDemo wxWizard and wxSingleChoiceDialog examples. I run Citrus Perl 5.16 and on my system these can be found at home/CitrusPerl/perl/vendor/bin/wxperl_demo.pl. Look under the Managed Windows and Dialogs sections.

Please repost your working application to add to the example base.

Update1:See if the following code can be integrated with your XML code.

#!/usr/bin/perl # Highly Modified CppTrial-pg225.pl in Answer to Perl Monks question # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 225 - Single Choice Dialog # Ported to wxPerl by James M. Lynes Jr. - Last Modified 1/5/2013 use 5.010; use strict; use warnings; use Wx qw(:everything); use Wx::Event qw(EVT_PAINT); # create the WxApplication my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new(undef, -1, 'Company Survey', wxDefaultPosit +ion, wxDefaultSize); # Parse your XML into $title, $question, & @choices and pass into subr +outine, loop for all questions myStdDialogs1($frame); # Duplicate calls to sim +ulate a loop myStdDialogs2($frame); # Duplicate calls to sim +ulate a loop $frame->Show; $app->MainLoop; sub myStdDialogs1 { my ( $self ) = @_; my $title = "Survey question: TNHSCS010001"; # Hard cod +ed for example...pass in, in live code my $question = "Jenkins is primiary used of ........?"; my @choices = ("1 Nightly Builds", "3 CI Builds", "4 Report Generation", "1 All the above"); my $singleChoiceDialog = Wx::SingleChoiceDialog->new($self, $quest +ion, $title, \@choices); if( $singleChoiceDialog->ShowModal() == wxID_OK) { Wx::MessageBox($singleChoiceDialog->GetStringSelection(), "Selected Answer", wxOK | wxICON_INFORMATION, $self); } $singleChoiceDialog->Destroy; } sub myStdDialogs2 { my ( $self ) = @_; my $title = "Survey question: TNHSCS010001"; # Hard cod +ed for example...pass in, in live code my $question = "Jenkins is primiary used of ........?"; my @choices = ("1 Nightly Builds", "3 CI Builds", "4 Report Generation", "1 All the above"); my $singleChoiceDialog = Wx::SingleChoiceDialog->new($self, $quest +ion, $title, \@choices); if( $singleChoiceDialog->ShowModal() == wxID_OK) { Wx::MessageBox($singleChoiceDialog->GetStringSelection(), "Selected Answer", wxOK | wxICON_INFORMATION, $self); } $singleChoiceDialog->Destroy; }

Update2:Just for completeness a wxWizard example follows.

#!/usr/bin/perl # wxWizard.pl # Adapted from wxperl_demo.pl from the wxPerl distribution # James M. Lynes Jr. - Last Modified 1/6/2013 use 5.010; use strict; use warnings; use Wx qw(:everything); use Wx::Event qw(EVT_WIZARD_PAGE_CHANGED EVT_BUTTON EVT_WIZARD_FINISHE +D EVT_WIZARD_CANCEL); # create the WxApplication my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new( undef, -1,'wxWizard.pl', wxDefaultPosi +tion, wxDefaultSize ); my $panel = Wx::Panel->new($frame, -1, wxDefaultPosition, wxDefaul +tSize); Wx::StaticText->new($panel, -1, "WxWizard Sample Program", Wx::Poi +nt->new(100,100), Wx::Size->new(200,200), wxALIGN_CENTER); my $button = Wx::Button->new( $panel, -1, "Start Wizard", Wx::Poin +t->new(150, 225), wxDefaultSize ); Wx::InitAllImageHandlers(); my $bmp = Wx::Bitmap->new("logo.png", wxBITMAP_TYPE_PNG); my $wizard = Wx::Wizard->new( $panel, -1, "Wizard Example", $bmp ) +; # first page my $page1 = Wx::WizardPageSimple->new( $wizard ); Wx::TextCtrl->new( $page1, -1, "First page", wxDefaultPosition, Wx +::Size->new(200,25) ); # second page my $page2 = Wx::WizardPageSimple->new( $wizard ); Wx::TextCtrl->new( $page2, -1, "Second page", wxDefaultPosition, W +x::Size->new(200,25) ); # third page my $page3 = Wx::WizardPageSimple->new( $wizard ); Wx::TextCtrl->new( $page3, -1, "Third page", wxDefaultPosition, Wx +::Size->new(200,25) ); # fourth page my $page4 = Wx::WizardPageSimple->new( $wizard ); Wx::TextCtrl->new( $page4, -1, "Fourth page", wxDefaultPosition, W +x::Size->new(200,25) ); Wx::WizardPageSimple::Chain( $page1, $page2 ); Wx::WizardPageSimple::Chain( $page2, $page3 ); Wx::WizardPageSimple::Chain( $page3, $page4 ); EVT_BUTTON( $panel, $button, sub {$wizard->RunWizard( $page1 ); } +); EVT_WIZARD_CANCEL( $panel, $wizard, sub {Wx::Wizard->Destroy();} ) +; EVT_WIZARD_FINISHED($panel, $wizard, sub { Wx::Wizard->Destroy(); +} ); # Testing Messages comment out matching event above # EVT_WIZARD_FINISHED($panel, $wizard, sub { Wx::LogMessage( "Wizar +d Canceled" ); } ); # EVT_WIZARD_PAGE_CHANGED( $panel, $wizard, sub {Wx::LogMessage( "W +izard page changed" ); } ); # EVT_WIZARD_CANCEL( $panel, $wizard, sub {Wx::LogMessage( "Wizard +Canceled" ); } ); $frame->Show; $app->MainLoop;

James

There's never enough time to do it right, but always enough time to do it over...


Comment on Re: WxPerl Next button
Select or Download Code
Re^2: WxPerl Next button
by saran73 (Initiate) on Jan 06, 2013 at 08:49 UTC
    Hi James/Stefan, Thanks for the valuable input. Since I have to print line-by-line as we select the correct answer (this app is just to verify the correct answers), I chose not to use XML parsers since anytime the actual XML file several additional nodes that I don't need in (both inside and outside the question node). I have made some good progress by destroying and recreating RadioBox when the user selects next button. After testing the code thoroughly, I will post it and you can modify (if required) and add it to the examples. Regards Saran

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2014-09-18 07:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (109 votes), past polls