I've been using the following for handling double click:
def do_button_press_event(self, eb: Gdk.EventButton):
if eb.type == Gdk.EventType._2BUTTON_PRESS:
# todo: code double click
pass
Accessing the private property _2BUTTON_PRESS
feels a bit dirty. Is there a better way to handle this?
It's not a private property: it's an artefact of the C enumeration member being GDK_2BUTTON_PRESS
. Python does not allow identifiers to start with a number, so when translating the symbol GDK_2BUTTON_PRESS
in the GdkEventType
C enumeration into a field in Gdk.EventType
Python class, PyGOBject needs to escape the 2BUTTON_PRESS
part.
To avoid this, GTK introduced a GDK_DOUBLE_BUTTON_PRESS
, which is correctly translated as Gdk.EventType.DOUBLE_BUTTON_PRESS
.
The same explanation also applies to the GDK_3BUTTON_PRESS
/GDK_TRIPLE_BUTTON_PRESS
enumeration fields.