properties_workspace.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. import bpy
  20. from bpy.types import (
  21. Panel,
  22. )
  23. from rna_prop_ui import PropertyPanel
  24. class WorkSpaceButtonsPanel:
  25. # bl_space_type = 'PROPERTIES'
  26. # bl_region_type = 'WINDOW'
  27. # bl_context = ".workspace"
  28. # Developer note: this is displayed in tool settings as well as the 3D view.
  29. bl_space_type = 'VIEW_3D'
  30. bl_region_type = 'UI'
  31. bl_category = "Tool"
  32. class WORKSPACE_PT_main(WorkSpaceButtonsPanel, Panel):
  33. bl_label = "Workspace"
  34. bl_options = {'DEFAULT_CLOSED'}
  35. def draw(self, context):
  36. workspace = context.workspace
  37. layout = self.layout
  38. layout.use_property_split = True
  39. layout.use_property_decorate = False
  40. layout.prop(workspace, "object_mode", text="Mode")
  41. class WORKSPACE_PT_addons(WorkSpaceButtonsPanel, Panel):
  42. bl_label = "Filter Add-ons"
  43. bl_parent_id = "WORKSPACE_PT_main"
  44. def draw_header(self, context):
  45. workspace = context.workspace
  46. self.layout.prop(workspace, "use_filter_by_owner", text="")
  47. def draw(self, context):
  48. layout = self.layout
  49. # align just to pack more tightly
  50. col = layout.box().column(align=True)
  51. workspace = context.workspace
  52. prefs = context.preferences
  53. col.active = workspace.use_filter_by_owner
  54. import addon_utils
  55. addon_map = {mod.__name__: mod for mod in addon_utils.modules()}
  56. owner_ids = {owner_id.name for owner_id in workspace.owner_ids}
  57. for addon in prefs.addons:
  58. module_name = addon.module
  59. module = addon_map.get(module_name)
  60. if module is None:
  61. continue
  62. info = addon_utils.module_bl_info(module)
  63. if not info["use_owner"]:
  64. continue
  65. is_enabled = module_name in owner_ids
  66. row = col.row()
  67. row.alignment = 'LEFT'
  68. row.operator(
  69. "wm.owner_disable" if is_enabled else "wm.owner_enable",
  70. icon='CHECKBOX_HLT' if is_enabled else 'CHECKBOX_DEHLT',
  71. text="%s: %s" % (info["category"], info["name"]),
  72. emboss=False,
  73. ).owner_id = module_name
  74. if is_enabled:
  75. owner_ids.remove(module_name)
  76. # Detect unused
  77. if owner_ids:
  78. layout.label(text="Unknown add-ons", icon='ERROR')
  79. col = layout.box().column(align=True)
  80. for module_name in sorted(owner_ids):
  81. row = col.row()
  82. row.alignment = 'LEFT'
  83. row.operator(
  84. "wm.owner_disable",
  85. icon='CHECKBOX_HLT',
  86. text=module_name,
  87. emboss=False,
  88. ).owner_id = module_name
  89. class WORKSPACE_PT_custom_props(WorkSpaceButtonsPanel, PropertyPanel, Panel):
  90. bl_parent_id = "WORKSPACE_PT_main"
  91. _context_path = "workspace"
  92. _property_type = bpy.types.WorkSpace
  93. classes = (
  94. WORKSPACE_PT_main,
  95. WORKSPACE_PT_addons,
  96. WORKSPACE_PT_custom_props,
  97. )
  98. if __name__ == "__main__": # only for live edit.
  99. from bpy.utils import register_class
  100. for cls in classes:
  101. register_class(cls)