I'm looking at the wxTimer Doc. and I am trying to create an event timer.have created an event timer.
this is the code I have so far, but it's not working. I can't seem to figure out what I'm doing wrong. It works, but seems to eat resources, even though it's not doing much...
#!/usr/bin/perl
use strict;
use warnings;
use Wx;
package MyFrame;
use base 'Wx::Frame';
use Wx::Event qw(EVT_BUTTON);
sub new {
my $ref = shift;
my $self = $ref->SUPER::new(
undef, #Parent Window
-1, #Window ID (-1 means any)
'wxPerl', #Window Title
[-1, -11], #Default Position
[250, 250], #size
);
#create panel
my $panel = Wx::Panel->new (
$self, #parent window
-1, #id
);
#create button
my $button = Wx::Button->new(
$panel, # Parent Panel
-1, # id
'Click Me!', # label
[30, 20], # position
[-1, -1], # default size
);
my $timer = Wx::Timer->new(
$self, # Parent Frame
-1, # Timer ID
);
$timer->Start(1);
EVT_TIMER $self, $timer, \&do_stuff;
EVT_BUTTON $self, $button, \&on_click_button;
return $self;
}
sub on_click_button {
my ($self, $event) = @_;
$self->SetTitle( 'Clicked');
}
sub do_stuff {
#get current focus Id;
#determine if the ID has changed
#etc
}
package MyTimer;
use base 'Wx::Timer';
sub new {
my $self = shift;
my $timer = Wx::Timer->wxTimer();
return $timer;
}
1;
package MyApp;
use base 'Wx::App';
sub OnInit {
my $timer = MyTimer->new;
$timer->Start(1);
my $frame = MyFrame->new;
$frame->Show(1);
}
package main;
my $app = MyApp->new;
$app->MainLoop;
I'm really not sure how to construct the MyTimer object.
EDIT: To fix timer
Timer problem has been resolved. Any suggestions on the new solution to the timer presented?
I started this thread to work on the timer part of the application. for the full application please refer to this thread.