Re: embedded perl/Gtk dialog




On Jul 4, 2005, at 10:46 AM, Carl Nygard wrote:

One question, is it bad to be calling 'use Gtk2 -init' every time I try to pop up a Dialog?

Nope. gtk_init() is set up to run the first time and then return immediately on subsequent invocations. In fact, if you call gtk_init () elsewhere in your app (before the Gtk2-Perl stuff), then you don't even need it in the script.


Another possibility [...] is that you're not letting the glib
main loop run after the call to $window->destroy [...].

Ok, tried that, still didn't work. I run the Gtk2 main loop before and
after I show/hide the dialog, so shouldn't deferred activity get done
there anyway?

Should, yes.

Is there any particular reason for the "main iteration while result hasn't been set by the button callback" setup instead of the more idiomatic "run a main loop and wait for the button callbacks to kill it" (a la Gtk2::Dialog::run) ?


[esoteric stuff about how to get a parent window].

Ugh.  Well, I could probably pass the XID to the MEL() script function
and let it do the magic Gdk stuff, that's not a big deal.  Hopefully I
don't have to mess with XS.  But thanks, this is exactly what I needed
to know for my next experiment.

Heh, if you're messing with an embedded interpreter, you're already off into deeper magic than XS. :-)



Here's the Dialog.pm class which provides a simple interface for popping up and populating dialog boxes. The MEL() script would create a Dialog, run it, then deal with the results from the user. Some explanation, you
probably only need to deal with Create() and DESTROY().  Most of the
other stuff is either cruft from the Glade methods, or infrastructure
for a derivation framework that makes the Perl modules seem like C++
objects (i.e. ctor, copy-ctor, operator=, MI, etc)

<Dialog.pm>

Incidentally, you can replace your hand-maintained "$PackageName" with the built-in "__PACKAGE__".

In Create(), you're creating a plain Gtk2::Window and filling it with widgets, including the action buttons. You may find it a little easier to use Gtk2::Dialog. In fact, when you were talking about a dialog, i thought you meant it was a Gtk2::Dialog. It has an action area and response system built in, which will handle some of the work you're doing by hand. Also, Gtk2::Dialog::run() will emit the "response" signal when the user attempts to close the window via the window manager ("delete-event"), whereas with a plain Gtk2::Window, the window will just be destroyed (as you have no delete-event handler) without doing anything to stop your dialog loop.

In fact, i don't see where you're hooking up most of the signals; i see where you connect to the buttons in Create(), but i don't see and autoconnect call in CreateGlade(), nor any connections to the window's signals.

Are you sure that Dialog::DESTROY is running? I presume that's why you have the print() in there...


--
Brian: If i recall correctly, this is the physics department.
Chris: That explains all that gravity.
    -- Family Guy, "The Story on Page One"




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