Skip to content

Commit 9b138e1

Browse files
committed
layout switching tweaks.
1 parent d75dff2 commit 9b138e1

File tree

6 files changed

+41
-15
lines changed

6 files changed

+41
-15
lines changed

NodeGraphQt/base/graph.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ def __init__(self, parent=None, **kwargs):
126126
self.setObjectName('NodeGraph')
127127
self._model = (
128128
kwargs.get('model') or NodeGraphModel())
129+
130+
layout_direction = kwargs.get('layout_direction')
131+
if layout_direction:
132+
if layout_direction not in [e.value for e in LayoutDirectionEnum]:
133+
layout_direction = LayoutDirectionEnum.HORIZONTAL.value
134+
self._model.layout_direction = layout_direction
135+
else:
136+
layout_direction = self._model.layout_direction
137+
129138
self._node_factory = (
130139
kwargs.get('node_factory') or NodeFactory())
131140

@@ -139,6 +148,7 @@ def __init__(self, parent=None, **kwargs):
139148

140149
self._viewer = (
141150
kwargs.get('viewer') or NodeViewer(undo_stack=self._undo_stack))
151+
self._viewer.set_layout_direction(layout_direction)
142152

143153
self._build_context_menu()
144154
self._register_builtin_nodes()
@@ -802,6 +812,8 @@ def set_layout_direction(self, direction):
802812
This function will also override the layout direction on all
803813
nodes in the current node graph.
804814
815+
`Implemented in` ``v0.3.0``
816+
805817
Note:
806818
By default node graph direction is set to "NODE_LAYOUT_HORIZONTAL".
807819
@@ -1906,7 +1918,11 @@ def expand_group_node(self, node):
19061918

19071919
# build new sub graph.
19081920
node_factory = copy.deepcopy(self.node_factory)
1909-
sub_graph = SubGraph(self, node=node, node_factory=node_factory)
1921+
layout_direction = self.layout_direction()
1922+
sub_graph = SubGraph(self,
1923+
node=node,
1924+
node_factory=node_factory,
1925+
layout_direction=layout_direction)
19101926

19111927
# populate the sub graph.
19121928
session = node.get_sub_graph_session()
@@ -1958,14 +1974,17 @@ class SubGraph(NodeGraph):
19581974
-
19591975
"""
19601976

1961-
def __init__(self, parent=None, node=None, node_factory=None):
1977+
def __init__(self, parent=None, node=None, node_factory=None, **kwargs):
19621978
"""
19631979
Args:
19641980
parent (object): object parent.
19651981
node (GroupNode): group node related to this sub graph.
19661982
node_factory (NodeFactory): override node factory.
1983+
**kwargs (dict): additional kwargs.
19671984
"""
1968-
super(SubGraph, self).__init__(parent, node_factory=node_factory)
1985+
super(SubGraph, self).__init__(
1986+
parent, node_factory=node_factory, **kwargs
1987+
)
19691988

19701989
# sub graph attributes.
19711990
self._node = node
@@ -2329,7 +2348,10 @@ def expand_group_node(self, node):
23292348

23302349
# build new sub graph.
23312350
node_factory = copy.deepcopy(self.node_factory)
2332-
sub_graph = SubGraph(self, node=node, node_factory=node_factory)
2351+
sub_graph = SubGraph(self,
2352+
node=node,
2353+
node_factory=node_factory,
2354+
layout_direction=self.layout_direction())
23332355

23342356
# populate the sub graph.
23352357
serialized_session = node.get_sub_graph_session()

NodeGraphQt/base/graph_actions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ def build_context_menu(graph):
5656
graph_menu = context_menu.add_menu('&Graph')
5757

5858
bg_menu = graph_menu.add_menu('&Background')
59-
bg_menu.add_command('None', _bg_grid_none)
60-
bg_menu.add_command('Lines', _bg_grid_lines)
61-
bg_menu.add_command('Dots', _bg_grid_dots)
59+
bg_menu.add_command('None', _bg_grid_none, 'Alt+1')
60+
bg_menu.add_command('Lines', _bg_grid_lines, 'Alt+2')
61+
bg_menu.add_command('Dots', _bg_grid_dots, 'Alt+3')
6262

6363
layout_menu = graph_menu.add_menu('&Layout')
64-
layout_menu.add_command('Horizontal', _layout_h_mode)
65-
layout_menu.add_command('Vertical', _layout_v_mode)
64+
layout_menu.add_command('Horizontal', _layout_h_mode, 'Shift+1')
65+
layout_menu.add_command('Vertical', _layout_v_mode, 'Shift+2')
6666

6767
# "Node" menu.
6868
# --------------------------------------------------------------------------

NodeGraphQt/base/node.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ def set_layout_direction(self, value=0):
474474
"""
475475
Sets the node layout direction to either horizontal or vertical.
476476
477+
`Implemented in` ``v0.3.0``
478+
477479
Note:
478480
This function does not register to the undo stack.
479481
@@ -482,3 +484,4 @@ def set_layout_direction(self, value=0):
482484
"""
483485
self.model.layout_direction = value
484486
self.view.layout_direction = value
487+

NodeGraphQt/nodes/base_node.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
from NodeGraphQt.base.node import NodeObject
55
from NodeGraphQt.base.port import Port
6-
from NodeGraphQt.constants import (LayoutDirectionEnum,
7-
NODE_PROP_QLABEL,
6+
from NodeGraphQt.constants import (NODE_PROP_QLABEL,
87
NODE_PROP_QLINEEDIT,
98
NODE_PROP_QCOMBO,
109
NODE_PROP_QCHECKBOX,
@@ -77,6 +76,8 @@ def set_layout_direction(self, value=0):
7776
"""
7877
Sets the node layout direction to either horizontal or vertical.
7978
79+
`Implemented in` ``v0.3.0``
80+
8081
Note:
8182
This function does not register to the undo stack.
8283

