tray publisher can be enabled using loclal settings

This commit is contained in:
Jakub Trllo 2022-02-24 11:49:44 +01:00
parent 68cf09d61c
commit 4e9131ccd8
7 changed files with 91 additions and 82 deletions

View file

@ -122,6 +122,7 @@ class ITrayAction(ITrayModule):
admin_action = False
_admin_submenu = None
_action_item = None
@property
@abstractmethod
@ -149,6 +150,7 @@ class ITrayAction(ITrayModule):
tray_menu.addAction(action)
action.triggered.connect(self.on_action_trigger)
self._action_item = action
def tray_start(self):
return

View file

@ -11,7 +11,7 @@ class TrayPublishAction(OpenPypeModule, ITrayAction):
def initialize(self, modules_settings):
import openpype
self.enabled = modules_settings[self.name]["enabled"]
self.enabled = True
self.publish_paths = [
os.path.join(
openpype.PACKAGE_DIR,
@ -21,9 +21,20 @@ class TrayPublishAction(OpenPypeModule, ITrayAction):
"publish"
)
]
self._experimental_tools = None
def tray_init(self):
return
from openpype.tools.experimental_tools import ExperimentalTools
self._experimental_tools = ExperimentalTools()
def tray_menu(self, *args, **kwargs):
super(TrayPublishAction, self).tray_menu(*args, **kwargs)
traypublisher = self._experimental_tools.get("traypublisher")
visible = False
if traypublisher and traypublisher.enabled:
visible = True
self._action_item.setVisible(visible)
def on_action_trigger(self):
self.run_traypublisher()

View file

@ -191,9 +191,6 @@
"standalonepublish_tool": {
"enabled": true
},
"traypublish_tool": {
"enabled": false
},
"project_manager": {
"enabled": true
},

View file

