Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jklymak merged 10 commits intomatplotlib:masterfromfariza:copy-tool
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes fromall 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
12 changes: 12 additions & 0 deletionslib/matplotlib/backend_tools.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1063,6 +1063,17 @@ def _get_help_html(self):
"<tbody>".join(rows[1:]) + "</tbody></table>")


class ToolCopyToClipboardBase(ToolBase):
"""Tool to copy the figure to the clipboard"""

description = 'Copy the canvas figure to clipboard'
default_keymap = rcParams['keymap.copy']

def trigger(self, *args, **kwargs):
message = "Copy tool is not available"
self.toolmanager.message_event(message, self)


default_tools = {'home': ToolHome, 'back': ToolBack, 'forward': ToolForward,
'zoom': ToolZoom, 'pan': ToolPan,
'subplots': 'ToolConfigureSubplots',
Expand All@@ -1081,6 +1092,7 @@ def _get_help_html(self):
'cursor': 'ToolSetCursor',
'rubberband': 'ToolRubberband',
'help': 'ToolHelp',
'copy': 'ToolCopyToClipboard',
}
"""Default tools"""

Expand Down
1 change: 1 addition & 0 deletionslib/matplotlib/backends/_backend_tk.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -976,6 +976,7 @@ def trigger(self, *args):
backend_tools.ToolSetCursor = SetCursorTk
backend_tools.ToolRubberband = RubberbandTk
backend_tools.ToolHelp = HelpTk
backend_tools.ToolCopyToClipboard = backend_tools.ToolCopyToClipboardBase
Toolbar = ToolbarTk


Expand Down
10 changes: 10 additions & 0 deletionslib/matplotlib/backends/backend_gtk3.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -856,6 +856,15 @@ def trigger(self, *args):
dialog.destroy()


class ToolCopyToClipboardGTK3(backend_tools.ToolCopyToClipboardBase):
def trigger(self, *args, **kwargs):
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
window = self.canvas.get_window()
x, y, width, height = window.get_geometry()
pb = Gdk.pixbuf_get_from_window(window, x, y, width, height)
clipboard.set_image(pb)


# Define the file to use as the GTk icon
if sys.platform == 'win32':
icon_filename = 'matplotlib.png'
Expand DownExpand Up@@ -888,6 +897,7 @@ def error_msg_gtk(msg, parent=None):
backend_tools.ToolSetCursor = SetCursorGTK3
backend_tools.ToolRubberband = RubberbandGTK3
backend_tools.ToolHelp = HelpGTK3
backend_tools.ToolCopyToClipboard = ToolCopyToClipboardGTK3

Toolbar = ToolbarGTK3

Expand Down
7 changes: 7 additions & 0 deletionslib/matplotlib/backends/backend_qt5.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1069,11 +1069,18 @@ def trigger(self, *args):
QtWidgets.QMessageBox.information(None, "Help", self._get_help_html())


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


backend_tools.ToolSaveFigure = SaveFigureQt
backend_tools.ToolConfigureSubplots = ConfigureSubplotsQt
backend_tools.ToolSetCursor = SetCursorQt
backend_tools.ToolRubberband = RubberbandQt
backend_tools.ToolHelp = HelpQt
backend_tools.ToolCopyToClipboard = ToolCopyToClipboardQT
Copy link
Member

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.

Copy link
MemberAuthor

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

Copy link
Member

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.

Copy link
MemberAuthor

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



def error_msg_qt(msg, parent=None):
Expand Down
13 changes: 13 additions & 0 deletionslib/matplotlib/backends/backend_wx.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1826,9 +1826,22 @@ def remove_rubberband(self, dc=None):
self._rect = None


class ToolCopyToClipboardWx(backend_tools.ToolCopyToClipboardBase):
def trigger(self, *args, **kwargs):
if not self.canvas._isDrawn:
self.canvas.draw()
if not self.canvas.bitmap.IsOk() or not wx.TheClipboard.Open():
return
try:
wx.TheClipboard.SetData(wx.BitmapDataObject(self.canvas.bitmap))
finally:
wx.TheClipboard.Close()


backend_tools.ToolSaveFigure = SaveFigureWx
backend_tools.ToolSetCursor = SetCursorWx
backend_tools.ToolRubberband = RubberbandWx
backend_tools.ToolCopyToClipboard = ToolCopyToClipboardWx


# < Additions for printing support: Matt Newville
Expand Down
1 change: 1 addition & 0 deletionslib/matplotlib/rcsetup.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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],

# sample data
'examples.directory': ['', validate_string],
Expand Down
1 change: 1 addition & 0 deletionsmatplotlibrc.template
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -591,6 +591,7 @@ backend : $TEMPLATE_BACKEND
#keymap.yscale : l ## toggle scaling of y-axes ('log'/'linear')
#keymap.xscale : k, L ## toggle scaling of x-axes ('log'/'linear')
#keymap.all_axes : a ## enable all axes
#keymap.copy : ctrl+c, cmd+c ## Copy figure to clipboard

## Control location of examples data files
#examples.directory : ## directory to look in for custom installation
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp