Packager/resource/packtest.pl untested

filter: Statementstmt 0.0% 0 / 174 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 29 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 226 CC 6 SCAR 12.8
CC
6
Cov
0%
get_resource_path
12.0
BEGIN
6.0
new
6.0
CRAP 3.6
1 ###################################################################################
2 # Distribution Wx::Perl::Packager
3 # File packtest.pl
4 # Description: simple test for packaging
5 # File Revision: $Id: packtest.pl 41 2010-03-13 22:37:13Z $
6 # License: This program is free software; you can redistribute it and/or
7 # modify it under the same terms as Perl itself
8 # Copyright: Copyright (c) 2006 - 2010 Mark Dootson
9 ###################################################################################
10 #!/usr/bin/perl
11  
12 # PACKAGE AND TEST ME
13  
14 BEGIN {
15 my $checkargs = join('', @ARGV);
16 $ENV{WXPERLPACKAGER_DEBUGPRINT_ON} = 1 if $checkargs =~ /debug/i;
17 $ENV{WXPERLPACKAGER_DEBUGPRINT_ON} = 1;
18 }
19  
20 use threads;
21 use Wx::Perl::Packager 0.20;
22 use strict;
23 use warnings;
24  
25 print qq(CONSOLE OUTPUT\n);
26  
27 #############################################################
28 # App
29 #############################################################
30  
31 package Packtest::App;
32 use Wx qw( :everything );
33 use base qw( Wx::App );
34  
35 sub OnInit {
36 my $self = shift;
37 Wx::InitAllImageHandlers;
38 my $mainwindow = Packtest::MainWindow->new();
39 $mainwindow->Show(1);
40 $self->SetTopWindow($mainwindow);
41 return 1;
42 }
43  
44 #############################################################
45 # Main Window
46 #############################################################
47  
48 package Packtest::MainWindow;
49 use Wx qw( :everything );
50 use Wx::Event qw( EVT_MENU );
51 use base qw( Wx::Frame );
52  
53 sub new {
54 my $class = shift;
55 my $framesize = [500,300];
56 my $self = $class->SUPER::new(undef, wxID_ANY, 'Wx Perl Packager Test Script', wxDefaultPosition, $framesize);
57
58 #---------------------------------------------------------------
59 # Commands
60 #---------------------------------------------------------------
61
62 my $menubar = Wx::MenuBar->new;
63 my $menu = Wx::Menu->new();
64 my $menuitem = Wx::MenuItem->new($menu,wxID_ANY, 'E&xit', 'Exit Application');
65 $menu->Append($menuitem);
66 EVT_MENU($self, $menuitem, sub { shift->OnMenuExit( @_ ); } );
67
68 $menubar->Append($menu, '&File');
69
70 $self->SetMenuBar($menubar);
71
72 #---------------------------------------------------------------
73 # Controls
74 #---------------------------------------------------------------
75 my $mainpanel = Wx::Panel->new($self, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxTAB_TRAVERSAL);
76 my $notebook = Packtest::Notebook->new($mainpanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
77
78 #---------------------------------------------------------------
79 # Layout
80 #---------------------------------------------------------------
81 my $mainsizer = Wx::BoxSizer->new(wxVERTICAL);
82 my $panelsizer = Wx::BoxSizer->new(wxVERTICAL);
83
84 $panelsizer->Add($notebook, 1, wxEXPAND|wxALL, 0);
85 $mainpanel->SetSizer($panelsizer);
86
87 $mainsizer->Add($mainpanel, 1, wxEXPAND|wxALL, 0);
88 $self->SetSizer($mainsizer);
89
90 #---------------------------------------------------------------
91 # Init
92 #---------------------------------------------------------------
93 my $xpmfile = $self->get_resource('packager.xpm');
94 $self->SetIcon( Wx::Icon->new( $xpmfile, wxBITMAP_TYPE_XPM ) ) if -f $xpmfile;
95 $self->Centre;
96 return $self;
97 }
98  
99 sub OnMenuExit {
100 my ($self, $event) = @_;
101 $self->Close;
102 }
103  
104 sub get_resource {
105 my ($self, $resource) = @_;
106 return $self->get_resource_path . '/' . $resource;
107 }
108  
109 sub get_resource_path {
110 # find path to resources
111 my $self = shift;
112 return $self->{_resourcepath} if exists $self->{_resourcepath};
113 foreach ( @INC ) {
114 my $path = "$_/Wx/Perl/Packager/packager.xpm";
115 if( -f $path) {
116 $path =~ s/packager\.xpm$/\/resource/;
117 $self->{_resourcepath} = $path;
118 last;
119 }
120 }
121 $self->{_resourcepath} ||= '';
122 return $self->{_resourcepath};
123 }
124  
125 #############################################################
126 # Main Notebook
127 #############################################################
128  
129 package Packtest::Notebook;
130 use Wx qw( :everything );
131 use base qw( Wx::Notebook );
132  
133 sub new {
134 my $class = shift;
135 my $self = $class->SUPER::new(@_);
136
137 #-------------------------------------------------------
138 # Panels
139 #-------------------------------------------------------
140
141 my $stcpanel = Packtest::Panel::STC->new($self);
142 $self->AddPage($stcpanel, 'Styled Text');
143
144 my $htmlpanel = Packtest::Panel::Html->new($self);
145 $self->AddPage($htmlpanel, 'Html Window');
146
147 my $listpanel = Packtest::Panel::ListCtrl->new($self);
148 $self->AddPage($listpanel, 'List Control');
149  
150 return $self;
151 }
152  
153 #############################################################
154 # Panel HTML
155 #############################################################
156  
157 package Packtest::Panel::Html;
158 use Wx qw( :everything );
159 use base qw( Wx::Panel );
160 use Wx::Html;
161  
162 sub new {
163 my ($class, $parent) = @_;
164 my $self = $class->SUPER::new($parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxTAB_TRAVERSAL);
165
166 my $htmlwindow = Wx::HtmlWindow->new($self, wxID_ANY);
167
168 my $html = q(<!-- If you see this and HTML tags, the HTML load has failed -->
169 <head><body><center>
170 <h1>Wx::HtmlWindow Header 1 Text</h1><br/>
171 <h2>Wx::HtmlWindow Header 2 Text</h2><br/>
172 <h3>Wx::HtmlWindow Header 3 Text</h3><br/>
173 <h4>Wx::HtmlWindow Header 4 Text</h4><br/>
174 </center>
175
176 </body></head>);
177 $htmlwindow->SetPage($html);
178
179 my $sizer = Wx::BoxSizer->new(wxVERTICAL);
180 $sizer->Add($htmlwindow, 1, wxEXPAND|wxALL, 0);
181 $self->SetSizer($sizer);
182 return $self;
183 }
184  
185 #############################################################
186 # Panel STC
187 #############################################################
188  
189 package Packtest::Panel::STC;
190 use Wx qw( :everything );
191 use Wx::STC;
192 use base qw( Wx::Panel );
193  
194 sub new {
195 my ($class, $parent) = @_;
196 my $self = $class->SUPER::new($parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxTAB_TRAVERSAL);
197
198 my $stcwindow;
199
200 $stcwindow = Wx::StyledTextCtrl->new($self, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
201
202 my $font = Wx::Font->new( 10, wxTELETYPE, wxNORMAL, wxNORMAL );
203 my $sizer = Wx::BoxSizer->new(wxVERTICAL);
204
205 #---------------------------------------
206 # STC Code taken directly from Wx::Demo
207 #---------------------------------------
208  
209 if( $stcwindow ) {
210  
211 $stcwindow->SetFont( $font );
212 $stcwindow->StyleSetFont( wxSTC_STYLE_DEFAULT, $font );
213 $stcwindow->StyleClearAll();
214
215 $stcwindow->StyleSetForeground( wxSTC_PL_DEFAULT, Wx::Colour->new(0x00, 0x00, 0x7f));
216 $stcwindow->StyleSetForeground( wxSTC_PL_ERROR, Wx::Colour->new(0xff, 0x00, 0x00));
217 $stcwindow->StyleSetForeground( wxSTC_PL_COMMENTLINE, Wx::Colour->new(0x00, 0x7f, 0x00)); # line green
218 $stcwindow->StyleSetForeground( wxSTC_PL_POD, Wx::Colour->new(0x7f, 0x7f, 0x7f));
219 $stcwindow->StyleSetForeground( wxSTC_PL_NUMBER, Wx::Colour->new(0x00, 0x7f, 0x7f));
220 $stcwindow->StyleSetForeground( wxSTC_PL_WORD, Wx::Colour->new(0x00, 0x00, 0x7f));
221 $stcwindow->StyleSetForeground( wxSTC_PL_STRING, Wx::Colour->new(0xff, 0x7f, 0x00)); # orange
222 $stcwindow->StyleSetForeground( wxSTC_PL_CHARACTER, Wx::Colour->new(0x7f, 0x00, 0x7f));
223 $stcwindow->StyleSetForeground( wxSTC_PL_PUNCTUATION, Wx::Colour->new(0x00, 0x00, 0x00));
224 $stcwindow->StyleSetForeground( wxSTC_PL_PREPROCESSOR, Wx::Colour->new(0x7f, 0x7f, 0x7f));
225 $stcwindow->StyleSetForeground( wxSTC_PL_OPERATOR, Wx::Colour->new(0x00, 0x00, 0x7f)); # dark blue
226 $stcwindow->StyleSetForeground( wxSTC_PL_IDENTIFIER, Wx::Colour->new(0x00, 0x00, 0xff)); # bright blue
227 $stcwindow->StyleSetForeground( wxSTC_PL_SCALAR, Wx::Colour->new(0x7f, 0x00, 0x7f)); # purple
228 $stcwindow->StyleSetForeground( wxSTC_PL_ARRAY, Wx::Colour->new(0x40, 0x80, 0xff)); # light blue
229 $stcwindow->StyleSetForeground( wxSTC_PL_HASH, Wx::Colour->new(0x00, 0x80, 0xff));
230 # wxSTC_PL_SYMBOLTABLE (15)
231 # missing SCE_PL_VARIABLE_INDEXER (16)
232 $stcwindow->StyleSetForeground( wxSTC_PL_REGEX, Wx::Colour->new(0xff, 0x00, 0x7f)); # red
233 $stcwindow->StyleSetForeground( wxSTC_PL_REGSUBST, Wx::Colour->new(0x7f, 0x7f, 0x00)); # light olive
234 # wxSTC_PL_LONGQUOTE (19)
235 # wxSTC_PL_BACKTICKS (20)
236 # wxSTC_PL_DATASECTION (21)
237 # wxSTC_PL_HERE_DELIM (22)
238 $stcwindow->StyleSetForeground( wxSTC_PL_HERE_Q, Wx::Colour->new(0x7f, 0x00, 0x7f));
239 # wxSTC_PL_HERE_QQ (24)
240 # wxSTC_PL_HERE_QX (25)
241 $stcwindow->StyleSetForeground( wxSTC_PL_STRING_Q, Wx::Colour->new(0x7f, 0x00, 0x7f));
242 $stcwindow->StyleSetForeground( wxSTC_PL_STRING_QQ, Wx::Colour->new(0xff, 0x7f, 0x00)); # orange
243 # wxSTC_PL_STRING_QX (28)
244 # wxSTC_PL_STRING_QR (29)
245 $stcwindow->StyleSetForeground( wxSTC_PL_STRING_QW, Wx::Colour->new(0x7f, 0x00, 0x7f));
246
247 #Set a style 12 bold
248 $stcwindow->StyleSetBold(12, 1);
249
250 # Apply tag style for selected lexer (blue)
251 $stcwindow->StyleSetSpec( wxSTC_H_TAG, "fore:#0000ff" );
252
253 $stcwindow->SetLexer( wxSTC_LEX_PERL );
254
255 #---------------------------------------
256 # Set some Perl
257 #---------------------------------------
258 my $code = q(TYPE SOMETHING IN HERE TO TEST
259 rmtree ON EXIT IN PDK FOR MSWIN
260 IF YOU DON'T INTERACT WITH THE
261 KEYBOARD, rmtree works anyway
262  
263 PACKTEST version 0.30
264  
265 use strict;
266 use warnings;
267 # If you are seeing this, styled text worked OK;
268  
269 our $var = "one";
270 print qq(Var is $var\n);
271 );
272
273
274  
275 $stcwindow->SetText($code);
276
277
278 $sizer->Add($stcwindow, 1, wxEXPAND|wxALL, 0);
279 }# end of if stcwindow
280
281 $self->SetSizer($sizer);
282 return $self;
283 }
284  
285 #############################################################
286 # Panel ListCtrl
287 #############################################################
288  
289 package Packtest::Panel::ListCtrl;
290 use Wx qw( :everything );
291 use base qw( Wx::Panel );
292  
293 sub new {
294 my ($class, $parent) = @_;
295 my $self = $class->SUPER::new($parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxTAB_TRAVERSAL);
296
297 my $list = Wx::ListCtrl->new($self, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxLC_VIRTUAL);
298 $list->InsertColumn(0, 'Column One', wxLIST_FORMAT_LEFT, 200);
299 $list->InsertColumn(1, 'Column Two', wxLIST_FORMAT_LEFT, 200);
300 my $sizer = Wx::BoxSizer->new(wxVERTICAL);
301 $sizer->Add($list, 1, wxEXPAND|wxALL, 0);
302 $self->SetSizer($sizer);
303 return $self;
304 }
305  
306  
307 #############################################################
308 # Load
309 #############################################################
310  
311 package main;
312  
313 my $app = Packtest::App->new;
314 $app->MainLoop;
315  
316 1;
317  
318 __END__