# # Copyright (c) 1997-2003 The Protein Laboratory, University of Copenhagen # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Created by Anton Berezin # # $Id: Prima.pm,v 1.85 2007/12/21 15:46:27 dk Exp $ package Prima; use strict; require DynaLoader; use vars qw($VERSION @ISA $__import @preload); @ISA = qw(DynaLoader); sub dl_load_flags { 0x00 } $VERSION = '1.24'; 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); sub END { &Prima::cleanup() if UNIVERSAL::can('Prima', 'cleanup'); } sub run { die "Prima was not properly initialized\n" unless $::application; $::application-> go if $::application-> alive; $::application = undef if $::application and not $::application->alive; } sub import { my @module = @_; while (@module) { my $module = shift @module; my %parameters = (); %parameters = %{shift @module} if @module && ref($module[0]) eq 'HASH'; next if $module eq 'Prima' || $module eq ''; $module = "Prima::$module" unless $module =~ /^Prima::/; $__import = caller; if ( $module) { eval "use $module \%parameters;"; die $@ if $@; } $__import = 0; } } 1; __END__ =pod =head1 NAME Prima - a perl graphic toolkit =head1 SYNOPSIS use Prima qw(Application Buttons); new Prima::MainWindow( text => 'Hello world!', size => [ 200, 200], )-> insert( Button => centered => 1, text => 'Hello world!', onClick => sub { $::application-> close }, ); run Prima; =head1 DESCRIPTION The toolkit is combined from two basic set of classes - core and external. The core classes are coded in C and form a base line 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 easily expandable set of widgets, written completely in perl and communicating with the system using Prima library calls. The core classes form an 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::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. =head1 BASIC PROGRAM The very basic code shown in L<"SYNOPSIS"> is explained here. The code creates a window with 'Hello, world' title and a centered button with the same text. The program terminates after the button is pressed. A basic construct for a program written with Prima obviously requires use Prima; code; however, the effective programming requires usage of the other modules, for example, C, which contains set of button widgets. C module can be invoked 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; sentence and requires a C object to be created beforehand. Invoking C standard module is one of the possible ways to create an application object. The program usually terminates after the event loop is finished. The window is created by invoking new Prima::Window(); or Prima::Window-> create() code with the additional parameters. Actually, all Prima objects are created by such a scheme. The class name is passed as the first parameter, and a custom set of parameters is passed afterwards. These parameters are usually represented in a hash syntax, although actually passed as an array. The hash syntax is preferred for the code readability: $new_object = new Class( parameter => value, parameter => value, ... ); Here, parameters are the class properties names, and differ from class to class. Classes often have common properties, primarily due to the object inheritance. In the example, the following properties are set : Window::text Window::size Button::text Button::centered Button::onClick Property values can be of any type, given that they are scalar. As depicted here, C<::text> property accepts a string, C<::size> - an anonymous array of two integers and C - a sub. onXxxx are special properties that form a class of I, which share the C/C syntax, and are additive when the regular properties are substitutive (read more in L). Events are called in the object context when a specific condition occurs. The C event here, for example, is called when the user presses (or otherwise activates) the button. =head1 API This section describes miscellaneous methods, registered in C namespace. =over =item message TEXT Displays a system message box with TEXT. =item run Enters the program event loop. The loop is ended when C's C or C 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 C<--help> argument to get the list of supported arguments. Programmaticaly, setting and obtaining these options can be done by using C routine. In cases where Prima argument parsing conflicts with application options, use L to disable automatic parsing; also see L. Alternatively, the construct BEGIN { local @ARGV; require Prima; } will also do. =head1 SEE ALSO The toolkit documentation is divided by several subjects, and the information can be found in the following files: =over =item Tutorials L - introductory tutorial =item Core toolkit classes L - basic object concepts, properties, events L - binder module for the core classes L - 2-D graphic interface L - bitmap routines L - image subsystem and file operations L - window management =over 2 =item * L - Tk::pack geometry manager =item * L - Tk::place geometry manager =back L - top-level window management L - GUI interprocess data exchange L - pull-down and pop-up menu objects L - programmable periodical events L - root of widget objects hierarchy L - system printing services L - asynchronous stream I/O =item Widget library L - buttons and button grouping widgets L - calendar widget L - combo box widget L - multi-column list viewer with controlling header widget L - a multi-column outline viewer with controlling header widget L - advanced dockable widgets L - dockable widgets L - text editor widget L - listbox with checkboxes L - frameset widget class L - grid widgets L - a multi-tabbed header widget L - the built-in POD file browser L - standard dialog for transparent color index selection L - bitmap viewer L - input line widget L - key combination widget and routines L - static text widget L - user-selectable item list widgets L - top-level windows emulation classes L - multipage widgets L - tree view widgets L - POD browser widget L - scroll bars L - scrollable generic document widget L - sliding bars, spin buttons and input lines, dial widget etc. L - a simplistic startup banner window L - rich text browser widget L - widget themes manager =item Standard dialogs L - color selection facilities L - find and replace dialogs L - file system related widgets and dialogs L - font dialog L - image file open and save dialogs L - message and input dialog boxes L - standard printer setup dialog L - wrapper module to the toolkit standard dialogs =item Visual Builder L - Visual Builder for the Prima toolkit L - Visual Builder file loader L - configuration tool for Visual Builder L - maintains visual builder widget palette configuration =item PostScript printer interface L - PostScript interface to C L - latin-based encodings L - PostScript device fonts metrics L - PostScript interface to C =item C interface to the toolkit L - Internal architecture L - Step-by-step image codec creation L - C, a class compiler tool. =item Miscellaneous L - frequently asked questions L - predefined toolkit constants L - event filtering L - support of Windows-like initialization files L - internal functions L - shared access to the standard toolkit bitmaps L - stress test module L - tie widget properties to scalars or arrays L - miscellaneous routines L - miscellaneous widget classes L - Graphic subsystem portability issues L - usage guide for X11 environment =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 C command. The command can produce output in text and pod formats; the latter feature is used by the standard Prima documentation viewer C ( see File/Run/p-class ). =back =head1 COPYRIGHT Copyright 1997, 2003 The Protein Laboratory, University of Copenhagen. All rights reserved. Copyright 2004 Dmitry Karasik. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHORS Dmitry Karasik Edmitry@karasik.eu.orgE, Anton Berezin Etobez@tobez.orgE, Vadim Belman Evoland@lflat.orgE, =cut