2017-10-16 17:15:03 -02:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
|
|
|
# <pep8 compliant>
|
|
|
|
import bpy
|
|
|
|
from bpy.types import (
|
2018-06-01 18:44:06 +02:00
|
|
|
Panel,
|
|
|
|
)
|
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
|
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',
|
2019-07-07 14:17:33 +10:00
|
|
|
text="%s: %s" % (info["category"], info["name"]),
|
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)
|