Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHOT-2850 Small update to the task_required UI display #130

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
103 changes: 87 additions & 16 deletions python/tk_multi_publish2/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,36 @@ def _create_item_details(self, tree_item):
self.ui.context_widget.show()

if item.context_change_allowed:
self.ui.context_widget.enable_editing(
True, "<p>Task and Entity Link to apply to the selected item:</p>"
)
# Check for task_required and change UI styling accordingly
if not self._validate_task_required():
# Change task label color to SG_ALERT_COLOR
self.ui.context_widget.ui.task_label.setStyleSheet(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I mentioned bellow, I'm not sure it's a good idea to go via the context_widget.ui, the widgets in there might get updated. Though it looks like this particular label is not exposed publicly.

I guess the correct thing to do would be to update the qtwidgets framework to publicly expose that label.
@jfboismenu what do you think?

"color: "
+ sgtk.platform.current_bundle().style_constants[
"SG_ALERT_COLOR"
]
)
# Also change the text and color of the label
# Use SG_HIGHLIGHT_COLOR for better readability
self.ui.context_widget.enable_editing(
True,
"<p>Task Required is <b>True</b> in your configuration. "
"Please select a Task to continue.</p>",
)
self.ui.context_widget.ui.label.setStyleSheet(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be able to use context_widget.context_label instead of going via the ui attribute?
I'm uncomfortable with us using the .ui property as that is not intended to be public .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also could the color be set through the enable_editing, via html tags? That would save you having to modify the stylesheet.

"color: "
+ sgtk.platform.current_bundle().style_constants[
"SG_HIGHLIGHT_COLOR"
]
)
else:
self.ui.context_widget.enable_editing(
True,
"<p>Task and Entity Link to apply to the selected item:</p>",
)
# Ensure styling overrides are cleared
self.ui.context_widget.ui.task_label.setStyleSheet("")
self.ui.context_widget.ui.label.setStyleSheet("")
else:
self.ui.context_widget.enable_editing(
False,
Expand Down Expand Up @@ -787,17 +814,63 @@ def _create_master_summary_details(self):
# the summary view's context widget
context_key = list(current_contexts.keys())[0]
self.ui.context_widget.set_context(current_contexts[context_key])
context_label_text = "Task and Entity Link to apply to all items:"
# Check for task_required and change UI styling accordingly
if not self._validate_task_required():
# Change task label color to SG_ALERT_COLOR
self.ui.context_widget.ui.task_label.setStyleSheet(
"color: "
+ sgtk.platform.current_bundle().style_constants["SG_ALERT_COLOR"]
)
# Also change the text and color of the label
# Use SG_HIGHLIGHT_COLOR for better readability
context_label_text = (
"<p>Task Required is <b>True</b> in your configuration. "
"Please confirm all Tasks are assigned to continue.</p>"
)
self.ui.context_widget.ui.label.setStyleSheet(
"color: "
+ sgtk.platform.current_bundle().style_constants[
"SG_HIGHLIGHT_COLOR"
]
)
else:
context_label_text = "Task and Entity Link to apply to all items:"
# Ensure styling overrides are cleared
self.ui.context_widget.ui.label.setStyleSheet("")
self.ui.context_widget.ui.task_label.setStyleSheet("")
Comment on lines +817 to +840
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the context_label_text text this looks like a duplication of the code at line 847-873, I wonder if this could be turned into a method?

else:
self.ui.context_widget.set_context(
None,
task_display_override=" -- Multiple values -- ",
link_display_override=" -- Multiple values -- ",
)
context_label_text = (
"Currently publishing items to %s contexts. "
"Override all items here:" % (len(current_contexts),)
)
# Check for task_required and change UI styling accordingly
if not self._validate_task_required():
# Change task label color to SG_ALERT_COLOR
self.ui.context_widget.ui.task_label.setStyleSheet(
"color: "
+ sgtk.platform.current_bundle().style_constants["SG_ALERT_COLOR"]
)
# Also change the text and color of the label
# Use SG_HIGHLIGHT_COLOR for better readability
context_label_text = (
"<p>Task Required is <b>True</b> in your configuration. "
"Please confirm all Tasks are assigned to continue.</p>"
)
self.ui.context_widget.ui.label.setStyleSheet(
"color: "
+ sgtk.platform.current_bundle().style_constants[
"SG_HIGHLIGHT_COLOR"
]
)
else:
context_label_text = (
"Currently publishing items to %s contexts. "
"Override all items here:" % (len(current_contexts),)
)
# Ensure styling overrides are cleared
self.ui.context_widget.ui.label.setStyleSheet("")
self.ui.context_widget.ui.task_label.setStyleSheet("")

self.ui.context_widget.show()
self.ui.context_widget.enable_editing(True, context_label_text)
Expand Down Expand Up @@ -1554,6 +1627,8 @@ def _on_item_context_change(self, context):

# Make the task validation if the setting `task_required` exists and it's True
self._validate_task_required()
# Re-draw the summary for styling updates
self._create_master_summary_details()

def _on_browse(self, folders=False):
"""Opens a file dialog to browse to files for publishing."""
Expand Down Expand Up @@ -1637,12 +1712,11 @@ def _show_no_items_error(self):
def _validate_task_required(self):
"""
Validates that a task is selected for every item and disables/enables the
validate and publish buttons and finally change the color for the task
label.
validate and publish buttons
"""
# Avoid validation if the setting `task_required` is False or not exists
if not self._bundle.get_setting("task_required"):
return
return True

all_items_selected_task = True
for context_index in range(self.ui.items_tree.topLevelItemCount()):
Expand All @@ -1656,15 +1730,12 @@ def _validate_task_required(self):
# disable buttons
self.ui.publish.setEnabled(False)
self.ui.validate.setEnabled(False)
# change task label color to RED
self.ui.context_widget.ui.task_label.setStyleSheet("color: red")
return False
else:
# enable buttons
self.ui.publish.setEnabled(True)
self.ui.validate.setEnabled(True)

# change task label color to the default value
self.ui.context_widget.ui.task_label.setStyleSheet("")
return True


class _TaskSelection(object):
Expand Down