Skip to content

Commit

Permalink
SHOT-4381: Show progress dialog when importing files async (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
staceyoue authored Aug 7, 2024
1 parent a2d363e commit f34f174
Show file tree
Hide file tree
Showing 4 changed files with 448 additions and 23 deletions.
55 changes: 55 additions & 0 deletions engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Autodesk Inc.

from typing import List
import logging
import os
import re
Expand Down Expand Up @@ -901,6 +902,60 @@ def save_current_file(self, file_path, set_render_path=True):
if set_render_path:
self.set_render_path(file_path)

def import_files(self, paths: List[str]):
"""
Import files from the given paths into the VRED scene.
:param paths: List of file paths to import.
"""

from sgtk.platform.qt import QtGui

if not paths:
return

# Import .vpb files separate from other files. On importing .vpb files
# VRED displays a progress bar, for non .vpbs it will not, so we will
# have to show our own in this case.
vpb_file_paths = []
other_file_paths = []
for path in paths:
if path.endswith(".vpb"):
vpb_file_paths.append(path)
else:
other_file_paths.append(path)

root_node = self.vredpy.vrScenegraph.getRootNode()

# Import .vpb files first. VRED will show a loading bar for these files
if vpb_file_paths:
self.vredpy.vrFileIOService.importFiles(vpb_file_paths, root_node)

# Import any non .vpb files, show our custom progress bar for these files
if other_file_paths:
progress_widget = None
if self.has_ui:
parent = (
QtGui.QApplication.activeWindow()
or self.__engine._get_dialog_parent()
)
progress_widget = self._tk_vred.VREDFileIOProgressWidget(
self.vredpy,
len(other_file_paths),
abort_callback=self.vredpy.vrFileIOService.abortImport,
parent=parent,
)
progress_widget.show()

# Start the import operation in VRED async
import_job_id = self.vredpy.vrFileIOService.importFiles(
other_file_paths, root_node
)

# Update the progress widget to track the import job
if progress_widget:
progress_widget.job_id = import_job_id

def set_render_path(self, file_path=None):
"""
Prepare render path when the file is selected or saved.
Expand Down
56 changes: 33 additions & 23 deletions hooks/tk-multi-loader2/basic/scene_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import os
import sgtk
from sgtk.platform.qt import QtCore, QtGui


HookBaseClass = sgtk.get_hook_baseclass()
Expand Down Expand Up @@ -239,28 +240,34 @@ def import_sceneplate(self, image_path):
"Import sceneplate for image file '{path}'".format(path=image_path)
)

# Get the Sceneplate Root object
vredSceneplateRoot = self.vredpy.vrSceneplateService.getRootNode()
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
try:
# Get the Sceneplate Root object
vredSceneplateRoot = self.vredpy.vrSceneplateService.getRootNode()

# Extract the filename for the name of the Sceneplate
nodeName = os.path.basename(image_path)
# Extract the filename for the name of the Sceneplate
nodeName = os.path.basename(image_path)

# Load in the image
imageObject = self.vredpy.vrImageService.loadImage(image_path)
# Load in the image
imageObject = self.vredpy.vrImageService.loadImage(image_path)

# Create the actual Sceneplate node
newSceneplateNode = self.vredpy.vrSceneplateService.createNode(
vredSceneplateRoot,
self.vredpy.vrSceneplateTypes.NodeType.Frontplate,
nodeName,
)
newSceneplate = self.vredpy.vrdSceneplateNode(newSceneplateNode)
# Create the actual Sceneplate node
newSceneplateNode = self.vredpy.vrSceneplateService.createNode(
vredSceneplateRoot,
self.vredpy.vrSceneplateTypes.NodeType.Frontplate,
nodeName,
)
newSceneplate = self.vredpy.vrdSceneplateNode(newSceneplateNode)

# Set the type to image
newSceneplate.setContentType(self.vredpy.vrSceneplateTypes.ContentType.Image)
# Set the type to image
newSceneplate.setContentType(
self.vredpy.vrSceneplateTypes.ContentType.Image
)

# Assign the image to the Sceneplate
newSceneplate.setImage(imageObject)
# Assign the image to the Sceneplate
newSceneplate.setImage(imageObject)
finally:
QtGui.QApplication.restoreOverrideCursor()

def create_smart_reference(self, path):
"""
Expand All @@ -275,10 +282,14 @@ def create_smart_reference(self, path):
ref_name = os.path.splitext(os.path.basename(path))[0]

# create the smart ref, load it and finally change the node name to reflect the ref path
ref_node = self.vredpy.vrReferenceService.createSmart()
ref_node.setSmartPath(path)
ref_node.load()
ref_node.setName(ref_name)
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
try:
ref_node = self.vredpy.vrReferenceService.createSmart()
ref_node.setSmartPath(path)
ref_node.load()
ref_node.setName(ref_name)
finally:
QtGui.QApplication.restoreOverrideCursor()

def import_files(self, paths):
"""
Expand All @@ -288,8 +299,7 @@ def import_files(self, paths):
:type paths: List[str]
"""

parent = self.vredpy.vrScenegraph.getRootNode()
self.vredpy.vrFileIOService.importFiles(paths, parent)
self.parent.engine.import_files(paths)

def import_file(self, path):
"""
Expand Down
1 change: 1 addition & 0 deletions python/tk_vred/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
from .menu_generation import VREDMenuGenerator
from .dock_widget import DockWidget
from .vred_py import VREDPy
from .progress_widget import VREDFileIOProgressWidget
Loading

0 comments on commit f34f174

Please sign in to comment.