__init__.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  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.
  7. #
  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.
  12. #
  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.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. # <pep8 compliant>
  19. # note, properties_animviz is a helper module only.
  20. # support reloading sub-modules
  21. if "bpy" in locals():
  22. from importlib import reload
  23. _modules_loaded[:] = [reload(val) for val in _modules_loaded]
  24. del reload
  25. _modules = [
  26. "properties_animviz",
  27. "properties_constraint",
  28. "properties_data_armature",
  29. "properties_data_bone",
  30. "properties_data_camera",
  31. "properties_data_curve",
  32. "properties_data_empty",
  33. "properties_data_gpencil",
  34. "properties_data_light",
  35. "properties_data_lattice",
  36. "properties_data_mesh",
  37. "properties_data_metaball",
  38. "properties_data_modifier",
  39. "properties_data_shaderfx",
  40. "properties_data_lightprobe",
  41. "properties_data_speaker",
  42. "properties_mask_common",
  43. "properties_material",
  44. "properties_material_gpencil",
  45. "properties_object",
  46. "properties_paint_common",
  47. "properties_grease_pencil_common",
  48. "properties_particle",
  49. "properties_physics_cloth",
  50. "properties_physics_common",
  51. "properties_physics_dynamicpaint",
  52. "properties_physics_field",
  53. "properties_physics_fluid",
  54. "properties_physics_rigidbody",
  55. "properties_physics_rigidbody_constraint",
  56. "properties_physics_smoke",
  57. "properties_physics_softbody",
  58. "properties_render",
  59. "properties_output",
  60. "properties_view_layer",
  61. "properties_scene",
  62. "properties_texture",
  63. "properties_world",
  64. # Generic Space Modules
  65. #
  66. # Depends on DNA_WORKSPACE_TOOL (C define).
  67. "space_toolsystem_common",
  68. "space_toolsystem_toolbar",
  69. "space_clip",
  70. "space_console",
  71. "space_dopesheet",
  72. "space_filebrowser",
  73. "space_graph",
  74. "space_image",
  75. "space_info",
  76. "space_nla",
  77. "space_node",
  78. "space_outliner",
  79. "space_properties",
  80. "space_sequencer",
  81. "space_statusbar",
  82. "space_text",
  83. "space_time",
  84. "space_topbar",
  85. "space_userpref",
  86. "space_view3d",
  87. "space_view3d_toolbar",
  88. # XXX, keep last so panels show after all other tool options.
  89. "properties_workspace",
  90. ]
  91. import bpy
  92. if bpy.app.build_options.freestyle:
  93. _modules.append("properties_freestyle")
  94. __import__(name=__name__, fromlist=_modules)
  95. _namespace = globals()
  96. _modules_loaded = [_namespace[name] for name in _modules]
  97. del _namespace
  98. def register():
  99. from bpy.utils import register_class
  100. for mod in _modules_loaded:
  101. for cls in mod.classes:
  102. register_class(cls)
  103. # space_userprefs.py
  104. from bpy.props import (
  105. EnumProperty,
  106. StringProperty,
  107. )
  108. from bpy.types import WindowManager
  109. def addon_filter_items(_self, _context):
  110. import addon_utils
  111. items = [
  112. ('All', "All", "All Add-ons"),
  113. ('User', "User", "All Add-ons Installed by User"),
  114. ('Enabled', "Enabled", "All Enabled Add-ons"),
  115. ('Disabled', "Disabled", "All Disabled Add-ons"),
  116. ]
  117. items_unique = set()
  118. for mod in addon_utils.modules(refresh=False):
  119. info = addon_utils.module_bl_info(mod)
  120. items_unique.add(info["category"])
  121. items.extend([(cat, cat, "") for cat in sorted(items_unique)])
  122. return items
  123. WindowManager.addon_search = StringProperty(
  124. name="Search",
  125. description="Search within the selected filter",
  126. options={'TEXTEDIT_UPDATE'},
  127. )
  128. WindowManager.addon_filter = EnumProperty(
  129. items=addon_filter_items,
  130. name="Category",
  131. description="Filter add-ons by category",
  132. )
  133. WindowManager.addon_support = EnumProperty(
  134. items=[
  135. ('OFFICIAL', "Official", "Officially supported"),
  136. ('COMMUNITY', "Community", "Maintained by community developers"),
  137. ('TESTING', "Testing", "Newly contributed scripts (excluded from release builds)")
  138. ],
  139. name="Support",
  140. description="Display support level",
  141. default={'OFFICIAL', 'COMMUNITY'},
  142. options={'ENUM_FLAG'},
  143. )
  144. # done...
  145. def unregister():
  146. from bpy.utils import unregister_class
  147. for mod in reversed(_modules_loaded):
  148. for cls in reversed(mod.classes):
  149. if cls.is_registered:
  150. unregister_class(cls)
  151. # Define a default UIList, when a list does not need any custom drawing...
  152. # Keep in sync with its #defined name in UI_interface.h
  153. class UI_UL_list(bpy.types.UIList):
  154. # These are common filtering or ordering operations (same as the default C ones!).
  155. @staticmethod
  156. def filter_items_by_name(pattern, bitflag, items, propname="name", flags=None, reverse=False):
  157. """
  158. Set FILTER_ITEM for items which name matches filter_name one (case-insensitive).
  159. pattern is the filtering pattern.
  160. propname is the name of the string property to use for filtering.
  161. flags must be a list of integers the same length as items, or None!
  162. return a list of flags (based on given flags if not None),
  163. or an empty list if no flags were given and no filtering has been done.
  164. """
  165. import fnmatch
  166. if not pattern or not items: # Empty pattern or list = no filtering!
  167. return flags or []
  168. if flags is None:
  169. flags = [0] * len(items)
  170. # Implicitly add heading/trailing wildcards.
  171. pattern = "*" + pattern + "*"
  172. for i, item in enumerate(items):
  173. name = getattr(item, propname, None)
  174. # This is similar to a logical xor
  175. if bool(name and fnmatch.fnmatchcase(name, pattern)) is not bool(reverse):
  176. flags[i] |= bitflag
  177. return flags
  178. @staticmethod
  179. def sort_items_helper(sort_data, key, reverse=False):
  180. """
  181. Common sorting utility. Returns a neworder list mapping org_idx -> new_idx.
  182. sort_data must be an (unordered) list of tuples [(org_idx, ...), (org_idx, ...), ...].
  183. key must be the same kind of callable you would use for sorted() builtin function.
  184. reverse will reverse the sorting!
  185. """
  186. sort_data.sort(key=key, reverse=reverse)
  187. neworder = [None] * len(sort_data)
  188. for newidx, (orgidx, *_) in enumerate(sort_data):
  189. neworder[orgidx] = newidx
  190. return neworder
  191. @classmethod
  192. def sort_items_by_name(cls, items, propname="name"):
  193. """
  194. Re-order items using their names (case-insensitive).
  195. propname is the name of the string property to use for sorting.
  196. return a list mapping org_idx -> new_idx,
  197. or an empty list if no sorting has been done.
  198. """
  199. _sort = [(idx, getattr(it, propname, "")) for idx, it in enumerate(items)]
  200. return cls.sort_items_helper(_sort, lambda e: e[1].lower())
  201. bpy.utils.register_class(UI_UL_list)