1

I am making an application using glade and python in Ubuntu. I used the about dialog widget to make an about page that is accessed via a drop down menu. When I open this about dialog the first time it works fine. When I close it with the 'x' in the top left corner it will not reopen. I have my 'delete-event' signal bound to a function close_about_window() which looks like this.

def close_about_window(self, *args):

---- self.about_window.hide()

Also if anyone knows the signal for the "close" button located at the bottom of the screen by license and credits that would be greatly appreciated.

2 Answers 2

1

Since the About page is a Dialog, when you run the dialog you can connect a callback to the response signal and you will get a response_id.

The body of your callback could be something like this:

if (response_id == Gtk.ResponseType.CANCEL || response_id == Gtk.ResponseType.DELETE_EVENT) {
    dialog.hide_on_delete ();
}

You also have the Dialog close signal which will work for keybindings, let's say, pressing ESC.

Sign up to request clarification or add additional context in comments.

5 Comments

The response signal will cover everything, including keybindings.
yes it will, it's just a note to that signal existence. Thanks @andlabs
You only set hide_on_delete() once, not in the callback.
@TingPing Check this and check the about dialog example.
No problem @TingPing It also improves the discussion. GL Peace
0

So the solution to the problem is really simple. I realized that a dialog box is not the same as a window. You want to show the window using .run() not .show_all() or .show(). Use .run() and then in the same function use .hide(). Your open_about_dialog() function will look like this.

def open_about_dialog():
    self.about_dialog.run()
    self.about_dialog.hide()

Just so there is no issue I imported my object from my glade file using the builder builder.get_object("about_dialog")

6 Comments

You can show the window using show_all(); in this case, though, your code returns immediately and you are responsible for handling response AND the delete-event yourself. You have to do the latter too because GtkWindow's default delete-event destroys the window, and GtkDialog inherits from GtkWindow without overriding that. In fact, this is probably the bug with your original code: delete-event requires you to return a boolean value that decides whether the default handler (that is, GtkWindow's) gets run or not, and you're not doing that. IDK how it works in Python though, sorry.
(GtkDialog.run() provides its own handlers for response and delete-event, as the GTK+ documentation points out.)
Yes thank you. I figured that the delete event was destroying the window even though I didn't write that in. I only now thought to check the parent.
Keep in mind that you can set response id's to buttons in Glade also. -3 is Gtk.ResponseType.ACCEPT and -6 is Gtk.ResponseType.CANCEL. This saves a lot of hand written code.
You should avoid .run() though as it creates another mainloop.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.