mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Merge branch 'develop' of github.com:pypeclub/pype into feature/sync_server_priority
This commit is contained in:
commit
4ab81a9b6b
29 changed files with 950 additions and 761 deletions
|
|
@ -9,6 +9,7 @@ from .settings import get_project_settings
|
|||
from .lib import (
|
||||
Anatomy,
|
||||
filter_pyblish_plugins,
|
||||
set_plugin_attributes_from_settings,
|
||||
change_timer_to_current_context
|
||||
)
|
||||
|
||||
|
|
@ -58,38 +59,8 @@ def patched_discover(superclass):
|
|||
# run original discover and get plugins
|
||||
plugins = _original_discover(superclass)
|
||||
|
||||
# determine host application to use for finding presets
|
||||
if avalon.registered_host() is None:
|
||||
return plugins
|
||||
host = avalon.registered_host().__name__.split(".")[-1]
|
||||
set_plugin_attributes_from_settings(plugins, superclass)
|
||||
|
||||
# map plugin superclass to preset json. Currenly suppoted is load and
|
||||
# create (avalon.api.Loader and avalon.api.Creator)
|
||||
plugin_type = "undefined"
|
||||
if superclass.__name__.split(".")[-1] == "Loader":
|
||||
plugin_type = "load"
|
||||
elif superclass.__name__.split(".")[-1] == "Creator":
|
||||
plugin_type = "create"
|
||||
|
||||
print(">>> Finding presets for {}:{} ...".format(host, plugin_type))
|
||||
try:
|
||||
settings = (
|
||||
get_project_settings(os.environ['AVALON_PROJECT'])
|
||||
[host][plugin_type]
|
||||
)
|
||||
except KeyError:
|
||||
print("*** no presets found.")
|
||||
else:
|
||||
for plugin in plugins:
|
||||
if plugin.__name__ in settings:
|
||||
print(">>> We have preset for {}".format(plugin.__name__))
|
||||
for option, value in settings[plugin.__name__].items():
|
||||
if option == "enabled" and value is False:
|
||||
setattr(plugin, "active", False)
|
||||
print(" - is disabled by preset")
|
||||
else:
|
||||
setattr(plugin, option, value)
|
||||
print(" - setting `{}`: `{}`".format(option, value))
|
||||
return plugins
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ from .plugin_tools import (
|
|||
TaskNotSetError,
|
||||
get_subset_name,
|
||||
filter_pyblish_plugins,
|
||||
set_plugin_attributes_from_settings,
|
||||
source_hash,
|
||||
get_unique_layer_name,
|
||||
get_background_layers,
|
||||
|
|
@ -207,6 +208,7 @@ __all__ = [
|
|||
"TaskNotSetError",
|
||||
"get_subset_name",
|
||||
"filter_pyblish_plugins",
|
||||
"set_plugin_attributes_from_settings",
|
||||
"source_hash",
|
||||
"get_unique_layer_name",
|
||||
"get_background_layers",
|
||||
|
|
|
|||
|
|
@ -150,6 +150,95 @@ def filter_pyblish_plugins(plugins):
|
|||
setattr(plugin, option, value)
|
||||
|
||||
|
||||
def set_plugin_attributes_from_settings(
|
||||
plugins, superclass, host_name=None, project_name=None
|
||||
):
|
||||
"""Change attribute values on Avalon plugins by project settings.
|
||||
|
||||
This function should be used only in host context. Modify
|
||||
behavior of plugins.
|
||||
|
||||
Args:
|
||||
plugins (list): Plugins discovered by origin avalon discover method.
|
||||
superclass (object): Superclass of plugin type (e.g. Cretor, Loader).
|
||||
host_name (str): Name of host for which plugins are loaded and from.
|
||||
Value from environment `AVALON_APP` is used if not entered.
|
||||
project_name (str): Name of project for which settings will be loaded.
|
||||
Value from environment `AVALON_PROJECT` is used if not entered.
|
||||
"""
|
||||
|
||||
# determine host application to use for finding presets
|
||||
if host_name is None:
|
||||
host_name = os.environ.get("AVALON_APP")
|
||||
|
||||
if project_name is None:
|
||||
project_name = os.environ.get("AVALON_PROJECT")
|
||||
|
||||
# map plugin superclass to preset json. Currenly suppoted is load and
|
||||
# create (avalon.api.Loader and avalon.api.Creator)
|
||||
plugin_type = None
|
||||
if superclass.__name__.split(".")[-1] == "Loader":
|
||||
plugin_type = "load"
|
||||
elif superclass.__name__.split(".")[-1] == "Creator":
|
||||
plugin_type = "create"
|
||||
|
||||
if not host_name or not project_name or plugin_type is None:
|
||||
msg = "Skipped attributes override from settings."
|
||||
if not host_name:
|
||||
msg += " Host name is not defined."
|
||||
|
||||
if not project_name:
|
||||
msg += " Project name is not defined."
|
||||
|
||||
if plugin_type is None:
|
||||
msg += " Plugin type is unsupported for class {}.".format(
|
||||
superclass.__name__
|
||||
)
|
||||
|
||||
print(msg)
|
||||
return
|
||||
|
||||
print(">>> Finding presets for {}:{} ...".format(host_name, plugin_type))
|
||||
|
||||
project_settings = get_project_settings(project_name)
|
||||
plugin_type_settings = (
|
||||
project_settings
|
||||
.get(host_name, {})
|
||||
.get(plugin_type, {})
|
||||
)
|
||||
global_type_settings = (
|
||||
project_settings
|
||||
.get("global", {})
|
||||
.get(plugin_type, {})
|
||||
)
|
||||
if not global_type_settings and not plugin_type_settings:
|
||||
return
|
||||
|
||||
for plugin in plugins:
|
||||
plugin_name = plugin.__name__
|
||||
|
||||
plugin_settings = None
|
||||
# Look for plugin settings in host specific settings
|
||||
if plugin_name in plugin_type_settings:
|
||||
plugin_settings = plugin_type_settings[plugin_name]
|
||||
|
||||
# Look for plugin settings in global settings
|
||||
elif plugin_name in global_type_settings:
|
||||
plugin_settings = global_type_settings[plugin_name]
|
||||
|
||||
if not plugin_settings:
|
||||
continue
|
||||
|
||||
print(">>> We have preset for {}".format(plugin_name))
|
||||
for option, value in plugin_settings.items():
|
||||
if option == "enabled" and value is False:
|
||||
setattr(plugin, "active", False)
|
||||
print(" - is disabled by preset")
|
||||
else:
|
||||
setattr(plugin, option, value)
|
||||
print(" - setting `{}`: `{}`".format(option, value))
|
||||
|
||||
|
||||
def source_hash(filepath, *args):
|
||||
"""Generate simple identifier for a source file.
|
||||
This is used to identify whether a source file has previously been
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ class ModifiableDictEmptyItem(QtWidgets.QWidget):
|
|||
super(ModifiableDictEmptyItem, self).__init__(parent)
|
||||
self.entity_widget = entity_widget
|
||||
self.collapsible_key = entity_widget.entity.collapsible_key
|
||||
self.ignore_input_changes = entity_widget.ignore_input_changes
|
||||
|
||||
self.is_duplicated = False
|
||||
self.key_is_valid = False
|
||||
|
|
@ -101,6 +102,10 @@ class ModifiableDictEmptyItem(QtWidgets.QWidget):
|
|||
def _on_key_change(self):
|
||||
key = self.key_input.text()
|
||||
self.key_is_valid = KEY_REGEX.match(key)
|
||||
|
||||
if self.ignore_input_changes:
|
||||
return
|
||||
|
||||
self.is_duplicated = self.entity_widget.is_key_duplicated(key)
|
||||
key_input_state = ""
|
||||
# Collapsible key and empty key are not invalid
|
||||
|
|
@ -355,6 +360,7 @@ class ModifiableDictItem(QtWidgets.QWidget):
|
|||
def set_label(self, label):
|
||||
if self.key_label_input and label is not None:
|
||||
self.key_label_input.setText(label)
|
||||
self.update_key_label()
|
||||
|
||||
def set_as_required(self, key):
|
||||
self.key_input.setText(key)
|
||||
|
|
@ -386,6 +392,9 @@ class ModifiableDictItem(QtWidgets.QWidget):
|
|||
self.set_edit_mode(False)
|
||||
|
||||
def _on_key_label_change(self):
|
||||
if self.ignore_input_changes:
|
||||
return
|
||||
|
||||
label = self.key_label_value()
|
||||
self.entity_widget.change_label(label, self)
|
||||
self.update_key_label()
|
||||
|
|
@ -393,6 +402,10 @@ class ModifiableDictItem(QtWidgets.QWidget):
|
|||
def _on_key_change(self):
|
||||
key = self.key_value()
|
||||
self.key_is_valid = KEY_REGEX.match(key)
|
||||
|
||||
if self.ignore_input_changes:
|
||||
return
|
||||
|
||||
is_key_duplicated = self.entity_widget.validate_key_duplication(
|
||||
self.temp_key, key, self
|
||||
)
|
||||
|
|
@ -422,7 +435,7 @@ class ModifiableDictItem(QtWidgets.QWidget):
|
|||
self.wrapper_widget.label_widget.setText(label)
|
||||
|
||||
def on_add_clicked(self):
|
||||
widget = self.entity_widget.add_new_key(None, None, self)
|
||||
widget = self.entity_widget.add_new_key(None, None)
|
||||
widget.key_input.setFocus(True)
|
||||
|
||||
def on_edit_pressed(self):
|
||||
|
|
@ -621,7 +634,7 @@ class DictMutableKeysWidget(BaseWidget):
|
|||
# TODO implement
|
||||
pass
|
||||
|
||||
def add_new_key(self, key, label=None, after_widget=None):
|
||||
def add_new_key(self, key, label=None):
|
||||
uuid_key = None
|
||||
entity_key = key
|
||||
if not key:
|
||||
|
|
@ -641,7 +654,7 @@ class DictMutableKeysWidget(BaseWidget):
|
|||
|
||||
# Backup solution (for testing)
|
||||
if input_field is None:
|
||||
input_field = self.add_widget_for_child(child_entity, after_widget)
|
||||
input_field = self.add_widget_for_child(child_entity)
|
||||
|
||||
if key:
|
||||
# Happens when created from collapsible key items where key
|
||||
|
|
@ -719,29 +732,16 @@ class DictMutableKeysWidget(BaseWidget):
|
|||
return
|
||||
self.entity.set_child_label(entity, label)
|
||||
|
||||
def add_widget_for_child(
|
||||
self, child_entity, after_widget=None, first=False
|
||||
):
|
||||
if first:
|
||||
new_widget_index = 0
|
||||
else:
|
||||
new_widget_index = len(self.input_fields)
|
||||
|
||||
if self.input_fields and not first:
|
||||
if not after_widget:
|
||||
after_widget = self.input_fields[-1]
|
||||
|
||||
for idx in range(self.content_layout.count()):
|
||||
item = self.content_layout.itemAt(idx)
|
||||
if item.widget() is after_widget:
|
||||
new_widget_index = idx + 1
|
||||
break
|
||||
|
||||
def add_widget_for_child(self, child_entity):
|
||||
input_field = ModifiableDictItem(
|
||||
self.entity.collapsible_key, child_entity, self
|
||||
)
|
||||
self.input_fields.append(input_field)
|
||||
|
||||
new_widget_index = self.content_layout.count() - 1
|
||||
|
||||
self.content_layout.insertWidget(new_widget_index, input_field)
|
||||
|
||||
return input_field
|
||||
|
||||
def remove_row(self, widget):
|
||||
|
|
@ -810,21 +810,15 @@ class DictMutableKeysWidget(BaseWidget):
|
|||
|
||||
for key, child_entity in self.entity.items():
|
||||
found = False
|
||||
previous_input = None
|
||||
for input_field in self.input_fields:
|
||||
if input_field.entity is not child_entity:
|
||||
previous_input = input_field
|
||||
else:
|
||||
if input_field.entity is child_entity:
|
||||
found = True
|
||||
break
|
||||
|
||||
if not found:
|
||||
changed = True
|
||||
args = [previous_input]
|
||||
if previous_input is None:
|
||||
args.append(True)
|
||||
|
||||
_input_field = self.add_widget_for_child(child_entity, *args)
|
||||
_input_field = self.add_widget_for_child(child_entity)
|
||||
_input_field.origin_key = key
|
||||
_input_field.set_key(key)
|
||||
if self.entity.collapsible_key:
|
||||
|
|
@ -855,9 +849,8 @@ class DictMutableKeysWidget(BaseWidget):
|
|||
if keys_order:
|
||||
last_required = keys_order[-1]
|
||||
for key in self.entity.keys():
|
||||
if key in keys_order:
|
||||
continue
|
||||
keys_order.append(key)
|
||||
if key not in keys_order:
|
||||
keys_order.append(key)
|
||||
|
||||
for key in keys_order:
|
||||
child_entity = self.entity[key]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue