Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Each tool gets destroyed on close.
- Each tool gets raised if there is an existing window.
- All tools' windows gets activated.
  • Loading branch information
tokejepsen committed Jan 27, 2020
1 parent add240f commit 94c9192
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 85 deletions.
30 changes: 17 additions & 13 deletions avalon/tools/contextmanager/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging

from ... import api

from avalon import style
from ...tools import lib
from ...vendor.Qt import QtWidgets, QtCore
from ..widgets import AssetWidget
from ..models import TasksModel
Expand All @@ -20,6 +21,7 @@ class App(QtWidgets.QDialog):
def __init__(self, parent=None):
QtWidgets.QDialog.__init__(self, parent)

self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
self.resize(640, 360)
project = api.Session["AVALON_PROJECT"]
self.setWindowTitle("Context Manager 1.0 - {}".format(project))
Expand Down Expand Up @@ -211,19 +213,21 @@ def select_asset(self, assetname):
self._assets.select_assets([assetname], expand=True)


def show(parent=None):
def create_window(parent):
window = App(parent)
window.show()
window.setStyleSheet(style.load_stylesheet())
module.window = window

from avalon import style
from ...tools import lib
try:
module.window.close()
del module.window
except (RuntimeError, AttributeError):
pass

def show(parent=None):
with lib.application():
window = App(parent)
window.show()
window.setStyleSheet(style.load_stylesheet())
if lib.existing_app:
try:
module.window.raise_()
except (RuntimeError, AttributeError):
create_window(parent)
else:
create_window(parent)

module.window = window
module.window.activateWindow()
25 changes: 16 additions & 9 deletions avalon/tools/creator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Window(QtWidgets.QDialog):

def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
self.setWindowTitle("Instance Creator")
self.setFocusPolicy(QtCore.Qt.StrongFocus)

Expand Down Expand Up @@ -553,6 +554,13 @@ def set_item(self, item):
self.help.setText(help)


def create_window(parent):
window = Window(parent)
window.show()
window.setStyleSheet(style.load_stylesheet())
module.window = window


def show(debug=False, parent=None):
"""Display asset creator GUI
Expand All @@ -564,10 +572,6 @@ def show(debug=False, parent=None):
"""

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

if debug:
from avalon import mock
for creator in mock.creators:
Expand All @@ -587,9 +591,12 @@ def show(debug=False, parent=None):
module.project = any_project["name"]

with lib.application():
window = Window(parent)
window.refresh()
window.show()
window.setStyleSheet(style.load_stylesheet())
if lib.existing_app:
try:
module.window.raise_()
except (RuntimeError, AttributeError):
create_window(parent)
else:
create_window(parent)

module.window = window
module.window.activateWindow()
2 changes: 2 additions & 0 deletions avalon/tools/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
self = sys.modules[__name__]
self._jobs = dict()
self._path = os.path.dirname(__file__)
self.existing_app = False


def resource(*path):
Expand All @@ -27,6 +28,7 @@ def application():
yield app
app.exec_()
else:
self.existing_app = True
print("Using existing QApplication..")
yield app

Expand Down
54 changes: 22 additions & 32 deletions avalon/tools/loader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Window(QtWidgets.QDialog):

