Re: Newbie trying to get started



muppet writes:
it can start as simple as:

   use Gtk2 -init;
   use Gtk2::GladeXML;

   $glade = Gtk2::GladeXML->new ('/path/to/interface/definition.glade');
   $glade->signal_autoconnect_from_package;
   Gtk2->main;

Just a follow-up with things I've learned since and some search engine
juice... As mentioned in

http://mail.gnome.org/archives/gtk-perl-list/2003-September/msg00132.html

You can use the script at

http://www.flutterby.com/software/gtk2-perl-tools/gtk2-perl-connect-signals.txt

to automatically generate stub functions for the signals you
connect. Note that signal_autoconnect_from_package seems to miss a few
things occasionally, if you think your function isn't getting called,
then you might want to set it up manually. Specifically, I wasn't
getting linkage for a button press event on a treeview, so I had to
explicitly do:

$treeview = $gladexml->get_widget('treeview1');
$treeview->signal_connect(button_press_event =>  \&on_treeview1_button_press_event);

Rather than just specifying it in glade-2[1]. Don't know why, because all
my drag-n-drop functions connect just fine. I was waiting 'til I had
the latest version before I tried to track this down and see if I
could do a fix, I'm still a few revs back and everything else is
working so I wasn't stressing about it.

And I'm still not sure of how to make it happen *after* the default
processing, so I'm trying to handle the selection list intelligently
myself.

Really, I'm not sure what more "code generation" I'd want, this lets
me diddle with the look in glade-2 and (except when I need to
automatically connect new signals) edit my source and not worry about
the connection between them. As a regular user of VisualStudio .NET,
which tries to keep track of edits to both the visual view and the
source code and reconcile them, I *far* prefer this method.

I haven't played with it yet, but Chas Owens' "one file" solution at

http://mail.gnome.org/archives/gtk-perl-list/2003-October/msg00061.html

Looks like the perfect packaging method when I get that far along (And
have I mentioned recently how much you guys *rock*, not just for the
whole Gtk2 thing, but for making sure that when I go Windows with this
it'll work? If you're ever in town (SF), the beers are on me).

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');

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};
    }

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


[1] I haven't kept track of all of the glade versions, but:

       $ glade-2 --version
       GTK Accessibility Module initialized
       Glade (GTK+) 2.0.0





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