Thread: [Java-gnome-developer] Glade and reusing a window
Brought to you by:
afcowie
From: Stefan P. <pr...@tz...> - 2005-08-13 15:18:33
|
Hi all, I have some problems using Glade for dialogs. I guess I'm on a wrong track somewhere, but I can't figure out where. I have built a smale glade application with two windows - a normal one (mainWindow) and a dialog window (adventWindow). I load them like that glade = new LibGlade("dsadb-tool.glade", this); mainWindow = (Window) glade.getWidget("MainWindow"); At first that lead to both windows showing up immediatly, but I figures that setting adventWindow to invisible stopped that. mainWindow contains a menu and one menu option triggers the display of the dialog window: public void on_abenteuer_activate() { System.out.println("on_abenteuer_activate"); adventWindow = (Window) glade.getWidget("AdventWindow"); adventWindow.show(); } Fine so far. The adventWindow-Dialog has a cancel button to close the dialog again. It also has the usual button "x" on (the top right) window frame to close the window. The cancel button triggers a call to adventWindow.hide() which works fine and allows me to call the show method again (even without re-retrieving the widget from Glade). My problem is: If I close the window with the "x"-Button on the frame the window closes but cannot be re-used. (java-gnome:32635): GLib-GObject-CRITICAL **: g_object_ref: assertion `G_IS_OBJECT (object)' failed (java-gnome:32635): GLib-GObject-WARNING **: instance of invalid non-instantiatable type `glong' (java-gnome:32635): GLib-GObject-CRITICAL **: g_signal_emit_valist: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed (java-gnome:32635): GLib-GObject-CRITICAL **: g_object_notify: assertion `G_IS_OBJECT (object)' failed (java-gnome:32635): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed I guess the glade instance of the window has been destroyed and cannot be reclaimed. I figured that I need to reload the whole glade file again, which is not very satisfying. What can I do to prevent this from happening? Or is there at least a way to disable the "x" button for the window? Regards, Stefan -- Stefan Prelle <pr...@tz...> |
From: Gian M. T. <g.t...@gm...> - 2005-08-13 15:30:11
|
2005/8/13, Stefan Prelle <pr...@tz...>: > Hi all, Hi Stefan =20 > [snip] =20 > My problem is: If I close the window with the "x"-Button on the frame > the window closes but cannot be re-used. you should connect the hide method also to the delete-event which is emitted by the windows when you press the "x"-Button on the frame. > What can I do to prevent this from happening? Or is there at least a way > to disable the "x" button for the window? Hiding (or disabling) the X button creates HIG problems, better don't do th= at. cheers --=20 Gian Mario Tagliaretti PyGTK GUI programming http://www.parafernalia.org/pygtk/ |
From: Stefan P. <pr...@tz...> - 2005-08-13 15:43:26
|
Hi Gian, Am Samstag, den 13.08.2005, 17:30 +0200 schrieb Gian Mario Tagliaretti: > > My problem is: If I close the window with the "x"-Button on the frame > > the window closes but cannot be re-used. > > you should connect the hide method also to the delete-event which is > emitted by the windows when you press the "x"-Button on the frame. I already tried that. I could verify that the method is called, but that doesn't change the fact that I wasn't able to re-display the window. The error was still the same. The problem must be somewhere else. But thanks for the idea anyway. Regards, Stefan |
From: Andrew C. <an...@op...> - 2005-08-14 01:58:14
|
On Sat, 2005-13-08 at 17:18 +0200, Stefan Prelle wrote: > The adventWindow-Dialog has a cancel button to close the > dialog again. It also has the usual button "x" on (the top right) window > frame to close the window. The cancel button triggers a call to > adventWindow.hide() > which works fine and allows me to call the show method again (even > without re-retrieving the widget from Glade). > > My problem is: If I close the window with the "x"-Button on the frame > the window closes but cannot be re-used. In GTK, the default handler for the delete-event signal is to stop emission of delete and re-emit destroy, which causes the window to be [C] free()'d. So, in your situation, it makes sense that [Java] hide()ing as result of hitting some button and then re-show()ing your window works fine, but 'x' does not. Hitting the 'x' button causes delete, which you're not handling in any particularly special way, which means that immediately thereafter GTK's default handler will turn the signal into destroy, and then most certainly you can't re-use it, and hence all the assertion error crud. What you need to do is handle the delete-event signal. In the Listener/Event pattern, it looks something like this: window.addListener(new LifeCycleListener() { public void lifeCycleEvent(LifeCycleEvent event) { System.out.println("DEBUG lifeCyleEvent(), " + event.getType().getName()); if (event.getType() == LifeCycleEvent.Type.HIDE) { // do something. hide() perhaps. } } public boolean lifeCycleQuery(LifeCycleEvent event) { System.out.println("DEBUG lifeCyleQuery() " + event.getType().getName()); if (event.getType() == LifeCycleEvent.Type.DELETE) { // do something, then, if ( whatever ) { // say to GTK that you've handled the signal, and // therefore to stop further emission of delete, // thereby avoiding an implicit destroy() return true; } else { // you want the default handler to carry on and destroy() return false; } } } }); Again, in your situation, you'll want to be hid()ing and returning true. In my experience, I end up calling external handlers (I called them hideHook() and deleteHook()) from this listener. It makes it easier for subclasses to override the behaviour. <shrug> ++ I had a long discussion with ijuma a couple of weeks ago about all this. I agree that what is presently called LifeCycleListener is a bit clumsy but it is what it is. Leave those debugs in for a while and watch the different events that get caught by this listener. It's instructive. AfC Sydney -- Andrew Frederick Cowie Operational Dynamics Consulting Pty Ltd Stand up and be counted! Register your Linux computers at http://counter.li.org/ |