MCPcopy Index your code
hub / github.com/bhowiebkr/PyFlowGraph / paste

Method paste

src/core/node_graph.py:264–299  ·  view source on GitHub ↗

Pastes nodes and connections from clipboard at mouse position or viewport center.

(self, mouse_position=None)

Source from the content-addressed store, hash-verified

262 return clipboard_data
263
264 def paste(self, mouse_position=None):
265 """Pastes nodes and connections from clipboard at mouse position or viewport center."""
266 clipboard_text = QApplication.clipboard().text()
267
268 # Use mouse position if provided, otherwise fall back to viewport center
269 if mouse_position is not None:
270 paste_pos = mouse_position
271 else:
272 # Existing fallback logic
273 paste_pos = QPointF(0, 0) # Default position
274 views = self.views()
275 if views:
276 paste_pos = views[0].mapToScene(views[0].viewport().rect().center())
277
278 try:
279 # Try to parse as markdown first
280 from data.flow_format import FlowFormatHandler
281 handler = FlowFormatHandler()
282 data = handler.markdown_to_data(clipboard_text)
283 self._paste_with_command(data, paste_pos)
284 except ImportError:
285 # FlowFormatHandler not available, try JSON
286 try:
287 import json
288 data = json.loads(clipboard_text)
289 self._paste_with_command(data, paste_pos)
290 except (json.JSONDecodeError, TypeError):
291 print("Clipboard does not contain valid graph data.")
292 except Exception:
293 # Fallback: try to parse as JSON for backward compatibility
294 try:
295 import json
296 data = json.loads(clipboard_text)
297 self._paste_with_command(data, paste_pos)
298 except (json.JSONDecodeError, TypeError):
299 print("Clipboard does not contain valid graph data.")
300
301 def _paste_with_command(self, data, paste_pos):
302 """Helper method to paste using PasteNodesCommand."""

Callers 1

keyPressEventMethod · 0.80

Calls 3

markdown_to_dataMethod · 0.95
_paste_with_commandMethod · 0.95
FlowFormatHandlerClass · 0.90

Tested by

no test coverage detected