2023-08-16 00:20:26 +10:00
|
|
|
# SPDX-FileCopyrightText: 2009-2023 Blender Authors
|
2023-06-15 13:09:04 +10:00
|
|
|
#
|
2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2023-06-15 13:09:04 +10:00
|
|
|
|
2017-10-16 17:15:03 -02:00
|
|
|
import bpy
|
|
|
|
|
from bpy.types import (
|
2018-06-01 18:44:06 +02:00
|
|
|
Panel,
|
|
|
|
|
)
|
2022-11-16 12:06:14 +01:00
|
|
|
from bpy.app.translations import pgettext_iface as iface_
|
2017-10-16 17:15:03 -02:00
|
|
|
|
|
|
|
|
from rna_prop_ui import PropertyPanel
|
|
|
|
|
|
2019-05-22 00:27:01 +10:00
|
|
|
|
2017-10-16 17:15:03 -02:00
|
|
|
class WorkSpaceButtonsPanel:
|
2019-05-10 13:43:07 +10:00
|
|
|
# bl_space_type = 'PROPERTIES'
|
|
|
|
|
# bl_region_type = 'WINDOW'
|
|
|
|
|
# bl_context = ".workspace"
|
|
|
|
|
|
|
|
|
|
# Developer note: this is displayed in tool settings as well as the 3D view.
|
|
|
|
|
bl_space_type = 'VIEW_3D'
|
|
|
|
|
bl_region_type = 'UI'
|
|
|
|
|
bl_category = "Tool"
|
2017-10-16 17:15:03 -02:00
|
|
|
|
|
|
|
|
|
2018-08-30 13:30:16 +10:00
|
|
|
class WORKSPACE_PT_main(WorkSpaceButtonsPanel, Panel):
|
|
|
|
|
bl_label = "Workspace"
|
|
|
|
|
bl_options = {'DEFAULT_CLOSED'}
|
|
|
|
|
|
|
|
|
|
def draw(self, context):
|
2018-08-21 15:27:29 +02:00
|
|
|
workspace = context.workspace
|
|
|
|
|
|
|
|
|
|
layout = self.layout
|
|
|
|
|
layout.use_property_split = True
|
2019-05-13 16:45:30 +10:00
|
|
|
layout.use_property_decorate = False
|
2022-07-07 17:51:18 +02:00
|
|
|
|
|
|
|
|
layout.prop(workspace, "use_pin_scene")
|
2018-08-21 15:27:29 +02:00
|
|
|
layout.prop(workspace, "object_mode", text="Mode")
|
2018-08-30 13:30:16 +10:00
|
|
|
|
|
|
|
|
|
2018-08-21 15:27:29 +02:00
|
|
|
class WORKSPACE_PT_addons(WorkSpaceButtonsPanel, Panel):
|
|
|
|
|
bl_label = "Filter Add-ons"
|
2018-08-30 13:30:16 +10:00
|
|
|
bl_parent_id = "WORKSPACE_PT_main"
|
2018-03-01 01:26:02 +11:00
|
|
|
|
|
|
|
|
def draw_header(self, context):
|
|
|
|
|
workspace = context.workspace
|
|
|
|
|
self.layout.prop(workspace, "use_filter_by_owner", text="")
|
|
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
|
layout = self.layout
|
|
|
|
|
# align just to pack more tightly
|
|
|
|
|
col = layout.box().column(align=True)
|
|
|
|
|
|
|
|
|
|
workspace = context.workspace
|
2018-12-21 12:47:44 +11:00
|
|
|
prefs = context.preferences
|
2018-03-01 01:26:02 +11:00
|
|
|
|
|
|
|
|
col.active = workspace.use_filter_by_owner
|
|
|
|
|
|
|
|
|
|
import addon_utils
|
2018-03-01 11:20:12 +11:00
|
|
|
addon_map = {mod.__name__: mod for mod in addon_utils.modules()}
|
2018-06-01 18:44:06 +02:00
|
|
|
owner_ids = {owner_id.name for owner_id in workspace.owner_ids}
|
2018-03-01 01:26:02 +11:00
|
|
|
|
2018-12-21 12:47:44 +11:00
|
|
|
for addon in prefs.addons:
|
2018-03-01 01:26:02 +11:00
|
|
|
module_name = addon.module
|
2019-07-07 14:15:28 +10:00
|
|
|
module = addon_map.get(module_name)
|
|
|
|
|
if module is None:
|
|
|
|
|
continue
|
|
|
|
|
info = addon_utils.module_bl_info(module)
|
2018-03-01 01:26:02 +11:00
|
|
|
is_enabled = module_name in owner_ids
|
|
|
|
|
row = col.row()
|
2019-07-07 14:17:33 +10:00
|
|
|
row.alignment = 'LEFT'
|
2018-03-01 01:26:02 +11:00
|
|
|
row.operator(
|
|
|
|
|
"wm.owner_disable" if is_enabled else "wm.owner_enable",
|
|
|
|
|
icon='CHECKBOX_HLT' if is_enabled else 'CHECKBOX_DEHLT',
|
2022-12-05 12:54:00 +11:00
|
|
|
text=iface_("%s: %s") % (iface_(info["category"]), iface_(info["name"])),
|
2022-11-16 12:06:14 +01:00
|
|
|
translate=False,
|
2018-03-01 01:26:02 +11:00
|
|
|
emboss=False,
|
|
|
|
|
).owner_id = module_name
|
|
|
|
|
if is_enabled:
|
|
|
|
|
owner_ids.remove(module_name)
|
|
|
|
|
|
|
|
|
|
# Detect unused
|
|
|
|
|
if owner_ids:
|
|
|
|
|
layout.label(text="Unknown add-ons", icon='ERROR')
|
|
|
|
|
col = layout.box().column(align=True)
|
|
|
|
|
for module_name in sorted(owner_ids):
|
|
|
|
|
row = col.row()
|
2019-07-07 14:17:33 +10:00
|
|
|
row.alignment = 'LEFT'
|
2018-03-01 01:26:02 +11:00
|
|
|
row.operator(
|
|
|
|
|
"wm.owner_disable",
|
|
|
|
|
icon='CHECKBOX_HLT',
|
2019-07-07 14:17:33 +10:00
|
|
|
text=module_name,
|
2018-03-01 01:26:02 +11:00
|
|
|
emboss=False,
|
|
|
|
|
).owner_id = module_name
|
|
|
|
|
|
|
|
|
|
|
2017-10-16 17:15:03 -02:00
|
|
|
class WORKSPACE_PT_custom_props(WorkSpaceButtonsPanel, PropertyPanel, Panel):
|
2018-08-30 13:30:16 +10:00
|
|
|
bl_parent_id = "WORKSPACE_PT_main"
|
|
|
|
|
|
2017-10-16 17:15:03 -02:00
|
|
|
_context_path = "workspace"
|
|
|
|
|
_property_type = bpy.types.WorkSpace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes = (
|
2018-08-30 13:30:16 +10:00
|
|
|
WORKSPACE_PT_main,
|
2018-08-21 15:27:29 +02:00
|
|
|
WORKSPACE_PT_addons,
|
2017-10-16 17:15:03 -02:00
|
|
|
WORKSPACE_PT_custom_props,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": # only for live edit.
|
|
|
|
|
from bpy.utils import register_class
|
|
|
|
|
for cls in classes:
|
|
|
|
|
register_class(cls)
|