File: WxTesting.pm

package info (click to toggle)
libwx-perl-processstream-perl 0.32-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176 kB
  • sloc: perl: 1,078; makefile: 4; sh: 3
file content (111 lines) | stat: -rw-r--r-- 2,368 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#############################################################################
## Name:        t/WxTesting.pm
## Purpose:     helper functions
## Author:      Mark Dootson
## Created:     20070326
## Copyright:   Based on the Wx distribution test helper which is 
##              (c) 2005,2006,2007 Mattia Barbon and is available in the 
##              wxPerl distribution.
##              This code is copyright (c) 2007 Mark Dootson
## Licence:     This program is free software; you can redistribute it and/or
##              modify it under the same terms as Perl itself
#############################################################################

package WxTesting::Handler;
use strict;
use Wx;
use base qw(Wx::EvtHandler);
use Wx::Event qw(EVT_TIMER);

sub new {
	my $class = shift;
	my $self = $class->SUPER::new( @_ );
	EVT_TIMER( $self, -1, \&OnTimer );
	return $self;
}

sub OnTimer {
	# run once when app starts
	my $frame = Wx::wxTheApp()->GetTopWindow;
	$frame->RunTests();
	$frame->Destroy;
	Wx::WakeUpIdle;
}

package WxTesting::Frame;
use strict;
use Wx;
use base qw( Wx::Frame );

sub new {
	my $class = shift;
	my $self = $class->SUPER::new( @_ );
	
	# start the test run timer
    $self->{_testtimer} = Wx::Timer->new( WxTesting::Handler->new );
	$self->{_testtimer}->Start( 800, 1 );
	
	return $self;	
}

sub RunTests {
	my $self = shift;
	die 'RunTests must be overridden in test script';
}

sub TestAppTimeOut {
	my $self = shift;
	$self->Destroy;
}

sub Destroy {
    my $self = shift;
    $self->SUPER::Destroy;
    $self->{_testtimer}->Destroy;
    Wx::wxTheApp()->ExitMainLoop;
    Wx::WakeUpIdle();
}

package WxTesting::App;

use base qw( Wx::App );

my $framesub;

sub new {
	my $class = shift;
	my ( $frameclass ) = @_;
	$framesub = sub { $frameclass; };
	my $self = $class->SUPER::new();
	$self->SetExitOnFrameDelete(1);
	return $self;
}

sub OnInit {
	my $self = shift;
	my $frameclass = &$framesub;
	my $mainwindow = $frameclass->new(undef, -1, 'Wx Testing Frame');
	$self->SetTopWindow($mainwindow);
	#$mainwindow->Show(1);
	return 1;
}

package WxTesting;

use strict;
use Wx;
require Exporter;

use vars qw(@ISA @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw( app_from_wxtesting_frame );
				 
sub app_from_wxtesting_frame {
	my ( $frameclass ) = @_;
	my $app = WxTesting::App->new( $frameclass );
	return $app;
}

1;
__END__