Skip to content

Conversation

@AdwaithBatchu
Copy link
Collaborator

PR summary

PR checklist

Copy link
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdwaithBatchu The backend implementation is slightly wrong right now. As discussed previously:

  • There should be no mention of 3d axes or view_init within the backend files. After all these files should be as general as possible.
  • You only need to add a function named context_menu in the FigureManager class.

Copy link
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdwaithBatchu I have some concerns about implementation in Gtk4 and MacOSX.

Apart from that, I want you to link to the official documentation of the context_menu for each backend. For example, I have added a comment for qt backend. Do this for the other implemented backends.

@AdwaithBatchu AdwaithBatchu requested a review from r3kste January 2, 2026 12:15

if (dx**2 + dy**2) > 5:
self._mouse_moved = True

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this threshold a bit too high?

Copy link
Owner

@r3kste r3kste Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This threshold is now not too high, but is still noticeable. If I move the cursor slightly, the plot is zoomed as well as the context menu is shown.

Copy link
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdwaithBatchu This is pretty close. The main thing is that

Make sure all backends use a consistent method for determining location
1. Current mouse position
2. Extract coords from event

Both will (should) give the exact same output, but for sake of consistency we should use a single method. I think (ii) is better, but let me know if you think otherwise

functools.partial(draw_lambda, elev=0, azim=0),
functools.partial(draw_lambda, elev=0, azim=-90)],
)
canvas.draw_idle()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
canvas.draw_idle()

This can be removed now

for label, action in zip(labels, actions):
item = Gtk.MenuItem(label=label)
menu.append(item)
item.connect('activate', lambda w, a=action: a())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a parameter is unused, just use underscore. Do this in other backends that use such lambdas (such as GTK4)

Suggested change
item.connect('activate', lambda w, a=action: a())
item.connect('activate', lambda _, a=action: a())

menu = Gio.Menu()
action_group = Gio.SimpleActionGroup()
for i, (label, action) in enumerate(zip(labels, actions)):
action_name = f"ctx_{i}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "ctx" have a special meaning that GTK understands, or can it be anything. If it can be anything, you could simply use the label instead.

Comment on lines +186 to +187
mouse_loc = AppKit.NSEvent.mouseLocation()
menu.popUpMenuPositioningItem_atLocation_inView_(None, mouse_loc, None)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other backends, the position is extracted from event or event.guiEvent. So try to follow that here as well, instead of using the current mouse location. Check this for other backends as well, for instance Qt and Wx


if (dx**2 + dy**2) > 5:
self._mouse_moved = True

Copy link
Owner

@r3kste r3kste Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This threshold is now not too high, but is still noticeable. If I move the cursor slightly, the plot is zoomed as well as the context menu is shown.

Comment on lines +649 to +655
def context_menu(self, event, labels=None, actions=None):
if labels is None or actions is None:
return
menu = tk.Menu(self.window, tearoff=0)
for label, action in zip(labels, actions):
menu.add_command(label=label, command=action)
menu.tk_popup(event.guiEvent.x_root, event.guiEvent.y_root)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is tk's context menu so horrible? 😂
Just check once whether you can do something about it, else lite only

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it looks fine only
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants