Skip to content

Commit 44bccc5

Browse files
authored
Merge pull request #1386 from janezd/graph-to-clipboard
[ENH] Implement copying graph to clipboard using Ctrl-C (Cmd-C)
2 parents ee5b063 + 55d31c1 commit 44bccc5

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

Orange/widgets/classify/owtreeviewer2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class OWTreeViewer2D(OWWidget):
361361
_DEF_NODE_WIDTH = 24
362362
_DEF_NODE_HEIGHT = 20
363363

364-
graph_name = True
364+
graph_name = "scene"
365365

366366
def __init__(self):
367367
super().__init__()

Orange/widgets/io.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from PyQt4 import QtGui, QtCore, QtSvg
2-
from PyQt4.QtGui import QGraphicsScene, QGraphicsView, QWidget
2+
from PyQt4.QtCore import QMimeData
3+
from PyQt4.QtGui import QGraphicsScene, QGraphicsView, QWidget, QApplication
34

45
from Orange.data.io import FileFormat
56

@@ -100,6 +101,23 @@ def _export(exporter, filename):
100101
buffer.save(filename, "png")
101102

102103

104+
class ClipboardFormat(PngFormat):
105+
EXTENSIONS = ()
106+
DESCRIPTION = 'System Clipboard'
107+
PRIORITY = 50
108+
109+
@staticmethod
110+
def _save_buffer(buffer, _):
111+
QApplication.clipboard().setPixmap(buffer)
112+
113+
@staticmethod
114+
def _export(exporter, _):
115+
buffer = exporter.export(toBytes=True)
116+
mimedata = QMimeData()
117+
mimedata.setData("image/png", buffer)
118+
QApplication.clipboard().setMimeData(mimedata)
119+
120+
103121
class SvgFormat(ImgFormat):
104122
EXTENSIONS = ('.svg',)
105123
DESCRIPTION = 'Scalable Vector Graphics'

Orange/widgets/widget.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from Orange.canvas.registry import description as widget_description
1919
from Orange.canvas.report import Report
2020
from Orange.widgets.gui import ControlledAttributesDict, notify_changed
21+
from Orange.widgets.io import ClipboardFormat
2122
from Orange.widgets.settings import SettingsHandler
2223
from Orange.widgets.utils import saveplot, getdeepattr
2324
from .utils.overlay import MessageOverlayWidget
@@ -198,6 +199,9 @@ def __new__(cls, *args, **kwargs):
198199
sc = QShortcut(QKeySequence(Qt.ShiftModifier | Qt.Key_F1), self)
199200
sc.activated.connect(self.__quicktip)
200201

202+
sc = QShortcut(QKeySequence.Copy, self)
203+
sc.activated.connect(self.copy_to_clipboard)
204+
201205
return self
202206

203207
def __init__(self, *args, **kwargs):
@@ -316,6 +320,12 @@ def save_graph(self):
316320
return
317321
saveplot.save_plot(graph_obj, self.graph_writers)
318322

323+
def copy_to_clipboard(self):
324+
graph_obj = getdeepattr(self, self.graph_name, None)
325+
if graph_obj is None:
326+
return
327+
ClipboardFormat.write_image(None, graph_obj)
328+
319329
def __restoreWidgetGeometry(self):
320330

321331
def _fullscreen_to_maximized(geometry):

0 commit comments

Comments
 (0)