1717from NodeGraphQt .base .node import NodeObject
1818from NodeGraphQt .base .port import Port
1919from NodeGraphQt .constants import (
20+ MIME_TYPE ,
2021 URI_SCHEME ,
2122 URN_SCHEME ,
2223 LayoutDirectionEnum ,
@@ -341,7 +342,7 @@ def _on_node_selection_changed(self, sel_ids, desel_ids):
341342 unsel_nodes = [self .get_node_by_id (nid ) for nid in desel_ids ]
342343 self .node_selection_changed .emit (sel_nodes , unsel_nodes )
343344
344- def _on_node_data_dropped (self , data , pos ):
345+ def _on_node_data_dropped (self , mimedata , pos ):
345346 """
346347 called when data has been dropped on the viewer.
347348
@@ -350,36 +351,52 @@ def _on_node_data_dropped(self, data, pos):
350351 URN = ngqt::node:com.nodes.MyNode1;node:com.nodes.MyNode2
351352
352353 Args:
353- data (QtCore.QMimeData): mime data.
354+ mimedata (QtCore.QMimeData): mime data.
354355 pos (QtCore.QPoint): scene position relative to the drop.
355356 """
356357 uri_regex = re .compile (r'{}(?:/*)([\w/]+)(\.\w+)' .format (URI_SCHEME ))
357358 urn_regex = re .compile (r'{}([\w\.:;]+)' .format (URN_SCHEME ))
358- if data .hasFormat ('text/uri-list' ):
359- for url in data .urls ():
359+ if mimedata .hasFormat (MIME_TYPE ):
360+ data = mimedata .data (MIME_TYPE ).data ().decode ()
361+ urn_search = urn_regex .search (data )
362+ if urn_search :
363+ search_str = urn_search .group (1 )
364+ node_ids = sorted (re .findall (r'node:([\w\.]+)' , search_str ))
365+ x , y = pos .x (), pos .y ()
366+ for node_id in node_ids :
367+ self .create_node (node_id , pos = [x , y ])
368+ x += 80
369+ y += 80
370+ elif mimedata .hasFormat ('text/uri-list' ):
371+ not_supported_urls = []
372+ for url in mimedata .urls ():
360373 local_file = url .toLocalFile ()
361374 if local_file :
362375 try :
363376 self .import_session (local_file )
364377 continue
365378 except Exception as e :
366- pass
379+ not_supported_urls . append ( url )
367380
368381 url_str = url .toString ()
369- uri_search = uri_regex .search (url_str )
370- urn_search = urn_regex .search (url_str )
371- if uri_search :
372- path = uri_search .group (1 )
373- ext = uri_search .group (2 )
374- self .import_session ('{}{}' .format (path , ext ))
375- elif urn_search :
376- search_str = urn_search .group (1 )
377- node_ids = sorted (re .findall ('node:([\w\\ .]+)' , search_str ))
378- x , y = pos .x (), pos .y ()
379- for node_id in node_ids :
380- self .create_node (node_id , pos = [x , y ])
381- x += 80
382- y += 80
382+ if url_str :
383+ uri_search = uri_regex .search (url_str )
384+ if uri_search :
385+ path = uri_search .group (1 )
386+ ext = uri_search .group (2 )
387+ try :
388+ self .import_session ('{}{}' .format (path , ext ))
389+ except Exception as e :
390+ not_supported_urls .append (url )
391+
392+ if not_supported_urls :
393+ print (
394+ 'Can\' t import the following urls: \n {}'
395+ .format ('\n ' .join (not_supported_urls ))
396+ )
397+ self .data_dropped .emit (mimedata , pos )
398+ else :
399+ self .data_dropped .emit (mimedata , pos )
383400
384401 def _on_nodes_moved (self , node_data ):
385402 """
@@ -640,7 +657,7 @@ def set_grid_mode(self, mode=None):
640657 :linenos:
641658
642659 graph = NodeGraph()
643- graph.set_grid_mode(ViewerEnum.CURVED .value)
660+ graph.set_grid_mode(ViewerEnum.GRID_DISPLAY_DOTS .value)
644661
645662 Args:
646663 mode (int): background style.
0 commit comments