Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3686 from pypeclub/feature/benevolent_context_lab…
Browse files Browse the repository at this point in the history
…le_collector

General: Benevolent context label collector
  • Loading branch information
iLLiCiTiT authored Aug 26, 2022
2 parents 52fdba8 + 8539c03 commit 0050b94
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
34 changes: 23 additions & 11 deletions openpype/plugins/publish/collect_context_label.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Requires:
Optional:
context -> hostName (str)
context -> currentFile (str)
Provides:
context -> label (str)
Expand All @@ -16,16 +17,27 @@ class CollectContextLabel(pyblish.api.ContextPlugin):
label = "Context Label"

def process(self, context):

# Get last registered host
host = pyblish.api.registered_hosts()[-1]

# Get scene name from "currentFile"
path = context.data.get("currentFile") or "<Unsaved>"
base = os.path.basename(path)
# Add ability to use custom context label
label = context.data.get("label")
if label:
self.log.debug("Context label is already set to \"{}\"".format(
label
))
return

host_name = context.data.get("hostName")
if not host_name:
host_name = pyblish.api.registered_hosts()[-1]
# Use host name as base for label
label = host_name.title()

# Get scene name from "currentFile" and use basename as ending of label
path = context.data.get("currentFile")
if path:
label += " - {}".format(os.path.basename(path))

# Set label
label = "{host} - {scene}".format(host=host.title(), scene=base)
if host == "standalonepublisher":
label = host.title()
context.data["label"] = label
self.log.debug("Context label is changed to \"{}\"".format(
label
))
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, report_data):

context_data = data["context"]
context_data["name"] = "context"
context_data["label"] = context_data["label"] or "Context"
context_data["label"] = context_data.get("label") or "Context"

logs = []
plugins_items_by_id = {}
Expand Down
2 changes: 0 additions & 2 deletions openpype/tools/publisher/widgets/publish_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,12 @@ def _on_instance_change(self, context, instance):
if instance is None:
new_name = (
context.data.get("label")
or getattr(context, "label", None)
or context.data.get("name")
or "Context"
)
else:
new_name = (
instance.data.get("label")
or getattr(instance, "label", None)
or instance.data["name"]
)

Expand Down
1 change: 0 additions & 1 deletion openpype/tools/pyblish_pype/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ def reset_context(self):
self.context.optional = False

self.context.data["publish"] = True
self.context.data["label"] = "Context"
self.context.data["name"] = "context"

self.context.data["host"] = reversed(pyblish.api.registered_hosts())
Expand Down
16 changes: 9 additions & 7 deletions openpype/tools/pyblish_pype/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,6 @@ def __init__(self, instance):
instance._logs = []
instance.optional = getattr(instance, "optional", True)
instance.data["publish"] = instance.data.get("publish", True)
instance.data["label"] = (
instance.data.get("label")
or getattr(instance, "label", None)
or instance.data["name"]
)

family = self.data(Roles.FamiliesRole)[0]
self.setData(
Expand All @@ -616,9 +611,16 @@ def type(self):

def data(self, role=QtCore.Qt.DisplayRole):
if role == QtCore.Qt.DisplayRole:
label = None
if settings.UseLabel:
return self.instance.data["label"]
return self.instance.data["name"]
label = self.instance.data.get("label")

if not label:
if self.is_context:
label = "Context"
else:
label = self.instance.data["name"]
return label

if role == QtCore.Qt.DecorationRole:
icon_name = self.instance.data.get("icon") or "file"
Expand Down

0 comments on commit 0050b94

Please sign in to comment.