@@ -171,13 +171,13 @@ def _insert_node(self, pipe, node_id, prev_node_pos):
171171 disconnected = [(pipe .input_port , pipe .output_port )]
172172 connected = []
173173
174- if node .inputs ():
174+ if node .input_ports ():
175175 connected .append (
176- (pipe .output_port , list ( node .inputs (). values () )[0 ].view )
176+ (pipe .output_port , node .input_ports ( )[0 ].view )
177177 )
178- if node .outputs ():
178+ if node .output_ports ():
179179 connected .append (
180- (list ( node .outputs (). values () )[0 ].view , pipe .input_port )
180+ (node .output_ports ( )[0 ].view , pipe .input_port )
181181 )
182182
183183 self ._undo_stack .beginMacro ('inserted node' )
@@ -224,8 +224,8 @@ def _on_node_double_clicked(self, node_id):
224224 """
225225 node = self .get_node_by_id (node_id )
226226 self .node_double_clicked .emit (node )
227- if isinstance (node ,SubGraph ):
228- node . enter ( )
227+ if isinstance (node , SubGraph ):
228+ self . set_node_space ( node )
229229
230230 def _on_node_selected (self , node_id ):
231231 """
@@ -420,6 +420,7 @@ def set_background_color(self, r, g, b):
420420 b (int): blue value.
421421 """
422422 self .scene ().background_color = (r , g , b )
423+ self ._viewer .force_update ()
423424
424425 def grid_color (self ):
425426 """
@@ -440,6 +441,7 @@ def set_grid_color(self, r, g, b):
440441 b (int): blue value.
441442 """
442443 self .scene ().grid_color = (r , g , b )
444+ self ._viewer .force_update ()
443445
444446 def display_grid (self , display = True ):
445447 """
@@ -449,6 +451,7 @@ def display_grid(self, display=True):
449451 display: False to not draw the background grid.
450452 """
451453 self .scene ().grid = display
454+ self ._viewer .force_update ()
452455
453456 def add_properties_bin (self , prop_bin ):
454457 """
@@ -795,7 +798,14 @@ def set_node_space(self, node):
795798 Args:
796799 node (NodeGraphQt.SubGraph): node object.
797800 """
801+ if self ._current_node_space is not None :
802+ [n .hide () for n in self ._current_node_space .children ()]
803+ self ._current_node_space .exit ()
804+
798805 self ._current_node_space = node
806+ if node is not None :
807+ [n .show () for n in node .children ()]
808+ node .enter ()
799809
800810 def get_node_space (self ):
801811 """
@@ -1097,7 +1107,8 @@ def save_session(self, file_path):
10971107 node_space = self .get_node_space ()
10981108 if node_space is not None :
10991109 node_space = node_space .id
1100- serliazed_data ['graph' ] = {'node_space' :node_space ,'pipe_layout' :self ._viewer .get_pipe_layout ()}
1110+ serliazed_data ['graph' ] = {'node_space' : node_space , 'pipe_layout' : self ._viewer .get_pipe_layout ()}
1111+ serliazed_data ['graph' ]['graph_rect' ] = self ._viewer .scene_rect ()
11011112 file_path = file_path .strip ()
11021113 with open (file_path , 'w' ) as file_out :
11031114 json .dump (serliazed_data , file_out , indent = 2 , separators = (',' , ':' ))
@@ -1144,6 +1155,8 @@ def import_session(self, file_path):
11441155 self .set_node_space (self .get_node_by_id (node_space_id ))
11451156 self ._viewer .set_pipe_layout (layout_data ['graph' ]['pipe_layout' ])
11461157
1158+ self ._viewer .set_scene_rect (layout_data ['graph' ]['graph_rect' ])
1159+
11471160 self ._undo_stack .clear ()
11481161 self ._model .session = file_path
11491162 self .session_changed .emit (file_path )
@@ -1314,6 +1327,24 @@ def save_dialog(self, current_dir=None, ext=None):
13141327
13151328 def use_opengl (self ):
13161329 """
1317- use opengl to draw the graph
1330+ Use OpenGL to draw the graph.
13181331 """
13191332 self ._viewer .use_opengl ()
1333+
1334+ def graph_rect (self ):
1335+ """
1336+ Get the graph viewer range.
1337+
1338+ Returns:
1339+ list: [x, y, width, height].
1340+ """
1341+ return self ._viewer .scene_rect ()
1342+
1343+ def set_graph_rect (self , rect ):
1344+ """
1345+ Set the graph viewer range.
1346+
1347+ Args:
1348+ rect (list): [x, y, width, height].
1349+ """
1350+ self ._viewer .set_scene_rect (rect )
0 commit comments