Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: Add version gate to GTK4 calls when necessary #29363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading