Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dialog boxes using Glade in python running, destroying, and reusing

I am using Glade to write a python GUI with a dialog box.

If I weren't using Glade, I would use a class to create a dialog window (dialag), run it (dialog.run), do whatever it does, then removing it (dialog.destroy). I would then just re-instantiate it when I need the dialog box again.

Glade puts a monkey wrench in this. After invoking Gtk.Builder, I can get the object with something like:

dialog = builder.get_object("dialog")
response = dialog.run()
#do stuff
dialog.destroy()

I prefer the run, use, destroy way of working as it removes it from memory.

Using Glade however, after I do the above, I can't get it to work a second time because the invocation has been destroyed, and I don't know a way of getting Glade to reinstantiate it.

In past programs I've written, I've done a this:

dialog = builder.get_object('dialog')
response = dialog.run()
# use it
dialog.hide()

When I need it again, I would do a:

dialog.show()
response = dialog.run()
# do stuff
dialog.hide()

To get around this limitation, but I haven't been satisfied with this way of doing it feeling it is a bit of a hack (and I guess with Glade, everything is created in the beginning anyway). Is there a way to get the Glade libs to re-instantiate a dialog box rather than doing all this showing and hiding?

Thanks,

Narnie

like image 934
narnie Avatar asked Nov 04 '22 09:11

narnie


1 Answers

Yes - you have to create a new builder object and re-load the Glade file though. One builder object creates one dialog, and if you destroy it then it's gone.

I don't necessarily think that hiding and showing the dialog is a hack. You might want to destroy and re-create if memory is a serious concern, but otherwise I don't think it makes much of a difference.

like image 64
ptomato Avatar answered Nov 08 '22 04:11

ptomato