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

Make debug and show behaviour consistent for all tools #513

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
29 changes: 6 additions & 23 deletions avalon/tools/creator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,37 +555,20 @@ def set_item(self, item):


def show(debug=False, parent=None):
"""Display asset creator GUI
"""Display Asset Creator GUI

Arguments:
debug (bool, optional): Run loader in debug-mode,
defaults to False
debug (bool, optional): Run loader in debug-mode, defaults to False
parent (QtCore.QObject, optional): When provided parent the interface
to this QObject.

"""

if module.window:
try:
module.window.close()
del(module.window)

if debug:
from avalon import mock
for creator in mock.creators:
api.register_plugin(api.Creator, creator)

import traceback
sys.excepthook = lambda typ, val, tb: traceback.print_last()

io.install()

any_project = next(
project for project in io.projects()
if project.get("active", True) is not False
)

api.Session["AVALON_PROJECT"] = any_project["name"]
module.project = any_project["name"]
del module.window
except (RuntimeError, AttributeError):
pass

with lib.application():
window = Window(parent)
Expand Down
32 changes: 6 additions & 26 deletions avalon/tools/loader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,37 +388,17 @@ def show(debug=False, parent=None, use_context=False):
"""Display Loader GUI

Arguments:
debug (bool, optional): Run loader in debug-mode,
defaults to False
debug (bool, optional): Run loader in debug-mode, defaults to False
parent (QtCore.QObject, optional): The Qt object to parent to.
use_context (bool): Whether to apply the current context upon launch

"""

# Remember window
if module.window is not None:
try:
module.window.show()

# If the window is minimized then unminimize it.
if module.window.windowState() & QtCore.Qt.WindowMinimized:
module.window.setWindowState(QtCore.Qt.WindowActive)

# Raise and activate the window
module.window.raise_() # for MacOS
module.window.activateWindow() # for Windows
module.window.refresh()
return
except RuntimeError as exc:
if not str(exc).rstrip().endswith("already deleted."):
raise

# Garbage collected
module.window = None

if debug:
import traceback
sys.excepthook = lambda typ, val, tb: traceback.print_last()
try:
module.window.close()
del module.window
except (RuntimeError, AttributeError):
pass

with lib.application():

Expand Down
6 changes: 1 addition & 5 deletions avalon/tools/projectmanager/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ def show(root=None, debug=False, parent=None):
"""Display Loader GUI

Arguments:
debug (bool, optional): Run loader in debug-mode,
defaults to False
debug (bool, optional): Run loader in debug-mode, defaults to False
parent (QtCore.QObject, optional): When provided parent the interface
to this QObject.

Expand All @@ -256,9 +255,6 @@ def show(root=None, debug=False, parent=None):
except (RuntimeError, AttributeError):
pass

if debug is True:
io.install()

with tools_lib.application():
window = Window(parent=parent)
window.show()
Expand Down
7 changes: 1 addition & 6 deletions avalon/tools/sceneinventory/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,7 @@ def show(root=None, debug=False, parent=None):
"""Display Scene Inventory GUI

Arguments:
debug (bool, optional): Run in debug-mode,
defaults to False
debug (bool, optional): Run in debug-mode, defaults to False
parent (QtCore.QObject, optional): When provided parent the interface
to this QObject.

Expand All @@ -940,10 +939,6 @@ def show(root=None, debug=False, parent=None):
except (RuntimeError, AttributeError):
pass

if debug:
import traceback
sys.excepthook = lambda typ, val, tb: traceback.print_last()

with tools_lib.application():
window = Window(parent)
window.show()
Expand Down
20 changes: 13 additions & 7 deletions avalon/tools/workfiles/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,12 +855,22 @@ def _on_task_changed(self):


def show(root=None, debug=False, parent=None, use_context=True):
"""Show Work Files GUI"""
"""Show Work Files GUI
# todo: remove `root` argument to show()

if module.window:
Arguments:
root (str, optional): The root for the work files app
debug (bool, optional): Run in debug-mode, defaults to False
parent (QtCore.QObject, optional): When provided parent the interface
to this QObject.

"""

try:
module.window.close()
del(module.window)
del module.window
except (RuntimeError, AttributeError):
pass

host = api.registered_host()
if host is None:
Expand All @@ -882,10 +892,6 @@ def show(root=None, debug=False, parent=None, use_context=True):
raise RuntimeError("Host is missing required Work Files interfaces: "
"%s (host: %s)" % (", ".join(missing), host))

if debug:
api.Session["AVALON_ASSET"] = "Mock"
api.Session["AVALON_TASK"] = "Testing"

with tools_lib.application():

window = Window(parent=parent)
Expand Down