Skip to content

copy to clipboard and icon for QT #22505

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

Closed
wants to merge 1 commit into from
Closed

copy to clipboard and icon for QT #22505

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Feb 19, 2022

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

Adding icon next to save figure to file and copying figure to clipboard. Tested on linux with QT environment.

@ghost
Copy link
Author

ghost commented Feb 19, 2022

copytoclipboard

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@oscargus
Copy link
Member

Thanks for this PR! Looks like a good idea!

The test failures are, as you may have realized, unrelated. However, is there a way to test this? Maybe add a test that copies an image and then check that the clipboard content has the correct type?

Also, please see #22503 which aims at deprecating qApp. Probably safest to replace it with QtWidgets.QApplication.instance() already now.

@oscargus
Copy link
Member

oscargus commented Feb 19, 2022

Probably the documentation for NavigationToolbar2 should be updated as well (as I think this will be required to implement for the other backends as well). Maybe one should also add a keyboard short-cut (ctrl+c)?

Edit: except that ctrl+c is already used to cancel stuff.

@ghost
Copy link
Author

ghost commented Feb 19, 2022

this is in one of the files - matplotlibrc:

#keymap.copy: ctrl+c, cmd+c # copy figure to clipboard

though it does not work for me... that is why I was trying to add icon. I will try to figure out how to create a test + how to update documentation as well.

@oscargus
Copy link
Member

After reading up a bit more (I have not looked that much into the backend code), I believe that there is an easier way to do it. It seems like there is already support for copying and that it is maybe enough to add 'copy' here (if it should be default, although there may be an earlier decision that it should not):

default_toolbar_tools = [['navigation', ['home', 'back', 'forward']],
['zoompan', ['pan', 'zoom', 'subplots']],
['io', ['save', 'help']]]

(Using an icon would be nice though.)

There is also

@backend_tools._register_tool_class(FigureCanvasQT)
class ToolCopyToClipboardQT(backend_tools.ToolCopyToClipboardBase):
def trigger(self, *args, **kwargs):
pixmap = self.canvas.grab()
qApp.clipboard().setPixmap(pixmap)

which I assume should be triggered by ctrl+c (or pressing the icon). I'm wondering if it may be that SIGSEGV is sent instead of ctrl+c when ctrl+c is pressed on Linux?

@oscargus
Copy link
Member

It should be possible to just add image = 'copyfigure' as a member to this class to get an icon:

class ToolCopyToClipboardBase(ToolBase):
"""Tool to copy the figure to the clipboard."""
description = 'Copy the canvas figure to clipboard'
default_keymap = property(lambda self: mpl.rcParams['keymap.copy'])
def trigger(self, *args, **kwargs):
message = "Copy tool is not available"
self.toolmanager.message_event(message, self)

@ghost
Copy link
Author

ghost commented Feb 19, 2022

yes, I found this as well:
ToolCopyToClipboardBase

though I have no idea how to call it. I tried to use it, but wasn't successful.

@ghost
Copy link
Author

ghost commented Feb 19, 2022

I am just going to close this as I am not really sure what would be "the right way" solution. Maybe I will start with some easier contribution to matplotlib. Thanks for the comments though!

@ghost ghost closed this Feb 19, 2022
@ghost
Copy link
Author

ghost commented Feb 19, 2022

Also, I tried this:

default_toolbar_tools = [['navigation', ['home', 'back', 'forward']],
['zoompan', ['pan', 'zoom', 'subplots']],
['io', ['save', 'help', 'copy']]]

but it did not show the copy thing when tried to test it out...
doesntwork

@ghost ghost deleted the copytoclipboard branch February 19, 2022 23:03
@oscargus
Copy link
Member

I think that if you are willing to contribute the icon, combined with image = 'copyfigure' on line 967 of backend tools, that would help to enable this as some stage.

Sorry for not being able assist further. I like the idea for sure!

@ghost
Copy link
Author

ghost commented Feb 22, 2022

I think I will leave this one to someone else. I took it as an exercise and now I have a new PR for different fix of matplotlib. Hopefully that one goes through. Thanks

@oscargus
Copy link
Member

OK! Do you mind if I take the icon, attribute the commit with the icon to you and create a PR?

@ghost
Copy link
Author

ghost commented Feb 24, 2022

Please go ahead - I just want my first PR to go smoothly (the other one) to learn how you guys do things. In future, I might be more adventurous and have more PRs at the same time. In meantime, just go ahead.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants