Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
small fixes to gtk4 and some checks
  • Loading branch information
AdwaithBatchu committed Jan 16, 2026
commit 5417d958627eee8ad9c00c498e847819cba0f310
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def full_screen_toggle(self):
self.window.attributes('-fullscreen', not is_fullscreen)

def context_menu(self, event, labels=None, actions=None):
if labels is None or actions is None:
if not labels or not actions:
return
menu = tk.Menu(self.window, tearoff=0)
for label, action in zip(labels, actions):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ class FigureManagerGTK3(_FigureManagerGTK):
_toolmanager_toolbar_class = ToolbarGTK3

def context_menu(self, event, labels=None, actions=None):
if labels is None or actions is None:
if not labels or not actions:
return
menu = Gtk.Menu()
for label, action in zip(labels, actions):
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/backends/backend_gtk4.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,17 +642,19 @@ def context_menu(self, event, labels=None, actions=None):
return
menu = Gio.Menu()
action_group = Gio.SimpleActionGroup()
for i, (label, action) in enumerate(zip(labels, actions)):
action_name = f"{label}"
for label, action in zip(labels, actions):
action_name = label.replace(" ", "_")
g_action = Gio.SimpleAction.new(action_name, None)
g_action.connect("activate", lambda *_, a=action: a())
action_group.add_action(g_action)
menu.append(label, f"win.{action_name}")

self.canvas.insert_action_group("win", action_group)
popover = Gtk.PopoverMenu.new_from_model(menu)
popover.set_parent(self.canvas)
popover.set_has_arrow(False)
popover.set_halign(Gtk.Align.START)

scale = self.canvas.get_scale_factor()
height = self.canvas.get_height()
rect = Gdk.Rectangle()
Expand Down
25 changes: 0 additions & 25 deletions lib/matplotlib/backends/backend_macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from matplotlib.backend_bases import (
_Backend, FigureCanvasBase, FigureManagerBase, NavigationToolbar2,
ResizeEvent, TimerBase, _allow_interrupt)
from Foundation import NSObject
import AppKit


class TimerMac(_macosx.Timer, TimerBase):
Expand Down Expand Up @@ -147,12 +145,6 @@ def save_figure(self, *args):
return filename


class MenuCallback(NSObject):
def action_(self, sender):
if hasattr(self, 'callback'):
self.callback()


class FigureManagerMac(_macosx.FigureManager, FigureManagerBase):
_toolbar2_class = NavigationToolbar2Mac

Expand All @@ -169,23 +161,6 @@ def __init__(self, canvas, num):
self.show()
self.canvas.draw_idle()

def context_menu(self, event, labels=None, actions=None):
if labels is None or actions is None:
return
menu = AppKit.NSMenu.alloc().init()
self._menu_callbacks = []
for label, action in zip(labels, actions):
>
target.callback = action
self._menu_callbacks.append(target)
item = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
label, "action:", ""
)
item.setTarget_(target)
menu.addItem_(item)
mouse_loc = AppKit.NSEvent.mouseLocation()
menu.popUpMenuPositioningItem_atLocation_inView_(None, mouse_loc, None)

def _close_button_pressed(self):
Gcf.destroy(self)
self.canvas.flush_events()
Expand Down
7 changes: 2 additions & 5 deletions lib/matplotlib/backends/backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,12 @@ def full_screen_toggle(self):
self.window.showFullScreen()

def context_menu(self, event, labels=None, actions=None):
if labels is None or actions is None:
if not labels or not actions:
return
menu = QtWidgets.QMenu(self.window)
for label, action in zip(labels, actions):
menu.addAction(label).triggered.connect(action)
if hasattr(event.guiEvent, 'globalPosition'):
menu.exec(event.guiEvent.globalPosition().toPoint())
else:
menu.exec(event.guiEvent.globalPos())
menu.exec(event.guiEvent.globalPos())

def _widgetclosed(self):
CloseEvent("close_event", self.canvas)._process()
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ def full_screen_toggle(self):
self.frame.ShowFullScreen(not self.frame.IsFullScreen())

def context_menu(self, event, labels=None, actions=None):
if labels is None or actions is None:
if not labels or not actions:
return
menu = wx.Menu()
for label, action in zip(labels, actions):
Expand Down
Loading