Skip to content

Commit

Permalink
Update README, make apps standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
mottosso committed Sep 20, 2016
1 parent f8d9f51 commit 202a995
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 68 deletions.
19 changes: 19 additions & 0 deletions pyblish_starter/__main__.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 0 additions & 2 deletions pyblish_starter/maya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
outmesh,
load,
create,
setup,
)


Expand All @@ -17,5 +16,4 @@
"outmesh",
"load",
"create",
"setup",
]
27 changes: 0 additions & 27 deletions pyblish_starter/maya/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
23 changes: 23 additions & 0 deletions pyblish_starter/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
3 changes: 3 additions & 0 deletions pyblish_starter/tools/asset_loader/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .app import (
show
)
4 changes: 3 additions & 1 deletion pyblish_starter/tools/asset_loader/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
from . import app

with app.application():
app.show()
app.show(root=os.path.expanduser("~"),
load=lambda name: None)
43 changes: 26 additions & 17 deletions pyblish_starter/tools/asset_loader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import contextlib

from ...vendor.Qt import QtWidgets, QtCore
from ...maya.lib import load
from ... import ls


Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand All @@ -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)
7 changes: 4 additions & 3 deletions pyblish_starter/tools/instance_creator/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import app
# from . import app

with app.application():
app.show()
print("hello")
# with app.application():
# app.show()
53 changes: 35 additions & 18 deletions pyblish_starter/tools/instance_creator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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()

0 comments on commit 202a995

Please sign in to comment.