-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
implementation of the copy canvas tool #10446
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
Conversation
@tacaswell can you help me out finding people with QT/Tk superpowers to help with the implementation for those two backends |
@anntzer thanks for the tip, QT was pretty easy The |
lib/matplotlib/rcsetup.py
Outdated
@@ -1389,6 +1389,7 @@ def _validate_linestyle(ls): | |||
'keymap.yscale': [['l'], validate_stringlist], | |||
'keymap.xscale': [['k', 'L'], validate_stringlist], | |||
'keymap.all_axes': [['a'], validate_stringlist], | |||
'keymap.copy': [('ctrl+c', 'cmd+c', 'shift+ctrl+c'), validate_stringlist], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list instead of tuple? (as above, basically)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anntzer Done
I didn't find a way to do it for tkinter, it seems this is not well supported. So I just emit a warning when called from tk backend The other option would be to just don't add it in TK, but this means allowing a disparity between backends for default tools. And that is something that we don't really want |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this code will only be triggered by a user action from a GUI, it‘s probably better to show the warning in a message box. A warning in the console may go unnoticed and the user may wonder why there is no image in the clipboard.
@timhoffm I change the message, now it appears in the statusbar |
I have just added and tested an implementation for the Wx backends. I would suggest more consistent names: Qt vs. QT and probably omit the
|
@DietmarSchwertberger I agree with the renaming, but it should be done in a separate PR, only for that. |
@DietmarSchwertberger when commiting to other's peoples PR you should open a PR against their branch, not commit directly. |
@fariza : sorry, I thought this would be the standard approach as anntzer suggested this on a previous PR of him. |
It's OK if the PR owner gives you ("verbal") permission to do so (which I gave to all devs for just my own PRs). |
Don't worry, I just wasn't expecting that |
See #10851 (comment). |
I did only test those parts that were used by the wx implementation and things worked as expected. I agreee with anntzer that some automated testing for the toolmanager tools is required, but we need a volunteer for that. @fariza I recently found the "Customize" tool of the |
This is failing all the tests. Probably not going to get merged until that's fixed! Looks like you need to update |
@DietmarSchwertberger that QT specific tool is one of the reasons this toolmanager exists, and MEP27 is been a work in progress for a long time. |
Yes.
I'm not bent against that, I just don't have the bandwidth to do a proper review right now, and tests would have helped. |
@anntzer I agree that we need to test this, but I agree with @DietmarSchwertberger about not holding this PRs because of that. |
@jklymak fixed, "all checks have passed" |
@@ -971,11 +971,18 @@ def trigger(self, *args): | |||
dialog.done = lambda num: dialog.frame.master.withdraw() | |||
|
|||
|
|||
class ToolCopyToClipboardTk(backend_tools.ToolCopyToClipboardBase): | |||
def trigger(self, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this to the base class ("The current backend does not implement the copy tool.").
In fact this could even be moved to ToolBase...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
def trigger(self, *args, **kwargs): | ||
message = "Copy tool is not available for Tk backend" | ||
self.toolmanager.message_event(message, self) | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... then you don't need this class anymore.
I would drop shift-ctrl-c as a default shortcut -- it is only useful in context where ctrl-c is not available (because that's an interrupt), not where ctrl-c is already a shortcut for copy. |
@anntzer it was @efiring that suggested shift+ctrl+c in #1987 (comment) do we keep it? |
But he suggested it instead of ctrl-c, not in addition. I would not keep both. |
lib/matplotlib/rcsetup.py
Outdated
@@ -1421,6 +1421,7 @@ def _validate_linestyle(ls): | |||
'keymap.xscale': [['k', 'L'], validate_stringlist], | |||
'keymap.all_axes': [['a'], validate_stringlist], | |||
'keymap.help': [['f1'], validate_stringlist], | |||
'keymap.copy': [('ctrl+c', 'cmd+c'), validate_stringlist], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list, not tuple
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
backend_tools.ToolSaveFigure = SaveFigureQt | ||
backend_tools.ToolConfigureSubplots = ConfigureSubplotsQt | ||
backend_tools.ToolSetCursor = SetCursorQt | ||
backend_tools.ToolRubberband = RubberbandQt | ||
backend_tools.ToolHelp = HelpQt | ||
backend_tools.ToolCopyToClipboard = ToolCopyToClipboardQT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the backend-specific tool classes do not have the "Tool" prefix. While, in general I would recommend to keep the prefix also in the backend specific classes, in the present situation I'm +0.3 not using it for consistency with the existing code. But I'm not familiar with that part of the code and don't know if there are any explicit policies on this. Maybe someone more experienced with that code can comment on this?
Same holds for the other backends.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timhoffm you are right, we have to make the naming more consistent.
We can make a separate PR fixing all those names at once. I don't think it is relevant here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we consider the backend implementations private? If so we can clean up the naming soon and this PR goes in as is.
If not, we need a deprecation cycle. In that case, I‘d prefer to remove the Tool prefix in this PR as well and change everything later together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the initial warning states. Tool names might change. So I don't see a problem doing all of them in a single PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll merge after giving @timhoffm a little bit if he still want the naming conventions fixed...
A week is fine ;-) |
Right now does the copy always give you a png? Would be great to support vector formats like svg as well. I manage to do this with Qt backend on windows, with something like this:
Then I can go to word to paste it as an svg image. |
Does copy work with PyQT5 on Mac? I am unable to get anything onto the clipboard with cmd-c. |
@jdtsmith are you using the toolmanager? it was tested long time ago, I don't have mac to test. If it's not working lets report a bug |
I figured that out thanks; copy and scroll to zoom both work for me on Mac with this: import warnings, matplotlib.pyplot as plt
plt.ion()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
plt.rcParams['toolbar'] = 'toolmanager' # scrollzoom + Cmd-C copy! Maybe |
Yes I agree, we need to properly pan and execute the transition |
Did the situation for tk change? Maybe add a comment in the starting post that tk is not working currently. |
PR Summary
Answering to #1987
This is the implementation of the CopyToClipboard tool
Before it get's merged we need to have the three backends that are supported by the ToolManager
PR Checklist