|
| 1 | +# Copyright (c) 2026 Autodesk. |
| 2 | +# |
| 3 | +# CONFIDENTIAL AND PROPRIETARY |
| 4 | +# |
| 5 | +# This work is provided "AS IS" and subject to the ShotGrid Pipeline Toolkit |
| 6 | +# Source Code License included in this distribution package. See LICENSE. |
| 7 | +# By accessing, using, copying or modifying this work you indicate your |
| 8 | +# agreement to the ShotGrid Pipeline Toolkit Source Code License. All rights |
| 9 | +# not expressly granted therein are reserved by Autodesk. |
| 10 | +"""Hook that defines how the command/action to show the publish dialog is displayed. |
| 11 | +
|
| 12 | +The output of methods in this hook are used as follows when calling |
| 13 | +`.sgtk.platform.Application.register_command`:: |
| 14 | +
|
| 15 | + app.register_command( |
| 16 | + app.execute_hook_method("display_hook", "menu_name"), |
| 17 | + ..., |
| 18 | + properties=app.execute_hook_method("display_hook", "menu_properties"), |
| 19 | + ) |
| 20 | +""" |
| 21 | + |
| 22 | +import os |
| 23 | +import re |
| 24 | +from typing import Any |
| 25 | + |
| 26 | +import sgtk |
| 27 | + |
| 28 | +HookBaseClass = sgtk.get_hook_baseclass() |
| 29 | + |
| 30 | + |
| 31 | +class DisplayHook(HookBaseClass): |
| 32 | + """Hook that defines how the action to show the publish dialog is displayed.""" |
| 33 | + |
| 34 | + @property |
| 35 | + def settings(self) -> dict[str, Any]: |
| 36 | + """Return the settings that are available for this hook.""" |
| 37 | + return self.parent.get_setting("display").get("settings") or {} |
| 38 | + |
| 39 | + @property |
| 40 | + def action_name(self) -> str: |
| 41 | + """Create text used when inferring to the "Publish" action in the GUI.""" |
| 42 | + return self.parent.get_setting("display_action_name") |
| 43 | + |
| 44 | + @property |
| 45 | + def button_name(self) -> str: |
| 46 | + """Create the label text used when for "Publish" button.""" |
| 47 | + return self.action_name |
| 48 | + |
| 49 | + @property |
| 50 | + def menu_name(self) -> str: |
| 51 | + """Create the command name used when registering the show dialog command.""" |
| 52 | + return f"{self.parent.get_setting('display_name')}..." |
| 53 | + |
| 54 | + @property |
| 55 | + def menu_properties(self) -> dict[str, Any]: |
| 56 | + """Create the properties used when registering the show dialog command. |
| 57 | +
|
| 58 | + See expected property details at `.sgtk.platform.Application.register_command`. |
| 59 | + """ |
| 60 | + display_name = self.parent.get_setting("display_name") |
| 61 | + command_name = re.sub(r"[^0-9a-zA-Z]+", "_", display_name.lower()) |
| 62 | + |
| 63 | + return { |
| 64 | + "short_name": command_name, |
| 65 | + "description": "Publishing of data to Flow Production Tracking", |
| 66 | + "icons": { |
| 67 | + "dark": { |
| 68 | + "png": os.path.join(self.parent.disk_location, "icon_256_dark.png") |
| 69 | + } |
| 70 | + }, |
| 71 | + } |
0 commit comments