NodeGraphQt/qgraphics/node_port_in.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def _align_label_horizontal(self, h_offset, v_offset):
188188
def _align_label_vertical(self, h_offset, v_offset):
189189
rect = self.boundingRect()
190190
text_rect = self._text_item.boundingRect()
191-
x = rect.center().x() - (text_rect.width() / 2)
191+
x = rect.center().x() - (text_rect.width() / 1.5) - 2.0
192192
y = rect.center().y() - text_rect.height() - 2.0
193193
self._text_item.setPos(x + h_offset, y + v_offset)
194194

@@ -202,7 +202,7 @@ def _align_ports_horizontal(self, v_offset):
202202
if ports:
203203
v_offset -= ports[0].boundingRect().height() / 2
204204
break
205-
super(PortInputNodeItem, self).align_ports(v_offset=v_offset)
205+
super(PortInputNodeItem, self)._align_ports_horizontal(v_offset)
206206

207207
def _align_ports_vertical(self, v_offset):
208208
super(PortInputNodeItem, self)._align_ports_vertical(v_offset)

NodeGraphQt/qgraphics/node_port_out.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def _align_label_horizontal(self, h_offset, v_offset):
188188
def _align_label_vertical(self, h_offset, v_offset):
189189
rect = self.boundingRect()
190190
text_rect = self._text_item.boundingRect()
191-
x = rect.center().x() - (text_rect.width() / 2)
191+
x = rect.center().x() - (text_rect.width() / 1.5) - 2.0
192192
y = rect.height() - text_rect.height() - 4.0
193193
self._text_item.setPos(x + h_offset, y + v_offset)
194194

@@ -202,7 +202,7 @@ def _align_ports_horizontal(self, v_offset):
202202
if ports:
203203
v_offset -= ports[0].boundingRect().height() / 2
204204
break
205-
super(PortOutputNodeItem, self).align_ports(v_offset=v_offset)
205+
super(PortOutputNodeItem, self)._align_ports_horizontal(v_offset)
206206

207207
def _align_ports_vertical(self, v_offset):
208208
super(PortOutputNodeItem, self)._align_ports_vertical(v_offset)

0 commit comments

Comments
 (0)