-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathapp.py
More file actions
125 lines (107 loc) · 5.12 KB
/
Copy pathapp.py
File metadata and controls
125 lines (107 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Copyright (c) 2015 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.
"""
A loader application that lets you add new items to the scene.
"""
from types import ModuleType
import sgtk
import os
class MultiLoader(sgtk.platform.Application):
def init_app(self):
"""
Called as the application is being initialized
"""
# We won't be able to do anything if there's no UI. The import
# of our tk-multi-loader module below required some Qt components,
# and will likely blow up.
if not self.engine.has_ui:
return
tk_multi_loader = self.import_module("tk_multi_loader")
self._flowam = tk_multi_loader.flowam
# the manager class provides the interface for loading. We store a
# reference to it to enable the create_loader_action_manager method exposed on
# the application itself
self._manager_class = tk_multi_loader.LoaderManager
# register command
cb = lambda: tk_multi_loader.show_dialog(self)
menu_caption = "%s..." % self.get_setting("menu_name")
menu_options = {
"short_name": self.get_setting("menu_name").replace(" ", "_"),
# dark themed icon for engines that recognize this format
"icons": {
"dark": {
"png": os.path.join(
os.path.dirname(__file__),
"resources",
"load_menu_icon.png",
),
}
},
}
self.engine.register_command(menu_caption, cb, menu_options)
@property
def context_change_allowed(self):
"""
Specifies that context changes are allowed.
"""
return True
def open_publish(self, title="Open Publish", action="Open", publish_types=None):
"""
Display the loader UI in an open-file style where a publish can be selected and the
artist can then click the action button. This will then return the selected publish.
:param title: The title to be used for the dialog
:param action: The label to use for the action button
:param publish_types: If specified then the UI will only show publishes
that matches these types - this overrides the setting
from the configuration.
:returns: A list of Shotgun publish records for the publish(es)
that were selected in the UI. Each record in the list
is garunteed to have a type and id but will usually
contain a much more complete list of fields from the
Shotgun PublishedFile entity
"""
publish_types = publish_types or []
tk_multi_loader = self.import_module("tk_multi_loader")
return tk_multi_loader.open_publish_browser(self, title, action, publish_types)
def create_loader_manager(self, bundle=None):
"""
Create and return a :class:`tk_multi_loader.LoaderManager` instance.
See the :class:`tk_multi_loader.LoaderManager` docs for details on
how it can be used to automate your loading workflows.
:param bundle: The bundle to use the loader manager with. If not
specified, the current Loader App bundle will be used.
Specifying a bundle is useful when you want to use the
LoaderManager api to create actions for a different app
and use the settings defined in that app's configuration.
:type bundle: :class:`sgtk.platform.TankBundle`
:returns: A :class:`tk_multi_loader.LoaderManager` instance
"""
return self._manager_class(bundle or self)
@property
def flowam_available(self) -> bool:
"""
Returns True if FlowAM integration is available in the running core.
:returns: True if FlowAM integration is available, False otherwise
:rtype: bool
"""
return (
getattr(self.context, "flow_project_id", None) is not None
and getattr(sgtk.platform.current_engine(), "flow_host", None) is not None
)
@property
def flowam(self) -> ModuleType:
"""
Access to the FlowAM integration module for this app. This module provides
drop-in replacements for the standard Shotgun-based Loader models and actions,
backed by Flow Asset Management (FlowAM) instead of the ShotGrid REST API.
:returns: The FlowAM integration module for this app
:rtype: :mod:`tk_multi_loader.flowam`
"""
return self._flowam