|
NAMEPrima::VB::VBLoader - Visual Builder file loader DESCRIPTIONThe module provides functionality for loading resource files, created by Visual Builder. After the successful load, the newly created window with all children is returned. SYNOPSISThe simple way to use the loader is as that: use Prima qw(Application);
use Prima::VB::VBLoader;
Prima::VBLoad( './your_resource.fm',
Form1 => { centered => 1 },
)-> execute;
A more complicated but more proof code can be met in the toolkit: use Prima qw(Application);
eval "use Prima::VB::VBLoader"; die "$@\n" if $@;
$form = Prima::VBLoad( $fi,
'Form1' => { visible => 0, centered => 1},
);
die "$@\n" unless $form;
All form widgets can be supplied with custom parameters, all together combined in a hash of hashes and passed as the second parameter to VBLoad() function. The example above supplies values for "::visible" and "::centered" to "Form1" widget, which is default name of a form window created by Visual Builder. All other widgets are accessible by their names in a similar fashion; after the creation, the widget hierarchy can be accessed in the standard way: $form = Prima::VBLoad( $fi,
....
'StartButton' => {
onMouseOver => sub { die "No start buttons here\n" },
}
);
...
$form-> StartButton-> hide;
In case a form is to be included not from a fm file but from other data source, AUTOFORM_REALIZE call can be used to transform perl array into set of widgets: $form = AUTOFORM_REALIZE( [ Form1 => {
class => 'Prima::Window',
parent => 1,
profile => {
name => 'Form1',
size => [ 330, 421],
}], {});
Real-life examples are met across the toolkit; for instance, Prima/PS/setup.fm dialog is used by "Prima::PS::Setup". APIMethods
EventsThe events, stored in .fm file are called during the loading process. The module provides no functionality for supplying the events during the load. This interface is useful only for developers of Visual Builder - ready classes. The events section is located in "actions" section of widget entry. There can be more than one event of each type, registered to different widgets. NAME parameter is a string with name of the widget; INSTANCE is a hash, created during load for every widget provided to keep internal event-specific or class-specific data there. "extras" section of widget entry is present there as an only predefined key.
FILE FORMATThe idea of format of .fm file is that is should be evaluated by perl eval() call without special manipulations, and kept as plain text. The file begins with a header, which is a #-prefixed string, and contains a signature, version of file format, and version of the creator of the file: # VBForm version file=1 builder=0.1 The header can also contain additional headers, also prefixed with #. These can be used to tell the loader that another perl module is needed to be loaded before the parsing; this is useful, for example, if a constant is declared in the module. # [preload] Prima::ComboBox The main part of a file is enclosed in "sub{}" statement. After evaluation, this sub returns array of paired scalars, where each first item is a widget name and second item is hash of its parameters and other associated data: sub
{
return (
'Form1' => {
class => 'Prima::Window',
module => 'Prima::Classes',
parent => 1,
code => GO_SUB('init()'),
profile => {
width => 144,
name => 'Form1',
origin => [ 490, 412],
size => [ 144, 100],
}},
);
}
The hash has several predefined keys:
AUTHORDmitry Karasik, <dmitry@karasik.eu.org>. SEE ALSOPrima, VB
|