@@ -9,25 +9,33 @@ class BlockRegistry:
99
1010 def __init__ (self ):
1111 self ._blocks = {}
12+ self ._localized_names = {}
1213
13- def register (self , block_id : str , group_id : str , block_class : Type [Block ]):
14+ def register (self , block_id : str , group_id : str , block_class : Type [Block ], localized_name : Optional [ str ] = None ):
1415 """注册一个 block
1516
1617 Args:
1718 block_id: block 的唯一标识
1819 group_id: 组标识(internal 为框架内置)
1920 block_class: block 类
21+ localized_name: 本地化名称
2022 """
2123 full_name = f"{ group_id } :{ block_id } "
2224 if full_name in self ._blocks :
2325 raise ValueError (f"Block { full_name } already registered" )
2426 self ._blocks [full_name ] = block_class
2527 block_class .id = block_id
28+ if localized_name :
29+ self ._localized_names [full_name ] = localized_name
2630
2731 def get (self , full_name : str ) -> Optional [Type [Block ]]:
2832 """获取已注册的 block 类"""
2933 return self ._blocks .get (full_name )
3034
35+ def get_localized_name (self , block_id : str ) -> Optional [str ]:
36+ """获取本地化名称"""
37+ return self ._localized_names .get (block_id , block_id )
38+
3139 def clear (self ):
3240 """清空注册表"""
3341 self ._blocks .clear ()
@@ -67,6 +75,7 @@ def extract_block_info(self, block_type: Type[Block]) -> Tuple[Dict[str, BlockIn
6775 for name , input_info in getattr (block_type , 'inputs' , {}).items ():
6876 inputs [name ] = BlockInput (
6977 name = name ,
78+ label = input_info .label ,
7079 description = input_info .description ,
7180 type = input_info .data_type .__name__ if hasattr (input_info .data_type , '__name__' ) else str (input_info .data_type ),
7281 required = True , # 假设所有输入都是必需的
@@ -77,6 +86,7 @@ def extract_block_info(self, block_type: Type[Block]) -> Tuple[Dict[str, BlockIn
7786 for name , output_info in getattr (block_type , 'outputs' , {}).items ():
7887 outputs [name ] = BlockOutput (
7988 name = name ,
89+ label = output_info .label ,
8090 description = output_info .description ,
8191 type = output_info .data_type .__name__ if hasattr (output_info .data_type , '__name__' ) else str (output_info .data_type )
8292 )
0 commit comments