def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
self.setWindowTitle(
"Asset Loader 2.1 - %s/%s" % (
api.registered_root(),
Expand Down Expand Up @@ -375,6 +376,13 @@ def on_group(self):
self.close()


def create_window(parent):
window = Window(parent)
window.show()
window.setStyleSheet(style.load_stylesheet())
module.window = window


def show(debug=False, parent=None, use_context=False):
"""Display Loader GUI
Expand All @@ -386,49 +394,31 @@ def show(debug=False, parent=None, use_context=False):
"""

# 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 e:
if not str(e).rstrip().endswith("already deleted."):
raise

# Garbage collected
module.window = None

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

with lib.application():

# TODO: Global state, remove these
lib.refresh_family_config_cache()
lib.refresh_group_config_cache()
# TODO: Global state, remove these
lib.refresh_family_config_cache()
lib.refresh_group_config_cache()

window = Window(parent)
window.show()
window.setStyleSheet(style.load_stylesheet())
with lib.application():
if lib.existing_app:
try:
module.window.raise_()
except (RuntimeError, AttributeError):
create_window(parent)
else:
create_window(parent)

if use_context:
context = {"asset": api.Session["AVALON_ASSET"],
"silo": api.Session["AVALON_SILO"]}
window.set_context(context, refresh=True)
module.window.set_context(context, refresh=True)
else:
window.refresh()
module.window.refresh()

module.window = window
module.window.activateWindow()


def cli(args):
Expand Down
28 changes: 16 additions & 12 deletions avalon/tools/projectmanager/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ def on_silo_changed(self, silo):
self.echo("Silo changed to: {0}".format(silo))


def create_window(parent):
window = Window(parent)
window.show()
window.setStyleSheet(style.load_stylesheet())
module.window = window


def show(root=None, debug=False, parent=None):
"""Display Loader GUI
Expand All @@ -222,22 +229,19 @@ def show(root=None, debug=False, parent=None):
"""

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

if debug is True:
io.install()

with tools_lib.application():
window = Window(parent)
window.show()
window.setStyleSheet(style.load_stylesheet())
window.refresh()

module.window = window
if tools_lib.existing_app:
try:
module.window.raise_()
except (RuntimeError, AttributeError):
create_window(parent)
else:
create_window(parent)

module.window.activateWindow()


def cli(args):
Expand Down
27 changes: 16 additions & 11 deletions avalon/tools/sceneinventory/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ class Window(QtWidgets.QDialog):

def __init__(self, parent=None):
QtWidgets.QDialog.__init__(self, parent)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)

self.resize(1100, 480)
self.setWindowTitle(
Expand Down Expand Up @@ -911,6 +912,13 @@ def refresh(self):
self.model.refresh()


def create_window(parent):
window = Window(parent)
window.show()
window.setStyleSheet(style.load_stylesheet())
module.window = window


def show(root=None, debug=False, parent=None):
"""Display Scene Inventory GUI
Expand All @@ -922,20 +930,17 @@ def show(root=None, debug=False, parent=None):
"""

try:
module.window.close()
del module.window
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()
window.setStyleSheet(style.load_stylesheet())
window.refresh()
if tools_lib.existing_app:
try:
module.window.raise_()
except (RuntimeError, AttributeError):
create_window(parent)
else:
create_window(parent)

module.window = window
module.window.activateWindow()
24 changes: 16 additions & 8 deletions avalon/tools/workfiles/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def __init__(self, root=None, parent=None):
super(Window, self).__init__(parent)
self.setWindowTitle("Work Files")
self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.WindowCloseButtonHint)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)

self.root = root

Expand Down Expand Up @@ -458,13 +459,16 @@ def on_save_as_pressed(self):
self.close()


def create_window(root, parent):
window = Window(root, parent=parent)
window.show()
window.setStyleSheet(style.load_stylesheet())
module.window = window


def show(root=None, debug=False, parent=None):
"""Show Work Files GUI"""

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

host = api.registered_host()
if host is None:
raise RuntimeError("No registered host.")
Expand Down Expand Up @@ -500,8 +504,12 @@ def show(root=None, debug=False, parent=None):
api.Session["AVALON_TASK"] = "Testing"

with tools_lib.application():
window = Window(root, parent=parent)
window.show()
window.setStyleSheet(style.load_stylesheet())
if tools_lib.existing_app:
try:
module.window.raise_()
except (RuntimeError, AttributeError):
create_window(root, parent)
else:
create_window(root, parent)

module.window = window
module.window.activateWindow()

0 comments on commit 94c9192

Please sign in to comment.