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,
|
2024-01-22 12:44:56 +11:00
|
|
|
UIList,
|
2018-06-01 18:44:06 +02:00
|
|
|
)
|
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")
|
VSE: Scene Selector & Scene Time Synchronization
Implements the proposed design (with some modifications) in #135058.
## Sequencer Scene
This adds a new property called `sequencer_scene` to workspaces. This scene is used
by the video sequence editors in the current workspace for their context.
This is a first step towards "detaching" the VSE from the active scene in the window.
Each sequencer timeline editor shows the sequencer scene that is being used.
By default, when no sequencer scene is selected, the timeline and preview are empty.
Pressing the "new" button will add a new scene and assign it to the sequencer
scene for the current workspace.
## Contextual Playback
Pressing `Space` (by default) for starting the animation playback is now contextual:
depending on the context (where your mouse cursor is), the scene that is played back
might be different. E.g. with a 3D Viewport and a Sequencer open, pressing "play"
in the 3D Viewport will play the _active scene_ of the window, while pressing "play"
in the sequencer will play the _sequencer scene_.
## Time & Scene Synchronization
Additionally, this adds a toggle called "Sync Active Scene".
With the property turned on, the active scene & scene time in the window will be
synced with the time & scene of the current scene strip in the sequencer.
Note that this is _not_ bi-directional. The sequencer can change the active scene
and map time, but it's not possible the other way around since it one can have
multiple strips using the same scene (+camera, and even time!).
Currently this setting is exposed in the footer of the sequencer timeline as well
as in the workspace settings.
This allows for one of the core concepts that the story tools projects aims at: Working
in a scene (e.g. in the 3D viewport) while also working with the edit
(in the sequencer timeline).
## Some technical notes
* Undoing while playback is running will now cancel playback. This is to avoid the timer,
that points to the scene and viewlayer that are playing, to get de-synced after loading
the memfile undo step.
* When the sequencer scene is not the same as the active scene, we ensure it has
a depsgraph.
* Normally, when a `NC_SCENE` notifier points to a specific scene, the notifier is dropped
if that scene doesn't match the active one in the window. We now also check that it
doesn't match the sequencer scene in the active workspace.
* When loading older files, we need to make sure that the active workspace in a window
uses the active scene as the sequencer scene. This is to make sure that the file opens with
the same sequences open.
* Tool settings are stored per scene. To make sure the sequencer uses the tool settings for
the sequencer scene, the "context.tool_settings" and `CTX_data_tool_settings` members
are overridden in the sequence editors.
Pull Request: https://projects.blender.org/blender/blender/pulls/140271
2025-08-25 11:58:17 +02:00
|
|
|
layout.prop(workspace, "sequencer_scene")
|
|
|
|
|
layout.prop(workspace, "use_scene_time_sync")
|
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"
|
2024-01-22 12:03:39 +11:00
|
|
|
addon_map = {}
|
|
|
|
|
owner_ids = set()
|
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
|
|
|
|
|
|
|
|
|
|
workspace = context.workspace
|
2018-12-21 12:47:44 +11:00
|
|
|
prefs = context.preferences
|
2018-03-01 01:26:02 +11:00
|
|
|
|
|
|
|
|
import addon_utils
|
2024-01-22 12:03:39 +11:00
|
|
|
WORKSPACE_PT_addons.addon_map = {mod.__name__: mod for mod in addon_utils.modules()}
|
|
|
|
|
WORKSPACE_PT_addons.owner_ids = {owner_id.name for owner_id in workspace.owner_ids}
|
|
|
|
|
known_addons = set()
|
2018-12-21 12:47:44 +11:00
|
|
|
for addon in prefs.addons:
|
2024-01-22 12:03:39 +11:00
|
|
|
if addon.module in WORKSPACE_PT_addons.owner_ids:
|
|
|
|
|
known_addons.add(addon.module)
|
|
|
|
|
unknown_addons = WORKSPACE_PT_addons.owner_ids.difference(known_addons)
|
|
|
|
|
layout.template_list(
|
|
|
|
|
"WORKSPACE_UL_addons_items",
|
|
|
|
|
"",
|
|
|
|
|
context.preferences,
|
|
|
|
|
"addons",
|
|
|
|
|
context.workspace,
|
|
|
|
|
"active_addon",
|
|
|
|
|
rows=8,
|
|
|
|
|
)
|
2018-03-01 01:26:02 +11:00
|
|
|
# Detect unused
|
2024-01-22 12:03:39 +11:00
|
|
|
if unknown_addons:
|
2018-03-01 01:26:02 +11:00
|
|
|
layout.label(text="Unknown add-ons", icon='ERROR')
|
|
|
|
|
col = layout.box().column(align=True)
|
2024-02-01 17:03:40 +11:00
|
|
|
for addon_module_name in sorted(unknown_addons):
|
2018-03-01 01:26:02 +11:00
|
|
|
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',
|
2024-02-01 17:03:40 +11:00
|
|
|
text=addon_module_name,
|
2018-03-01 01:26:02 +11:00
|
|
|
emboss=False,
|
2024-02-01 17:03:40 +11:00
|
|
|
).owner_id = addon_module_name
|
2018-03-01 01:26:02 +11:00
|
|
|
|
|
|
|
|
|
2024-01-22 12:44:56 +11:00
|
|
|
class WORKSPACE_UL_addons_items(UIList):
|
2024-01-22 12:03:39 +11:00
|
|
|
|
2024-01-22 12:44:54 +11:00
|
|
|
@staticmethod
|
|
|
|
|
def _ui_label_from_addon(addon):
|
|
|
|
|
# Return: `Category: Addon Name` when the add-on is known, otherwise it's module name.
|
|
|
|
|
import addon_utils
|
|
|
|
|
module = WORKSPACE_PT_addons.addon_map.get(addon.module)
|
|
|
|
|
if not module:
|
|
|
|
|
return addon.module
|
2024-02-01 17:03:40 +11:00
|
|
|
bl_info = addon_utils.module_bl_info(module)
|
2024-04-27 16:02:37 +10:00
|
|
|
return "{:s}: {:s}".format(iface_(bl_info["category"]), iface_(bl_info["name"]))
|
2024-01-22 12:03:39 +11:00
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _filter_addons_by_category_name(pattern, bitflag, addons, reverse=False):
|
|
|
|
|
# Set FILTER_ITEM for addons which category and name matches filter_name one (case-insensitive).
|
|
|
|
|
# pattern is the filtering pattern.
|
|
|
|
|
# return a list of flags based on given bit flag, or an empty list if no pattern is given
|
|
|
|
|
# or list addons is empty.
|
|
|
|
|
|
|
|
|
|
if not pattern or not addons: # Empty pattern or list = no filtering!
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
import fnmatch
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
# Implicitly add heading/trailing wildcards.
|
|
|
|
|
pattern_regex = re.compile(fnmatch.translate("*" + pattern + "*"), re.IGNORECASE)
|
|
|
|
|
|
|
|
|
|
flags = [0] * len(addons)
|
|
|
|
|
|
|
|
|
|
for i, addon in enumerate(addons):
|
2024-01-22 12:44:54 +11:00
|
|
|
name = WORKSPACE_UL_addons_items._ui_label_from_addon(addon)
|
2024-01-22 12:03:39 +11:00
|
|
|
# This is similar to a logical XOR.
|
|
|
|
|
if bool(name and pattern_regex.match(name)) is not reverse:
|
|
|
|
|
flags[i] |= bitflag
|
|
|
|
|
return flags
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _sort_addons_by_category_name(addons):
|
|
|
|
|
# Re-order addons using their categories and names (case-insensitive).
|
|
|
|
|
# return a list mapping org_idx -> new_idx, or an empty list if no sorting has been done.
|
2024-01-22 12:44:54 +11:00
|
|
|
_sort = [(idx, WORKSPACE_UL_addons_items._ui_label_from_addon(addon)) for idx, addon in enumerate(addons)]
|
2024-01-22 12:03:39 +11:00
|
|
|
return bpy.types.UI_UL_list.sort_items_helper(_sort, lambda e: e[1].lower())
|
|
|
|
|
|
|
|
|
|
def filter_items(self, _context, data, property):
|
|
|
|
|
addons = getattr(data, property)
|
|
|
|
|
flags = []
|
|
|
|
|
indices = []
|
|
|
|
|
|
|
|
|
|
# Filtering by category and name
|
|
|
|
|
if self.filter_name:
|
|
|
|
|
flags = self._filter_addons_by_category_name(
|
2025-01-14 12:46:40 +11:00
|
|
|
self.filter_name, self.bitflag_filter_item, addons, reverse=self.use_filter_invert,
|
|
|
|
|
)
|
2024-01-22 12:03:39 +11:00
|
|
|
if not flags:
|
|
|
|
|
flags = [self.bitflag_filter_item] * len(addons)
|
|
|
|
|
# Filer addons without registered modules
|
|
|
|
|
for idx, addon in enumerate(addons):
|
|
|
|
|
if not WORKSPACE_PT_addons.addon_map.get(addon.module):
|
|
|
|
|
flags[idx] = 0
|
|
|
|
|
if self.use_filter_sort_alpha:
|
|
|
|
|
indices = self._sort_addons_by_category_name(addons)
|
|
|
|
|
return flags, indices
|
|
|
|
|
|
2024-12-11 11:26:24 +11:00
|
|
|
def draw_item(self, context, layout, _data, addon, _icon, _active_data, _active_propname, _index):
|
2024-01-22 12:03:39 +11:00
|
|
|
row = layout.row()
|
|
|
|
|
row.active = context.workspace.use_filter_by_owner
|
|
|
|
|
row.emboss = 'NONE'
|
2024-01-22 12:44:54 +11:00
|
|
|
row.label(text=WORKSPACE_UL_addons_items._ui_label_from_addon(addon))
|
2024-01-22 12:03:39 +11:00
|
|
|
row = row.row()
|
|
|
|
|
row.alignment = 'RIGHT'
|
|
|
|
|
is_enabled = addon.module in WORKSPACE_PT_addons.owner_ids
|
|
|
|
|
row.operator(
|
|
|
|
|
"wm.owner_disable" if is_enabled else "wm.owner_enable",
|
|
|
|
|
icon='CHECKBOX_HLT' if is_enabled else 'CHECKBOX_DEHLT',
|
|
|
|
|
text="",
|
|
|
|
|
).owner_id = addon.module
|
|
|
|
|
|
|
|
|
|
|
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 = (
|
2024-01-22 12:03:39 +11:00
|
|
|
WORKSPACE_UL_addons_items,
|
|
|
|
|
|
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,
|
|
|
|
|
)
|
|
|
|
|
|
2024-01-22 12:03:39 +11:00
|
|
|
|
|
|
|
|
bpy.types.WorkSpace.active_addon = bpy.props.IntProperty(
|
2025-01-14 12:46:40 +11:00
|
|
|
name="Active Add-on",
|
|
|
|
|
description="Active Add-on in the Workspace Add-ons filter",
|
|
|
|
|
)
|
2024-01-22 12:03:39 +11:00
|
|
|
|
|
|
|
|
|
2017-10-16 17:15:03 -02:00
|
|
|
if __name__ == "__main__": # only for live edit.
|
|
|
|
|
from bpy.utils import register_class
|
|
|
|
|
for cls in classes:
|
|
|
|
|
register_class(cls)
|