Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SG-14250: Disables window closing during photoshopcc actions to prevent crashing #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 45 additions & 16 deletions hooks/tk-photoshopcc_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import os

import sgtk
from sgtk.platform.qt import QtGui
from sgtk.platform.qt import QtGui, QtCore
from sgtk.platform.qt.tankqdialog import TankQDialog

HookBaseClass = sgtk.get_hook_baseclass()

Expand Down Expand Up @@ -130,22 +131,50 @@ def execute_action(self, name, params, sg_publish_data):
:param sg_publish_data: Shotgun data dictionary with all the standard
publish fields.
"""
app = self.parent
app.log_debug("Execute action called for action %s. "
"Parameters: %s. Publish Data: %s" % (name, params, sg_publish_data))

# resolve path
# toolkit uses utf-8 encoded strings internally and the Photoshop API expects unicode
# so convert the path to ensure filenames containing complex characters are supported
path = self.get_publish_path(sg_publish_data).decode('utf-8')
# If the loader2 dialog is closed during processing it causes some stability problems
# on Windows and OSX. We'll just not allow it to be closed while we're working.
top_level_widgets = [w for w in QtGui.QApplication.topLevelWidgets() if isinstance(w, TankQDialog)]
top_level_widgets_flags = [(w, w.windowFlags()) for w in top_level_widgets]

if not os.path.exists(path):
raise Exception("File not found on disk - '%s'" % path)

if name == _OPEN_FILE:
self._open_file(path, sg_publish_data)
if name == _ADD_AS_A_LAYER:
self._place_file(path, sg_publish_data)
try:
# We don't have an easy way from here to get the current loader2 widget, but it's
# not the end of the world if we just disable the close button for all top level
# dialogs that we know came from sgtk while we're in progress.
#
# https://stackoverflow.com/questions/3211272/qt-hide-minimize-maximize-and-close-buttons#
#
for widget in top_level_widgets:
if widget.isVisible():
widget.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.WindowTitleHint | QtCore.Qt.CustomizeWindowHint)
# Changing the window flags hides the dialog, so we re-show it. Doing these in quick succession
# doesn't appear to cause any visual flicker.
widget.show()

# Make sure the window flag change is visible to the user before we move on.
QtCore.QCoreApplication.processEvents()

app = self.parent
app.log_debug("Execute action called for action %s. "
"Parameters: %s. Publish Data: %s" % (name, params, sg_publish_data))

# resolve path
# toolkit uses utf-8 encoded strings internally and the Photoshop API expects unicode
# so convert the path to ensure filenames containing complex characters are supported
path = self.get_publish_path(sg_publish_data).decode('utf-8')

if not os.path.exists(path):
raise Exception("File not found on disk - '%s'" % path)

if name == _OPEN_FILE:
self._open_file(path, sg_publish_data)
if name == _ADD_AS_A_LAYER:
self._place_file(path, sg_publish_data)
finally:
# Set back the original window flags.
for widget, window_flags in top_level_widgets_flags:
if widget.isVisible():
widget.setWindowFlags(window_flags)
widget.show()

###########################################################################
# helper methods
Expand Down