Skip to content

Commit 693a521

Browse files
committed
pipe style layout bugfix
1 parent b489fdf commit 693a521

File tree

4 files changed

+52
-21
lines changed

4 files changed

+52
-21
lines changed

NodeGraphQt/base/graph.py

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ def __init__(self, parent=None, **kwargs):
136136
self.setObjectName('NodeGraph')
137137
self._model = (
138138
kwargs.get('model') or NodeGraphModel())
139+
self._node_factory = (
140+
kwargs.get('node_factory') or NodeFactory())
141+
self._undo_view = None
142+
self._undo_stack = (
143+
kwargs.get('undo_stack') or QtWidgets.QUndoStack(self)
144+
)
145+
self._widget = None
146+
self._sub_graphs = {}
147+
self._viewer = (
148+
kwargs.get('viewer') or NodeViewer(undo_stack=self._undo_stack)
149+
)
139150

140151
layout_direction = kwargs.get('layout_direction')
141152
if layout_direction:
@@ -144,22 +155,17 @@ def __init__(self, parent=None, **kwargs):
144155
self._model.layout_direction = layout_direction
145156
else:
146157
layout_direction = self._model.layout_direction
147-
148-
self._node_factory = (
149-
kwargs.get('node_factory') or NodeFactory())
150-
151-
self._undo_view = None
152-
self._undo_stack = (
153-
kwargs.get('undo_stack') or QtWidgets.QUndoStack(self))
154-
155-
self._widget = None
156-
157-
self._sub_graphs = {}
158-
159-
self._viewer = (
160-
kwargs.get('viewer') or NodeViewer(undo_stack=self._undo_stack))
161158
self._viewer.set_layout_direction(layout_direction)
162159

160+
pipe_style = kwargs.get('pipe_style')
161+
if pipe_style is not None:
162+
if pipe_style not in [e.value for e in PipeLayoutEnum]:
163+
pipe_style = PipeLayoutEnum.CURVED.value
164+
self._model.pipe_style = pipe_style
165+
else:
166+
pipe_style = self._model.pipe_style
167+
self._viewer.set_pipe_layout(pipe_style)
168+
163169
# viewer needs a reference to the model port connection constrains
164170
# for the user interaction with the live pipe.
165171
self._viewer.accept_connection_types = self._model.accept_connection_types
@@ -953,6 +959,18 @@ def set_pipe_slicing(self, mode=True):
953959
self._model.pipe_slicing = mode
954960
self._viewer.pipe_slicing = self._model.pipe_slicing
955961

962+
def pipe_style(self):
963+
"""
964+
Returns the current pipe layout style.
965+
966+
See Also:
967+
:meth:`NodeGraph.set_pipe_style`
968+
969+
Returns:
970+
int: pipe style value. :attr:`NodeGraphQt.constants.PipeLayoutEnum`
971+
"""
972+
return self._model.pipe_style
973+
956974
def set_pipe_style(self, style=PipeLayoutEnum.CURVED.value):
957975
"""
958976
Set node graph pipes to be drawn as curved `(default)`, straight or angled.
@@ -976,6 +994,7 @@ def set_pipe_style(self, style=PipeLayoutEnum.CURVED.value):
976994
PipeLayoutEnum.STRAIGHT.value,
977995
PipeLayoutEnum.ANGLE.value])
978996
style = style if 0 <= style <= pipe_max else PipeLayoutEnum.CURVED.value
997+
self._model.pipe_style = style
979998
self._viewer.set_pipe_layout(style)
980999

9811000
def layout_direction(self):
@@ -990,7 +1009,7 @@ def layout_direction(self):
9901009
Returns:
9911010
int: layout direction.
9921011
"""
993-
return self.model.layout_direction
1012+
return self._model.layout_direction
9941013

9951014
def set_layout_direction(self, direction):
9961015
"""
@@ -1624,6 +1643,7 @@ def _serialize(self, nodes):
16241643
serial_data['graph']['acyclic'] = self.acyclic()
16251644
serial_data['graph']['pipe_collision'] = self.pipe_collision()
16261645
serial_data['graph']['pipe_slicing'] = self.pipe_slicing()
1646+
serial_data['graph']['pipe_style'] = self.pipe_style()
16271647

16281648
# connection constrains.
16291649
serial_data['graph']['accept_connection_types'] = self.model.accept_connection_types
@@ -1692,6 +1712,8 @@ def _deserialize(self, data, relative_pos=False, pos=None):
16921712
self.set_pipe_collision(attr_value)
16931713
elif attr_name == 'pipe_slicing':
16941714
self.set_pipe_slicing(attr_value)
1715+
elif attr_name == 'pipe_style':
1716+
self.set_pipe_style(attr_value)
16951717

16961718
# connection constrains.
16971719
elif attr_name == 'accept_connection_types':
@@ -2316,10 +2338,14 @@ def expand_group_node(self, node):
23162338
# build new sub graph.
23172339
node_factory = copy.deepcopy(self.node_factory)
23182340
layout_direction = self.layout_direction()
2341+
kwargs = {
2342+
'layout_direction': self.layout_direction(),
2343+
'pipe_style': self.pipe_style(),
2344+
}
23192345
sub_graph = SubGraph(self,
23202346
node=node,
23212347
node_factory=node_factory,
2322-
layout_direction=layout_direction)
2348+
**kwargs)
23232349

23242350
# populate the sub graph.
23252351
session = node.get_sub_graph_session()

NodeGraphQt/base/model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
import json
33
from collections import defaultdict
44

5-
from NodeGraphQt.constants import LayoutDirectionEnum, NodePropWidgetEnum
5+
from NodeGraphQt.constants import (
6+
LayoutDirectionEnum,
7+
NodePropWidgetEnum,
8+
PipeLayoutEnum
9+
)
610
from NodeGraphQt.errors import NodePropertyError
711

812

@@ -444,6 +448,7 @@ def __init__(self):
444448
self.acyclic = True
445449
self.pipe_collision = False
446450
self.pipe_slicing = True
451+
self.pipe_style = PipeLayoutEnum.CURVED.value
447452
self.layout_direction = LayoutDirectionEnum.HORIZONTAL.value
448453

449454
def common_properties(self):

NodeGraphQt/pkg_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3-
__version__ = '0.6.0'
3+
__version__ = '0.6.1'
44
__status__ = 'Work in Progress'
55
__license__ = 'MIT'
66

examples/hotkeys/hotkeys.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,21 +265,21 @@
265265
"label":"Curved",
266266
"file":"../examples/hotkeys/hotkey_functions.py",
267267
"function_name":"curved_pipe",
268-
"shortcut":""
268+
"shortcut":"Ctrl+1"
269269
},
270270
{
271271
"type":"command",
272272
"label":"Straight",
273273
"file":"../examples/hotkeys/hotkey_functions.py",
274274
"function_name":"straight_pipe",
275-
"shortcut":""
275+
"shortcut":"Ctrl+2"
276276
},
277277
{
278278
"type":"command",
279279
"label":"Angle",
280280
"file":"../examples/hotkeys/hotkey_functions.py",
281281
"function_name":"angle_pipe",
282-
"shortcut":""
282+
"shortcut":"Ctrl+3"
283283
}
284284
]
285285
}

0 commit comments

Comments
 (0)