@@ -1478,7 +1478,7 @@ def delete_nodes(self, nodes, push_undo=True):
14781478
14791479 def extract_nodes (self , nodes , push_undo = True , prompt_warning = True ):
14801480 """
1481- Extract select nodes from it connections.
1481+ Extract select nodes from its connections.
14821482
14831483 Args:
14841484 nodes (list[NodeGraphQt.BaseNode]): list of node instances.
@@ -1843,7 +1843,8 @@ def serialize_session(self):
18431843 """
18441844 return self ._serialize (self .all_nodes ())
18451845
1846- def deserialize_session (self , layout_data ):
1846+ def deserialize_session (self , layout_data , clear_session = True ,
1847+ clear_undo_stack = True ):
18471848 """
18481849 Load node graph session from a dictionary object.
18491850
@@ -1854,11 +1855,15 @@ def deserialize_session(self, layout_data):
18541855
18551856 Args:
18561857 layout_data (dict): dictionary object containing a node session.
1858+ clear_session (bool): clear current session.
1859+ clear_undo_stack (bool): clear the undo stack.
18571860 """
1858- self .clear_session ()
1861+ if clear_session :
1862+ self .clear_session ()
18591863 self ._deserialize (layout_data )
18601864 self .clear_selection ()
1861- self ._undo_stack .clear ()
1865+ if clear_undo_stack :
1866+ self ._undo_stack .clear ()
18621867
18631868 def save_session (self , file_path ):
18641869 """
@@ -1872,7 +1877,7 @@ def save_session(self, file_path):
18721877 Args:
18731878 file_path (str): path to the saved node layout.
18741879 """
1875- serialized_data = self ._serialize ( self . all_nodes () )
1880+ serialized_data = self .serialize_session ( )
18761881 file_path = file_path .strip ()
18771882
18781883 def default (obj ):
@@ -1906,14 +1911,15 @@ def load_session(self, file_path):
19061911 raise IOError ('file does not exist: {}' .format (file_path ))
19071912
19081913 self .clear_session ()
1909- self .import_session (file_path )
1914+ self .import_session (file_path , clear_undo_stack = True )
19101915
1911- def import_session (self , file_path ):
1916+ def import_session (self , file_path , clear_undo_stack = True ):
19121917 """
1913- Import node graph session layout file .
1918+ Import node graph into the current session .
19141919
19151920 Args:
19161921 file_path (str): path to the serialized layout file.
1922+ clear_undo_stack (bool): clear the undo stack after import.
19171923 """
19181924 file_path = file_path .strip ()
19191925 if not os .path .isfile (file_path ):
@@ -1929,15 +1935,18 @@ def import_session(self, file_path):
19291935 if not layout_data :
19301936 return
19311937
1932- self ._deserialize (layout_data )
1933- self ._undo_stack .clear ()
1938+ self .deserialize_session (
1939+ layout_data ,
1940+ clear_session = False ,
1941+ clear_undo_stack = clear_undo_stack
1942+ )
19341943 self ._model .session = file_path
19351944
19361945 self .session_changed .emit (file_path )
19371946
19381947 def copy_nodes (self , nodes = None ):
19391948 """
1940- Copy nodes to the clipboard.
1949+ Copy nodes to the clipboard as a JSON formatted ``str`` .
19411950
19421951 See Also:
19431952 :meth:`NodeGraph.cut_nodes`
@@ -1959,7 +1968,7 @@ def copy_nodes(self, nodes=None):
19591968
19601969 def cut_nodes (self , nodes = None ):
19611970 """
1962- Cut nodes to the clipboard.
1971+ Cut nodes to the clipboard as a JSON formatted ``str`` .
19631972
19641973 Note:
19651974 This function doesn't trigger the
@@ -2245,7 +2254,7 @@ def auto_layout_nodes(self, nodes=None, down_stream=True, start_nodes=None):
22452254 # convenience dialog functions.
22462255 # --------------------------------------------------------------------------
22472256
2248- def question_dialog (self , text , title = 'Node Graph' ):
2257+ def question_dialog (self , text , title = 'Node Graph' , parent = None ):
22492258 """
22502259 Prompts a question open dialog with ``"Yes"`` and ``"No"`` buttons in
22512260 the node graph.
@@ -2257,13 +2266,14 @@ def question_dialog(self, text, title='Node Graph'):
22572266 Args:
22582267 text (str): question text.
22592268 title (str): dialog window title.
2269+ parent (QtWidgets.QObject): override dialog parent. (optional)
22602270
22612271 Returns:
22622272 bool: true if user clicked yes.
22632273 """
2264- return self ._viewer .question_dialog (text , title )
2274+ return self ._viewer .question_dialog (text , title , parent )
22652275
2266- def message_dialog (self , text , title = 'Node Graph' ):
2276+ def message_dialog (self , text , title = 'Node Graph' , parent = None ):
22672277 """
22682278 Prompts a file open dialog in the node graph.
22692279
@@ -2274,10 +2284,11 @@ def message_dialog(self, text, title='Node Graph'):
22742284 Args:
22752285 text (str): message text.
22762286 title (str): dialog window title.
2287+ parent (QtWidgets.QObject): override dialog parent. (optional)
22772288 """
2278- self ._viewer .message_dialog (text , title )
2289+ self ._viewer .message_dialog (text , title , parent )
22792290
2280- def load_dialog (self , current_dir = None , ext = None ):
2291+ def load_dialog (self , current_dir = None , ext = None , parent = None ):
22812292 """
22822293 Prompts a file open dialog in the node graph.
22832294
@@ -2288,13 +2299,14 @@ def load_dialog(self, current_dir=None, ext=None):
22882299 Args:
22892300 current_dir (str): path to a directory.
22902301 ext (str): custom file type extension (default: ``"json"``)
2302+ parent (QtWidgets.QObject): override dialog parent. (optional)
22912303
22922304 Returns:
22932305 str: selected file path.
22942306 """
2295- return self ._viewer .load_dialog (current_dir , ext )
2307+ return self ._viewer .load_dialog (current_dir , ext , parent )
22962308
2297- def save_dialog (self , current_dir = None , ext = None ):
2309+ def save_dialog (self , current_dir = None , ext = None , parent = None ):
22982310 """
22992311 Prompts a file save dialog in the node graph.
23002312
@@ -2305,11 +2317,12 @@ def save_dialog(self, current_dir=None, ext=None):
23052317 Args:
23062318 current_dir (str): path to a directory.
23072319 ext (str): custom file type extension (default: ``"json"``)
2320+ parent (QtWidgets.QObject): override dialog parent. (optional)
23082321
23092322 Returns:
23102323 str: selected file path.
23112324 """
2312- return self ._viewer .save_dialog (current_dir , ext )
2325+ return self ._viewer .save_dialog (current_dir , ext , parent )
23132326
23142327 # group node / sub graph.
23152328 # --------------------------------------------------------------------------
0 commit comments