diff --git a/pype/tools/launcher/__init__.py b/pype/tools/launcher/__init__.py index 3b88ebe984..8f7bf5a769 100644 --- a/pype/tools/launcher/__init__.py +++ b/pype/tools/launcher/__init__.py @@ -1,10 +1,7 @@ - -from .app import ( - show, - cli -) +from .app import LauncherWindow +from . import actions __all__ = [ - "show", - "cli", + "LauncherWindow", + "actions" ] diff --git a/pype/tools/launcher/__main__.py b/pype/tools/launcher/__main__.py deleted file mode 100644 index 50642c46cd..0000000000 --- a/pype/tools/launcher/__main__.py +++ /dev/null @@ -1,5 +0,0 @@ -from app import cli - -if __name__ == '__main__': - import sys - sys.exit(cli(sys.argv[1:])) diff --git a/pype/tools/launcher/actions.py b/pype/tools/launcher/actions.py index 44ba9a3a60..80e6f71ae7 100644 --- a/pype/tools/launcher/actions.py +++ b/pype/tools/launcher/actions.py @@ -8,7 +8,6 @@ class ProjectManagerAction(api.Action): name = "projectmanager" label = "Project Manager" icon = "gear" - group = "Test" order = 999 # at the end def is_compatible(self, session): @@ -28,8 +27,7 @@ class LoaderAction(api.Action): name = "loader" label = "Loader" icon = "cloud-download" - order = 998 # at the end - group = "Test" + order = 998 def is_compatible(self, session): return "AVALON_PROJECT" in session @@ -38,7 +36,7 @@ class LoaderAction(api.Action): return lib.launch( executable="python", args=[ - "-u", "-m", "avalon.tools.cbloader", session['AVALON_PROJECT'] + "-u", "-m", "avalon.tools.loader", session['AVALON_PROJECT'] ] ) @@ -72,8 +70,10 @@ def register_config_actions(): module_name = os.environ["AVALON_CONFIG"] config = importlib.import_module(module_name) if not hasattr(config, "register_launcher_actions"): - print("Current configuration `%s` has no 'register_launcher_actions'" - % config.__name__) + print( + "Current configuration `%s` has no 'register_launcher_actions'" + % config.__name__ + ) return config.register_launcher_actions() diff --git a/pype/tools/launcher/app.py b/pype/tools/launcher/app.py index 6f554110dc..b6a7d4dab2 100644 --- a/pype/tools/launcher/app.py +++ b/pype/tools/launcher/app.py @@ -1,10 +1,10 @@ -import sys import copy -from avalon.vendor.Qt import QtWidgets, QtCore, QtGui +from Qt import QtWidgets, QtCore, QtGui from avalon import style from pype.modules.ftrack.lib.io_nonsingleton import DbConnector +from pype.api import resources from avalon.tools import lib as tools_lib from avalon.tools.widgets import AssetWidget @@ -16,10 +16,6 @@ from .widgets import ( from .flickcharm import FlickCharm -module = sys.modules[__name__] -module.window = None - - class IconListView(QtWidgets.QListView): """Styled ListView that allows to toggle between icon and list mode. @@ -244,17 +240,21 @@ class AssetsPanel(QtWidgets.QWidget): return session -class Window(QtWidgets.QDialog): +class LauncherWindow(QtWidgets.QDialog): """Launcher interface""" def __init__(self, parent=None): - super(Window, self).__init__(parent) + super(LauncherWindow, self).__init__(parent) self.dbcon = DbConnector() self.setWindowTitle("Launcher") self.setFocusPolicy(QtCore.Qt.StrongFocus) - self.setAttribute(QtCore.Qt.WA_DeleteOnClose) + self.setAttribute(QtCore.Qt.WA_DeleteOnClose, False) + + icon = QtGui.QIcon(resources.pype_icon_filepath()) + self.setWindowIcon(icon) + self.setStyleSheet(style.load_stylesheet()) # Allow minimize self.setWindowFlags( @@ -287,8 +287,10 @@ class Window(QtWidgets.QDialog): # Vertically split Pages and Actions body = QtWidgets.QSplitter() body.setContentsMargins(0, 0, 0, 0) - body.setSizePolicy(QtWidgets.QSizePolicy.Expanding, - QtWidgets.QSizePolicy.Expanding) + body.setSizePolicy( + QtWidgets.QSizePolicy.Expanding, + QtWidgets.QSizePolicy.Expanding + ) body.setOrientation(QtCore.Qt.Vertical) body.addWidget(page_slider) body.addWidget(actions_bar) @@ -462,221 +464,3 @@ class Window(QtWidgets.QDialog): # requires a forced refresh first self.asset_panel.on_asset_changed() self.asset_panel.assets_widget.select_task(task_name) - - -class Application(QtWidgets.QApplication): - def __init__(self, *args): - super(Application, self).__init__(*args) - - # Set app icon - icon_path = tools_lib.resource("icons", "png", "avalon-logo-16.png") - icon = QtGui.QIcon(icon_path) - - self.setWindowIcon(icon) - - # Toggles - self.toggles = {"autoHide": False} - - # Timers - keep_visible = QtCore.QTimer(self) - keep_visible.setInterval(100) - keep_visible.setSingleShot(True) - - timers = {"keepVisible": keep_visible} - - tray = QtWidgets.QSystemTrayIcon(icon) - tray.setToolTip("Avalon Launcher") - - # Signals - tray.activated.connect(self.on_tray_activated) - self.aboutToQuit.connect(self.on_quit) - - menu = self.build_menu() - tray.setContextMenu(menu) - tray.show() - - tray.showMessage("Avalon", "Launcher started.") - - # Don't close the app when we close the log window. - # self.setQuitOnLastWindowClosed(False) - - self.focusChanged.connect(self.on_focus_changed) - - window = Window() - window.setAttribute(QtCore.Qt.WA_DeleteOnClose, False) - - self.timers = timers - self._tray = tray - self._window = window - - # geometry = self.calculate_window_geometry(window) - # window.setGeometry(geometry) - - def show(self): - """Show the primary GUI - - This also activates the window and deals with platform-differences. - - """ - - self._window.show() - self._window.raise_() - self._window.activateWindow() - - self.timers["keepVisible"].start() - - def on_tray_activated(self, reason): - if self._window.isVisible(): - self._window.hide() - - elif reason == QtWidgets.QSystemTrayIcon.Trigger: - self.show() - - def on_focus_changed(self, old, new): - """Respond to window losing focus""" - window = new - keep_visible = self.timers["keepVisible"].isActive() - self._window.hide() if (self.toggles["autoHide"] and - not window and - not keep_visible) else None - - def on_autohide_changed(self, auto_hide): - """Respond to changes to auto-hide - - Auto-hide is changed in the UI and determines whether or not - the UI hides upon losing focus. - - """ - - self.toggles["autoHide"] = auto_hide - self.echo("Hiding when losing focus" if auto_hide else "Stays visible") - - def on_quit(self): - """Respond to the application quitting""" - self._tray.hide() - - def build_menu(self): - """Build the right-mouse context menu for the tray icon""" - menu = QtWidgets.QMenu() - - icon = qtawesome.icon("fa.eye", color=style.colors.default) - open = QtWidgets.QAction(icon, "Open", self) - open.triggered.connect(self.show) - - def toggle(): - self.on_autohide_changed(not self.toggles['autoHide']) - - keep_open = QtWidgets.QAction("Keep open", self) - keep_open.setCheckable(True) - keep_open.setChecked(not self.toggles['autoHide']) - keep_open.triggered.connect(toggle) - - quit = QtWidgets.QAction("Quit", self) - quit.triggered.connect(self.quit) - - menu.setStyleSheet(""" - QMenu { - padding: 0px; - margin: 0px; - } - """) - - for action in [open, keep_open, quit]: - menu.addAction(action) - - return menu - - def calculate_window_geometry(self, window): - """Respond to status changes - - On creation, align window with where the tray icon is - located. For example, if the tray icon is in the upper - right corner of the screen, then this is where the - window is supposed to appear. - - Arguments: - status (int): Provided by Qt, the status flag of - loading the input file. - - """ - - tray_x = self._tray.geometry().x() - tray_y = self._tray.geometry().y() - - width = window.width() - width = max(width, window.minimumWidth()) - - height = window.height() - height = max(height, window.sizeHint().height()) - - desktop_geometry = QtWidgets.QDesktopWidget().availableGeometry() - screen_geometry = window.geometry() - - screen_width = screen_geometry.width() - screen_height = screen_geometry.height() - - # Calculate width and height of system tray - systray_width = screen_geometry.width() - desktop_geometry.width() - systray_height = screen_geometry.height() - desktop_geometry.height() - - padding = 10 - - x = screen_width - width - y = screen_height - height - - if tray_x < (screen_width / 2): - x = 0 + systray_width + padding - else: - x -= systray_width + padding - - if tray_y < (screen_height / 2): - y = 0 + systray_height + padding - else: - y -= systray_height + padding - - return QtCore.QRect(x, y, width, height) - - -def show(root=None, debug=False, parent=None): - """Display Loader GUI - - Arguments: - debug (bool, optional): Run loader in debug-mode, - defaults to False - parent (QtCore.QObject, optional): When provided parent the interface - to this QObject. - - """ - - app = Application(sys.argv) - app.setStyleSheet(style.load_stylesheet()) - - # Show the window on launch - app.show() - - app.exec_() - - -def cli(args): - import argparse - parser = argparse.ArgumentParser() - #parser.add_argument("project") - - args = parser.parse_args(args) - #project = args.project - - import launcher.actions as actions - print("Registering default actions..") - actions.register_default_actions() - print("Registering config actions..") - actions.register_config_actions() - print("Registering environment actions..") - actions.register_environment_actions() - io.install() - - #io.Session["AVALON_PROJECT"] = project - - import traceback - sys.excepthook = lambda typ, val, tb: traceback.print_last() - - show() diff --git a/pype/tools/launcher/lib.py b/pype/tools/launcher/lib.py index 027ae96e84..d307e146d5 100644 --- a/pype/tools/launcher/lib.py +++ b/pype/tools/launcher/lib.py @@ -95,6 +95,7 @@ def get_action_icon(action): ) except Exception: + ICON_CACHE[icon_name] = NOT_FOUND print("Can't load icon \"{}\"".format(icon_name)) return icon