Glade-Perl

 view release on metacpan or  search on metacpan

Documentation/FAQ  view on Meta::CPAN

This is the Frequently Asked Question list for Glade-Perl source generator
--------------------------------------------------------------------------
Q   When I try to update Glade-Perl with 'perl -MCPAN -e shell' I get:

    Warning: Cannot install Glade-Perl, don't know what it is.
    Try the command

        i /Glade-Perl/

A   I don't think that it is possible to install 'Glade-Perl' but you must
    install one of the sub modules and CPAN.pm will fetch and build all the
    Glade-Perl modules for you. There is another problem as CPAN.pm reads
    the version numbers from 02packages.data.txt and they're not all correct.
    I don't know whether this my fault or some historical accident but it
    _is_ possible to get the latest version by installing Glade::PerlRun.
    
        perl -MCPAN -e shell
    
    and then in the interactive shell you enter:
    
        install Glade::PerlRun
        
    and this should fetch, build, test and install Glade-Perl for you.
    You must be superuser to actually install the modules of course.

--------------------------------------------------------------------------
Q   How do I see diagnostic messages when using glade2perl or from Glade?

A   The simplest way (from version 0.58) is to call glade2perl from the
    command line and specify a verbosity of 2 so:
        glade2perl project.glade 2
    
    will give you a log file called project.glade2perl.log wherever the
    project.glade file is.
    
    Otherwise copy glade2perl and edit the 'verbose' line to read
        'verbose' => 2,     # for some diagnostics
        'verbose' => 4,     # for more diagnostics
        'verbose' => 6,     # for lots of diagnostics (more than you want ?)
        'verbose' => 10,    # for every diagnostic message available

    1)  Then either run Glade from a terminal, 
    2)  call the edited glade2perl directly (and maybe redirect STDOUT to a file)
    3)  specify a log_file in glade2perl if you want to save the diagnostics.
        'log_file' => $log_file, # Save diagnostics to Project.glade2perl.log
        This last option might be best, then all glade2perl runs will save the
        diagnostics to a file.
    4)  Edit the project.glade2perl.xml file to specify a line like
        <diag>
            <verbose>2</verbose>
        </diag>
        This will generate diagnostics every time that you generate this
        project (but no others)
        
--------------------------------------------------------------------------
Q   How do I get the value of a GtkOptionMenu using Glade-Perl?

A   One way is to connect a handler to the 'hide' signal of the
    GtkOptionMenu's menu and then inspect the widget. eg. in a Gnome project
    called 'Reference' with 'optionmenu4' - edit the app_run() method in
    Reference.pm and write new on_optionmenu4_hide() to be:

    sub app_run {
        my ($class) = @_;
        $class->load_translations('Reference');
        # You can use the line below to load a test .mo file before it is
        # installed in the normal place 
        #     (eg /usr/local/share/locale//LC_MESSAGES/Reference.mo)
    #    $class->load_translations('Reference', 'test', undef, 
    #        '/home/dermot/Devel/Glade-Perl/Example/Reference/ppo/Reference.mo');
        Gnome->init('Reference', '0.53');
        my $window = $class->new;
        $window->TOPLEVEL->show;

        $window->FORM->{'optionmenu4'}->get_menu->signal_connect( 
            'hide', "$class\::on_optionmenu4_hide", '', 'optionmenu4', 
            $window->INSTANCE );

        Gtk->main;

    } # End of sub app_run

    sub on_optionmenu4_hide {
        my ($class, $data, $object, $instance, $event) = @_;
        my $me = __PACKAGE__."->on_optionmenu4_hide";
        # Get ref to hash of all widgets on our form
        my $form = $__PACKAGE__::all_forms->{$instance};

        my $selected_string = ($class->get_active->children)[0]->get;
        print "We have selected string $selected_string\n";

    } # End of sub on_optionmenu4_hide    

--------------------------------------------------------------------------
Q   How do I set fonts, colours and bg-pixmaps of widgets at run time?

A   To change the fonts, colours and bg-pixmaps of widgets at run-time you can
    use something like the code below. This is for a button so it sets the 
    style of the button->child (in other words the label in the button) and the 
    actual way that you set the style will depend on what type of widget you are 
    working with. 
    
    There are many ways to get the colours but this is one approach:

    my $style = new Gtk::Style;
    my $cm = $form->{'button43'}->get_toplevel->window->get_colormap;

    $style->font(  Gtk::Gdk::Font->load(
        '-*-times-bold-r-normal-*-*-120-*-*-p-*-iso8859-1'));
    $style->fg('normal',   $cm->color_alloc(
        {red=>65000, green=>0,     blue=>0}));
    $style->fg('prelight', $cm->color_alloc(
        {red=>0,     green=>30000, blue=>0}));
    $style->fg('active',   $cm->color_alloc(
        {red=>0,     green=>0,     blue=>65000 }));

    $form->{'button43'}->child->set_style($style);

--------------------------------------------------------------------------



( run in 3.149 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )