Skip to content

Instantly share code, notes, and snippets.

View theodox's full-sized avatar

Steve Theodore theodox

View GitHub Profile
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):
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
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
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 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):
# 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
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")
from mGui.gui import *
# note the caps: all of these are wrapper objects, not maya.cmds!
window = Window('main window', title="How's this")
with ColumnLayout('gui', width = 256) as gui:
with FrameLayout("t_buttons", label = "buttons column"):
with ColumnLayout("col"):
Button('mkSphere', label = "Make Sphere")
Button('mkCone', label ="Make Cone")
Button('mkCube', label ="Make Cube")
class Nested(Control):
'''
Base class for all the nested context-manager classes which automatically parent themselves
'''
ACTIVE_LAYOUT = None
def __init__(self, key, *args, **kwargs):
self.Controls = []
super(Nested, self).__init__(key, *args, **kwargs)
class Control(Styled, BindableObject):
'''
Base class for all mGui controls. Provides the necessary frameworks for
CtlProperty and CallbackProperty access to the underlying widget.
NOTE this is not exactly identical to the code on github - more advanced stuff is removed to make the progression clearer
'''
CMD = cmds.control
_ATTRIBS = ['annotation', 'backgroundColor', 'defineTemplate', 'docTag', 'enable', 'enableBackground', 'exists', 'fullPathName', 'height', 'manage', 'noBackground', 'numberOfPopupMenus', 'parent', 'popupMenuArray', 'preventOverride', 'useTemplate', 'visible', 'visibleChangeCommand', 'width']
_CALLBACKS = ['dragCallback', 'dropCallback', 'visibleChangeCommand']