1- import typing
21import bpy
3- from bpy .types import Panel , Context , Menu
2+ from bpy .types import Context , Menu , Panel
43
54button_classes = {}
65panel_names = []
76
87ui_space_types = [
9- 'CLIP_EDITOR' , 'NODE_EDITOR' , 'TEXT_EDITOR' , 'SEQUENCE_EDITOR' , 'NLA_EDITOR' ,
10- 'DOPESHEET_EDITOR' , 'VIEW_3D' , 'GRAPH_EDITOR' , 'IMAGE_EDITOR'
8+ "CLIP_EDITOR" ,
9+ "NODE_EDITOR" ,
10+ "TEXT_EDITOR" ,
11+ "SEQUENCE_EDITOR" ,
12+ "NLA_EDITOR" ,
13+ "DOPESHEET_EDITOR" ,
14+ "VIEW_3D" ,
15+ "GRAPH_EDITOR" ,
16+ "IMAGE_EDITOR" ,
1117] # blender spaces with UI region
1218
1319
@@ -22,6 +28,7 @@ def unregister_button_panel(name: str):
2228def unregister_register_button_panel (name : str , register : bool ):
2329 index = len (panel_names ) - (not register )
2430 for space_type in ui_space_types :
31+
2532 class STB_PT_Buttons (Panel ):
2633 bl_idname = "STB_PT_Buttons_%s_%s" % (index , space_type )
2734 bl_label = ""
@@ -37,7 +44,9 @@ def poll(self, context: Context) -> bool:
3744 stb = context .scene .stb
3845 area = context .area .ui_type
3946 panel = panel_names [self .bl_order ]
40- return any ((button .panel == panel and area in button .areas ) for button in stb )
47+ return any (
48+ (button .panel == panel and area in button .areas ) for button in stb
49+ )
4150
4251 def draw_header (self , context : Context ):
4352 layout = self .layout
@@ -48,21 +57,21 @@ def draw(self, context):
4857 area = context .area .ui_type
4958 panel = panel_names [self .bl_order ]
5059 buttons = filter (
51- lambda x : area in x .areas and x .panel == panel ,
52- context .scene .stb
60+ lambda x : area in x .areas and x .panel == panel , context .scene .stb
5361 )
5462 for button in sorted (buttons , key = lambda x : x .name ):
5563 row = layout .row (align = True )
5664 row .prop (
57- button , 'selected' ,
65+ button ,
66+ "selected" ,
5867 toggle = True ,
5968 text = "" ,
60- icon = ' RADIOBUT_ON' if button .selected else ' RADIOBUT_OFF'
69+ icon = " RADIOBUT_ON" if button .selected else " RADIOBUT_OFF" ,
6170 )
6271 row .operator (
63- "stb.script_button" ,
64- text = button .name
72+ "stb.script_button" , text = button .name
6573 ).name = button .name
74+
6675 STB_PT_Buttons .__name__ = "STB_PT_Buttons_%s_%s" % (index , space_type )
6776
6877 global button_classes
@@ -86,21 +95,22 @@ def poll(self, context: Context) -> bool:
8695 return False
8796 area = context .area .ui_type
8897 panel = panel_names [self .bl_order ]
89- return any ((button .panel == panel and area in button .areas ) for button in stb )
98+ return any (
99+ (button .panel == panel and area in button .areas ) for button in stb
100+ )
90101
91102 def draw (self , context : Context ):
92103 layout = self .layout
93104 area = context .area .ui_type
94105 panel = panel_names [self .bl_order ]
95106 buttons = filter (
96- lambda x : area in x .areas and x .panel == panel ,
97- context .scene .stb
107+ lambda x : area in x .areas and x .panel == panel , context .scene .stb
98108 )
99109 for button in sorted (buttons , key = lambda x : x .name ):
100110 layout .operator (
101- "stb.script_button" ,
102- text = button .name
111+ "stb.script_button" , text = button .name
103112 ).name = button .name
113+
104114 STB_MT_Buttons .__name__ = "STB_MT_Buttons_%s" % index
105115
106116 if register :
0 commit comments