4

I made a GtkDialog object, but I want to disable or handle the escape press event, how can I do it?

liberforce
  • 11,189
  • 37
  • 48
ssoto
  • 469
  • 5
  • 19

2 Answers2

2

Connect to the delete-event, and in the callback, check if the event has been triggered by the ESC key press. Returning TRUE stops event propagation (this is what you want to ignore the ESC key press), returning FALSE will propagate the event and close the dialog.

liberforce
  • 11,189
  • 37
  • 48
  • It doesn't look like you can hook a Dialog's delete-event, unortunately, if I am notmistaken – phil294 Aug 21 '22 at 03:12
  • This was a very old question, with a very old answer. `delete-event` has been removed on GTK 4, and the changes backported in GTK 3 (See https://docs.gtk.org/gtk4/migrating-3to4.html#stop-using-gtkwidget-event-signals ). This being said, when that signal existed in GTK 3, it was inherited from `GtkWidget`. `GtkDialog` [inherits](https://docs.gtk.org/gtk3/class.Dialog.html#hierarchy) (indirectly) from `GtkWidget`, so you should still be able to connect to `delete-event` on a `GtkDialog`. – liberforce Aug 21 '22 at 23:16
0

It is working if you:

enter image description here

bind the response signal to an event:

    def on_dialogBigLabel_response(self, widget, response_id):
        print('on_dialogBigLabel_response Widget: %s | response_id: %s' % (widget, response_id))

        if response_id == Gtk.ResponseType.OK:
            print('OK')
            self.dialogBigLabel.hide()
        else:
            print('Response: %i' % response_id)

Now the escape response is -4 and here we aren't hiding or destroying the dialog.

Andreas
  • 85
  • 1
  • 13