From 4b5d97fa4d295eb30a04f551bd7486f880816f0d Mon Sep 17 00:00:00 2001 From: Jerome Drese Date: Tue, 1 Oct 2024 15:56:48 +0200 Subject: [PATCH 1/5] Fix AttributeError for API change on QWheelEvent from Qt5 --- NodeGraphQt/widgets/viewer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/NodeGraphQt/widgets/viewer.py b/NodeGraphQt/widgets/viewer.py index 9de9bfbb..ccaf5a07 100644 --- a/NodeGraphQt/widgets/viewer.py +++ b/NodeGraphQt/widgets/viewer.py @@ -669,7 +669,11 @@ def wheelEvent(self, event): delta = event.angleDelta().y() if delta == 0: delta = event.angleDelta().x() - self._set_viewer_zoom(delta, pos=event.pos()) + try: + self._set_viewer_zoom(delta, pos=event.pos()) + except AttributeError: + # For PyQt5 and above + self._set_viewer_zoom(delta, pos=event.position().toPoint()) def dropEvent(self, event): pos = self.mapToScene(event.pos()) From e56c46b25b7071e646cf349ab582f7b702ca71b0 Mon Sep 17 00:00:00 2001 From: Johnny Chan Date: Mon, 7 Oct 2024 11:35:31 +1300 Subject: [PATCH 2/5] addressing issue #434 --- NodeGraphQt/base/graph.py | 16 ++++++++++++---- NodeGraphQt/base/model.py | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/NodeGraphQt/base/graph.py b/NodeGraphQt/base/graph.py index 5bed6341..c3231128 100644 --- a/NodeGraphQt/base/graph.py +++ b/NodeGraphQt/base/graph.py @@ -1727,8 +1727,12 @@ def _serialize(self, nodes): serial_data['graph']['pipe_style'] = self.pipe_style() # connection constrains. - serial_data['graph']['accept_connection_types'] = self.model.accept_connection_types - serial_data['graph']['reject_connection_types'] = self.model.reject_connection_types + serial_data['graph']['accept_connection_types'] = { + k: list(v) for k, v in self.model.accept_connection_types.items() + } + serial_data['graph']['reject_connection_types'] = { + k: list(v) for k, v in self.model.reject_connection_types.items() + } # serialize nodes. for n in nodes: @@ -1798,9 +1802,13 @@ def _deserialize(self, data, relative_pos=False, pos=None): # connection constrains. elif attr_name == 'accept_connection_types': - self.model.accept_connection_types = attr_value + self.model.accept_connection_types = { + k: set(v) for k, v in attr_value.items() + } elif attr_name == 'reject_connection_types': - self.model.reject_connection_types = attr_value + self.model.reject_connection_types = { + k: set(v) for k, v in attr_value.items() + } # build the nodes. nodes = {} diff --git a/NodeGraphQt/base/model.py b/NodeGraphQt/base/model.py index 8d1e8a37..e5896324 100644 --- a/NodeGraphQt/base/model.py +++ b/NodeGraphQt/base/model.py @@ -245,7 +245,7 @@ def add_port_accept_connection_type( ): """ Convenience function for adding to the "accept_connection_types" dict. - If the node graph model is unavailable yet then we store it to a + If the node graph model is unavailable, yet then we store it to a temp var that gets deleted. Args: From 4b8a49114d5ffefe785b233a34a20e2b64d7faef Mon Sep 17 00:00:00 2001 From: Johnny Chan Date: Mon, 7 Oct 2024 11:40:08 +1300 Subject: [PATCH 3/5] changed update mode suggestion from @JamesDeAntonis #431 --- NodeGraphQt/widgets/viewer.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/NodeGraphQt/widgets/viewer.py b/NodeGraphQt/widgets/viewer.py index ccaf5a07..6aeeba3c 100644 --- a/NodeGraphQt/widgets/viewer.py +++ b/NodeGraphQt/widgets/viewer.py @@ -66,10 +66,9 @@ def __init__(self, parent=None, undo_stack=None): self.setRenderHint(QtGui.QPainter.Antialiasing, True) self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) - self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate) + self.setViewportUpdateMode(QtWidgets.QGraphicsView.BoundingRectViewportUpdate) self.setCacheMode(QtWidgets.QGraphicsView.CacheBackground) - self.setOptimizationFlag( - QtWidgets.QGraphicsView.DontAdjustForAntialiasing) + self.setOptimizationFlag(QtWidgets.QGraphicsView.DontAdjustForAntialiasing) self.setAcceptDrops(True) self.resize(850, 800) From 3ac59f5bce3fe0090c23a32bce3746b98de30ce2 Mon Sep 17 00:00:00 2001 From: Johnny Chan Date: Mon, 7 Oct 2024 11:42:18 +1300 Subject: [PATCH 4/5] minor fix. --- NodeGraphQt/qgraphics/node_backdrop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NodeGraphQt/qgraphics/node_backdrop.py b/NodeGraphQt/qgraphics/node_backdrop.py index 7696623d..6ff2236a 100644 --- a/NodeGraphQt/qgraphics/node_backdrop.py +++ b/NodeGraphQt/qgraphics/node_backdrop.py @@ -152,7 +152,7 @@ def mousePressEvent(self, event): def mouseReleaseEvent(self, event): super(BackdropNodeItem, self).mouseReleaseEvent(event) - self.setFlag(self.ItemIsMovable, True) + self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, True) [n.setSelected(True) for n in self._nodes] self._nodes = [self] From 8a76045a14530ceabe9b309e48be45e094e14a51 Mon Sep 17 00:00:00 2001 From: Johnny Chan Date: Mon, 7 Oct 2024 11:48:03 +1300 Subject: [PATCH 5/5] context menu fix #430 suggestion form @KwentiN-ui --- NodeGraphQt/base/graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NodeGraphQt/base/graph.py b/NodeGraphQt/base/graph.py index c3231128..0bfeadc5 100644 --- a/NodeGraphQt/base/graph.py +++ b/NodeGraphQt/base/graph.py @@ -907,7 +907,7 @@ def set_context_menu_from_file(self, file_path, menu='graph'): if not file.is_file(): raise IOError('file doesn\'t exist: "{}"'.format(file)) - with file.open() as f: + with file.open(encoding='utf8') as f: data = json.load(f) context_menu = self.get_context_menu(menu) self._deserialize_context_menu(context_menu, data, file)