<s> """<STR_LIT>""" <EOL> from optparse import OptionParser <EOL> try : <EOL> import maya <EOL> except ImportError , e : <EOL> print ( "<STR_LIT>" ) <EOL> raise e <EOL> import IPython . ipapi <EOL> ip = IPython . ipapi . get ( ) <EOL> from IPython . ColorANSI import TermColors , ColorScheme , ColorSchemeTable <EOL> from IPython . genutils import page <EOL> try : <EOL> import readline <EOL> except ImportError : <EOL> import pyreadline as readline <EOL> delim = readline . get_completer_delims ( ) <EOL> delim = delim . replace ( '<STR_LIT:|>' , '<STR_LIT>' ) <EOL> delim = delim . replace ( '<STR_LIT::>' , '<STR_LIT>' ) <EOL> readline . set_completer_delims ( delim ) <EOL> import inspect , re , glob , os , shlex , sys <EOL> from pymel import core <EOL> import maya . cmds as cmds <EOL> import IPython . Extensions . ipy_completers <EOL> _scheme_default = '<STR_LIT>' <EOL> Colors = TermColors <EOL> NoColor = ColorScheme ( <EOL> '<STR_LIT>' , { <EOL> '<STR_LIT>' : Colors . NoColor , <EOL> '<STR_LIT>' : Colors . NoColor , <EOL> '<STR_LIT>' : Colors . NoColor , <EOL> '<STR_LIT>' : Colors . NoColor , <EOL> '<STR_LIT>' : Colors . NoColor , <EOL> '<STR_LIT>' : Colors . NoColor , <EOL> '<STR_LIT>' : Colors . NoColor , <EOL> '<STR_LIT>' : Colors . NoColor <EOL> } ) <EOL> LinuxColors = ColorScheme ( <EOL> '<STR_LIT>' , { <EOL> '<STR_LIT>' : Colors . LightCyan , <EOL> '<STR_LIT>' : Colors . Yellow , <EOL> '<STR_LIT>' : Colors . Green , <EOL> '<STR_LIT>' : Colors . White , <EOL> '<STR_LIT>' : Colors . LightGray , <EOL> '<STR_LIT>' : Colors . Red , <EOL> '<STR_LIT>' : Colors . LightRed , <EOL> '<STR_LIT>' : Colors . Normal <EOL> } ) <EOL> LightBGColors = ColorScheme ( <EOL> '<STR_LIT>' , { <EOL> '<STR_LIT>' : Colors . Cyan , <EOL> '<STR_LIT>' : Colors . LightGreen , <EOL> '<STR_LIT>' : Colors . Blue , <EOL> '<STR_LIT>' : Colors . DarkGray , <EOL> '<STR_LIT>' : Colors . Black , <EOL> '<STR_LIT>' : Colors . Red , <EOL> '<STR_LIT>' : Colors . LightRed , <EOL> '<STR_LIT>' : Colors . Normal <EOL> } ) <EOL> color_table = ColorSchemeTable ( [ NoColor , LinuxColors , LightBGColors ] , <EOL> _scheme_default ) <EOL> def finalPipe ( obj ) : <EOL> """<STR_LIT>""" <EOL> if cmds . listRelatives ( obj ) : <EOL> return obj + "<STR_LIT:|>" <EOL> return obj <EOL> def splitDag ( obj ) : <EOL> buf = obj . split ( '<STR_LIT:|>' ) <EOL> tail = buf [ - <NUM_LIT:1> ] <EOL> path = '<STR_LIT:|>' . join ( buf [ : - <NUM_LIT:1> ] ) <EOL> return path , tail <EOL> def expand ( obj ) : <EOL> """<STR_LIT>""" <EOL> return ( obj + '<STR_LIT:*>' , obj + '<STR_LIT>' , obj + '<STR_LIT>' ) <EOL> def complete_node_with_no_path ( node ) : <EOL> tmpres = cmds . ls ( expand ( node ) ) <EOL> res = [ ] <EOL> for x in tmpres : <EOL> x = finalPipe ( x . split ( '<STR_LIT:|>' ) [ - <NUM_LIT:1> ] ) <EOL> if x not in res : <EOL> res . append ( x ) <EOL> return res <EOL> def complete_node_with_attr ( node , attr ) : <EOL> long_attrs = cmds . listAttr ( node ) <EOL> short_attrs = cmds . listAttr ( node , shortNames = <NUM_LIT:1> ) <EOL> if '<STR_LIT:.>' in node : <EOL> attrs = long_attrs [ <NUM_LIT:1> : ] + short_attrs [ <NUM_LIT:1> : ] <EOL> else : <EOL> attrs = long_attrs + short_attrs <EOL> return [ u'<STR_LIT>' % ( node , a ) for a in attrs if a . startswith ( attr ) ] <EOL> def pymel_name_completer ( self , event ) : <EOL> def get_children ( obj ) : <EOL> path , partialObj = splitDag ( obj ) <EOL> try : <EOL> fullpath = cmds . ls ( path , l = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> if not fullpath : return [ ] <EOL> children = cmds . listRelatives ( fullpath , f = <NUM_LIT:1> , c = <NUM_LIT:1> ) <EOL> if not children : return [ ] <EOL> except : <EOL> return [ ] <EOL> matchStr = fullpath + '<STR_LIT:|>' + partialObj <EOL> matches = [ x . replace ( fullpath , path , <NUM_LIT:1> ) for x in children if x . startswith ( matchStr ) ] <EOL> return matches <EOL> line = event . symbol <EOL> matches = None <EOL> m = re . match ( r"""<STR_LIT>""" , line ) <EOL> if m : <EOL> node , attr = m . groups ( ) <EOL> if node == '<STR_LIT>' : <EOL> res = cmds . ls ( attr + '<STR_LIT:*>' ) <EOL> if res : <EOL> matches = [ '<STR_LIT>' + x for x in res if '<STR_LIT:|>' not in x ] <EOL> elif node . startswith ( '<STR_LIT>' ) : <EOL> node = node . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> matches = [ '<STR_LIT>' + x for x in complete_node_with_attr ( node , attr ) if '<STR_LIT:|>' not in x ] <EOL> else : <EOL> matches = complete_node_with_attr ( node , attr ) <EOL> else : <EOL> if '<STR_LIT:|>' not in line or ( line . startswith ( '<STR_LIT:|>' ) and line . count ( '<STR_LIT:|>' ) == <NUM_LIT:1> ) : <EOL> kwargs = { } <EOL> if line . startswith ( '<STR_LIT:|>' ) : <EOL> kwargs [ '<STR_LIT:l>' ] = True <EOL> matches = cmds . ls ( expand ( line ) , ** kwargs ) <EOL> else : <EOL> matches = get_children ( line ) <EOL> if not matches : <EOL> raise IPython . ipapi . TryNext <EOL> if len ( matches ) == <NUM_LIT:1> : <EOL> res = get_children ( matches [ <NUM_LIT:0> ] + '<STR_LIT:|>' ) <EOL> matches += res <EOL> return matches <EOL> def pymel_python_completer ( self , event ) : <EOL> """<STR_LIT>""" <EOL> text = event . symbol <EOL> m = re . match ( r"<STR_LIT>" , text ) <EOL> if not m : <EOL> raise IPython . ipapi . TryNext <EOL> expr , attr = m . group ( <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> try : <EOL> obj = eval ( expr , self . Completer . namespace ) <EOL> except : <EOL> try : <EOL> obj = eval ( expr , self . Completer . global_namespace ) <EOL> except : <EOL> raise IPython . ipapi . TryNext <EOL> if isinstance ( obj , ( core . nt . DependNode , core . Attribute ) ) : <EOL> node = unicode ( obj ) <EOL> long_attrs = cmds . listAttr ( node ) <EOL> short_attrs = cmds . listAttr ( node , shortNames = <NUM_LIT:1> ) <EOL> matches = [ ] <EOL> matches = self . Completer . python_matches ( text ) <EOL> if '<STR_LIT:.>' in node : <EOL> attrs = long_attrs [ <NUM_LIT:1> : ] + short_attrs [ <NUM_LIT:1> : ] <EOL> else : <EOL> attrs = long_attrs + short_attrs <EOL> matches += [ expr + '<STR_LIT:.>' + at for at in attrs ] <EOL> return matches <EOL> raise IPython . ipapi . TryNext <EOL> def buildRecentFileMenu ( ) : <EOL> if "<STR_LIT>" not in core . optionVar : <EOL> return <EOL> RecentFilesList = core . optionVar [ "<STR_LIT>" ] <EOL> nNumItems = len ( RecentFilesList ) <EOL> RecentFilesMaxSize = core . optionVar [ "<STR_LIT>" ] <EOL> if nNumItems > <NUM_LIT:0> : <EOL> if "<STR_LIT>" not in core . optionVar : <EOL> core . mel . initRecentFilesTypeList ( RecentFilesList ) <EOL> RecentFilesTypeList = core . optionVar [ "<STR_LIT>" ] <EOL> def open_completer ( self , event ) : <EOL> relpath = event . symbol <EOL> if '<STR_LIT>' in event . line : <EOL> bkms = self . db . get ( '<STR_LIT>' , { } ) <EOL> return bkms . keys ( ) <EOL> if event . symbol == '<STR_LIT:->' : <EOL> print "<STR_LIT>" <EOL> width_dh = str ( len ( str ( len ( ip . user_ns [ '<STR_LIT>' ] ) + <NUM_LIT:1> ) ) ) <EOL> print width_dh <EOL> fmt = '<STR_LIT>' + width_dh + '<STR_LIT>' <EOL> ents = [ fmt % ( i , s ) for i , s in enumerate ( ip . user_ns [ '<STR_LIT>' ] ) ] <EOL> if len ( ents ) > <NUM_LIT:1> : <EOL> return ents <EOL> return [ ] <EOL> raise IPython . ipapi . TryNext <EOL> class TreePager ( object ) : <EOL> def __init__ ( self , colors , options ) : <EOL> self . colors = colors <EOL> self . options = options <EOL> def do_level ( self , obj , depth , isLast ) : <EOL> if isLast [ - <NUM_LIT:1> ] : <EOL> sep = '<STR_LIT>' <EOL> else : <EOL> sep = '<STR_LIT>' <EOL> depth += <NUM_LIT:1> <EOL> branch = '<STR_LIT>' <EOL> for x in isLast [ : - <NUM_LIT:1> ] : <EOL> if x : <EOL> branch += '<STR_LIT:U+0020>' <EOL> else : <EOL> branch += '<STR_LIT>' <EOL> branch = self . colors [ '<STR_LIT>' ] + branch + sep + self . colors [ '<STR_LIT>' ] <EOL> children = self . getChildren ( obj ) <EOL> name = self . getName ( obj ) <EOL> num = len ( children ) - <NUM_LIT:1> <EOL> if children : <EOL> if self . options . maxdepth and depth >= self . options . maxdepth : <EOL> state = '<STR_LIT:+>' <EOL> else : <EOL> state = '<STR_LIT:->' <EOL> pre = self . colors [ '<STR_LIT>' ] + state + '<STR_LIT:U+0020>' <EOL> else : <EOL> pre = '<STR_LIT:U+0020>' <EOL> yield pre + branch + name + self . colors [ '<STR_LIT>' ] + '<STR_LIT:\n>' <EOL> if not self . options . maxdepth or depth < self . options . maxdepth : <EOL> for i , x in enumerate ( children ) : <EOL> for line in self . do_level ( x , depth , isLast + [ i == num ] ) : <EOL> yield line <EOL> def make_tree ( self , roots ) : <EOL> num = len ( roots ) - <NUM_LIT:1> <EOL> tree = '<STR_LIT>' <EOL> for i , x in enumerate ( roots ) : <EOL> for line in self . do_level ( x , <NUM_LIT:0> , [ i == num ] ) : <EOL> tree += line <EOL> return tree <EOL> class DagTree ( TreePager ) : <EOL> def getChildren ( self , obj ) : <EOL> if self . options . shapes : <EOL> return obj . getChildren ( ) <EOL> else : <EOL> return obj . getChildren ( type = '<STR_LIT>' ) <EOL> def getName ( self , obj ) : <EOL> name = obj . nodeName ( ) <EOL> if obj . isInstanced ( ) : <EOL> if isinstance ( obj , core . nt . Transform ) : <EOL> color = self . colors [ '<STR_LIT>' ] <EOL> else : <EOL> color = self . colors [ '<STR_LIT>' ] <EOL> id = obj . instanceNumber ( ) <EOL> if id != <NUM_LIT:0> : <EOL> source = '<STR_LIT>' % obj . getOtherInstances ( ) [ <NUM_LIT:0> ] <EOL> else : <EOL> source = '<STR_LIT>' <EOL> name = color + name + self . colors [ '<STR_LIT>' ] + '<STR_LIT>' + str ( id ) + '<STR_LIT:]>' + source <EOL> elif not obj . isUniquelyNamed ( ) : <EOL> if isinstance ( obj , core . nt . Transform ) : <EOL> color = self . colors [ '<STR_LIT>' ] <EOL> else : <EOL> color = self . colors [ '<STR_LIT>' ] <EOL> name = color + name <EOL> elif isinstance ( obj , core . nt . Transform ) : <EOL> name = self . colors [ '<STR_LIT>' ] + name <EOL> else : <EOL> name = self . colors [ '<STR_LIT>' ] + name <EOL> return name <EOL> dag_parser = OptionParser ( ) <EOL> dag_parser . add_option ( "<STR_LIT>" , type = "<STR_LIT:int>" , dest = "<STR_LIT>" ) <EOL> dag_parser . add_option ( "<STR_LIT>" , action = "<STR_LIT>" , dest = "<STR_LIT>" , default = True ) <EOL> dag_parser . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" ) <EOL> def magic_dag ( self , parameter_s = '<STR_LIT>' ) : <EOL> """<STR_LIT:U+0020>""" <EOL> options , args = dag_parser . parse_args ( parameter_s . split ( ) ) <EOL> colors = color_table [ self . rc . colors ] . colors <EOL> dagtree = DagTree ( colors , options ) <EOL> if args : <EOL> roots = [ core . PyNode ( args [ <NUM_LIT:0> ] ) ] <EOL> else : <EOL> roots = core . ls ( assemblies = <NUM_LIT:1> ) <EOL> page ( dagtree . make_tree ( roots ) ) <EOL> class DGHistoryTree ( TreePager ) : <EOL> def getChildren ( self , obj ) : <EOL> source , dest = obj <EOL> return source . node ( ) . listConnections ( plugs = True , connections = True , source = True , destination = False , sourceFirst = True ) <EOL> def getName ( self , obj ) : <EOL> source , dest = obj <EOL> name = "<STR_LIT>" % ( source , dest ) <EOL> return name <EOL> def make_tree ( self , root ) : <EOL> roots = core . listConnections ( root , plugs = True , connections = True , source = True , destination = False , sourceFirst = True ) <EOL> return TreePager . make_tree ( self , roots ) <EOL> dg_parser = OptionParser ( ) <EOL> dg_parser . add_option ( "<STR_LIT>" , type = "<STR_LIT:int>" , dest = "<STR_LIT>" ) <EOL> dg_parser . add_option ( "<STR_LIT>" , action = "<STR_LIT>" , dest = "<STR_LIT>" , default = True ) <EOL> dg_parser . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" ) <EOL> def magic_dghist ( self , parameter_s = '<STR_LIT>' ) : <EOL> """<STR_LIT:U+0020>""" <EOL> options , args = dg_parser . parse_args ( parameter_s . split ( ) ) <EOL> colors = color_table [ self . rc . colors ] . colors <EOL> dgtree = DGHistoryTree ( colors , options ) <EOL> roots = [ core . PyNode ( args [ <NUM_LIT:0> ] ) ] <EOL> page ( dgtree . make_tree ( roots ) ) <EOL> def magic_open ( self , parameter_s = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> parameter_s = parameter_s . strip ( ) <EOL> oldcwd = os . getcwd ( ) <EOL> numcd = re . match ( r'<STR_LIT>' , parameter_s ) <EOL> if numcd : <EOL> nn = int ( numcd . group ( <NUM_LIT:2> ) ) <EOL> try : <EOL> ps = ip . ev ( '<STR_LIT>' % nn ) <EOL> except IndexError : <EOL> print '<STR_LIT>' <EOL> return <EOL> else : <EOL> opts = { } <EOL> else : <EOL> parameter_s = re . sub ( r'<STR_LIT>' , '<STR_LIT:/>' , parameter_s ) <EOL> opts , ps = self . parse_options ( parameter_s , '<STR_LIT>' , mode = '<STR_LIT:string>' ) <EOL> if ps == '<STR_LIT:->' : <EOL> try : <EOL> ps = ip . ev ( '<STR_LIT>' % nn ) <EOL> except IndexError : <EOL> raise UsageError ( '<STR_LIT>' ) <EOL> if ps : <EOL> ip . ex ( '<STR_LIT>' % ps ) <EOL> def setup ( ) : <EOL> ip = IPython . ipapi . get ( ) <EOL> ip . set_hook ( '<STR_LIT>' , pymel_python_completer , re_key = "<STR_LIT>" ) <EOL> ip . set_hook ( '<STR_LIT>' , pymel_name_completer , re_key = "<STR_LIT>" ) <EOL> ip . set_hook ( '<STR_LIT>' , open_completer , str_key = "<STR_LIT>" ) <EOL> ip . ex ( "<STR_LIT>" ) <EOL> ip . expose_magic ( '<STR_LIT>' , magic_open ) <EOL> ip . expose_magic ( '<STR_LIT>' , magic_dag ) <EOL> ip . expose_magic ( '<STR_LIT>' , magic_dghist ) <EOL> ip . ex ( """<STR_LIT>""" ) <EOL> ip . ex ( """<STR_LIT>""" ) <EOL> def main ( ) : <EOL> import IPython . Shell <EOL> s = IPython . Shell . start ( ) <EOL> setup ( ) <EOL> s . mainloop ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
