line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################# |
2
|
|
|
|
|
|
|
## Name: lib/Wx/Demo.pm |
3
|
|
|
|
|
|
|
## Purpose: wxPerl demo main module |
4
|
|
|
|
|
|
|
## Author: Mattia Barbon |
5
|
|
|
|
|
|
|
## Modified by: |
6
|
|
|
|
|
|
|
## Created: 20/08/2006 |
7
|
|
|
|
|
|
|
## RCS-ID: $Id: Demo.pm 3496 2013-04-23 00:23:19Z mdootson $ |
8
|
|
|
|
|
|
|
## Copyright: (c) 2006-2011 Mattia Barbon |
9
|
|
|
|
|
|
|
## Licence: This program is free software; you can redistribute it and/or |
10
|
|
|
|
|
|
|
## modify it under the same terms as Perl itself |
11
|
|
|
|
|
|
|
############################################################################# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Wx::Demo; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Wx::Demo - the wxPerl demo |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Every demo is a module in the Wx::DemoModules::* namespace. |
22
|
|
|
|
|
|
|
On startup Wx::Demo collects the lits of Demo Modules, tries to load |
23
|
|
|
|
|
|
|
each one of them and displays a list of them based on a categorization |
24
|
|
|
|
|
|
|
within the Demo Modules. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
You can also locate Demos based on the widget being use or based |
27
|
|
|
|
|
|
|
on the event used in the example. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 Demo Modules |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Every Demo Module can supply a C method that should return |
32
|
|
|
|
|
|
|
extra deep categorization. It should return a reference to a two element |
33
|
|
|
|
|
|
|
array where the first element is the category hierarchy: maincat/subcat |
34
|
|
|
|
|
|
|
and the second element is the title of the given category. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
The main categories are hard-coded in the Wx::Demo module |
37
|
|
|
|
|
|
|
(new, controls, windows, etc...) |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Every module can have an C method that should return |
40
|
|
|
|
|
|
|
a list of names of the categories the module belongs to so these |
41
|
|
|
|
|
|
|
should be strings such as "new", "control", etc... which are |
42
|
|
|
|
|
|
|
main categories or "control/xyz" which is a subcategory definde by |
43
|
|
|
|
|
|
|
one of the Demo modules. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
If there is no add_to_tags or if it does not return anything |
46
|
|
|
|
|
|
|
then the demo can only be found from the list of widgets or events. |
47
|
|
|
|
|
|
|
Currently the reason that some packages might have not add_to_tags method |
48
|
|
|
|
|
|
|
is that some of the demos are implemented as several packages in one file. |
49
|
|
|
|
|
|
|
In such case only the main package has the add_to_tags method as only that |
50
|
|
|
|
|
|
|
needs to be added to the list of demos. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Every module must have a C method that returns its title. |
53
|
|
|
|
|
|
|
As far as I can see, the titles are usually the same as the filename. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
When one of the Demo Modules is selected in the left pane, the Demo will |
57
|
|
|
|
|
|
|
try to execute its C and if it does not exists then the C |
58
|
|
|
|
|
|
|
method. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
There is also an optional C method in the Demo Modules. I think |
61
|
|
|
|
|
|
|
it is used in case there are more than one Demo Packages in the same |
62
|
|
|
|
|
|
|
file. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Some of the Demo Modules use L as |
65
|
|
|
|
|
|
|
a base class. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 AUTHOR |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Mattia Barbon |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 LICENSE |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
75
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
1
|
|
1514
|
use Wx; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
use strict; |
82
|
|
|
|
|
|
|
use base qw(Wx::Frame Class::Accessor::Fast); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
use Wx qw(:textctrl :sizer :window :id); |
85
|
|
|
|
|
|
|
use Wx qw(wxDefaultPosition wxDefaultSize wxTheClipboard wxWINDOW_VARIANT_SMALL |
86
|
|
|
|
|
|
|
wxDEFAULT_FRAME_STYLE wxNO_FULL_REPAINT_ON_RESIZE wxCLIP_CHILDREN); |
87
|
|
|
|
|
|
|
use Wx::Event qw(EVT_TREE_SEL_CHANGED EVT_MENU EVT_CLOSE); |
88
|
|
|
|
|
|
|
use File::Slurp; |
89
|
|
|
|
|
|
|
use File::Basename qw(); |
90
|
|
|
|
|
|
|
use File::Spec; |
91
|
|
|
|
|
|
|
use UNIVERSAL::require; |
92
|
|
|
|
|
|
|
use Module::Pluggable::Object; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
use Wx::Demo::Source; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
our $VERSION = '0.22'; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( qw(tree widget_tree events_tree source notebook left_notebook failwidgets) ); |
99
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw(search_term ) ); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#if( Wx::wxMAC()) { |
102
|
|
|
|
|
|
|
#Modern Mac defaults look better than our settings |
103
|
|
|
|
|
|
|
# Wx::SystemOptions::SetOptionInt('window-default-variant', wxWINDOW_VARIANT_SMALL); |
104
|
|
|
|
|
|
|
# Wx::SystemOptions::SetOptionInt('mac.listctrl.always_use_generic', 1); |
105
|
|
|
|
|
|
|
#} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub new { |
108
|
|
|
|
|
|
|
my( $class ) = @_; |
109
|
|
|
|
|
|
|
my $self = $class->SUPER::new |
110
|
|
|
|
|
|
|
( undef, -1, 'wxPerl demo', wxDefaultPosition, [ 800, 600 ], |
111
|
|
|
|
|
|
|
wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN ); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# $self->SetLayoutDirection( Wx::wxLayout_RightToLeft() ); |
114
|
|
|
|
|
|
|
Wx::InitAllImageHandlers(); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# create menu bar |
117
|
|
|
|
|
|
|
my $bar = Wx::MenuBar->new; |
118
|
|
|
|
|
|
|
my $file = Wx::Menu->new; |
119
|
|
|
|
|
|
|
my $help = Wx::Menu->new; |
120
|
|
|
|
|
|
|
my $edit = Wx::Menu->new; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$file->Append( wxID_EXIT, '' ); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$help->Append( wxID_ABOUT, '' ); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$edit->Append( wxID_COPY, '' ); |
127
|
|
|
|
|
|
|
$edit->Append( wxID_FIND, '' ); |
128
|
|
|
|
|
|
|
my $find_again = $edit->Append( -1, "Find Again\tF3" ); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
$bar->Append( $file, "&File" ); |
131
|
|
|
|
|
|
|
$bar->Append( $edit, "&Edit" ); |
132
|
|
|
|
|
|
|
$bar->Append( $help, "&Help" ); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$self->SetMenuBar( $bar ); |
135
|
|
|
|
|
|
|
$self->{menu_count} = $self->GetMenuBar->GetMenuCount; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# create splitters |
138
|
|
|
|
|
|
|
my $split1 = Wx::SplitterWindow->new |
139
|
|
|
|
|
|
|
( $self, -1, wxDefaultPosition, wxDefaultSize, |
140
|
|
|
|
|
|
|
wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN ); |
141
|
|
|
|
|
|
|
my $split2 = Wx::SplitterWindow->new |
142
|
|
|
|
|
|
|
( $split1, -1, wxDefaultPosition, wxDefaultSize, |
143
|
|
|
|
|
|
|
wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN ); |
144
|
|
|
|
|
|
|
my $left_nb = Wx::Notebook->new |
145
|
|
|
|
|
|
|
( $split1, -1, wxDefaultPosition, wxDefaultSize, |
146
|
|
|
|
|
|
|
wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN ); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# As per rt#84591 |
149
|
|
|
|
|
|
|
$split1->SetMinimumPaneSize( 30 ); |
150
|
|
|
|
|
|
|
$split2->SetMinimumPaneSize( 30 ); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my $tree = Wx::TreeCtrl->new( $left_nb, -1 ); |
153
|
|
|
|
|
|
|
my $widget_tree = Wx::TreeCtrl->new( $left_nb, -1 ); |
154
|
|
|
|
|
|
|
my $events_tree = Wx::TreeCtrl->new( $left_nb, -1 ); |
155
|
|
|
|
|
|
|
$left_nb->AddPage( $tree, 'Categories', 0 ); |
156
|
|
|
|
|
|
|
$left_nb->AddPage( $widget_tree, 'Widgets', 0 ); |
157
|
|
|
|
|
|
|
$left_nb->AddPage( $events_tree, 'Events', 0 ); |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $text = Wx::TextCtrl->new |
160
|
|
|
|
|
|
|
( $split2, -1, "", wxDefaultPosition, wxDefaultSize, |
161
|
|
|
|
|
|
|
wxTE_READONLY|wxTE_MULTILINE|wxNO_FULL_REPAINT_ON_RESIZE ); |
162
|
|
|
|
|
|
|
my $log = Wx::LogTextCtrl->new( $text ); |
163
|
|
|
|
|
|
|
$self->{old_log} = Wx::Log::SetActiveTarget( $log ); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
my $nb = Wx::Notebook->new |
166
|
|
|
|
|
|
|
( $split2, -1, wxDefaultPosition, wxDefaultSize, |
167
|
|
|
|
|
|
|
wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN ); |
168
|
|
|
|
|
|
|
my $code = Wx::Demo::Source->new( $nb ); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
$nb->AddPage( $code, "Source", 0 ); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
$split1->SplitVertically( $left_nb, $split2, 250 ); |
173
|
|
|
|
|
|
|
$split2->SplitHorizontally( $nb, $text, 300 ); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
$self->{tree} = $tree; |
176
|
|
|
|
|
|
|
$self->{widget_tree} = $widget_tree; |
177
|
|
|
|
|
|
|
$self->{events_tree} = $events_tree; |
178
|
|
|
|
|
|
|
$self->{source} = $code; |
179
|
|
|
|
|
|
|
$self->{notebook} = $nb; |
180
|
|
|
|
|
|
|
$self->{left_notebook} = $left_nb; |
181
|
|
|
|
|
|
|
$self->{failwidgets} = []; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
EVT_TREE_SEL_CHANGED( $self, $tree, sub { on_show_module($tree, @_) } ); |
184
|
|
|
|
|
|
|
EVT_TREE_SEL_CHANGED( $self, $widget_tree, sub { on_show_module($widget_tree, @_) } ); |
185
|
|
|
|
|
|
|
EVT_TREE_SEL_CHANGED( $self, $events_tree, sub { on_show_module($events_tree, @_) } ); |
186
|
|
|
|
|
|
|
EVT_CLOSE( $self, \&on_close ); |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
EVT_MENU( $self, wxID_ABOUT, \&on_about ); |
189
|
|
|
|
|
|
|
EVT_MENU( $self, wxID_EXIT, sub { $self->Close } ); |
190
|
|
|
|
|
|
|
EVT_MENU( $self, wxID_COPY, \&on_copy ); |
191
|
|
|
|
|
|
|
EVT_MENU( $self, wxID_FIND, \&on_find ); |
192
|
|
|
|
|
|
|
EVT_MENU( $self, $find_again, \&on_find_again ); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
$self->populate_modules; |
195
|
|
|
|
|
|
|
$self->populate_widgets; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
$self->SetIcon( Wx::GetWxPerlIcon() ); |
198
|
|
|
|
|
|
|
$self->Show; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Wx::LogMessage( "Welcome to wxPerl!" ); |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
return $self; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub on_find { |
206
|
|
|
|
|
|
|
my( $self ) = @_; |
207
|
|
|
|
|
|
|
$self->get_search_term; |
208
|
|
|
|
|
|
|
$self->search; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
return; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub on_find_again { |
214
|
|
|
|
|
|
|
my( $self ) = @_; |
215
|
|
|
|
|
|
|
if (not $self->search_term) { |
216
|
|
|
|
|
|
|
$self->get_search_term; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
$self->search; |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
return; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub get_search_term { |
224
|
|
|
|
|
|
|
my ($self) = @_; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
my $search_term = $self->search_term || ''; |
227
|
|
|
|
|
|
|
my $dialog = Wx::TextEntryDialog->new( $self, "", "Search term", $search_term ); |
228
|
|
|
|
|
|
|
if ($dialog->ShowModal == wxID_CANCEL) { |
229
|
|
|
|
|
|
|
$dialog->Destroy; |
230
|
|
|
|
|
|
|
return; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
$search_term = $dialog->GetValue; |
233
|
|
|
|
|
|
|
$self->search_term($search_term); |
234
|
|
|
|
|
|
|
$dialog->Destroy; |
235
|
|
|
|
|
|
|
return; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
sub search { |
238
|
|
|
|
|
|
|
my ($self) = @_; |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
my $search_term = $self->search_term; |
241
|
|
|
|
|
|
|
return if not $search_term; |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
my $code = $self->{source}; |
244
|
|
|
|
|
|
|
my ($from, $to) = $code->GetSelection; |
245
|
|
|
|
|
|
|
my $last = $code->isa( 'Wx::TextCtrl' ) ? $code->GetLastPosition() : $code->GetLength(); |
246
|
|
|
|
|
|
|
my $str = $code->isa( 'Wx::TextCtrl' ) ? $code->GetRange(0, $last) : $code->GetTextRange(0, $last); |
247
|
|
|
|
|
|
|
my $pos = index($str, $search_term, $from+1); |
248
|
|
|
|
|
|
|
if (-1 == $pos) { |
249
|
|
|
|
|
|
|
$pos = index($str, $search_term); |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
if (-1 == $pos) { |
252
|
|
|
|
|
|
|
return; # not found |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
$code->SetSelection($pos, $pos+length($search_term)); |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
return; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub on_close { |
261
|
|
|
|
|
|
|
my( $self, $event ) = @_; |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Wx::Log::SetActiveTarget( $self->{old_log} ); |
264
|
|
|
|
|
|
|
$event->Skip; |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub on_about { |
268
|
|
|
|
|
|
|
my( $self ) = @_; |
269
|
|
|
|
|
|
|
use Wx qw(wxOK wxCENTRE wxVERSION_STRING); |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Wx::MessageBox( "wxPerl demo version $VERSION, (c) 2001-2011 Mattia Barbon\n" . |
272
|
|
|
|
|
|
|
"wxPerl $Wx::VERSION, " . wxVERSION_STRING, |
273
|
|
|
|
|
|
|
"About wxPerl demo", wxOK|wxCENTRE, $self ); |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# TODO: disallow copy when not the code is in focus |
277
|
|
|
|
|
|
|
# or copy the text from the log window too. |
278
|
|
|
|
|
|
|
sub on_copy { |
279
|
|
|
|
|
|
|
my( $self ) = @_; |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
my $code = $self->{source}; |
282
|
|
|
|
|
|
|
my ($from, $to) = $code->GetSelection; |
283
|
|
|
|
|
|
|
my $str = $code->isa( 'Wx::TextCtrl' ) ? $code->GetRange($from, $to) : $code->GetTextRange($from, $to); |
284
|
|
|
|
|
|
|
if (wxTheClipboard->Open()) { |
285
|
|
|
|
|
|
|
wxTheClipboard->SetData( Wx::TextDataObject->new($str) ); |
286
|
|
|
|
|
|
|
wxTheClipboard->Close(); |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
return; |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
sub on_show_module { |
294
|
|
|
|
|
|
|
my( $tree, $self, $event ) = @_; |
295
|
|
|
|
|
|
|
my $module = $tree->GetPlData( $event->GetItem ); |
296
|
|
|
|
|
|
|
return unless $module; |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
$self->show_module( $module ); |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
sub _module_file { |
302
|
|
|
|
|
|
|
my( $module ) = @_; |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
return $module->file if $module->can( 'file' ); |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
my $mod_file = $module; |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
$mod_file =~ s{::}{/}g; |
309
|
|
|
|
|
|
|
$mod_file .= '.pm'; |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
return $INC{$mod_file} |
312
|
|
|
|
|
|
|
} |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
sub _add_menus { |
315
|
|
|
|
|
|
|
my( $self, %menus ) = @_; |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
while( my( $title, $menu ) = each %menus ) { |
318
|
|
|
|
|
|
|
$self->GetMenuBar->Insert( $self->{menu_count}, $menu, $title ); |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
sub _remove_menus { |
323
|
|
|
|
|
|
|
my( $self ) = @_; |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
for ($self->{menu_count}+1 .. $self->GetMenuBar->GetMenuCount) { |
326
|
|
|
|
|
|
|
$self->GetMenuBar->Remove( $self->{menu_count} )->Destroy; |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
sub activate_module { |
331
|
|
|
|
|
|
|
my( $self, $module ) = @_; |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
my( $package ) = grep $_->title eq $module, |
334
|
|
|
|
|
|
|
grep $_->can( 'title' ), |
335
|
|
|
|
|
|
|
$self->plugins; |
336
|
|
|
|
|
|
|
return unless $package; |
337
|
|
|
|
|
|
|
$self->show_module( $package ); |
338
|
|
|
|
|
|
|
$self->show_demo_window; |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
sub show_demo_window { |
342
|
|
|
|
|
|
|
my( $self ) = @_; |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
$self->notebook->SetSelection( 1 ) if $self->notebook->GetPageCount == 2; |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
sub show_module { |
348
|
|
|
|
|
|
|
my( $self, $module ) = @_; |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
$self->source->set_source( scalar read_file _module_file( $module ) ); |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
my $nb = $self->notebook; |
353
|
|
|
|
|
|
|
my $window = $module->can( 'window' ) ? $module->window( $nb ) : |
354
|
|
|
|
|
|
|
$module->new( $nb ); |
355
|
|
|
|
|
|
|
my $sel = $nb->GetSelection; |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
if( $nb->GetPageCount == 2 ) { |
358
|
|
|
|
|
|
|
$nb->SetSelection( 0 ) if $sel == 1; |
359
|
|
|
|
|
|
|
$nb->DeletePage( 1 ); |
360
|
|
|
|
|
|
|
$self->_remove_menus; |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
if( ref( $window ) ) { |
363
|
|
|
|
|
|
|
if( !$window->IsTopLevel ) { |
364
|
|
|
|
|
|
|
$self->notebook->AddPage( $window, 'Demo' ); |
365
|
|
|
|
|
|
|
$nb->SetSelection( $sel ) if $sel == 1; |
366
|
|
|
|
|
|
|
} else { |
367
|
|
|
|
|
|
|
$window->Show; |
368
|
|
|
|
|
|
|
} |
369
|
|
|
|
|
|
|
$self->_add_menus( $window->menu ) if $window->can( 'menu' ); |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
} |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
my @tags = |
374
|
|
|
|
|
|
|
( [ new => 'New' ], |
375
|
|
|
|
|
|
|
[ controls => 'Controls' ], |
376
|
|
|
|
|
|
|
[ windows => 'Windows' ], |
377
|
|
|
|
|
|
|
[ managed => 'Managed Windows' ], |
378
|
|
|
|
|
|
|
[ dialogs => 'Dialogs' ], |
379
|
|
|
|
|
|
|
[ sizers => 'Sizers' ], |
380
|
|
|
|
|
|
|
[ dnd => 'Drag & Drop' ], |
381
|
|
|
|
|
|
|
[ misc => 'Miscellanea' ], |
382
|
|
|
|
|
|
|
); |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
sub d($) { Wx::TreeItemData->new( $_[0] ) } |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
# poor man's insertion sort |
387
|
|
|
|
|
|
|
sub add_item { |
388
|
|
|
|
|
|
|
my( $tree, $id, $module ) = @_; |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
my $title = $module->title; |
391
|
|
|
|
|
|
|
my( $child, $cookie ) = $tree->GetFirstChild( $id ); |
392
|
|
|
|
|
|
|
my $childtitle = $child ? $tree->GetItemText( $child ) : ''; |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
if( !$child || $childtitle gt $title ) { |
395
|
|
|
|
|
|
|
$tree->PrependItem( $id, $title, -1, -1, d $module ); |
396
|
|
|
|
|
|
|
} else { |
397
|
|
|
|
|
|
|
my $pchild = $child; |
398
|
|
|
|
|
|
|
while( ( $child, $cookie ) = $tree->GetNextChild( $id, $cookie ) ) { |
399
|
|
|
|
|
|
|
last unless $child; |
400
|
|
|
|
|
|
|
$childtitle = $tree->GetItemText( $child ); |
401
|
|
|
|
|
|
|
if( $childtitle lt $title ) { |
402
|
|
|
|
|
|
|
$pchild = $child; |
403
|
|
|
|
|
|
|
} else { |
404
|
|
|
|
|
|
|
$tree->InsertItem( $id, $pchild, $title, -1, -1, d $module ); |
405
|
|
|
|
|
|
|
return; |
406
|
|
|
|
|
|
|
} |
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
$tree->AppendItem( $id, $title, -1, -1, d $module ); |
410
|
|
|
|
|
|
|
} |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
sub populate_widgets { |
414
|
|
|
|
|
|
|
my( $self ) = @_; |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
my $widget_tree = $self->widget_tree; |
417
|
|
|
|
|
|
|
my $events_tree = $self->events_tree; |
418
|
|
|
|
|
|
|
my $widgets = $self->widgets; |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
my $wt_root_id = $widget_tree->AddRoot( 'wxPerl', -1, -1 ); |
421
|
|
|
|
|
|
|
my $et_root_id = $events_tree->AddRoot( 'wxPerl', -1, -1 ); |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
foreach my $widget (sort keys %$widgets) { |
424
|
|
|
|
|
|
|
if ($widget =~ /^EVT/) { |
425
|
|
|
|
|
|
|
my $parent_id = $events_tree->AppendItem( $et_root_id, $widget, -1, -1 ); |
426
|
|
|
|
|
|
|
foreach my $name (sort keys %{ $widgets->{$widget} }) { |
427
|
|
|
|
|
|
|
my $id = $events_tree->AppendItem( $parent_id, $name, -1, -1, Wx::TreeItemData->new($name) ); |
428
|
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
|
} else { |
430
|
|
|
|
|
|
|
my $parent_id = $widget_tree->AppendItem( $wt_root_id, $widget, -1, -1 ); |
431
|
|
|
|
|
|
|
foreach my $name (sort keys %{ $widgets->{$widget} }) { |
432
|
|
|
|
|
|
|
my $id = $widget_tree->AppendItem( $parent_id, $name, -1, -1, Wx::TreeItemData->new($name) ); |
433
|
|
|
|
|
|
|
} |
434
|
|
|
|
|
|
|
} |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
$widget_tree->Expand( $wt_root_id ); |
438
|
|
|
|
|
|
|
$events_tree->Expand( $et_root_id ); |
439
|
|
|
|
|
|
|
return; |
440
|
|
|
|
|
|
|
} |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
sub populate_modules { |
443
|
|
|
|
|
|
|
my( $self ) = @_; |
444
|
|
|
|
|
|
|
my $tree = $self->tree; |
445
|
|
|
|
|
|
|
my @modules = $self->plugins; |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
my $root_id = $tree->AddRoot( 'wxPerl', -1, -1 ); |
448
|
|
|
|
|
|
|
my %tag_map; |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
foreach my $tag ( @tags, map $_->tags, grep $_->can( 'tags' ), @modules ) { |
451
|
|
|
|
|
|
|
my( $parent_id, $last ); |
452
|
|
|
|
|
|
|
if( ( my $last_slash = rindex $tag->[0], '/' ) != -1 ) { |
453
|
|
|
|
|
|
|
$parent_id = $tag_map{ substr $tag->[0], 0, $last_slash }; |
454
|
|
|
|
|
|
|
} else { |
455
|
|
|
|
|
|
|
$parent_id = $root_id; |
456
|
|
|
|
|
|
|
} |
457
|
|
|
|
|
|
|
die "'$tag' has no parent" unless $parent_id; |
458
|
|
|
|
|
|
|
next if $tag_map{$tag->[0]}; |
459
|
|
|
|
|
|
|
my $id = $tree->AppendItem( $parent_id, $tag->[1], -1, -1 ); |
460
|
|
|
|
|
|
|
$tag_map{$tag->[0]} = $id; |
461
|
|
|
|
|
|
|
} |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
foreach my $module ( grep $_->can( 'add_to_tags' ), @modules ) { |
464
|
|
|
|
|
|
|
foreach my $tag ( $module->add_to_tags ) { |
465
|
|
|
|
|
|
|
my $parent_id = $tag_map{$tag}; |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
unless( $parent_id ) { |
468
|
|
|
|
|
|
|
Wx::LogWarning( 'Wrong parent: %s', $tag ); |
469
|
|
|
|
|
|
|
next; |
470
|
|
|
|
|
|
|
} |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
add_item( $tree, $parent_id, $module ); |
473
|
|
|
|
|
|
|
} |
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
if( @{ $self->failwidgets } ) { |
477
|
|
|
|
|
|
|
my $id = $tree->AppendItem( $root_id, 'Not Loaded', -1, -1 ); |
478
|
|
|
|
|
|
|
$tag_map{fail} = $id; |
479
|
|
|
|
|
|
|
} |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
foreach my $module ( grep $_->can( 'add_to_tags' ), @{ $self->failwidgets } ) { |
482
|
|
|
|
|
|
|
foreach my $tag ( $module->add_to_tags ) { |
483
|
|
|
|
|
|
|
my $parent_id = $tag_map{$tag}; |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
unless( $parent_id ) { |
486
|
|
|
|
|
|
|
Wx::LogWarning( 'Wrong parent: %s', $tag ); |
487
|
|
|
|
|
|
|
next; |
488
|
|
|
|
|
|
|
} |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
add_item( $tree, $parent_id, $module ); |
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
$tree->Expand( $root_id ); |
498
|
|
|
|
|
|
|
} |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
sub plugins { |
501
|
|
|
|
|
|
|
my( $self ) = @_; |
502
|
|
|
|
|
|
|
return @{$self->{plugins}} if $self->{plugins}; |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
($self->{plugins}, $self->{widgets}) = $self->load_plugins(sub { Wx::LogWarning( @_ ) }); |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
return @{$self->{plugins}}; |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
sub widgets { |
510
|
|
|
|
|
|
|
my( $self ) = @_; |
511
|
|
|
|
|
|
|
if (not $self->{widgets}) { |
512
|
|
|
|
|
|
|
$self->plugins; |
513
|
|
|
|
|
|
|
} |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
return $self->{widgets}; |
516
|
|
|
|
|
|
|
} |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
# allow ignoring load failures |
519
|
|
|
|
|
|
|
sub load_plugins { |
520
|
|
|
|
|
|
|
my( $self , $w ) = @_; |
521
|
|
|
|
|
|
|
my %skip; |
522
|
|
|
|
|
|
|
my %widgets; |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
# allow modules to provide a hint module and |
525
|
|
|
|
|
|
|
# rplacement info module if they |
526
|
|
|
|
|
|
|
# should not be loaded |
527
|
|
|
|
|
|
|
my $hintfinder = Module::Pluggable::Object->new |
528
|
|
|
|
|
|
|
( search_path => [ qw(Wx::DemoHints) ], |
529
|
|
|
|
|
|
|
require => 0, |
530
|
|
|
|
|
|
|
filename => __FILE__, |
531
|
|
|
|
|
|
|
); |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
my %hashints = map { 'Wx::DemoModules::' . (split(/::/, $_))[-1] => $_ } $hintfinder->plugins; |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
# load the core hints |
536
|
|
|
|
|
|
|
my %corehints; |
537
|
|
|
|
|
|
|
require Wx::DemoHints::CoreHints; |
538
|
|
|
|
|
|
|
for my $hint ( Wx::DemoHints::CoreHints->hint_packages ) { |
539
|
|
|
|
|
|
|
my $module = $hint; |
540
|
|
|
|
|
|
|
$module =~ s/DemoHints/DemoModules/; |
541
|
|
|
|
|
|
|
$corehints{$module} = $hint; |
542
|
|
|
|
|
|
|
} |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
my $finder = Module::Pluggable::Object->new |
545
|
|
|
|
|
|
|
( search_path => [ qw(Wx::DemoModules) ], |
546
|
|
|
|
|
|
|
require => 0, |
547
|
|
|
|
|
|
|
filename => __FILE__, |
548
|
|
|
|
|
|
|
); |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
foreach my $package ( $finder->plugins ) { |
551
|
|
|
|
|
|
|
next if $skip{$package}; |
552
|
|
|
|
|
|
|
my $f = "$package.pm"; $f =~ s{::}{/}g; |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
# use file and core hints to avoid loading packages |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
if( $hashints{$package} ) { |
557
|
|
|
|
|
|
|
if($hashints{$package}->require && !$hashints{$package}->can_load ) { |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
push( @{ $self->{failwidgets} }, $hashints{$package} ); |
560
|
|
|
|
|
|
|
# and skip |
561
|
|
|
|
|
|
|
$skip{$package} = 1; |
562
|
|
|
|
|
|
|
next; |
563
|
|
|
|
|
|
|
} |
564
|
|
|
|
|
|
|
} elsif( $corehints{$package} ) { |
565
|
|
|
|
|
|
|
unless( $corehints{$package}->can_load ) { |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
push( @{ $self->{failwidgets} }, $corehints{$package} ); |
568
|
|
|
|
|
|
|
# and skip |
569
|
|
|
|
|
|
|
$skip{$package} = 1; |
570
|
|
|
|
|
|
|
next; |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
} |
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
if( $package->require ) { |
575
|
|
|
|
|
|
|
$self->parse_file($package, $f, $w, \%widgets); |
576
|
|
|
|
|
|
|
} else { |
577
|
|
|
|
|
|
|
$w->( "Skipping module '%s'", $package ); |
578
|
|
|
|
|
|
|
$w->( $_ ) foreach split /\n/, $@; |
579
|
|
|
|
|
|
|
# delete $INC{$f}; # for Perl 5.10 |
580
|
|
|
|
|
|
|
# $INC{$f} = 'skip it'; |
581
|
|
|
|
|
|
|
$INC{$f} = 'skip it' unless exists $INC{$f}; |
582
|
|
|
|
|
|
|
$skip{$package} = 1; |
583
|
|
|
|
|
|
|
}; |
584
|
|
|
|
|
|
|
} |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
# search inner packages (needed as there some files with multiple packages inside) |
587
|
|
|
|
|
|
|
my @plugins = Module::Pluggable::Object->new |
588
|
|
|
|
|
|
|
( search_path => [ qw(Wx::DemoModules) ], |
589
|
|
|
|
|
|
|
require => 1, |
590
|
|
|
|
|
|
|
filename => __FILE__, |
591
|
|
|
|
|
|
|
except => [ ( keys (%skip) ) ], |
592
|
|
|
|
|
|
|
)->plugins; |
593
|
|
|
|
|
|
|
return (\@plugins, \%widgets); |
594
|
|
|
|
|
|
|
} |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
sub parse_file { |
597
|
|
|
|
|
|
|
my ($self, $package, $path, $w, $widgets) = @_; |
598
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
if (open my $fh, '<', $INC{$path}) { |
600
|
|
|
|
|
|
|
while (my $line = <$fh>) { |
601
|
|
|
|
|
|
|
for ($line =~ /\b(Wx(::\w+)+)\b/g) { |
602
|
|
|
|
|
|
|
my $name = $1; |
603
|
|
|
|
|
|
|
next if $name =~ /^Wx::DemoModules/; |
604
|
|
|
|
|
|
|
$widgets->{$name}{$package} = 1; |
605
|
|
|
|
|
|
|
} |
606
|
|
|
|
|
|
|
for ($line =~ /\b(wx\w+)\b/g) { |
607
|
|
|
|
|
|
|
$widgets->{$1}{$package} = 1; |
608
|
|
|
|
|
|
|
} |
609
|
|
|
|
|
|
|
for ($line =~ /\b(EVT_\w+)\b/g) { |
610
|
|
|
|
|
|
|
$widgets->{$1}{$package} = 1; |
611
|
|
|
|
|
|
|
} |
612
|
|
|
|
|
|
|
} |
613
|
|
|
|
|
|
|
} else { |
614
|
|
|
|
|
|
|
$w->("Could not open $INC{$path} for $path $!"); |
615
|
|
|
|
|
|
|
} |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
return; |
618
|
|
|
|
|
|
|
} |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
sub get_data_file { |
621
|
|
|
|
|
|
|
my( $class, $file ) = @_; |
622
|
|
|
|
|
|
|
( undef, my $filename ) = caller; |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
my $dir = File::Basename::dirname( $filename ); |
625
|
|
|
|
|
|
|
until( -d File::Spec->catdir( $dir, 'files' ) ) { |
626
|
|
|
|
|
|
|
$dir = File::Basename::dirname( $dir ) |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
return File::Spec->catdir( $dir, 'files', $file ); |
630
|
|
|
|
|
|
|
} |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
1; |