TGI has asked for the wisdom of the Perl Monks concerning the following question:

I am putting together a very simple wizard application using wxPerl. For obvious reasons I am planning to use the wxWizard class. While the example in wxperl_demo is great for showing how to use the wxWizard class inside a larger application, it does not give much guidance for setting up a very simple app.

All I want to do is create and run a wizard to collect some survey info. Any processing will be done as the user steps through the pages. The problem is, how do I start the wizard?

I've come up with two approaches that seem to "work" but both feel dodgy. I can get the wizard to run by putting the RunWizard call into the application's OnInit handler. I've also tried removing the call to start the MainLoop, and just called RunWizard() instead.

use strict; use warnings; use Wx; package WizTest; use base qw(Wx::App); # Inherit from Wx::App use Wx::Event qw(EVT_WIZARD_FINISHED); sub OnInit { my $self = shift; my $wizard = Wx::Wizard->new( undef, -1, "Wizard test" ); # first page my $page1 = Wx::WizardPageSimple->new( $wizard ); Wx::TextCtrl->new( $page1, -1, "First page" ); # second page my $page2 = Wx::WizardPageSimple->new( $wizard ); Wx::TextCtrl->new( $page2, -1, "Second page" ); Wx::WizardPageSimple::Chain( $page1, $page2 ); EVT_WIZARD_FINISHED( $self, $wizard, sub { warn "Wizard finished\n"; } ); # Preempt everything and run the wizard now. # $wizard->RunWizard( $page1 ); $self->{wizard} = $wizard; $self->{start_page} = $page1; } package main; my $app = WizTest->new(); # New HelloWorld application # Note that I don't start the MainLoop $app->{wizard}->RunWizard( $app->{start_page} );

Neither approach seems right. My intuition tells me that I really ought to be running the main loop and then triggering the wizard somehow.

Anyone have any suggestions on how to start my wizard up?


TGI says moo

Replies are listed 'Best First'.
Re: Simple wxWizard application
by igelkott (Priest) on Nov 06, 2007 at 08:26 UTC
    I've never actually used this module but I just happened to be looking into it and found a tutorial which might be applicable to your problem: the "Adding interaction" example of http://www.perl.com/lpt/a/588. Note that the Event class is used in a different package than the OnInit subroutine.

      Thanks for the idea. Events are the key. I just started a one shot timer to trigger the wizard after the main loop is started.

      use strict; use warnings; use Wx; package WizTest; use base qw(Wx::App); # Inherit from Wx::App use Wx::Event qw(EVT_WIZARD_FINISHED EVT_WIZARD_CANCEL EVT_TIMER); sub OnInit { my $self = shift; my $wizard = Wx::Wizard->new( undef, -1, "Wizard test" ); # first page my $page1 = Wx::WizardPageSimple->new( $wizard ); Wx::TextCtrl->new( $page1, -1, "First page" ); # second page my $page2 = Wx::WizardPageSimple->new( $wizard ); Wx::TextCtrl->new( $page2, -1, "Second page" ); Wx::WizardPageSimple::Chain( $page1, $page2 ); # use a timer to start the wizard after we have the event loop run +ning. my $timer = Wx::Timer->new(); $timer->Start( 50, 1 ); EVT_TIMER( $self, $timer, \&StartWizard ); EVT_WIZARD_FINISHED( $self, $wizard, 'WizardFinished' ); EVT_WIZARD_CANCEL( $self, $wizard, 'WizardFinished' ); $self->{wizard} = $wizard; $self->{start_page} = $page1; } sub StartWizard { my $self = shift; $self->{wizard}->RunWizard( $self->{start_page} ); } sub WizardFinished { my $self = shift; warn "Wizard finished: $self @_\n"; $self->{wizard}->Destroy; return; } package main; my $app = WizTest->new(); # New HelloWorld application $app->MainLoop; warn "Exited main loop";


      TGI says moo

Re: Simple wxWizard application
by Anonymous Monk on Nov 06, 2007 at 10:11 UTC
    http://www.wxwidgets.org/wiki/index.php/WxWizard
    Using WxWizard as your only window
    The trick is to construct your wxApp, then construct your wizard and call RunWizard() on it, and only then (once RunWizard() has returned) call wxApp.MainLoop() to clean up.