Glade::PerlRun - Utility methods for Glade-Perl (and generated applications).
use vars qw(@ISA); use Glade::PerlRun qw(:METHODS :VARS); @ISA = qw( Glade::PerlRun );
# 1) CLASS methods
my $Object = Glade::PerlRun->new(%params);
$Object->glade->file($supplied_path);
$widget = $window->lookup_widget('clist1');
# 2) OPTIONS handling
$options = Glade::PerlRun->options(%params);
$normalised_value = Glade::PerlRun->normalise('True');
$new_hash_ref = Glade::PerlRun->merge_into_hash_from(
$to_hash_ref, # Hash to be updated
$from_hash_ref, # Input data to be merged
'set accessors'); # Any value will add AUTOLOAD() accessors
# for these keys.
$Object->save_app_options($mru_filename);
$Object->save_options;
my $string = Glade::PerlRun->string_from_file('/path/to/file');
Glade::PerlRun->save_file_from_string('/path/to/file', $string);
# 3) Diagnostic message printing
$Object->start_log('log_filename');
$Object->diag_print(2, "This is a diagnostics message");
$Object->diag_print(2, $hashref, "Prefix to message");
$Object->stop_log;
# 4) I18N
Glade::PerlRun->load_translations('MyApp', 'fr', '/usr/local/share/locale/',
undef, '__S', 'Merge with already loaded translations');
sprintf(_("A message '%s'"), $value);
sprintf(gettext('__S', "A message '%s'"), $value);
Glade::PerlRun->start_checking_gettext_strings("__S");
Glade::PerlRun->stop_checking_gettext_strings("__S");
Glade::PerlRun->write_missing_gettext_strings('__S');
# 5) UI methods
my $image = Glade::PerlRun->create_image('new.xpm', ['dir1', 'dir2']);
my $pixmap = Glade::PerlRun->create_pixmap($form, 'new.xpm', ['dir1', 'dir2']);
Glade::PerlRun->show_skeleton_message(
$me, \@_, __PACKAGE__, "$Glade::PerlRun::pixmaps_directory/Logo.xpm");
Glade::PerlRun->message_box(
$message, # Message to display
$title, # Dialog title string
[_('Dismiss'), _("Quit")." Program"], # Buttons to show
1, # Default button is 1st
$pixmap, # pixmap filename
[&dismiss, &quit], # Button click handlers
$entry_needed); # Whether to show an entry
# widget for user data
# 6) General methods $path = $Object->full_Path($Object->glade->file, $dir); $path = Glade::PerlRun->relative_Path($relative_path, $directory);
$Object->reload_any_altered_modules;
Glade::PerlRun provides some utility methods that Glade-Perl modules and also the generated classes need to run. These methods can be inherited and called in any app that use()s Glade::PerlRun and quotes Glade::PerlRun in its @ISA array.
Broadly, the utilities are of seven types.
1) Class methods 2) Options handling 3) Diagnostic message printing 4) I18N 5) UI methods 6) General methods
The class methods provide an object constructor and data accessors.
new(%params)e.g. my $Object = Glade::PerlRun->new(%params);
AUTOLOAD()e.g. my $glade_filename = $Object->glade->file; or $Object->glade->file('path/to/glade/file');
lookup_widget($widgetname)e.g. my $widget = $window->lookup_widget('clist1');
OR my $form = $window->FORM; # or use $form in signal handlers
my $widget = $form->lookup_widget('clist1');
These methods will load, merge, reduce and save a hierarchical options structure that is stored in one or more XML files and accessed with AUTOLOAD methods.
options(%params)e.g. Glade::PerlRun->options(%params); my options = $Object->options(%params);
normalise($value)e.g. my $normalised_value = Glade::PerlRun->normalise('True');
e.g. $new_hash_ref = Glade::PerlRun->merge_into_hash_from(
$to_hash_ref, # Hash to be updated
$from_hash_ref, # Input data to be merged
'set accessors'); # Any value will add AUTOLOAD() accessors
# for these keys.
e.g. Glade::PerlRun->save_app_options($mru_filename);
e.g. $Object->save_options;
e.g. my options = $Object->write_options($hash_ref, '/path/to/file');
e.g. my options = $Object->reduce_hash( $options_to_reduce, $user_options, $site_options, $app_defaults, $base_defaults '*work*proto*', '*My::Class*');
e.g. Glade::PerlRun->save_file_from_string('/path/to/file', $string);
These methods will start logging diagnostic messages, produce standardised I18N messages and then stop logging and close any open files.
diag_print()e.g. $Object->diag_print(2, ``This is a diagnostics message''); $Object->diag_print(2, $hashref, ``Prefix to message'');
start_log()e.g. $Object->start_log('log_filename');
stop_log()e.g. $Object->stop_log;
These methods will load translations, translate messages, check for any missing translations and write a .pot file containing these missing messages.
_()e.g. sprintf(_(``A message '%s'''), $value);
gettext()e.g. sprintf(gettext('__S', "A message '%s'"), $value);
start_checking_gettext_strings()
eg. $class->start_checking_gettext_strings("__S");
stop_checking_gettext_strings()
eg. $class->stop_checking_gettext_strings("__S");
write_missing_gettext_strings()
eg. $object->write_missing_gettext_strings('__S');
load_translations()
e.g. To load translations in current LANG from default locations
$class->load_translations('MyApp');
OR $class->load_translations('MyApp', 'test', undef,
'/home/dermot/Devel/Glade-Perl/ppo/en.mo');
OR $class->load_translations('MyApp', 'fr', '/usr/local/share/locale/',
undef, '__D', 'Merge with already loaded translations');
These methods will provide some useful UI methods to load pixmaps and images and show message boxes of various types.
create_pixmap()e.g. my $pixmap = Glade::PerlRun->create_pixmap( $form, 'new.xpm', ['dir1', 'dir2']);
create_image()e.g. my $image = Glade::PerlRun->create_image( 'new.xpm', ['dir1', 'dir2']);
$caller where we were called $data the args that were supplied to the caller $package $pixmap pixmap to show
e.g. Glade::PerlRun->show_skeleton_message( $me, \@_, __PACKAGE__, ``$Glade::PerlRun::pixmaps_directory/Logo.xpm'');
message_box()e.g. Glade::PerlRun->message_box( $message, # Message to display $title, # Dialog title string [_('Dismiss'), _(``Quit'').`` Program''], # Buttons to show 1, # Default button is 1st $pixmap, # pixmap filename [&dismiss, &quit], # Button click handlers $entry_needed); # Whether to show an entry # widget for user data
These are some general purpose methods that are useful to Glade::PerlGenerate and generated apps.
full_Path()e.g. my $path = Glade::PerlRun->full_Path($relative_path, $directory);
e.g. my $path = Glade::PerlRun->relative_Path($relative_path, $directory);
string_from_File()e.g. my $string = Glade::PerlRun->string_from_file('/path/to/file');
reload_any_altered_modules()It is impossible to reload the UI module (called something like ProjectUI.pm) while the app is running without crashing it so don't run glade2perl and then call this method. Similarly, any modules that construct objects in their own namespace will cause unpredictable failures.
I usually call this in a button's signal handler so that I can edit the modules and easily reload the edited versions of modules.
e.g. Glade::PerlRun->reload_any_altered_modules;
Glade::PerlGenerate(3) glade2perl(1)
Dermot Musgrove <dermot.musgrove@virgin.net>