From: Mattia B. <mb...@ds...> - 2001-11-28 21:18:03
|
> Hey guys, > I've been seaching through the doc's for a way to fire off Events even if I'm running a loop such as... > > foreach my $i (0..999999) {...} > > I've found the Yield() and SafeYield() functions. But those only allow the GUI to be updated for interaction, but don't allow the functions tied to the events to be called. At least, as far as I can tell anyhow. Anyone have any advice? The only "real" solution to your problem is to use threads; as an ( ugly ) workaround you might use a wxTimer; using wxYield is _strongly_ discouraged because it can lead to unexpected reentrancy problems ( of course there are cases where you can't do without ). I never used it, so I can't tell if the handlers not being fired is a wxPerl or a wxWindows problem ( will check ). Regards Mattia |
From: Mattia B. <mb...@ds...> - 2001-11-28 22:43:01
|
> > > Hey guys, > > > I've been seaching through the doc's for a way to fire off Events > > even if I'm running a loop such as... > > > > > > foreach my $i (0..999999) {...} > > > > > > I've found the Yield() and SafeYield() functions. But those only > > allow the GUI to be updated for interaction, but don't allow the > > functions tied to the events to be called. At least, as far as I can > > tell anyhow. Anyone have any advice? > > The only "real" solution to your problem is to use threads; as an > > I was afraid of that. :( Are threads available in wxPerl? All I *really* > need to do is toggle a variable by pressing a button to make the loop stop. No, but Perl threads might just work, if you don't call GUI functions from them ( but I _never_ tried ) OTOH, you don't need threads for just a 'stop me' button. I modified the minimal sample like this: ------- sub OnAbout { my( $this, $event ) = @_; MyDialog->new( $this, -1, "AAA" ); foreach ( 1 .. 100000 ) { sleep 1;Wx::Yield(); } # display a simple about box Wx::MessageBox( "This is the about dialog of minimal sample.\n" . "Welcome to wxPerl " . $Wx::VERSION . "\n" . wxVERSION_STRING, "About minimal", wxOK | wxICON_INFORMATION, $this ); } package MyDialog; use vars qw(@ISA); @ISA = qw(Wx::Dialog); use Wx::Event qw(EVT_BUTTON); use Wx qw(wxOK wxICON_INFORMATION wxVERSION_STRING); sub new { my $class = shift; my $this = $class->SUPER::new( @_ ); my $button = Wx::Button->new( $this, -1, "Click" ); EVT_BUTTON( $this, $button, \&Foo ); $this->Show( 1 ); return $this; } sub Foo { Wx::MessageBox( "AA", "BB", wxOK, $_[0] ); } ------ And clicking on the button shows a dialog, just does so once every second, though, so if every iteration of the loop takes, say, 20 seconds, you will be able to stop the calculation just once every 20 seconds > > ( ugly ) workaround you might use a wxTimer; using wxYield is _strongly_ > > discouraged because it can lead to unexpected reentrancy > > problems ( of course there are cases where you can't do without ). > > I never used it, so I can't tell if the handlers not being fired is > > a wxPerl or a wxWindows problem ( will check ). Regards Mattia |
From: Casey W. <wil...@nc...> - 2001-11-28 21:33:12
|
> > Hey guys, > > I've been seaching through the doc's for a way to fire off Events > even if I'm running a loop such as... > > > > foreach my $i (0..999999) {...} > > > > I've found the Yield() and SafeYield() functions. But those only > allow the GUI to be updated for interaction, but don't allow the > functions tied to the events to be called. At least, as far as I can > tell anyhow. Anyone have any advice? > The only "real" solution to your problem is to use threads; as an I was afraid of that. :( Are threads available in wxPerl? All I *really* need to do is toggle a variable by pressing a button to make the loop stop. > ( ugly ) workaround you might use a wxTimer; using wxYield is _strongly_ > discouraged because it can lead to unexpected reentrancy > problems ( of course there are cases where you can't do without ). > I never used it, so I can't tell if the handlers not being fired is > a wxPerl or a wxWindows problem ( will check ). Thanks again! |
From: Casey W. <wil...@nc...> - 2001-11-28 21:56:49
|
Ok, I figured out the variable thing...I was using an anonymous sub instead of a regular sub ref in the Event function. ----- Original Message ----- From: "Casey Williams" <wil...@nc...> To: <wxp...@li...> Sent: Wednesday, November 28, 2001 3:33 PM Subject: Re: [wxperl-users] How to kick off event functions while in a loop > > > Hey guys, > > > I've been seaching through the doc's for a way to fire off Events > > even if I'm running a loop such as... > > > > > > foreach my $i (0..999999) {...} > > > > > > I've found the Yield() and SafeYield() functions. But those only > > allow the GUI to be updated for interaction, but don't allow the > > functions tied to the events to be called. At least, as far as I can > > tell anyhow. Anyone have any advice? > > The only "real" solution to your problem is to use threads; as an > > I was afraid of that. :( Are threads available in wxPerl? All I *really* > need to do is toggle a variable by pressing a button to make the loop stop. > > > ( ugly ) workaround you might use a wxTimer; using wxYield is _strongly_ > > discouraged because it can lead to unexpected reentrancy > > problems ( of course there are cases where you can't do without ). > > I never used it, so I can't tell if the handlers not being fired is > > a wxPerl or a wxWindows problem ( will check ). > > Thanks again! > > > _______________________________________________ > wxperl-users mailing list > wxp...@li... > https://lists.sourceforge.net/lists/listinfo/wxperl-users > |
From: Casey W. <wil...@nc...> - 2001-11-29 22:02:54
|
Correction: The whole problem was in my variable declaration (should have been 'our' not 'my'), not the funtion stuff. *blush* -Casey > Ok, I figured out the variable thing...I was using an anonymous sub instead > of a regular sub ref in the Event function. > > ----- Original Message ----- > From: "Casey Williams" <wil...@nc...> > To: <wxp...@li...> > Sent: Wednesday, November 28, 2001 3:33 PM > Subject: Re: [wxperl-users] How to kick off event functions while in a loop > > > > > > Hey guys, > > > > I've been seaching through the doc's for a way to fire off Events > > > even if I'm running a loop such as... > > > > > > > > foreach my $i (0..999999) {...} > > > > > > > > I've found the Yield() and SafeYield() functions. But those only > > > allow the GUI to be updated for interaction, but don't allow the > > > functions tied to the events to be called. At least, as far as I can > > > tell anyhow. Anyone have any advice? > > > The only "real" solution to your problem is to use threads; as an > > > > I was afraid of that. :( Are threads available in wxPerl? All I *really* > > need to do is toggle a variable by pressing a button to make the loop > stop. > > > > > ( ugly ) workaround you might use a wxTimer; using wxYield is _strongly_ > > > discouraged because it can lead to unexpected reentrancy > > > problems ( of course there are cases where you can't do without ). > > > I never used it, so I can't tell if the handlers not being fired is > > > a wxPerl or a wxWindows problem ( will check ). > > > > Thanks again! |