-
Notifications
You must be signed in to change notification settings - Fork 27
/
Prima.pm
592 lines (385 loc) · 14.8 KB
/
Prima.pm
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
#
# Created by Anton Berezin <[email protected]>
#
package Prima;
use strict;
use warnings;
require DynaLoader;
use vars qw($VERSION @ISA $__import @preload $pid);
@ISA = qw(DynaLoader);
sub dl_load_flags { 0x00 }
$VERSION = '1.74';
$pid = $$;
bootstrap Prima $VERSION;
unless ( UNIVERSAL::can('Prima', 'init')) {
$::application = 0;
return 0;
}
$::application = undef;
require Prima::Const;
require Prima::Classes;
sub parse_argv
{
my %options = Prima::options();
my @ret;
for ( my $i = 0; $i < @_; $i++) {
if ( $_[$i] =~ m/^--(?:([^\=]+)\=)?(.*)$/) {
my ( $option, $value) = ( defined( $1) ? ( $1, $2) : ( $2, undef));
last unless defined($option);
if ( $option eq 'help') {
my @options = Prima::options();
printf " --%-10s - %s\n", shift @options, shift @options
while @options;
exit(0);
}
next unless exists $options{$option};
Prima::options( $option, $value);
} else {
push @ret, $_[$i];
}
}
return @ret;
}
{
my ( $i, $skip_argv, @argv);
for ( $i = 0; $i < @preload; $i++) {
if ( $preload[$i] eq 'argv') {
push @argv, $preload[++$i];
} elsif ( $preload[$i] eq 'noargv') {
$skip_argv++;
}
}
parse_argv( @argv) if @argv;
@ARGV = parse_argv( @ARGV) if @ARGV and not $skip_argv;
}
Prima::init($VERSION) unless $^C;
sub CLONE { $pid = 0 }
sub END
{
&Prima::cleanup() if $pid == $$ && UNIVERSAL::can('Prima', 'cleanup');
}
sub run
{
die "Prima was not properly initialized\n" unless $::application;
while ( 1 ) {
my $stack;
my $got_exception;
{
local $SIG{__DIE__} = sub {
$got_exception = 1;
$stack //= Carp::longmess();
die @_;
};
eval {
$::application-> go if $::application-> alive;
$got_exception = 0;
};
}
last unless defined $@ && $got_exception;
next if $::application->alive && !$::application->notify('Die', "$@", $stack);
die $@;
}
$::application-> destroy if $::application && $::application-> alive;
$::application = undef if $::application and not $::application->alive;
}
sub import
{
my @module = @_;
while (@module) {
my $module = shift @module;
next if $module eq 'Prima' || $module eq '';
$module = "Prima::$module" unless $module =~ /^Prima::/;
next unless $module;
local $__import = caller;
eval "use $module;";
die $@ if $@;
if ( $module->isa('Exporter') && $module->can('export')) {
no strict 'refs';
if ( exists ${$module.'::'}{'EXPORT'} && (my $ok = \@{"${module}::EXPORT"})) {
$module->export( $__import, @$ok) if @$ok;
}
}
$__import = 0;
}
}
1;
__END__
=pod
=head1 NAME
Prima - a Perl graphic toolkit
=head1 SYNOPSIS
=for podview <img src="Prima/hello-world.gif">
=for html <p><img src="https://raw.githubusercontent.com/dk/Prima/master/pod/Prima/hello-world.gif">
use Prima qw(Application Buttons);
Prima::MainWindow->new(
text => 'Hello world!',
size => [ 200, 200],
)-> insert( Button =>
centered => 1,
text => 'Hello world!',
onClick => sub { $::application-> close },
);
run Prima;
See more screenshots at L<http://prima.eu.org/big-picture>.
=head1 DESCRIPTION
Prima is a classic 2D GUI toolkit that works under Windows and X11
environments. The toolkit features a rich widget library, extensive 2D
graphic support, PDF generation, modern Unicode text input and output, and
supports a wide set of image formats. Additionally, the RAD-style Visual
Builder and POD viewer are included. The toolkit can interoperate with other
popular event loop libraries.
=head1 CLASS HIERARCHY
The toolkit is built with a combination of two basic sets of classes - core and
external. The core classes are coded in C and form a baseline for every Prima
object written in Perl. The usage of C is possible together with the toolkit;
however, its full power is revealed in the Perl domain. The external classes
present an easily expandable set of widgets, written entirely in Perl and
communicating with the system using Prima library calls.
The core classes form a hierarchy, which is displayed below:
Prima::Object
Prima::Component
Prima::AbstractMenu
Prima::AccelTable
Prima::Menu
Prima::Popup
Prima::Clipboard
Prima::Drawable
Prima::DeviceBitmap
Prima::Printer
Prima::Image
Prima::Icon
Prima::File
Prima::Region
Prima::Timer
Prima::Widget
Prima::Application
Prima::Window
The external classes are derived from these; the list of widget classes
can be found below in L</SEE ALSO>.
=head1 BASIC PROGRAM
The very basic code shown in L<"SYNOPSIS"> is explained here. The code creates
a window with a 'Hello, world' title and a button with the same text.
The program terminates after the button is pressed.
A basic construct for a program written with Prima requires
use Prima;
code; however, effective programming requires the usage of the other modules, for
example, C<Prima::Buttons>, which contains various button widgets. The
C<Prima.pm> module can be invoked together with a list of such modules, which makes the
construction
use Prima;
use Prima::Application;
use Prima::Buttons;
shorter by using the following scheme:
use Prima qw(Application Buttons);
Another basic issue is the event loop, which is called by
run Prima;
code and requires a C<Prima::Application> object to be created beforehand.
Invoking the C<Prima::Application> standard module is one of the possible ways
to create an application object. The program usually terminates after the event
loop is finished.
The main window is created by invoking
Prima::MainWindow->new();
or
Prima::MainWindow->create()
code with additional parameters. All Prima objects are created by the same
scheme; the class name is passed as the first parameter, and a custom set
of parameters is passed afterward:
$new_object = Class->new(
parameter => value,
parameter => value,
...
);
Here, parameters are the class property names, and they differ from class to
class. Classes often have common properties, primarily due to object
inheritance.
In the example, the following properties are used:
Window::text
Window::size
Button::text
Button::centered
Button::onClick
Property values can be of any scalar type. For example, the C<::text> property
accepts a string, C<::size> - an anonymous array of two integers, and
C<onClick> - a sub.
onXxxx are special properties that describe I<events> that can be used together
with the C<new>/C<create> syntax, and are additive when the regular properties
are substitutive (read more in L<Prima::Object>). Events are called in the
object context when a specific condition occurs. The C<onClick> event here,
for example, is called when the user presses (or otherwise activates) the
button.
=head1 API
This section describes miscellaneous methods, registered in the C<Prima::>
namespace.
=over
=item message TEXT
Displays a system message box with TEXT.
=item open_file, save_file
When the C<Prima::Dialog::FileDialog> module is loaded, these shortcut methods
are registered in the C<Prima::> namespace as an alternative to the same
methods in the module's namespace. The methods execute standard file open
and save dialogs, correspondingly.
See L<Prima::Dialog::FileDialog> for more.
=item run
Enters the program event loop. The loop is ended when C<Prima::Application>'s C<destroy>
or C<close> method is called.
=item parse_argv @ARGS
Parses Prima options from @ARGS, returns unparsed arguments.
=back
=head1 OPTIONS
Prima applications do not have a portable set of arguments; it depends on the
particular platform. Run
perl -e '$ARGV[0]=q(--help); require Prima'
or any Prima program with a C<--help> argument to get the list of supported
arguments. Programmatically, setting and obtaining these options can be done
by using the C<Prima::options> routine.
In cases where the Prima argument parsing conflicts with the application
options, use L<Prima::noARGV> to disable the automatic parsing; also see
L<parse_argv>. Alternatively, the construct
BEGIN { local @ARGV; require Prima; }
will also do.
=head1 SEE ALSO
The toolkit documentation is divided into several sections; the individual
manuals can be found in the following files:
=over
=item Tutorials
L<Prima::tutorial> - introductory tutorial
=item Core toolkit classes
L<Prima::Object> - basic object concepts, properties, events
L<Prima::Classes> - binder module for the core classes
L<Prima::Drawable> - 2-D graphic interface
L<Prima::Region> - generic shape for clipping and hit testing
L<Prima::Image> - bitmap routines
L<Prima::image-load> - image subsystem and file operations
L<Prima::Widget> - window management
=over 2
=item *
L<Prima::Widget::pack> - Tk::pack geometry manager
=item *
L<Prima::Widget::place> - Tk::place geometry manager
=back
L<Prima::Window> - top-level window management
L<Prima::Clipboard> - GUI interprocess data exchange
L<Prima::Menu> - pull-down and pop-up menu objects
L<Prima::Timer> - programmable periodical events
L<Prima::Application> - the root of widget objects hierarchy
L<Prima::Printer> - system printing services
L<Prima::File> - asynchronous stream I/O
=item Widget library
L<Prima::Buttons> - buttons, checkboxes, radios
L<Prima::Calendar> - calendar widget
L<Prima::ComboBox> - combo box widget
L<Prima::DetailedList> - multi-column list viewer with controlling header widget
L<Prima::DetailedOutline> - multi-column outline viewer with controlling header widget
L<Prima::DockManager> - advanced dockable widgets
L<Prima::Docks> - dockable widgets
L<Prima::Edit> - text editor
L<Prima::ExtLists> - listbox with checkboxes
L<Prima::FrameSet> - frameset widget
L<Prima::Grids> - grid widgets
L<Prima::HelpViewer> - the built-in POD browser
L<Prima::ImageViewer> - image viewer
L<Prima::InputLine> - input line widget
L<Prima::KeySelector> - key combination widget and routines
L<Prima::Menus> - menu widgets
L<Prima::Label> - static text widget
L<Prima::Lists> - list widgets
L<Prima::MDI> - top-level window emulation
L<Prima::Notebooks> - multipage widgets
L<Prima::Outlines> - tree view widgets
L<Prima::PodView> - POD browser widget
L<Prima::ScrollBar> - scroll bars
L<Prima::Sliders> - sliding bars, spin buttons, dial widgets, etc.
L<Prima::Spinner> - spinner animation widget
L<Prima::TextView> - rich text browser widget
L<Prima::Widget::Date> - date picker widget
L<Prima::Widget::Time> - time input widget
=item Standard dialogs
L<Prima::Dialog::ColorDialog> - color selection facilities
L<Prima::Dialog::FindDialog> - find and replace dialogs
L<Prima::Dialog::FileDialog> - file system-related widgets and dialogs
L<Prima::Dialog::FontDialog> - font dialog
L<Prima::Dialog::ImageDialog> - image file open and save dialogs
L<Prima::Image::TransparencyControl> - transparent color index selection
L<Prima::MsgBox> - message and input dialog boxes
L<Prima::Dialog::PrintDialog> - standard printer setup dialog
=item Drawing helpers
L<Prima::Drawable::Antialias> - alternative API for antialiased shapes
L<Prima::Drawable::CurvedText> - fit text to path
L<Prima::Drawable::Glyphs> - bi-directional text input and complex scripts output
L<Prima::Drawable::Gradient> - gradient fills for primitives
L<Prima::Drawable::Markup> - allow markup in widgets
L<Prima::Drawable::Metafile> - graphics recorder
L<Prima::Drawable::Path> - stroke and fill complex paths
L<Prima::Drawable::Pod> - POD parser and renderer
L<Prima::Drawable::Subcanvas> - paint a hierarchy of widgets to any drawable
L<Prima::Drawable::TextBlock> - rich text representation
=item Visual Builder
L<VB> - Visual Builder for the Prima toolkit
L<Prima::VB::VBLoader> - Visual Builder file loader
L<prima-cfgmaint> - configuration tool for Visual Builder
L<Prima::VB::CfgMaint> - configures the widget palette in the Visual Builder
L<prima-fmview> - .fm file viewer
=item PostScript printer interface
L<Prima::PS::PostScript> - PostScript interface to C<Prima::Drawable>
L<Prima::PS::PDF> - PDF interface to C<Prima::Drawable>
L<Prima::PS::Printer> - PostScript and PDF interfaces to C<Prima::Printer>
=item Widget helpers
L<Prima::Widget::BidiInput> - heuristics for i18n input
L<Prima::Widget::Fader> - fading- in/out functions
L<Prima::Widget::GroupScroller> - optional automatic scroll bars
L<Prima::Widget::Header> - multi-column header widget
L<Prima::Widget::IntIndents> - indenting support
L<Prima::Widget::Link> - links embedded in widgets
L<Prima::Widget::ListBoxUtils> - common paint routine for listboxes
L<Prima::Widget::MouseScroller> - auto-repeating mouse events
L<Prima::Widget::Panel> - simple panel widget
L<Prima::Widget::RubberBand> - dynamic rubberbands
L<Prima::Widget::ScrollWidget> - scrollable generic document widget
L<Prima::Widget::StartupWindow> - a simplistic startup banner window
L<Prima::Widget::UndoActions> - undo and redo the content of editable widgets
=item C interface to the toolkit
L<Prima::internals> - Internal architecture
L<Prima::codecs> - Step-by-step image codec creation
L<prima-gencls> - C<prima-gencls>, a class compiler tool.
L<prima-tmlink> - C<prima-tmlink>, optimizer tool for files produced by prima-gencls.
=item Miscellaneous
L<Prima::faq> - frequently asked questions
L<Prima::Const> - predefined toolkit constants
L<Prima::EventHook> - event filtering
L<Prima::Image::Animate> - animate gif and webp files
L<Prima::Image::base64> - hardcoded image files
L<Prima::Image::Exif> - manipulate Exif records
L<Prima::Image::Loader> - progressive loading and saving for multiframe images
L<Prima::IniFile> - support of Windows-like initialization files
L<podview> - POD viewer
L<prima-pod2pdf> - POD printer
L<Prima::StdBitmap> - shared access to the standard bitmaps
L<Prima::Stress> - stress test module
L<Prima::Themes> - widget themes manager
L<Prima::Tie> - tie widget properties to scalars and arrays
L<Prima::types> - builtin types
L<Prima::Utils> - miscellaneous routines
=item System-specific modules and documentation
L<Prima::gp-problems> - Graphic subsystem portability issues
L<Prima::X11> - usage guide for X11 environment
L<Prima::sys::gtk::FileDialog> - GTK file system dialogs
L<Prima::sys::win32::FileDialog> - Windows file system dialogs
L<Prima::sys::XQuartz> - MacOSX/XQuartz facilities
L<Prima::sys::FS> - unicode-aware core file functions
=item Class information
The Prima manual pages often provide information for more than one Prima class.
To quickly find out the manual page of a desired class, as well as display the
inheritance information, use the C<prima-class> command. The command can
produce output in the text and pod formats; the latter feature is used by the
standard Prima documentation viewer C<podview> ( see File/Run/prima-class ).
=back
=head1 COPYRIGHT
Copyright 1997-2003 The Protein Laboratory, University of Copenhagen. All
rights reserved.
Copyright 2004-2024 Dmitry Karasik. All rights reserved.
This program is distributed under the BSD License.
=head1 AUTHORS
Dmitry Karasik E<lt>[email protected]<gt>,
Anton Berezin E<lt>[email protected]<gt>,
Vadim Belman E<lt>[email protected]<gt>,
=cut