Glade::App - Utility methods for Glade-Perl (and generated applications).
use vars qw(@ISA); use Glade::App qw(:METHODS :VARS); @ISA = qw( Glade::App); # 1) CLASS methods my $Object = Glade::App->new(%params); $Object->glade->file($supplied_path); $widget = $window->lookup_widget('clist1'); # 2) OPTIONS handling $options = Glade::App->options(%params); $normalised_value = Glade::App->normalise('True'); $new_hash_ref = Glade::App->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::App->string_from_file('/path/to/file'); Glade::App->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::App->load_translations('MyApp', 'fr', '/usr/local/share/locale/', undef, $SOURCE_LANG, 'Merge with already loaded translations'); sprintf(_("A message '%s'"), $value); sprintf(gettext($SOURCE_LANG, "A message '%s'"), $value); Glade::App->start_checking_gettext_strings($SOURCE_LANG); Glade::App->stop_checking_gettext_strings($SOURCE_LANG); Glade::App->write_missing_gettext_strings($SOURCE_LANG); # 5) UI methods my $image = Glade::App->create_image('new.xpm', ['dir1', 'dir2']); my $pixmap = Glade::App->create_pixmap($form, 'new.xpm', ['dir1', 'dir2']); Glade::App->show_skeleton_message( $me, \@_, __PACKAGE__, "$Glade::App::pixmaps_directory/Logo.xpm"); Glade::App->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::App->relative_Path($relative_path, $directory); $Object->reload_any_altered_modules;
Glade::App 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::App and quotes Glade::App 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.
Construct a Glade::App object
e.g. my $Object = Glade::App->new(%params);
Accesses all class data
e.g. my $glade_filename = $Object->glade->file; or $Object->glade->file('path/to/glade/file');
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.
Loads and merges all app options.
e.g. Glade::App->options(%params); my options = $Object->options(%params);
Return a normalised value ie. convert 'True'|'Yes'|'y'|'On' to 1 and 'False'|'No'|'n'|'Off' to 0. The comparisons are case-insensitive.
e.g. my $normalised_value = Glade::App->normalise('True');
Recursively merge a hash into an existing one - overwriting any keys with a defined value. It will also optionally set accessors for the keys to be used via AUTOLOAD().
e.g. $new_hash_ref = Glade::App->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.
Updates mru and saves all app/user options. This will save the mru file in the user options file (if one is named in $class->{$class->type}->xml->user).
e.g. Glade::App->save_app_options($mru_filename);
Reduce and save the supplied options to the file specified.
e.g. $Object->save_options;
Write an options hash to XML file.
e.g. my options = $Object->write_options($hash_ref, '/path/to/file');
Removes any options that are equivalent to site/user/project options or that are specified to be pruned. We will descend into any hash types specified.
e.g. my options = $Object->reduce_hash( $options_to_reduce, $user_options, $site_options, $app_defaults, $base_defaults '*work*proto*', '*My::Class*');
Glade::Two::Generate(3) glade2perl-2(1)
Dermot Musgrove <dermot.musgrove@virgin.net>
To install Glade::Two::Gtk, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Glade::Two::Gtk
CPAN shell
perl -MCPAN -e shell install Glade::Two::Gtk
For more information on module installation, please visit the detailed CPAN module installation guide.