Re: Newbie trying to get started



James Curbo writes:
Another way, pointed out earlier on this list, is to put all your 
windows in one glade file, but get to them like so:

$gladexml = Gtk2::GladeXML->new('my.glade', 'window1');

Cool. For right now I only have the one type of main window, I just
want multiple instances of it.

Gtk2::GladeXML has a get_widget function already.

$gladexml->get_widget(NAME)

I think you're missing my bit of functionality, as my code is actually
calling this. Say you've got your basic filebrowser thingie; browse a
filesystem with a treeview, and displays images in an image when an
appropriate node is activated.

The window structure looks something like:

window1->[...packing widgets...]->treeview1
window1->[...other packing widgets...]->image1

sub on_treeview1_row_activated
{
    my ($treeview, $treepath, $treeviewcolumn) = @_;
    my ($filename);

    # ... do stuff to set the filename from the tree node ...

    my $imageWidget = $gladexml->get_widget('image1');
    $imageWidget->set_from_file($filename);
}

If you then end up with *two* top windows, for instance if you have a
menu "File->New" which calls:

sub on_new1_activate
{
        my $gladexml = Gtk2::GladeXML->new('my.glade', 'window1');
        push @gladexml, $gladexml;
}

It's important to distinguish between which of the @gladexml values
you're calling the "get_widget" on, otherwise you may end up selecting
a node on one window1's treewidget1, and having it appear in the
*other* window1.

This is the point of my code. You can replace the line

    my $imageWidget = $gladexml->get_widget('image1');

with

    my $imageWidget = main::get_widget($treewidget,'image1');

And that will get the sibling image1 widget for the instance of
window1 that this treewidget1 exists under. And cache it away in a
hash so that next time it's faster.

Dan




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]