Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable accelerators when typing text in GTK+

Tags:

python

gtk

I'm using some predefined accelerators connected with certain hot keys. Is it possible to temporarily disable them? I don't want to change the hot keys, in order not to confuse users. The accelerators are activated when typing into a combo box, which really is unacceptable.

like image 259
user3484510 Avatar asked Apr 01 '14 10:04

user3484510


1 Answers

I asked this again on the GTK+ mailing list and the people there had two suggestions that came with real-life implementations from their own projects (not linked here but you can check the thread if you want to see them):

  1. Intercept and handle all key presses, thus overriding GTK+'s normal mechanism and allowing you to make exceptions for your accelerators.
  2. Having a list of accelerators that you remove manually when a text editing widget gets focus, then add them again when the widget loses focus. In GTK+ 3 this is accomplished with gtk_application_set_accels_for_action.

In the thread I linked you can find example code for both approaches. The second approach even has an example in GTK+ 2 and one in GTK+ 3.

like image 88
smheidrich Avatar answered Oct 18 '22 05:10

smheidrich