Re: propagate_key_event




On Mar 8, 2005, at 5:43 AM, Grant McLean wrote:

Can the propagate_key_event method in Gtk2::Window be used to feed a
key-press to a window?

not really. the point of propagate_key_event is to allow widget (container) implementations to say to its parent "i (nor any of my children) don't know how to handle this key, so why don't you have a go?" that is, propagate an event up the widget chain starting at the focus widget. you want to go *down* the chain.

now, somebody more intimate with gtk+ key handling should feel free to point out my mistake, but basically you're trying to close a dialog programmatically and there are much easier ways.


The reason I'm trying to do this is I have a regression test which activates a button which pops up the dialog. The fact the the dialog appears is good enough for me, but my test script stops at that point waiting for the dialog to be closed.

We do this a lot in the gtk2-perl test suite. the basic trick is to use a single-shot idle handler that cdoes your deferred actions. for example:

   $dialog = create_a_big_hairy_dialog();
   Glib::Idle->add (sub { $dialog->response ('cancel');  FALSE });
$response = $dialog->run; # blocks with a main loop until the dialog gets a response
   is ($response, 'cancel');

there's a helper module called Gtk2::TestHelper that has a couple of interesting methods such as run_main, ok_idle, and is_idle, which wrap up some of the tedium of doing the above. (these functions are new in 1.080, iirc)


I did achieve my aim by getting a handle on the dialog window, walking
through the tree of child widgets to find the cancel button and then
calling its 'clicked' method.  Although it did do the job, I get a
series of errors like this printed out:

this works, but is no fun to do, and can be rather brittle -- while the API is frozen for compatibility reasons, the organization of the widget tree can change without notice.

--
If I lived in Teletubby Land, the homicide rate would be four.
  -- elysse




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