@@ -162,7 +162,6 @@ def __init__(
162162 with dpg .node_editor (
163163 tag = self ._node_editor_tag ,
164164 callback = self ._callback_link ,
165- delink_callback = self ._callback_delink ,
166165 minimap = True ,
167166 minimap_location = dpg .mvNodeMiniMap_Location_BottomRight ,
168167 ):
@@ -245,25 +244,27 @@ def _callback_add_node(self, sender, data, user_data):
245244
246245 def _callback_link (self , sender , data ):
247246 # 各接続子の型を取得
248- source_type = data [0 ].split (':' )[2 ]
249- destination_type = data [1 ].split (':' )[2 ]
247+ source = dpg .get_item_alias (data [0 ])
248+ destination = dpg .get_item_alias (data [1 ])
249+ source_type = source .split (':' )[2 ]
250+ destination_type = destination .split (':' )[2 ]
250251
251252 # 型が一致するもののみ処理
252253 if source_type == destination_type :
253254 # 初回ノード生成時
254255 if len (self ._node_link_list ) == 0 :
255- dpg .add_node_link (data [ 0 ], data [ 1 ] , parent = sender )
256- self ._node_link_list .append ([data [ 0 ], data [ 1 ] ])
256+ dpg .add_node_link (source , destination , parent = sender )
257+ self ._node_link_list .append ([source , destination ])
257258 # 2回目以降
258259 else :
259260 # 入力端子に複数接続しようとしていないかチェック
260261 duplicate_flag = False
261262 for node_link in self ._node_link_list :
262- if data [ 1 ] == node_link [1 ]:
263+ if destination == node_link [1 ]:
263264 duplicate_flag = True
264265 if not duplicate_flag :
265- dpg .add_node_link (data [ 0 ], data [ 1 ] , parent = sender )
266- self ._node_link_list .append ([data [ 0 ], data [ 1 ] ])
266+ dpg .add_node_link (source , destination , parent = sender )
267+ self ._node_link_list .append ([source , destination ])
267268
268269 # ノードグラフ再生成
269270 self ._node_connection_dict = self ._sort_node_graph (
@@ -274,38 +275,13 @@ def _callback_link(self, sender, data):
274275 if self ._use_debug_print :
275276 print ('**** _callback_link ****' )
276277 print (' sender : ' + str (sender ))
277- print (' data : ' + ', ' . join ( data ) )
278+ print (' data : ' , data )
278279 print (' self._node_list : ' , self ._node_list )
279280 print (' self._node_link_list : ' , self ._node_link_list )
280281 print (' self._node_connection_dict : ' ,
281282 self ._node_connection_dict )
282283 print ()
283284
284- def _callback_delink (self , sender , data ):
285- # リンクリストから削除
286- self ._node_link_list .remove ([
287- dpg .get_item_configuration (data )['attr_1' ],
288- dpg .get_item_configuration (data )['attr_2' ]
289- ])
290-
291- # ノードグラフ再生成
292- self ._node_connection_dict = self ._sort_node_graph (
293- self ._node_list ,
294- self ._node_link_list ,
295- )
296-
297- # アイテム削除
298- dpg .delete_item (data )
299-
300- if self ._use_debug_print :
301- print ('**** _callback_delink ****' )
302- print (' sender : ' + str (sender ))
303- print (' data : ' + str (data ))
304- print (' self._node_list : ' , self ._node_list )
305- print (' self._node_link_list : ' , self ._node_link_list )
306- print (' self._node_connection_dict : ' ,
307- self ._node_connection_dict )
308- print ()
309285
310286 def _callback_close_window (self , sender ):
311287 dpg .delete_item (sender )
@@ -316,16 +292,16 @@ def _sort_node_graph(self, node_list, node_link_list):
316292
317293 # ノードIDとノード接続を辞書形式で整理
318294 for node_link_info in node_link_list :
319- source_id = int (node_link_info [0 ].split (':' )[0 ])
320- destination_id = int (node_link_info [1 ].split (':' )[0 ])
295+ source = dpg .get_item_alias (node_link_info [0 ])
296+ destination = dpg .get_item_alias (node_link_info [1 ])
297+ source_id = int (source .split (':' )[0 ])
298+ destination_id = int (destination .split (':' )[0 ])
321299
322300 if destination_id not in node_id_dict :
323301 node_id_dict [destination_id ] = [source_id ]
324302 else :
325303 node_id_dict [destination_id ].append (source_id )
326304
327- source = node_link_info [0 ]
328- destination = node_link_info [1 ]
329305 split_destination = destination .split (':' )
330306
331307 node_name = split_destination [0 ] + ':' + split_destination [1 ]
@@ -531,6 +507,19 @@ def _callback_mv_key_del(self):
531507 # アイテム削除
532508 dpg .delete_item (item_id )
533509
510+ if len (dpg .get_selected_links (self ._node_editor_tag )) > 0 :
511+ self ._node_link_list .remove ([
512+ dpg .get_item_alias (dpg .get_item_configuration (dpg .get_selected_links (self ._node_editor_tag )[0 ])['attr_1' ]),
513+ dpg .get_item_alias (dpg .get_item_configuration (dpg .get_selected_links (self ._node_editor_tag )[0 ])['attr_2' ])
514+ ])
515+
516+ self ._node_connection_dict = self ._sort_node_graph (
517+ self ._node_list ,
518+ self ._node_link_list ,
519+ )
520+
521+ dpg .delete_item (dpg .get_selected_links (self ._node_editor_tag )[0 ])
522+
534523 if self ._use_debug_print :
535524 print ('**** _callback_mv_key_del ****' )
536525 print (' self._node_list : ' , self ._node_list )
0 commit comments