Snapper.pm -- Parse application XML
use Snapper;
$SnapRun::xml = Snapper->new();
$SnapRun::xml->build_file( 'pizza.xml' );
$SnapRun::xml->source_scripts( 'MAIN' );
This module reads an xml file created by snapmake and runs the
application. Snapmake combines perl scripts, GladeXML, etc into
an application XML file.
There are five methods in the Snapper module, new, build_memory,
build_file, source_scripts, and get_glade_xml. Along with the
methods are three global variables, $Snapper::Verbose,
$Snapper::CurrentObject, and $Snapper::PixmapDirectory.
New creates the snapper object. It either returns the object on
successful creation or undef upon failure. $! is set the the
error code if any.
Source_scripts will evaluate all of the scripts it finds under
the specified module. The scripts are sorted first. If the
pixmap directory is specified the global $Snapper::PixmapDirectory
will be set.
Get_glade_xml will return a string containing the GladeXML found
in the specified module. This string can be passed to
Gtk::GladeXML::new_from_memory.
Example:
my $xml = Gtk::GladeXML::new_from_memory('GladeXML',
$Snapper::CurrentObject->get_glade_xml('MAIN'));
or if activated via the thin client, the snapper object is
contained in the global $SnapRun::xml.
my $xml = Gtk::GladeXML::new_from_memory('GladeXML',
$SnapRun::xml->get_glade_xml('MAIN'));
CurrentObject contains the current snapper object. This can
be used by scripts that are being sourced via source_scripts to
perform operations on the current object, such as get_glade_xml.
This method will be deprecited in the future in favor of a global
application object hash implemented via the SharkAPI. Currently
the thin client ``snaprun'' set the variable $SnapRun::xml to contain
the current Snapper object.
This variable, if non-zero, will cause the XML parser to report
what it is doing as the application XML file is parsed.
PixmapDirectory is used during the building of the glade XML.
If a pixmap is found this path will be prepened to the name.
The following code details how to use GtkPerl. The script should
be named so it is evaluated last because of the event loop. This
script assumes that the generic startup script will be used, SnapRun
or a custom startup script that sets ``$SnapRun::xml''.
#----------------------------------------------------
# Startup Perl Script 999_startup.pl
#
# This file contains the Perl executed at startup
#
#----------------------------------------------------
use Gtk;
use Gtk::GladeXML;
eval {
require Gtk::Gdk::ImlibImage;
init Gtk::Gdk::ImlibImage;
};
#
# Init GtkPerl
#
init Gtk;
Gtk::GladeXML->init;
#
# Grab XML, Connect Signals, Then Show Main Window
#
$Snapper::MyXML = Gtk::GladeXML::new_from_memory('GladeXML',
$SnapRun::xml->get_glade_xml('MAIN'));
$Snapper::MyXML->signal_autoconnect_from_package('Snapper');
#
# clean up snapper object
undef $SnapRun::xml;
#
my $w = $Snapper::MyXML->get_widget('MAIN');
$w->show;
#
# Drop into main loop
#
print "\ndropping into gtk_main!\n";
main Gtk;
#
# Callbacks...
#
sub Snapper::gtk_main_quit {
Gtk->exit( 0 );
return 0;
}
sub Snapper::gtk_widget_hide {
shift->hide();
return 1;
}
sub Snapper::gtk_widget_show {
my ($w) = shift;
$w->show;
}
1;
Bill Walz, bill@landsharklinux.com
perl(1).
Gtk http://www.gtkperl.org/
Gtk::GladeXML.
GTK http://www.gtk.org/
Glade http://glade.pn.org/
LibGlade http://www.daa.com.au/~james/gnome/
You may distribute under the terms of either the GNU General Public
License or the Artistic License, as specified in the Perl README file,
with the exception that it cannot be placed on a CD-ROM or similar media
for commercial distribution without the prior approval of the author.
|