def __init__(self, cmpname=None, methods=[], ishards={}): """ Generates a pygame kamaelia component if all required methods and shards are supplied, else raises a DependencyError Arguments: cmpname = string of component name, will be used as class name. If None, an auto-generated name will be used. methods = the methods to be added into the class, as function objects or shard objects. At minimum these must include this class's required methods, else a DependencyError will be raised. Objects must be named as the method they are supplying ishards = the inline shards required should be specified as keyword arguments to the shard or function object from which they are to be imported. Non-required shards will be ignored """ mshards = self.makeMethodShards(methods) self.checkDependencies(mshards, ishards) # create default methods and add in shards compInit = initShard(clsname=cmpname, exkwarg='argd', shards=[ishards['__INIT__']]) waitLoop = forShard(name='wait', inVar=r'self.waitBox("callback")', shards=[['yield 1\n']]) mainLoop = whileShard(name='mainLoop', condition='not done', shards=[ ishards['HandleShutdown'], ishards['LoopOverPygameEvents'], ['self.pause()\n', 'yield 1\n'] ]) compMain = functionShard( funcname="main", args=['self'], shards=[ ishards["RequestDisplay"], waitLoop, ishards['GrabDisplay'], ['self.drawBG()\n', 'self.blitToSurface()\n'], ishards['SetEventOptions'], ['done = False\n'], mainLoop ]) # construct class with full shard set classShard.__init__(self, cmpname, superclasses=self.sclasses, docstring=self.dstr, inboxes=self.inbxs, outboxes=self.outbxs, shards=[compInit] + mshards + [compMain])
def __init__(self, cmpname = None, methods = [], ishards = {}): """ Generates a pygame kamaelia component if all required methods and shards are supplied, else raises a DependencyError Arguments: cmpname = string of component name, will be used as class name. If None, an auto-generated name will be used. methods = the methods to be added into the class, as function objects or shard objects. At minimum these must include this class's required methods, else a DependencyError will be raised. Objects must be named as the method they are supplying ishards = the inline shards required should be specified as keyword arguments to the shard or function object from which they are to be imported. Non-required shards will be ignored """ mshards = self.makeMethodShards(methods) self.checkDependencies(mshards, ishards) # create default methods and add in shards compInit = initShard(clsname = cmpname, exkwarg = 'argd', shards = [ishards['__INIT__']]) waitLoop = forShard(name = 'wait', inVar = r'self.waitBox("callback")', shards = [['yield 1\n']]) mainLoop = whileShard(name = 'mainLoop', condition = 'not done', shards = [ishards['HandleShutdown'], ishards['LoopOverPygameEvents'], ['self.pause()\n', 'yield 1\n']]) compMain = functionShard(funcname = "main", args = ['self'], shards = [ishards["RequestDisplay"], waitLoop, ishards['GrabDisplay'], ['self.drawBG()\n', 'self.blitToSurface()\n'], ishards['SetEventOptions'], ['done = False\n'], mainLoop]) # construct class with full shard set classShard.__init__(self, cmpname, superclasses = self.sclasses, docstring = self.dstr, inboxes = self.inbxs, outboxes = self.outbxs, shards = [compInit] + mshards + [compMain])
def __init__(self, name = None, shards = []): mshards = [] ishards = {} for s in shards: if isinstance(s, shard): sname = s.name else: # assume function sname = s.func_name if sname in self.requiredIShards: ishards[sname] = s else: mshards.append(s) mshards = self.makeMethodShards(mshards) self.checkDependencies(mshards, ishards) # create default methods and add in shards compInit = initShard(clsname = name, exkwarg = 'argd', shards = [ishards['__INIT__']]) waitLoop = forShard(name = 'wait', inVar = r'self.waitBox("callback")', shards = [['yield 1\n']]) mainLoop = whileShard(name = 'mainLoop', condition = 'not done', shards = [ishards['ShutdownHandler'], ishards['LoopOverPygameEvents'], ['self.pause()\n', 'yield 1\n']]) compMain = functionShard(funcname = "main", args = ['self'], shards = [ishards["RequestDisplay"], waitLoop, ishards['GrabDisplay'], ['self.drawBG()\n', 'self.blitToSurface()\n'], ishards['SetEventOptions'], ['done = False\n'], mainLoop]) # construct pygame component with default and supplied shards componentShard.__init__(self, name, superclasses = self.sclasses, docstring = self.dstr, inboxes = self.inbxs, outboxes = self.outbxs, shards = [compInit] + mshards + [compMain])