I appreciate the perspective. While also unconventional, what do you think of flipping it?
lock( objA ).tx.s
lock( objB ).t.r.s
lock( objC ).t.s
I’ve done *args in the past but hate passing in all those strings. It didn’t occur to me till now that I could do it like a named tuple.
lock( objA, 'tx s' )
lock( objB, 't r s' )
lock( objC, 't s' )
Are either of those more appealing? I agree that the original would bring up a lot of questions but, and I might be wrong, I think it’s still clear as to what’s happening. But it does, at least initially, add friction by being mysterious.
I think packing the attributes at the end still looks nice (and has a much nicer implementation) but in writing this, the namedtuple inspired version seems the most reasonable of the three; the intent is clear and I don’t think it implies clever tricks like the others do.
The implementations for the curious:
class lock(object):
''' Streamlined way of locking attrs. Ex, `lock(obj)` locks all, `lock(obj).tx` or `lock(obj).ty.r.s`
'''
validAttrs = ['t', 'r', 's'] + [t + a for t in 'trs' for a in 'xyz']
def __getattr__(self, attr):
assert attr in self.validAttrs, 'Only transforms can be locked, not "%s"' % attr
if attr in 'trs': # setKeyable doesn't work on compound attr
for axis in 'xyz':
self.obj.attr(attr + axis).lock()
self.obj.attr(attr + axis).setKeyable(False)
self.obj.attr(attr + axis).showInChannelBox(False)
else:
self.obj.attr(attr).lock()
self.obj.attr(attr).setKeyable(False)
self.obj.attr(attr).showInChannelBox(False)
return self
def __init__(self, obj):
self.obj = obj
def lock(obj, attrs='t r s'):
''' Streamlined way of locking attrs. Ex, `lock(obj)` locks all, `lock(obj, 'tx')` or `lock(obj, 'ty r s')`
'''
validAttrs = ['t', 'r', 's'] + [t + a for t in 'trs' for a in 'xyz']
for attr in attrs.split():
assert attr in validAttrs, 'Only transforms can be locked, not "%s"' % attr
if attr in 'trs': # setKeyable doesn't work on compound attr
for axis in 'xyz':
obj.attr(attr + axis).lock()
obj.attr(attr + axis).setKeyable(False)
obj.attr(attr + axis).showInChannelBox(False)
else:
obj.attr(attr).lock()
obj.attr(attr).setKeyable(False)
obj.attr(attr).showInChannelBox(False)