Copy selected node's content to the clipboard when Ctrl+C is pressed

When Ctrl+C is pressed while a node selected, its content is formatted
to JSON and copied to the system's clipboard.
This commit is contained in:
Candice Bentéjac 2022-08-18 15:46:13 +02:00
parent 92e77e77a9
commit 751bad96c6
2 changed files with 31 additions and 4 deletions

View file

@ -3,6 +3,7 @@
import logging
import os
import time
import json
from enum import Enum
from threading import Thread, Event, Lock
from multiprocessing.pool import ThreadPool
@ -753,6 +754,18 @@ class UIGraph(QObject):
""" Reset currently hovered node to None. """
self.hoveredNode = None
@Slot(result=str)
def getSelectedNodeContent(self):
"""
Return the content of the currently selected node in a string, formatted to JSON.
If no node is currently selected, an empty string is returned.
"""
if self._selectedNode:
d = self._graph.toDict()
node = d[self._selectedNode.name]
return json.dumps(node, indent=4)
return ''
undoStack = Property(QObject, lambda self: self._undoStack, constant=True)
graphChanged = Signal()
graph = Property(Graph, lambda self: self._graph, notify=graphChanged)