Re: GtkEntry - did not receive focus-out-event.



muppet wrote:


This is a lot easier to understand with a timeline:

- focus into GtkEntry
  - GtkEntry installs timeout for cursor blinking
- focus out of entry
  - GtkEntry emits focus-out-event
     - your handler runs **before the default handler**.
        - your handler traps exception and creates dialog box
        - dialog box runs nested event loop
           - event processing continues, focus goes to another widget
- entry's cursor blink timeout is still installed, and runs again. entry does not have focus, but timeout has run, so the widget is in an invalid state and calls g_error() with a nastygram.
     - default handler runs, uninstalls cursor blink timeout

The problem is that you're allowing the event loop to run in your handler for focus-out.

The solution is to get the entry's default handler to run before you do anything that can run a main loop. There are two easy solutions:


a) use signal_connect_after to have your handler run *after* the default handler for focus-out-event instead of before.

b) leave the signal connected normally, but in your "catch" block, instead of running the dialog right then, defer it with an idle, like this:

    if ($@) {
# oh, crap. pop up the error message when the main loop is idle.
        Glib::Idle->add (sub {
            Gtk2::Ex::Dialogs::ErrorMsg->new_and_run(
                           title    => "Error in Query!",
                           text    => "DB Server says:\n$@"
            );
            FALSE;  # don't run again
        });
        # return control immediately.
        return FALSE;
    }


and, of course, option c) is "do both."


Hope that works.

Yes, that makes it a lot clearer. Thanks :)

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak nusconsulting com au
website: http://www.nusconsulting.com.au



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