From 202a9954a269d72524ec44476da5d19aea4da556 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Tue, 20 Sep 2016 07:41:31 +0100 Subject: [PATCH] Update README, make apps standalone --- pyblish_starter/__main__.py | 19 +++++++ pyblish_starter/maya/__init__.py | 2 - pyblish_starter/maya/lib.py | 27 ---------- pyblish_starter/pipeline.py | 23 ++++++++ .../tools/asset_loader/__init__.py | 3 ++ .../tools/asset_loader/__main__.py | 4 +- pyblish_starter/tools/asset_loader/app.py | 43 +++++++++------ .../tools/instance_creator/__main__.py | 7 +-- pyblish_starter/tools/instance_creator/app.py | 53 ++++++++++++------- 9 files changed, 113 insertions(+), 68 deletions(-) create mode 100644 pyblish_starter/__main__.py diff --git a/pyblish_starter/__main__.py b/pyblish_starter/__main__.py new file mode 100644 index 0000000..f980aff --- /dev/null +++ b/pyblish_starter/__main__.py @@ -0,0 +1,19 @@ + +if __name__ == '__main__': + import os + import argparse + + parser = argparse.ArgumentParser() + parser.add_argument("--create", action="store_true") + parser.add_argument("--load", action="store_true") + + args = parser.parse_args() + + if args.create: + from .tools import instance_creator + instance_creator.show(create=lambda *args, **kwargs: None) + + if args.load: + from .tools import asset_loader + asset_loader.show(root=os.path.expanduser("~"), + load=lambda name: None) diff --git a/pyblish_starter/maya/__init__.py b/pyblish_starter/maya/__init__.py index 72d5962..2c66239 100644 --- a/pyblish_starter/maya/__init__.py +++ b/pyblish_starter/maya/__init__.py @@ -7,7 +7,6 @@ outmesh, load, create, - setup, ) @@ -17,5 +16,4 @@ "outmesh", "load", "create", - "setup", ] diff --git a/pyblish_starter/maya/lib.py b/pyblish_starter/maya/lib.py index ce4282e..4cf7e2a 100644 --- a/pyblish_starter/maya/lib.py +++ b/pyblish_starter/maya/lib.py @@ -4,38 +4,11 @@ from maya import cmds from ..pipeline import ( - register_default, - register_family, _registered_defaults, _registered_families, ) -def setup(): - register_default({ - "key": "id", - "value": "pyblish.starter.instance" - }) - - register_default({"key": "label", "value": "{name}"}) - register_default({"key": "family", "value": "{family}"}) - - register_family({ - "name": "starter.model", - "help": "Polygonal geometry for animation" - }) - - register_family({ - "name": "starter.rig", - "help": "Character rig" - }) - - register_family({ - "name": "starter.animation", - "help": "Pointcache" - }) - - def hierarchy_from_string(hierarchy): parents = {} diff --git a/pyblish_starter/pipeline.py b/pyblish_starter/pipeline.py index 06af9e9..943e90b 100644 --- a/pyblish_starter/pipeline.py +++ b/pyblish_starter/pipeline.py @@ -10,6 +10,29 @@ def setup(): register_plugins() + register_default({ + "key": "id", + "value": "pyblish.starter.instance" + }) + + register_default({"key": "label", "value": "{name}"}) + register_default({"key": "family", "value": "{family}"}) + + register_family({ + "name": "starter.model", + "help": "Polygonal geometry for animation" + }) + + register_family({ + "name": "starter.rig", + "help": "Character rig" + }) + + register_family({ + "name": "starter.animation", + "help": "Pointcache" + }) + def ls(root): """List available assets""" diff --git a/pyblish_starter/tools/asset_loader/__init__.py b/pyblish_starter/tools/asset_loader/__init__.py index e69de29..99c74c8 100644 --- a/pyblish_starter/tools/asset_loader/__init__.py +++ b/pyblish_starter/tools/asset_loader/__init__.py @@ -0,0 +1,3 @@ +from .app import ( + show +) diff --git a/pyblish_starter/tools/asset_loader/__main__.py b/pyblish_starter/tools/asset_loader/__main__.py index a85ff25..5667d32 100644 --- a/pyblish_starter/tools/asset_loader/__main__.py +++ b/pyblish_starter/tools/asset_loader/__main__.py @@ -1,4 +1,6 @@ +import os from . import app with app.application(): - app.show() + app.show(root=os.path.expanduser("~"), + load=lambda name: None) diff --git a/pyblish_starter/tools/asset_loader/app.py b/pyblish_starter/tools/asset_loader/app.py index 18ac1f2..31c96d6 100644 --- a/pyblish_starter/tools/asset_loader/app.py +++ b/pyblish_starter/tools/asset_loader/app.py @@ -2,7 +2,6 @@ import contextlib from ...vendor.Qt import QtWidgets, QtCore -from ...maya.lib import load from ... import ls @@ -11,11 +10,13 @@ class Window(QtWidgets.QDialog): - def __init__(self, parent=None): + def __init__(self, load, parent=None): super(Window, self).__init__(parent) - self.setWindowTitle("Starter Asset Loader") + self.setWindowTitle("Asset Loader") self.setFocusPolicy(QtCore.Qt.StrongFocus) + self.load = load + body = QtWidgets.QWidget() footer = QtWidgets.QWidget() @@ -131,7 +132,21 @@ def on_load(self): self.close() -def show(root): +@contextlib.contextmanager +def application(): + app = QtWidgets.QApplication.instance() + + if not app: + print("Starting new QApplication..") + app = QtWidgets.QApplication(sys.argv) + yield app + app.exec_() + else: + print("Using existing QApplication..") + yield app + + +def show(root, load): if self._window: self._window.close() del(self._window) @@ -143,22 +158,16 @@ def show(root): except KeyError: parent = None - window = Window(parent) - window.show() - window.refresh(root) - - self._window = window - + with application(): + window = Window(load, parent) + window.show() + window.refresh(root) -@contextlib.contextmanager -def application(): - app = QtWidgets.QApplication(sys.argv) - yield - app.exec_() + self._window = window if __name__ == '__main__': import os - with application(): - show(os.path.expanduser("~")) + show(root=os.path.expanduser("~"), + load=lambda name: None) diff --git a/pyblish_starter/tools/instance_creator/__main__.py b/pyblish_starter/tools/instance_creator/__main__.py index a85ff25..371be70 100644 --- a/pyblish_starter/tools/instance_creator/__main__.py +++ b/pyblish_starter/tools/instance_creator/__main__.py @@ -1,4 +1,5 @@ -from . import app +# from . import app -with app.application(): - app.show() +print("hello") +# with app.application(): +# app.show() diff --git a/pyblish_starter/tools/instance_creator/app.py b/pyblish_starter/tools/instance_creator/app.py index c6fde25..00758cb 100644 --- a/pyblish_starter/tools/instance_creator/app.py +++ b/pyblish_starter/tools/instance_creator/app.py @@ -2,20 +2,30 @@ import contextlib from ...vendor.Qt import QtWidgets, QtCore -from ...maya.lib import create from ... import _registered_families - self = sys.modules[__name__] self._window = None class Window(QtWidgets.QDialog): - def __init__(self, parent=None): + """Instance creator + + Arguments: + create (func): Function responsible for creating the instance + Takes (name=str, family=str, use_selection=bool) + parent (QWidget, optional): Window parent + + """ + + def __init__(self, create, parent=None): super(Window, self).__init__(parent) - self.setWindowTitle("Starter Instance Creator") + self.setWindowTitle("Instance Creator") self.setFocusPolicy(QtCore.Qt.StrongFocus) + # Dependency injected creation function + self.create = create + body = QtWidgets.QWidget() lists = QtWidgets.QWidget() footer = QtWidgets.QWidget() @@ -159,7 +169,21 @@ def on_create(self): self.close() -def show(): +@contextlib.contextmanager +def application(): + app = QtWidgets.QApplication.instance() + + if not app: + print("Starting new QApplication..") + app = QtWidgets.QApplication(sys.argv) + yield app + app.exec_() + else: + print("Using existing QApplication..") + yield app + + +def show(create): if self._window: self._window.close() del(self._window) @@ -171,20 +195,13 @@ def show(): except KeyError: parent = None - window = Window(parent) - window.show() - window.refresh() - - self._window = window - + with application(): + window = Window(create, parent) + window.show() + window.refresh() -@contextlib.contextmanager -def application(): - app = QtWidgets.QApplication(sys.argv) - yield - app.exec_() + self._window = window if __name__ == '__main__': - with application(): - show() + show()