5

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

narnie
  • 1,742
  • 1
  • 18
  • 34

1 Answers1

2

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.

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • OK. I'm glad for your opinion about its being a hack or not. I thought about loading it in again, but then it won't automatically be associated with the parent window again, plus, would it not just be the same problem as loading in an entire other builder object loading in a main window, the about window, and another other dialog windows? Perhaps I should just separate out the individual windows as different glade files if I really want to do it that way and use the Gtk.Dialog.set_parent method and reload each window's instance when I need it and that way I could destroy it then. Thots? – narnie Dec 09 '12 at 20:22
  • 1
    Yes, you'd have to separate the windows out into separate Glade files. But I really wouldn't go to all that trouble; to the end user, it really doesn't matter whether the window is destroyed or hidden, does it? It only makes a difference if you are in danger of running out of memory. – ptomato Dec 09 '12 at 21:31