From 97fc854afa5977b8fa45a225a8e3a0c815153c41 Mon Sep 17 00:00:00 2001 From: Donal McMullan Date: Tue, 12 Dec 2017 12:11:26 +0000 Subject: [PATCH 1/8] for py3: Add brackets to print statements. Swap 'unicode' with 'six.text_type' --- nodz_demo.py | 30 ++++++++++++++-------------- nodz_main.py | 51 ++++++++++++++++++++++++------------------------ nodz_utils.py | 10 +++++----- requirements.txt | 2 ++ 4 files changed, 48 insertions(+), 45 deletions(-) create mode 100644 requirements.txt diff --git a/nodz_demo.py b/nodz_demo.py index 67187c8..18da16d 100644 --- a/nodz_demo.py +++ b/nodz_demo.py @@ -20,63 +20,63 @@ # Nodes @QtCore.Slot(str) def on_nodeCreated(nodeName): - print 'node created : ', nodeName + print('node created : ', nodeName) @QtCore.Slot(str) def on_nodeDeleted(nodeName): - print 'node deleted : ', nodeName + print('node deleted : ', nodeName) @QtCore.Slot(str, str) def on_nodeEdited(nodeName, newName): - print 'node edited : {0}, new name : {1}'.format(nodeName, newName) + print('node edited : {0}, new name : {1}'.format(nodeName, newName)) @QtCore.Slot(str) def on_nodeSelected(nodesName): - print 'node selected : ', nodesName + print('node selected : ', nodesName) # Attrs @QtCore.Slot(str, int) def on_attrCreated(nodeName, attrId): - print 'attr created : {0} at index : {1}'.format(nodeName, attrId) + print('attr created : {0} at index : {1}'.format(nodeName, attrId)) @QtCore.Slot(str, int) def on_attrDeleted(nodeName, attrId): - print 'attr Deleted : {0} at old index : {1}'.format(nodeName, attrId) + print('attr Deleted : {0} at old index : {1}'.format(nodeName, attrId)) @QtCore.Slot(str, int, int) def on_attrEdited(nodeName, oldId, newId): - print 'attr Edited : {0} at old index : {1}, new index : {2}'.format(nodeName, oldId, newId) + print('attr Edited : {0} at old index : {1}, new index : {2}'.format(nodeName, oldId, newId)) # Connections @QtCore.Slot(str, str, str, str) def on_connected(srcNodeName, srcPlugName, destNodeName, dstSocketName): - print 'connected src: "{0}" at "{1}" to dst: "{2}" at "{3}"'.format(srcNodeName, srcPlugName, destNodeName, dstSocketName) + print('connected src: "{0}" at "{1}" to dst: "{2}" at "{3}"'.format(srcNodeName, srcPlugName, destNodeName, dstSocketName)) @QtCore.Slot(str, str, str, str) def on_disconnected(srcNodeName, srcPlugName, destNodeName, dstSocketName): - print 'disconnected src: "{0}" at "{1}" from dst: "{2}" at "{3}"'.format(srcNodeName, srcPlugName, destNodeName, dstSocketName) + print('disconnected src: "{0}" at "{1}" from dst: "{2}" at "{3}"'.format(srcNodeName, srcPlugName, destNodeName, dstSocketName)) # Graph @QtCore.Slot() def on_graphSaved(): - print 'graph saved !' + print('graph saved !') @QtCore.Slot() def on_graphLoaded(): - print 'graph loaded !' + print('graph loaded !') @QtCore.Slot() def on_graphCleared(): - print 'graph cleared !' + print('graph cleared !') @QtCore.Slot() def on_graphEvaluated(): - print 'graph evaluated !' + print('graph evaluated !') # Other @QtCore.Slot(object) def on_keyPressed(key): - print 'key pressed : ', key + print('key pressed : ', key) nodz.signal_NodeCreated.connect(on_nodeCreated) nodz.signal_NodeDeleted.connect(on_nodeDeleted) @@ -185,7 +185,7 @@ def on_keyPressed(key): # Graph -print nodz.evaluateGraph() +print(nodz.evaluateGraph()) nodz.saveGraph(filePath='Enter your path') diff --git a/nodz_main.py b/nodz_main.py index b416a6d..6023c09 100644 --- a/nodz_main.py +++ b/nodz_main.py @@ -1,6 +1,7 @@ import os import re import json +import six from Qt import QtGui, QtCore, QtWidgets import nodz_utils as utils @@ -498,8 +499,8 @@ def createNode(self, name='default', preset='node_default', position=None, alter """ # Check for name clashes if name in self.scene().nodes.keys(): - print 'A node with the same name already exists : {0}'.format(name) - print 'Node creation aborted !' + print('A node with the same name already exists : {0}'.format(name)) + print('Node creation aborted !') return else: nodeItem = NodeItem(name=name, alternate=alternate, preset=preset, @@ -530,8 +531,8 @@ def deleteNode(self, node): """ if not node in self.scene().nodes.values(): - print 'Node object does not exist !' - print 'Node deletion aborted !' + print('Node object does not exist !') + print('Node deletion aborted !') return if node in self.scene().nodes.values(): @@ -553,8 +554,8 @@ def editNode(self, node, newName=None): """ if not node in self.scene().nodes.values(): - print 'Node object does not exist !' - print 'Node edition aborted !' + print('Node object does not exist !') + print('Node edition aborted !') return oldName = node.name @@ -562,8 +563,8 @@ def editNode(self, node, newName=None): if newName != None: # Check for name clashes if newName in self.scene().nodes.keys(): - print 'A node with the same name already exists : {0}'.format(newName) - print 'Node edition aborted !' + print('A node with the same name already exists : {0}'.format(newName)) + print('Node edition aborted !') return else: node.name = newName @@ -622,13 +623,13 @@ def createAttribute(self, node, name='default', index=-1, preset='attr_default', """ if not node in self.scene().nodes.values(): - print 'Node object does not exist !' - print 'Attribute creation aborted !' + print('Node object does not exist !') + print('Attribute creation aborted !') return if name in node.attrs: - print 'An attribute with the same name already exists : {0}'.format(name) - print 'Attribute creation aborted !' + print('An attribute with the same name already exists : {0}'.format(name)) + print('Attribute creation aborted !') return node._createAttribute(name=name, index=index, preset=preset, plug=plug, socket=socket, dataType=dataType) @@ -648,8 +649,8 @@ def deleteAttribute(self, node, index): """ if not node in self.scene().nodes.values(): - print 'Node object does not exist !' - print 'Attribute deletion aborted !' + print('Node object does not exist !') + print('Attribute deletion aborted !') return node._deleteAttribute(index) @@ -675,14 +676,14 @@ def editAttribute(self, node, index, newName=None, newIndex=None): """ if not node in self.scene().nodes.values(): - print 'Node object does not exist !' - print 'Attribute creation aborted !' + print('Node object does not exist !') + print('Attribute creation aborted !') return if newName != None: if newName in node.attrs: - print 'An attribute with the same name already exists : {0}'.format(newName) - print 'Attribute edition aborted !' + print('An attribute with the same name already exists : {0}'.format(newName)) + print('Attribute edition aborted !') return else: oldName = node.attrs[index] @@ -798,8 +799,8 @@ def saveGraph(self, filePath='path'): try: utils._saveData(filePath=filePath, data=data) except: - print 'Invalid path : {0}'.format(filePath) - print 'Save aborted !' + print('Invalid path : {0}'.format(filePath)) + print('Save aborted !') return False # Emit signal. @@ -818,8 +819,8 @@ def loadGraph(self, filePath='path'): if os.path.exists(filePath): data = utils._loadData(filePath=filePath) else: - print 'Invalid path : {0}'.format(filePath) - print 'Load aborted !' + print('Invalid path : {0}'.format(filePath)) + print('Load aborted !') return False # Apply nodes data. @@ -849,7 +850,7 @@ def loadGraph(self, filePath='path'): dataType = attrData['dataType'] # un-serialize data type if needed - if (isinstance(dataType, unicode) and dataType.find('<') == 0): + if (isinstance(dataType, six.text_type) and dataType.find('<') == 0): dataType = eval(str(dataType.split('\'')[1])) self.createAttribute(node=node, @@ -1190,8 +1191,8 @@ def _createAttribute(self, name, index, preset, plug, socket, dataType): """ if name in self.attrs: - print 'An attribute with the same name already exists on this node : {0}'.format(name) - print 'Attribute creation aborted !' + print('An attribute with the same name already exists on this node : {0}'.format(name)) + print('Attribute creation aborted !') return self.attrPreset = preset diff --git a/nodz_utils.py b/nodz_utils.py index 7fe2ec9..bd5ca4a 100644 --- a/nodz_utils.py +++ b/nodz_utils.py @@ -39,9 +39,9 @@ def _convertDataToColor(data=None, alternate=False, av=20): # wrong else: - print 'Color from configuration is not recognized : ', data - print 'Can only be [R, G, B] or [R, G, B, A]' - print 'Using default color !' + print('Color from configuration is not recognized : ', data) + print('Can only be [R, G, B] or [R, G, B, A]') + print('Using default color !') color = QtGui.QColor(120, 120, 120) if alternate: color = QtGui.QColor(120-av, 120-av, 120-av) @@ -150,7 +150,7 @@ def _saveData(filePath, data): ensure_ascii=False)) f.close() - print "Data successfully saved !" + print("Data successfully saved !") def _loadData(filePath): """ @@ -165,6 +165,6 @@ def _loadData(filePath): json_file.close() - print "Data successfully loaded !" + print("Data successfully loaded !") return j_data diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e99ed3b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Qt.py +six From dbbb94bc3f4e6edcc711f9bef4606977829ed198 Mon Sep 17 00:00:00 2001 From: Donal McMullan Date: Tue, 12 Dec 2017 17:04:08 +0000 Subject: [PATCH 2/8] remove unused imports (re and json) and unused variable attrName --- nodz_main.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/nodz_main.py b/nodz_main.py index 6023c09..1ab73f3 100644 --- a/nodz_main.py +++ b/nodz_main.py @@ -1,6 +1,4 @@ import os -import re -import json import six from Qt import QtGui, QtCore, QtWidgets @@ -710,8 +708,6 @@ def editAttribute(self, node, index, newName=None, newIndex=None): node.attrs[index] = newName if isinstance(newIndex, int): - attrName = node.attrs[index] - utils._swapListIndices(node.attrs, index, newIndex) # Refresh connections. From 29b6267c2415eb1b0476ac6295a53b5cba8fb895 Mon Sep 17 00:00:00 2001 From: Donal McMullan Date: Tue, 12 Dec 2017 18:48:43 +0000 Subject: [PATCH 3/8] add methods to load and save graphs as networkx/json --- nodz_main.py | 121 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 115 insertions(+), 6 deletions(-) diff --git a/nodz_main.py b/nodz_main.py index 1ab73f3..c1a43bc 100644 --- a/nodz_main.py +++ b/nodz_main.py @@ -1,6 +1,14 @@ import os +import json import six +try: + import networkx as nx + from networkx.readwrite import json_graph +except ImportError: + nx = None + json_graph = None + from Qt import QtGui, QtCore, QtWidgets import nodz_utils as utils @@ -802,6 +810,97 @@ def saveGraph(self, filePath='path'): # Emit signal. self.signal_GraphSaved.emit() + def saveGraphAsNetworkX(self, filePath='path'): + if nx is None: + raise Exception("Failed to import networkx") + graph = nx.MultiDiGraph() + for name, node in self.scene().nodes.items(): + attributes = [] + for attr in node.attrs: + attrData = node.attrsData[attr] + + # serialize dataType if needed. + if isinstance(attrData['dataType'], type): + attrData['dataType'] = str(attrData['dataType']) + + attributes.append(attrData) + + graph.add_node(name, + preset=node.nodePreset, + position=(node.pos().x(), node.pos().y()), + alternate=node.alternate, + attributes=attributes) + + edges = self.evaluateGraph(tuples=True) + for edge in edges: + (plugNode, plugAttr), (socketNode, socketAttr) = edge + graph.add_edge(plugNode, socketNode, plug=plugAttr, socket=socketAttr) + + serialized = json_graph.node_link_data(graph) + jsonized = json.dumps(serialized, indent=4) + try: + fh = open(filePath, 'w') + fh.write(jsonized) + fh.close() + except Exception as e: + print("Failed to write JSON data to file '%s': %s" % (filePath, e)) + raise + + def loadGraphAsNetworkx(self, filePath): + try: + fh = open(filePath, 'r') + data = json.load(fh) + fh.close() + except Exception as e: + print("Failed to open json file at '%s': %s" % (filePath, e)) + raise e + graph = json_graph.node_link_graph(data) + print('nodes') + nodes = list(graph.nodes(data=True)) + for nodename, nodedata in nodes: + print(nodename) + p = nodedata['position'] + point = QtCore.QPointF(p[0], p[1]) + node = self.createNode(name=nodename, + preset=nodedata['preset'], + position=point, + alternate=nodedata['alternate']) + + for index, attrData in enumerate(nodedata['attributes']): + + name = attrData['name'] + plug = attrData['plug'] + socket = attrData['socket'] + preset = attrData['preset'] + dataType = attrData['dataType'] + + # un-serialize data type if needed + if (isinstance(dataType, six.text_type) and dataType.find('<') == 0): + dataType = eval(str(dataType.split('\'')[1])) + + self.createAttribute(node=node, + name=name, + index=index, + preset=preset, + plug=plug, + socket=socket, + dataType=dataType) + + # Apply connections data. + edges = graph.edges(data=True) + print(edges) + for source, target, data in edges: + print(source) + + self.createConnection(source, data['plug'], + target, data['socket']) + + self.scene().update() + + # Emit signal. + self.signal_GraphLoaded.emit() + + def loadGraph(self, filePath='path'): """ Get all the stored info from the .json file at the given location @@ -914,7 +1013,7 @@ def createConnection(self, sourceNode, sourceAttr, targetNode, targetAttr): return connection - def evaluateGraph(self): + def evaluateGraph(self, tuples=False): """ Create a list of connection tuples. [("sourceNode.attribute", "TargetNode.attribute"), ...] @@ -925,10 +1024,20 @@ def evaluateGraph(self): data = list() for item in scene.items(): - if isinstance(item, ConnectionItem): - connection = item + if not isinstance(item, ConnectionItem): + continue + + connection = item - data.append(connection._outputConnectionData()) + cdata = connection._outputConnectionData() + + if tuples: + pair = cdata + else: + plugData, socketData = cdata + pair = ("{0}.{1}".format(*plugData), + "{0}.{1}".format(*socketData)) + data.append(pair) # Emit Signal self.signal_GraphEvaluated.emit() @@ -1947,8 +2056,8 @@ def _outputConnectionData(self): . """ - return ("{0}.{1}".format(self.plugNode, self.plugAttr), - "{0}.{1}".format(self.socketNode, self.socketAttr)) + return ((self.plugNode, self.plugAttr), + (self.socketNode, self.socketAttr)) def mousePressEvent(self, event): """ From f23bc99a472bcdfc2b43568b347c52c4430a3a7d Mon Sep 17 00:00:00 2001 From: Donal McMullan Date: Fri, 2 Feb 2018 10:36:53 +0000 Subject: [PATCH 4/8] add getNetworkxGraph and createNxNode methods --- nodz_main.py | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/nodz_main.py b/nodz_main.py index c1a43bc..79b7218 100644 --- a/nodz_main.py +++ b/nodz_main.py @@ -479,8 +479,11 @@ def initialize(self): self.scene().selectionChanged.connect(self._returnSelection) + def createNxNode(self, name='default', preset='node_default', position=None, alternate=True, **extended_attributes): + return self.createNode(name, preset, position, alternate, extended_attributes) + # NODES - def createNode(self, name='default', preset='node_default', position=None, alternate=True): + def createNode(self, name='default', preset='node_default', position=None, alternate=True, extended_attributes=None): """ Create a new node with a given name, position and color. @@ -510,7 +513,7 @@ def createNode(self, name='default', preset='node_default', position=None, alter return else: nodeItem = NodeItem(name=name, alternate=alternate, preset=preset, - config=self.config) + config=self.config, extended_attributes=extended_attributes) # Store node in scene. self.scene().nodes[name] = nodeItem @@ -810,7 +813,77 @@ def saveGraph(self, filePath='path'): # Emit signal. self.signal_GraphSaved.emit() + def getNetworkxGraph(self): + if nx is None: + raise Exception("Failed to import networkx") + graph = nx.MultiDiGraph() + for name, node in self.scene().nodes.items(): + attributes = [] + for attr in node.attrs: + attrData = node.attrsData[attr] + + # serialize dataType if needed. + if isinstance(attrData['dataType'], type): + attrData['dataType'] = str(attrData['dataType']) + + attributes.append(attrData) + + graph.add_node(name, + preset=node.nodePreset, + position=(node.pos().x(), node.pos().y()), + alternate=node.alternate, + attributes=attributes, **node.extended_attributes) + + edges = self.evaluateGraph(tuples=True) + for edge in edges: + (plugNode, plugAttr), (socketNode, socketAttr) = edge + graph.add_edge(plugNode, socketNode, plug=plugAttr, socket=socketAttr) + + return graph + + def executeGraph(self, filePath='path'): + graph = self.getNetworkxGraph() + ''' + if nx is None: + raise Exception("Failed to import networkx") + graph = nx.MultiDiGraph() + for name, node in self.scene().nodes.items(): + attributes = [] + for attr in node.attrs: + attrData = node.attrsData[attr] + + # serialize dataType if needed. + if isinstance(attrData['dataType'], type): + attrData['dataType'] = str(attrData['dataType']) + + attributes.append(attrData) + + graph.add_node(name, + preset=node.nodePreset, + position=(node.pos().x(), node.pos().y()), + alternate=node.alternate, + attributes=attributes) + + edges = self.evaluateGraph(tuples=True) + for edge in edges: + (plugNode, plugAttr), (socketNode, socketAttr) = edge + graph.add_edge(plugNode, socketNode, plug=plugAttr, socket=socketAttr) + ''' + + commands = [] + for node in graph.nodes: + if graph.predecessors(node): + continue + command = self.buildNodeCommand(node) + commands.append(command) + + + def buildNodeCommand(self, node): + return 'aasdfa' + def saveGraphAsNetworkX(self, filePath='path'): + graph = self.getNetworkxGraph() + ''' if nx is None: raise Exception("Failed to import networkx") graph = nx.MultiDiGraph() @@ -835,6 +908,7 @@ def saveGraphAsNetworkX(self, filePath='path'): for edge in edges: (plugNode, plugAttr), (socketNode, socketAttr) = edge graph.add_edge(plugNode, socketNode, plug=plugAttr, socket=socketAttr) + ''' serialized = json_graph.node_link_data(graph) jsonized = json.dumps(serialized, indent=4) @@ -1151,7 +1225,7 @@ class NodeItem(QtWidgets.QGraphicsItem): """ - def __init__(self, name, alternate, preset, config): + def __init__(self, name, alternate, preset, config, extended_attributes=None): """ Initialize the class. @@ -1187,6 +1261,11 @@ def __init__(self, name, alternate, preset, config): self.plugs = dict() self.sockets = dict() + # Extended attributes + self.extended_attributes = {} + if extended_attributes: + self.extended_attributes = extended_attributes + # Methods. self._createStyle(config) From 12c1725010b757744716efef8124e1da06574df9 Mon Sep 17 00:00:00 2001 From: Donal McMullan Date: Fri, 2 Feb 2018 10:38:30 +0000 Subject: [PATCH 5/8] py3 fix - use brackets for print statement --- nodz_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodz_demo.py b/nodz_demo.py index d855688..d9e333e 100644 --- a/nodz_demo.py +++ b/nodz_demo.py @@ -36,7 +36,7 @@ def on_nodeSelected(nodesName): @QtCore.Slot(str, object) def on_nodeMoved(nodeName, nodePos): - print 'node {0} moved to {1}'.format(nodeName, nodePos) + print('node {0} moved to {1}'.format(nodeName, nodePos)) # Attrs @QtCore.Slot(str, int) From 483698d4b150a7685c67c7df667fec0798ff64ae Mon Sep 17 00:00:00 2001 From: Donal McMullan Date: Fri, 2 Feb 2018 10:39:36 +0000 Subject: [PATCH 6/8] use relative import for nodz_utils --- nodz_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodz_main.py b/nodz_main.py index f9ccf6c..10c59c1 100644 --- a/nodz_main.py +++ b/nodz_main.py @@ -10,7 +10,7 @@ json_graph = None from Qt import QtGui, QtCore, QtWidgets -import nodz_utils as utils +from . import nodz_utils as utils From 9d37b5a90f574cc7ce1b7f62596c9bd3f1fb3baf Mon Sep 17 00:00:00 2001 From: Donal McMullan Date: Wed, 28 Mar 2018 18:11:00 +0100 Subject: [PATCH 7/8] switch from Qt.py to PyQt5 --- nodz_main.py | 43 +++++++++++++++++++++++-------------------- nodz_utils.py | 6 +++++- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/nodz_main.py b/nodz_main.py index 773e749..19457fd 100644 --- a/nodz_main.py +++ b/nodz_main.py @@ -9,7 +9,10 @@ nx = None json_graph = None -from Qt import QtGui, QtCore, QtWidgets +from PyQt5.QtCore import Qt +from PyQt5 import QtWidgets +from PyQt5 import QtCore +from PyQt5 import QtGui from . import nodz_utils as utils @@ -27,28 +30,28 @@ class Nodz(QtWidgets.QGraphicsView): """ - signal_NodeCreated = QtCore.Signal(object) - signal_NodeDeleted = QtCore.Signal(object) - signal_NodeEdited = QtCore.Signal(object, object) - signal_NodeSelected = QtCore.Signal(object) - signal_NodeMoved = QtCore.Signal(str, object) + signal_NodeCreated = QtCore.pyqtSignal(object) + signal_NodeDeleted = QtCore.pyqtSignal(object) + signal_NodeEdited = QtCore.pyqtSignal(object, object) + signal_NodeSelected = QtCore.pyqtSignal(object) + signal_NodeMoved = QtCore.pyqtSignal(str, object) - signal_AttrCreated = QtCore.Signal(object, object) - signal_AttrDeleted = QtCore.Signal(object, object) - signal_AttrEdited = QtCore.Signal(object, object, object) + signal_AttrCreated = QtCore.pyqtSignal(object, object) + signal_AttrDeleted = QtCore.pyqtSignal(object, object) + signal_AttrEdited = QtCore.pyqtSignal(object, object, object) - signal_PlugConnected = QtCore.Signal(object, object, object, object) - signal_PlugDisconnected = QtCore.Signal(object, object, object, object) - signal_SocketConnected = QtCore.Signal(object, object, object, object) - signal_SocketDisconnected = QtCore.Signal(object, object, object, object) + signal_PlugConnected = QtCore.pyqtSignal(object, object, object, object) + signal_PlugDisconnected = QtCore.pyqtSignal(object, object, object, object) + signal_SocketConnected = QtCore.pyqtSignal(object, object, object, object) + signal_SocketDisconnected = QtCore.pyqtSignal(object, object, object, object) - signal_GraphSaved = QtCore.Signal() - signal_GraphLoaded = QtCore.Signal() - signal_GraphCleared = QtCore.Signal() - signal_GraphEvaluated = QtCore.Signal() + signal_GraphSaved = QtCore.pyqtSignal() + signal_GraphLoaded = QtCore.pyqtSignal() + signal_GraphCleared = QtCore.pyqtSignal() + signal_GraphEvaluated = QtCore.pyqtSignal() - signal_KeyPressed = QtCore.Signal(object) - signal_Dropped = QtCore.Signal() + signal_KeyPressed = QtCore.pyqtSignal(object) + signal_Dropped = QtCore.pyqtSignal(object) def __init__(self, parent, configPath=defaultConfigPath): """ @@ -1143,7 +1146,7 @@ class NodeScene(QtWidgets.QGraphicsScene): The scene displaying all the nodes. """ - signal_NodeMoved = QtCore.Signal(str, object) + signal_NodeMoved = QtCore.pyqtSignal(str, object) def __init__(self, parent): """ diff --git a/nodz_utils.py b/nodz_utils.py index bd5ca4a..051626a 100644 --- a/nodz_utils.py +++ b/nodz_utils.py @@ -1,7 +1,11 @@ import os import json import re -from Qt import QtCore, QtGui + +from PyQt5.QtCore import Qt +from PyQt5 import QtWidgets +from PyQt5 import QtCore +from PyQt5 import QtGui def _convertDataToColor(data=None, alternate=False, av=20): From 08b5756774a9f212f2b6d66c7a66163883ad084b Mon Sep 17 00:00:00 2001 From: Donal McMullan Date: Wed, 28 Mar 2018 18:11:38 +0100 Subject: [PATCH 8/8] update drop event handling --- nodz_main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nodz_main.py b/nodz_main.py index 19457fd..0237bfe 100644 --- a/nodz_main.py +++ b/nodz_main.py @@ -1154,6 +1154,8 @@ def __init__(self, parent): """ super(NodeScene, self).__init__(parent) + #self.setAcceptDrops(True) + print("SEL PAR: %s :: %s" % (parent, self.parent(),)) # General. self.gridSize = parent.config['grid_size'] @@ -1183,7 +1185,11 @@ def dropEvent(self, event): """ # Emit signal. - self.signal_Dropped.emit(event.scenePos()) + self.parent().signal_Dropped.emit(event.scenePos()) + print("DROP EVENT") + print(event.mimeData().text()) + print(event.scenePos()) + print("") event.accept()