1.

I Want My Callback To Execute, But Not The Default Callback (or, How To I Stop Gtk From Doing The Default Action When Doing X)?

Answer»

Many times, you are customizing behaviour of a widget, or changing a policy in GTK, and the default action it does it not what you want. To get around this, we RELY on a FUNDAMENTAL point in GTK: that GTK, as well as applications, mainly uses signals to get things done in the interface.

The process to disable a default action is:

  • Find out what signal is being emitted and handled by the default HANDLER. Many times you already know the signal since you may be hooking to it already, and observing the default action happen after yours.
  • call widget.emit_stop_by_name("signal_name") (to stop the signal emission in the current widget)
  • RETURN True (to make sure that the signal won't propagate into parent handlers that may be the actual culprits for the default action)

An example of this usage was reported by Graham Ashton. He had customized a keypress handler for a window, but every time the user triggered the Alt-arrow combination he was handling, the focus moved around between the widgets in the interface (as is the default behaviour).

The solution was simply calling window.emit_stop_by_name("key_press_event") and returning True.

Many times, you are customizing behaviour of a widget, or changing a policy in GTK, and the default action it does it not what you want. To get around this, we rely on a fundamental point in GTK: that GTK, as well as applications, mainly uses signals to get things done in the interface.

The process to disable a default action is:

An example of this usage was reported by Graham Ashton. He had customized a keypress handler for a window, but every time the user triggered the Alt-arrow combination he was handling, the focus moved around between the widgets in the interface (as is the default behaviour).

The solution was simply calling window.emit_stop_by_name("key_press_event") and returning True.



Discussion

No Comment Found