Skip to content
This repository was archived by the owner on Oct 10, 2024. It is now read-only.

Commit 9c3601b

Browse files
authored
Merge pull request #109 from pypeclub/feature/merge_upstream_021920
Feature/merge upstream 021920 (GetAvalon update 19. Feb 2020)
2 parents 70140a7 + fc8e8c5 commit 9c3601b

File tree

23 files changed

+1124
-902
lines changed

23 files changed

+1124
-902
lines changed

avalon/blender/ops.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import bpy
1111
import bpy.utils.previews
1212

13-
from ..tools.contextmanager.app import App as contextmanager_window
1413
from ..tools.creator.app import Window as creator_window
1514
from ..tools.loader.app import Window as loader_window
1615
from ..tools.workfiles.app import Window as workfiles_window
@@ -134,7 +133,10 @@ def execute(self, context):
134133
self._app.store_window(self.bl_idname, window)
135134
self._window = window
136135

137-
if not isinstance(self._window, (QtWidgets.QDialog, ModuleType)):
136+
if not isinstance(
137+
self._window,
138+
(QtWidgets.QMainWindow, QtWidgets.QDialog, ModuleType)
139+
):
138140
raise AttributeError(
139141
"`window` should be a `QDialog or module`. Got: {}".format(
140142
str(type(window))
@@ -178,14 +180,6 @@ def before_window_show(self):
178180
return
179181

180182

181-
class LaunchContextManager(LaunchQtApp):
182-
"""Launch Avalon Context Manager."""
183-
184-
bl_idname = "wm.avalon_contextmanager"
185-
bl_label = "Set Avalon Context..."
186-
_window_class = contextmanager_window
187-
188-
189183
class LaunchCreator(LaunchQtApp):
190184
"""Launch Avalon Creator."""
191185

@@ -242,13 +236,13 @@ class LaunchWorkFiles(LaunchQtApp):
242236
_window_class = workfiles_window
243237

244238
def execute(self, context):
245-
self._init_kwargs = {
246-
"root": str(Path(
247-
os.environ.get("AVALON_WORKDIR", ""),
248-
os.environ.get("AVALON_SCENEDIR", ""),
249-
))
250-
}
251-
return super().execute(context)
239+
result = super().execute(context)
240+
self._window.set_context({
241+
"asset": api.Session["AVALON_ASSET"],
242+
"silo": api.Session["AVALON_SILO"],
243+
"task": api.Session["AVALON_TASK"]
244+
})
245+
return result
252246

253247
def before_window_show(self):
254248
self._window.root = str(Path(
@@ -279,7 +273,11 @@ def draw(self, context):
279273
asset = api.Session['AVALON_ASSET']
280274
task = api.Session['AVALON_TASK']
281275
context_label = f"{asset}, {task}"
282-
layout.operator(LaunchContextManager.bl_idname, text=context_label)
276+
context_label_item = layout.row()
277+
context_label_item.operator(
278+
LaunchWorkFiles.bl_idname, text=context_label
279+
)
280+
context_label_item.enabled = False
283281
layout.separator()
284282
layout.operator(LaunchCreator.bl_idname, text="Create...")
285283
layout.operator(LaunchLoader.bl_idname, text="Load...")
@@ -302,7 +300,6 @@ def draw_avalon_menu(self, context):
302300

303301

304302
classes = [
305-
LaunchContextManager,
306303
LaunchCreator,
307304
LaunchLoader,
308305
LaunchPublisher,

avalon/blender/workio.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ def file_extensions() -> List[str]:
6262
return [".blend"]
6363

6464

65-
def work_root() -> str:
65+
def work_root(session: dict) -> str:
6666
"""Return the default root to browse for work files."""
6767

68-
from .. import api
69-
70-
work_dir = api.Session["AVALON_WORKDIR"]
71-
scene_dir = api.Session.get("AVALON_SCENEDIR")
68+
work_dir = session["AVALON_WORKDIR"]
69+
scene_dir = session.get("AVALON_SCENEDIR")
7270
if scene_dir:
7371
return str(Path(work_dir, scene_dir))
7472
return work_dir

avalon/fusion/pipeline.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def ls():
4949
yield container
5050

5151

52-
def install(config):
52+
def install():
5353
"""Install Fusion-specific functionality of avalon-core.
5454
5555
This function is called automatically on calling `api.install(fusion)`.
@@ -76,14 +76,10 @@ def install(config):
7676
logger.setLevel(logging.DEBUG)
7777

7878

79-
def uninstall(config):
79+
def uninstall():
8080
"""Uninstall Fusion-specific functionality of avalon-core.
8181
8282
This function is called automatically on calling `api.uninstall()`.
83-
84-
Args:
85-
config: configuration module
86-
8783
"""
8884

8985
pyblish.api.deregister_host("fusion")

avalon/fusion/workio.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ def current_file():
3939
return current_filepath
4040

4141

42-
def work_root():
43-
from avalon import Session
44-
45-
work_dir = Session["AVALON_WORKDIR"]
46-
scene_dir = Session.get("AVALON_SCENEDIR")
42+
def work_root(session):
43+
work_dir = session["AVALON_WORKDIR"]
44+
scene_dir = session.get("AVALON_SCENEDIR")
4745
if scene_dir:
4846
return os.path.join(work_dir, scene_dir)
4947
else:

avalon/houdini/pipeline.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
IS_HEADLESS = not hasattr(hou, "ui")
2525

2626

27-
def install(config):
27+
def install():
2828
"""Setup integration
2929
Register plug-ins and integrate into the host
3030
@@ -40,14 +40,10 @@ def install(config):
4040
self._has_been_setup = True
4141

4242

43-
def uninstall(config):
43+
def uninstall():
4444
"""Uninstall Houdini-specific functionality of avalon-core.
4545
4646
This function is called automatically on calling `api.uninstall()`.
47-
48-
Args:
49-
config: configuration module
50-
5147
"""
5248

5349
pyblish.api.deregister_host("hython")

avalon/houdini/workio.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ def current_file():
4848
return current_filepath
4949

5050

51-
def work_root():
52-
from avalon import Session
53-
54-
work_dir = Session["AVALON_WORKDIR"]
55-
scene_dir = Session.get("AVALON_SCENEDIR")
51+
def work_root(session):
52+
work_dir = session["AVALON_WORKDIR"]
53+
scene_dir = session.get("AVALON_SCENEDIR")
5654
if scene_dir:
5755
return os.path.join(work_dir, scene_dir)
5856
else:

avalon/io.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ def _from_environment():
138138
# Optional path to scenes directory (see Work Files API)
139139
("AVALON_SCENEDIR", None),
140140

141+
# Optional hierarchy for the current Asset. This can be referenced
142+
# as `{hierarchy}` in your file templates.
143+
# This will be (re-)computed when you switch the context to another
144+
# asset. It is computed by checking asset['data']['parents'] and
145+
# joining those together with `os.path.sep`.
146+
# E.g.: ['ep101', 'scn0010'] -> 'ep101/scn0010'.
147+
("AVALON_HIERARCHY", None),
148+
141149
# Name of current Config
142150
# TODO(marcus): Establish a suitable default config
143151
("AVALON_CONFIG", "no_config"),

avalon/maya/pipeline.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def get_main_window():
9090
return self._parent
9191

9292

93-
def uninstall(config):
93+
def uninstall():
9494
"""Uninstall Maya-specific functionality of avalon-core.
9595
9696
This function is called automatically on calling `api.uninstall()`.
@@ -111,8 +111,7 @@ def _install_menu():
111111
loader,
112112
publish,
113113
sceneinventory,
114-
libraryloader,
115-
contextmanager
114+
libraryloader
116115
)
117116

118117
from . import interactive
@@ -126,19 +125,16 @@ def deferred():
126125
parent="MayaWindow")
127126

128127
# Create context menu
129-
context_label = "{}, {}".format(api.Session["AVALON_ASSET"],
130-
api.Session["AVALON_TASK"])
131-
context_menu = cmds.menuItem("currentContext",
132-
label=context_label,
133-
parent=self._menu,
134-
subMenu=True)
135-
136-
cmds.menuItem("setCurrentContext",
137-
label="Edit Context..",
138-
parent=context_menu,
139-
command=lambda *args: contextmanager.show(
140-
parent=self._parent
141-
))
128+
context_label = "{}, {}".format(
129+
api.Session["AVALON_ASSET"],
130+
api.Session["AVALON_TASK"]
131+
)
132+
cmds.menuItem(
133+
"currentContext",
134+
label=context_label,
135+
parent=self._menu,
136+
enable=False
137+
)
142138

143139
cmds.setParent("..", menu=True)
144140

avalon/maya/workio.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,33 @@ def current_file():
3030
return current_filepath
3131

3232

33-
def work_root():
34-
35-
# Base the root on the current Maya workspace.
36-
return os.path.join(
37-
cmds.workspace(query=True, rootDirectory=True),
38-
cmds.workspace(fileRuleEntry="scene")
39-
)
33+
def work_root(session):
34+
work_dir = session["AVALON_WORKDIR"]
35+
scene_dir = None
36+
37+
# Query scene file rule from workspace.mel if it exists in WORKDIR
38+
# We are parsing the workspace.mel manually as opposed to temporarily
39+
# setting the Workspace in Maya in a context manager since Maya had a
40+
# tendency to crash on frequently changing the workspace when this
41+
# function was called many times as one scrolled through Work Files assets.
42+
workspace_mel = os.path.join(work_dir, "workspace.mel")
43+
if os.path.exists(workspace_mel):
44+
scene_rule = 'workspace -fr "scene" '
45+
# We need to use builtins as `open` is overridden by the workio API
46+
open_file = __builtins__["open"]
47+
with open_file(workspace_mel, "r") as f:
48+
for line in f:
49+
if line.strip().startswith(scene_rule):
50+
# remainder == "rule";
51+
remainder = line[len(scene_rule):]
52+
# scene_dir == rule
53+
scene_dir = remainder.split('"')[1]
54+
else:
55+
# We can't query a workspace that does not exist
56+
# so we return similar to what we do in other hosts.
57+
scene_dir = session.get("AVALON_SCENEDIR")
58+
59+
if scene_dir:
60+
return os.path.join(work_dir, scene_dir)
61+
else:
62+
return work_dir

avalon/nuke/pipeline.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def install():
254254
pyblish.register_host("nuke")
255255

256256

257-
def uninstall(config):
257+
def uninstall():
258258
"""Uninstall all that was previously installed
259259
260260
This is where you undo everything that was done in `install()`.
@@ -280,19 +280,26 @@ def _install_menu():
280280
workfiles,
281281
loader,
282282
sceneinventory,
283-
contextmanager,
284283
libraryloader
285284
)
286-
285+
from ..vendor.Qt import QtWidgets
286+
287+
main_window = None
288+
for widget in QtWidgets.QApplication.topLevelWidgets():
289+
if widget.isWindow():
290+
if widget.parentWidget() is None:
291+
if widget.windowTitle() != '':
292+
main_window = widget
293+
break
287294
# Create menu
288295
menubar = nuke.menu("Nuke")
289296
menu = menubar.addMenu(api.Session["AVALON_LABEL"])
290297

291298
label = "{0}, {1}".format(
292299
api.Session["AVALON_ASSET"], api.Session["AVALON_TASK"]
293300
)
294-
context_menu = menu.addMenu(label)
295-
context_menu.addCommand("Set Context", contextmanager.show)
301+
context_action = menu.addCommand(label)
302+
context_action.setEnabled(False)
296303

297304
menu.addSeparator()
298305
menu.addCommand("Work Files...",
@@ -306,7 +313,10 @@ def _install_menu():
306313
"Load...", command=lambda *args:
307314
loader.show(use_context=True)
308315
)
309-
menu.addCommand("Publish...", publish.show)
316+
menu.addCommand(
317+
"Publish...",
318+
lambda *args: publish.show(parent=main_window)
319+
)
310320
menu.addCommand("Manage...", sceneinventory.show)
311321
menu.addCommand("Library...", libraryloader.show)
312322

0 commit comments

Comments
 (0)