@ -233,20 +233,6 @@
}
]
},
{
"type": "dict",
"key": "traypublish_tool",
"label": "Tray Publish (beta)",
"collapsible": true,
"checkbox_key": "enabled",
"children": [
{
"type": "boolean",
"key": "enabled",
"label": "Enabled"
}
]
},
{
"type": "dict",
"key": "project_manager",

View file

@ -82,7 +82,7 @@ class ExperimentalToolsDialog(QtWidgets.QDialog):
tool_btns_layout.addWidget(tool_btns_label, 0)
experimental_tools = ExperimentalTools(
parent=parent, filter_hosts=True
parent_widget=parent, refresh=False
)
# Main layout
@ -116,7 +116,8 @@ class ExperimentalToolsDialog(QtWidgets.QDialog):
self._experimental_tools.refresh_availability()
buttons_to_remove = set(self._buttons_by_tool_identifier.keys())
for idx, tool in enumerate(self._experimental_tools.tools):
tools = self._experimental_tools.get_tools_for_host()
for idx, tool in enumerate(tools):
identifier = tool.identifier
if identifier in buttons_to_remove:
buttons_to_remove.remove(identifier)

View file

@ -5,7 +5,32 @@ from openpype.settings import get_local_settings
LOCAL_EXPERIMENTAL_KEY = "experimental_tools"
class ExperimentalTool:
class ExperimentalTool(object):
"""Definition of experimental tool.
Definition is used in local settings.
Args:
identifier (str): String identifier of tool (unique).
label (str): Label shown in UI.
"""
def __init__(self, identifier, label, tooltip):
self.identifier = identifier
self.label = label
self.tooltip = tooltip
self._enabled = True
@property
def enabled(self):
"""Is tool enabled and button is clickable."""
return self._enabled
def set_enabled(self, enabled=True):
"""Change if tool is enabled."""
self._enabled = enabled
class ExperimentalHostTool(ExperimentalTool):
"""Definition of experimental tool.
Definition is used in local settings and in experimental tools dialog.
@ -19,12 +44,10 @@ class ExperimentalTool:
Some tools may not be available in all hosts.
"""
def __init__(
self, identifier, label, callback, tooltip, hosts_filter=None
self, identifier, label, tooltip, callback, hosts_filter=None
):
self.identifier = identifier
self.label = label
super(ExperimentalHostTool, self).__init__(identifier, label, tooltip)
self.callback = callback
self.tooltip = tooltip
self.hosts_filter = hosts_filter
self._enabled = True
@ -33,18 +56,9 @@ class ExperimentalTool:
return host_name in self.hosts_filter
return True
@property
def enabled(self):
"""Is tool enabled and button is clickable."""
return self._enabled
def set_enabled(self, enabled=True):
"""Change if tool is enabled."""
self._enabled = enabled
def execute(self):
def execute(self, *args, **kwargs):
"""Trigger registered callback."""
self.callback()
self.callback(*args, **kwargs)
class ExperimentalTools:
@ -53,57 +67,36 @@ class ExperimentalTools:
To add/remove experimental tool just add/remove tool to
`experimental_tools` variable in __init__ function.
Args:
parent (QtWidgets.QWidget): Parent widget for tools.
host_name (str): Name of host in which context we're now. Environment
value 'AVALON_APP' is used when not passed.
filter_hosts (bool): Should filter tools. By default is set to 'True'
when 'host_name' is passed. Is always set to 'False' if 'host_name'
is not defined.
--- Example tool (callback will just print on click) ---
def example_callback(*args):
print("Triggered tool")
experimental_tools = [
ExperimentalHostTool(
"example",
"Example experimental tool",
example_callback,
"Example tool tooltip."
)
]
---
"""
def __init__(self, parent=None, host_name=None, filter_hosts=None):
def __init__(self, parent_widget=None, refresh=True):
# Definition of experimental tools
experimental_tools = [
ExperimentalTool(
ExperimentalHostTool(
"publisher",
"New publisher",
self._show_publisher,
"Combined creation and publishing into one tool."
"Combined creation and publishing into one tool.",
self._show_publisher
),
ExperimentalTool(
"traypublisher",
"New Standalone Publisher",
"Standalone publisher using new publisher. Requires restart"
)
]
# --- Example tool (callback will just print on click) ---
# def example_callback(*args):
# print("Triggered tool")
#
# experimental_tools = [
# ExperimentalTool(
# "example",
# "Example experimental tool",
# example_callback,
# "Example tool tooltip."
# )
# ]
# Try to get host name from env variable `AVALON_APP`
if not host_name:
host_name = os.environ.get("AVALON_APP")
# Decide if filtering by host name should happen
if filter_hosts is None:
filter_hosts = host_name is not None
if filter_hosts and not host_name:
filter_hosts = False
# Filter tools by host name
if filter_hosts:
experimental_tools = [
tool
for tool in experimental_tools
if tool.is_available_for_host(host_name)
]
# Store tools by identifier
tools_by_identifier = {}
for tool in experimental_tools:
@ -115,10 +108,13 @@ class ExperimentalTools:
self._tools_by_identifier = tools_by_identifier
self._tools = experimental_tools
self._parent_widget = parent
self._parent_widget = parent_widget
self._publisher_tool = None
if refresh:
self.refresh_availability()
@property
def tools(self):
"""Tools in list.
@ -139,6 +135,22 @@ class ExperimentalTools:
"""
return self._tools_by_identifier
def get(self, tool_identifier):
"""Get tool by identifier."""
return self.tools_by_identifier.get(tool_identifier)
def get_tools_for_host(self, host_name=None):
if not host_name:
host_name = os.environ.get("AVALON_APP")
tools = []
for tool in self.tools:
if (
isinstance(tool, ExperimentalHostTool)
and tool.is_available_for_host(host_name)
):
tools.append(tool)
return tools
def refresh_availability(self):
"""Reload local settings and check if any tool changed ability."""
local_settings = get_local_settings()

View file

@ -28,7 +28,7 @@ class LocalExperimentalToolsWidgets(QtWidgets.QWidget):
layout.addRow(empty_label)
experimental_defs = ExperimentalTools(filter_hosts=False)
experimental_defs = ExperimentalTools(refresh=False)
checkboxes_by_identifier = {}
for tool in experimental_defs.tools:
checkbox = QtWidgets.QCheckBox(self)