Skip to content

Commit

Permalink
Backport PR matplotlib#29363: FIX: Add version gate to GTK4 calls whe…
Browse files Browse the repository at this point in the history
…n necessary
  • Loading branch information
greglucas authored and meeseeksmachine committed Jan 6, 2025
1 parent 2a0cd72 commit 462555c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/matplotlib/backends/backend_gtk4.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
TimerGTK as TimerGTK4,
)

_GOBJECT_GE_3_47 = gi.version_info >= (3, 47, 0)


class FigureCanvasGTK4(_FigureCanvasGTK, Gtk.DrawingArea):
required_interactive_framework = "gtk4"
Expand Down Expand Up @@ -115,7 +117,7 @@ def scroll_event(self, controller, dx, dy):
MouseEvent(
"scroll_event", self, *self._mpl_coords(), step=dy,
modifiers=self._mpl_modifiers(controller),
guiEvent=controller.get_current_event(),
guiEvent=controller.get_current_event() if _GOBJECT_GE_3_47 else None,
)._process()
return True

Expand All @@ -124,7 +126,7 @@ def button_press_event(self, controller, n_press, x, y):
"button_press_event", self, *self._mpl_coords((x, y)),
controller.get_current_button(),
modifiers=self._mpl_modifiers(controller),
guiEvent=controller.get_current_event(),
guiEvent=controller.get_current_event() if _GOBJECT_GE_3_47 else None,
)._process()
self.grab_focus()

Expand All @@ -133,22 +135,22 @@ def button_release_event(self, controller, n_press, x, y):
"button_release_event", self, *self._mpl_coords((x, y)),
controller.get_current_button(),
modifiers=self._mpl_modifiers(controller),
guiEvent=controller.get_current_event(),
guiEvent=controller.get_current_event() if _GOBJECT_GE_3_47 else None,
)._process()

def key_press_event(self, controller, keyval, keycode, state):
KeyEvent(
"key_press_event", self, self._get_key(keyval, keycode, state),
*self._mpl_coords(),
guiEvent=controller.get_current_event(),
guiEvent=controller.get_current_event() if _GOBJECT_GE_3_47 else None,
)._process()
return True

def key_release_event(self, controller, keyval, keycode, state):
KeyEvent(
"key_release_event", self, self._get_key(keyval, keycode, state),
*self._mpl_coords(),
guiEvent=controller.get_current_event(),
guiEvent=controller.get_current_event() if _GOBJECT_GE_3_47 else None,
)._process()
return True

Expand All @@ -157,21 +159,21 @@ def motion_notify_event(self, controller, x, y):
"motion_notify_event", self, *self._mpl_coords((x, y)),
buttons=self._mpl_buttons(controller),
modifiers=self._mpl_modifiers(controller),
guiEvent=controller.get_current_event(),
guiEvent=controller.get_current_event() if _GOBJECT_GE_3_47 else None,
)._process()

def enter_notify_event(self, controller, x, y):
LocationEvent(
"figure_enter_event", self, *self._mpl_coords((x, y)),
modifiers=self._mpl_modifiers(),
guiEvent=controller.get_current_event(),
guiEvent=controller.get_current_event() if _GOBJECT_GE_3_47 else None,
)._process()

def leave_notify_event(self, controller):
LocationEvent(
"figure_leave_event", self, *self._mpl_coords(),
modifiers=self._mpl_modifiers(),
guiEvent=controller.get_current_event(),
guiEvent=controller.get_current_event() if _GOBJECT_GE_3_47 else None,
)._process()

def resize_event(self, area, width, height):
Expand Down

0 comments on commit 462555c

Please sign in to comment.