Fix T52833: OBJ triangulate doesn't match viewport
[blender-addons.git] / development_ui_classes.py
blob18b692f42358096e42f344a99f75dbd764ba65e0
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # <pep8 compliant>
21 bl_info = {
22 "name": "UI Classes Overview",
23 "author": "lijenstina",
24 "version": (1, 0, 1),
25 "blender": (2, 78, 0),
26 "location": "Text Editor > Properties",
27 "description": "Print the UI classes in a text-block",
28 "warning": "",
29 "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/"
30 "Py/Scripts/Development/Classes_Overview",
31 "category": "Development"
34 import bpy
35 from bpy.types import (
36 Operator,
37 Panel,
38 PropertyGroup,
40 from bpy.props import (
41 BoolProperty,
42 EnumProperty,
43 PointerProperty,
47 class TEXT_PT_ui_cheat_sheet(Panel):
48 bl_space_type = "TEXT_EDITOR"
49 bl_region_type = "UI"
50 bl_label = "UI Cheat Sheet"
51 bl_options = {"DEFAULT_CLOSED"}
53 def draw(self, context):
54 layout = self.layout
55 scene = context.scene.dev_text_ui
57 col = layout.column(align=True)
58 col.prop(scene, "dev_ui_cheat_type", expand=True)
60 row = layout.row(align=True)
61 split = row.split(percentage=0.8, align=True)
62 split.operator("text.ui_cheat_sheet")
63 split.prop(scene, "searchable", text="", icon='SHORTDISPLAY')
66 class TEXT_OT_ui_cheat_sheet(Operator):
67 bl_idname = "text.ui_cheat_sheet"
68 bl_label = "Generate UI list"
69 bl_description = ("List the UI Menus, Panels and Headers in a textblock\n"
70 "The newly generated list will be made active in the Text Editor\n"
71 "To access the previous ones, select them from the Header dropdown")
73 def ui_list_name(self, context):
74 new_name, def_name, ext = "", "UIList", ".txt"
75 suffix = 1
76 try:
77 # first slap a simple linear count + 1 for numeric suffix, if it fails
78 # harvest for the rightmost numbers and append the max value
79 list_txt = []
80 data_txt = bpy.data.texts
81 list_txt = [txt.name for txt in data_txt if txt.name.startswith("UIList")]
82 new_name = "{}_{}{}".format(def_name, len(list_txt) + 1, ext)
84 if new_name in list_txt:
85 from re import findall
86 test_num = [findall("\d+", words) for words in list_txt]
87 suffix += max([int(l[-1]) for l in test_num])
88 new_name = "{}_{}{}".format(def_name, suffix, ext)
89 return new_name
90 except:
91 return None
93 def execute(self, context):
94 from collections import defaultdict
96 scene = context.scene.dev_text_ui
97 ui_type = scene.dev_ui_cheat_type
98 op_string_ui = defaultdict(list)
99 searchable = scene.searchable
101 try:
102 file_name = self.ui_list_name(context) or "UIList.txt"
103 classes = ["Panel", "Menu", "Header"] if ui_type in "all" else [ui_type]
104 string_line = "---\n%s\nModule path: %s" if not searchable else "\n'%s': '%s',"
105 print_line = '\n\n\n[%s]\nitems: %d\n' if not searchable else '\n\n%s = {\n# items: %d\n'
106 close_line = '\n' if not searchable else '\n}'
107 start_note = (
108 "\n\n# Classes starting with 'NODE_PT_category_' and 'NODE_MT_category_'\n"
109 "# are generated in startup\\nodeitems_builtins.py" if ui_type not in "Header" else ""
112 for cls_name in classes:
113 cls = getattr(bpy.types, cls_name)
114 for op_module in cls.__subclasses__():
115 if op_module:
116 module_name = op_module.__module__
117 module_name = module_name.replace('.', '\\')
118 text = (string_line % (op_module.__name__, module_name))
119 op_string_ui[cls_name].append(text)
121 textblock = bpy.data.texts.new(file_name)
122 total = sum([len(op_string_ui[cls_name]) for cls_name in classes])
123 textblock.write('# %d Total Items' % (total))
124 textblock.write(start_note)
126 for cls_name in classes:
127 textblock.write(print_line % (cls_name, len(op_string_ui[cls_name])))
128 textblock.write(('\n' if not searchable else '').join(sorted(op_string_ui[cls_name])))
129 textblock.write(close_line)
131 context.space_data.text = bpy.data.texts[file_name]
132 self.report({'INFO'}, "See %s textblock" % file_name)
134 return {'FINISHED'}
135 except:
136 self.report({'WARNING'},
137 "Failure to write the UI list (Check the console for more info)")
138 import traceback
139 traceback.print_exc()
141 return {'CANCELLED'}
144 # Properties
145 class text_ui_cheat_props(PropertyGroup):
146 dev_ui_cheat_type = EnumProperty(
147 name="Choose a Type",
148 description="Choose what Classes to include in a Text-Block",
149 items=(('all', "All", "Print all the types"),
150 ('Panel', "Panels", "Print Panel UI types"),
151 ('Menu', "Menus", "Print Menu UI types"),
152 ('Header', "Headers", "Print Header UI types"),
154 default='all',
156 searchable = BoolProperty(
157 name="Format searchable",
158 description="Generate the list as Python dictionary,\n"
159 "using the format Class: Path",
160 default=False
164 # Register
165 classes = (
166 TEXT_OT_ui_cheat_sheet,
167 TEXT_PT_ui_cheat_sheet,
168 text_ui_cheat_props
172 def register():
173 for cls in classes:
174 bpy.utils.register_class(cls)
176 bpy.types.Scene.dev_text_ui = PointerProperty(type=text_ui_cheat_props)
179 def unregister():
180 for cls in classes:
181 bpy.utils.unregister_class(cls)
183 del bpy.types.Scene.dev_text_ui
186 if __name__ == "__main__":
187 register()