Re: Newbie trying to get started

Dan Lyke wrote:


I hope to come up with some better packagings for my idioms for
dealing with multiple main windows, right now I have global
@gladexml and %gladexml variables, on "new" I do:

    $gladexml = Gtk2::GladeXML->new('');
    push @gladexml, $gladexml;

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('', 'window1');
push @gladexml, $gladexml;
# other stuff

And I get my widgets by name with:

    sub get_widget($$)
        my ($widget, $name) = @_;
if (!defined($gladexml{$widget}))
            my ($n, $gladexml);
            $n = $widget->get_name();
            foreach (@gladexml)
                my ($w);
$w = $_->get_widget($n); $gladexml = $_ if ($w eq $widget);
            $gladexml{$widget} = [$gladexml, {}];
        if (!defined($gladexml{$widget}->[1]->{$name}))
            $gladexml{$widget}->[1]->{$name} =
        return $gladexml{$widget}->[1]->{$name};

Gtk2::GladeXML has a get_widget function already.


Return the widget created by the XML file with NAME or undef if no such name exists.

Which gives me the widget in my hierarchy, with caching. I'm not yet
doing the clean-up I need to be doing on the "on delete" signals, to
remove the deleted window from the @gladexml array and clean up the
%gladexml hash, but that should be fairly simple.

I'm waiting to publish anything coherent 'til I learn a little bit
more, but dive in!



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