Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 6, 2024
2 parents 68a75cf + 8a76045 commit af49a04
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
18 changes: 13 additions & 5 deletions NodeGraphQt/base/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 = {}
Expand Down
2 changes: 1 addition & 1 deletion NodeGraphQt/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion NodeGraphQt/qgraphics/node_backdrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
11 changes: 7 additions & 4 deletions NodeGraphQt/widgets/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -669,7 +668,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())
Expand Down

0 comments on commit af49a04

Please sign in to comment.