Re: Newbie trying to get started
- From: James Curbo <james teyandei net>
- To: Dan Lyke <danlyke flutterby com>
- Cc: gtk-perl list <gtk-perl-list gnome org>
- Subject: Re: Newbie trying to get started
- Date: Mon, 13 Oct 2003 00:43:36 -0500
Dan Lyke wrote:
[snip]
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('MyGladeFile.glade');
push @gladexml, $gladexml;
$gladexml->signal_autoconnect_from_package('main');
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');
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} =
$gladexml{$widget}->[0]->get_widget($name);
}
return $gladexml{$widget}->[1]->{$name};
}
Gtk2::GladeXML has a get_widget function already.
$gladexml->get_widget(NAME)
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!
Dan
James
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]