This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!c:\Python27\python | |
"""The Command Pattern | |
An illustration of how the Command Pattern can be used | |
to facilitate scripting and multi-level undo/redo. | |
In this example, the user works against an in-memory | |
datastore, DATASTORE (see below); creates, modified and | |
deletes values, while the Invoker keeps track of what | |
happens in which order; the user may then undo previous |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Request(object): | |
def __call__(self, *args, **kwargs): | |
return self.request_first(*args, **kwargs) | |
def __init__(self, **kwargs): | |
self.__slots = [] | |
def request(self, *args, **kwargs): | |
"""Return generator, yielding one return value per slot""" | |
for subs in self.__slots: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Request(object): | |
""" | |
In contrast to Signal, this object emits a request for data. | |
The observer(s) then transmits requested data. | |
If there is more than one observer, each observer transmits | |
requested until no more data exists. That way, a minimal amount | |
of observers will ever have to process. | |
Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mirror transform | |
from maya import cmds | |
def mirror_transforms(nodes): | |
"""Mirror transforms `nodes` across the YZ axis | |
Arguments: | |
nodes (list): Transforms to be mirrored |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This example is part of a comment from a Pyblish pull-request, #71 | |
https://github.com/abstractfactory/pyblish/pull/72 | |
""" | |
import os | |
import pyblish.backend.plugin | |
context = pyblish.backend.plugin.Context() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given a node following the convention <side>_<name>_<suffix>, look for an | |
equivalent side with matching suffix and transfer attribute values across. | |
.. note:: This assumes controllers are mirrored by *behaviour*; i.e. | |
Identical values produce mirrored results. | |
""" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Store and restore default values | |
Current keyable values are stored in a `defaults` attribute | |
within each node using `store()` and later restored using | |
`restore()`. This way, channels which could otherwise not | |
have a native default value (such as plain transform and rotate) | |
may carry defaults alongside user-defined attributes. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyblish.api | |
from maya import cmds | |
class SelectSelected(pyblish.api.Selector): | |
"""Create instance from the currently selected nodes""" | |
def process_context(self, context): | |
selection = cmds.ls(sl=1) | |
if not selection: | |
raise pyblish.api.SelectionError("Select something") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Library versioning using the default Python syntax | |
Example: | |
>>> is_compatible("pyblish<=1", (0, 9, 0)) | |
True | |
>>> is_compatible("pyblish>=1.1, <2.1", (2, 0, 0)) | |
True | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python | |
import logging | |
# Pick up the "root" logger | |
log = logging.getLogger() | |
# In addition, Modo doesn't come with a handler; handlers | |
# are the objects actually performing any printing. So we'll | |
# add a vanilla handler that simply prints what the user asks |
OlderNewer