Skip to content

Instantly share code, notes, and snippets.

View theodox's full-sized avatar

Steve Theodore theodox

View GitHub Profile
win = window('main window', title="Ugly version")
columnLayout('gui', width = 256)
frameLayout("t_buttons", label = "buttons column")
columnLayout("col")
sphere_1 = button('mkSphere', label = "Make Sphere", c = make_sphere)
cone_1 = button('mkCone', label ="Make Cone", c = make_cone)
cube_1 = button('mkCube', label ="Make Cube", c = make_cube)
setParen("..")
setParent("..")
frameLayout("r_buttons", label = "buttons row")
# using the iterability of the layout to set widths
for item in gui.t_buttons:
item.width = 256
for item in gui.r_buttons.row:
item.width = 85
item.width = 256 # the last item is gui.r_buttons.row itself
item.columnWidth3 = (85,85,85) # ditto
import weakref
import maya.utils
from functools import partial
class Event( object ):
'''
FOR COMPLETE DOCS SEE https://github.com/theodox/mGui/blob/master/mGui/events.py
'''
def __init__( self, **data):
from mGui.events import Event
test_event = Event(name='test event')
def test_handler (*args, **kwargs):
print args, kwargs
test_event += test_handler # attach the handler
test_event()
#>> () {'name': 'test event', 'event': <mGui.events.Event object at 0x000000002C7FEC88>}
import time
class OverCoupled(object):
def __init__(self):
self.window = cmds.window()
self.col = cmds.columnLayout()
cmds.button('start', c= self.some_complex_function)
self.msg = cmds.text('...')
self.counter = cmds.text('0')
self._counter = 0
import mGui.gui as gui
import maya.cmds as cmds
import mGui.events as events
def move_down(*args, **kwargs):
cmds.xform(kwargs['target'], t=(0,-10,0), r=True)
# make a window with buttons for each transform. Clicking buttons
# moves them down 10 units
from mGui.events import Event
import mGui.gui as gui
# in this example we can completely disentangle the processing from the UI behavior using events
class ItemProcessor():
'''
The processor does the work - and doesn't know anything about the GUI
'''
def __init__ (self):
@theodox
theodox / mayaPyManager.py
Last active September 23, 2024 22:15
Exposes the MayaPyManager class, which is used to run instances of MayaPy with explict control over paths and environment variables. A Manager can run scripts, modules, or command strings in a separate MayaPy environment; results and errors are captured and returned.
'''
Exposes the MayaPyManager class, which is used to run instances of MayaPy with explict control over paths and environment variables. A Manager can run scripts, modules, or command strings in a separate MayaPy environment; results and errors are captured and returned.
Typical uses might be:
- running unit tests
- running a copy of Maya.standalone as a headless RPC server with StandaloneRPC https://github.com/theodox/standaloneRPC
- spawning multipe copies of maya to batch process files in parallel on a multi-core machine
- do any of the above on multiple maya versions concurrently
'''
web_shim.py
Exposes a custom module loader and importer which allow for download, cache and
load of python modules stored on an HTTP server
To activate, add the class to sys.path_hooks:
sys.path_hooks.append(WebFinder)
'''
# usess the same imports as WebFinder.py
class WebLoader(object):
'''
Import loader (see http://pymotw.com/2/sys/imports.html for background)
which loads modules cached by a WebFinder using imp.load_source
'''
def __init__(self, url, filepath, name):
self.url = url
self.name = name