def _parseLevelOneNodeStr( self, dumpy_data): ##consumer ## can be multiple threads while not self._producer_work_done or not self._level_one_str_queue.empty( ): try: node_str = self._level_one_str_queue.get_nowait() parser = xml.XMLParser(node_str) children = parser.getVirtualRoot().getChildren() assert (len(children) == 1) #print "consumer" level_node_xml_obj = children[0] self._root_lock.acquire() self._root.addChild(level_node_xml_obj) self._root_lock.release() except Queue.Empty: ## may sleep a little bit? time.sleep(0.001)
def LoadFromFile(self, infilename): infile = open(infilename, "r") data = xml.XMLParser(infile.read()).Parse() infile.close() for child in data.children: if child.tag == "source": # Source object pos = (0, 0) initspeed = 0.0 initdirection = 0.0 initspeedrandrange = 0.0 initdirectionrandrange = 0.0 particlesperframe = 0 particlelife = 0 genspacing = 0 drawtype = DRAWTYPE_POINT colour = (0, 0, 0) radius = 0.0 length = 0.0 imagepath = None keyframes = None particlekeyframes = None for parameter in child.children: if parameter.tag == "pos": pos = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "initspeed": initspeed = float(parameter.inside) elif parameter.tag == "initdirection": initdirection = float(parameter.inside) elif parameter.tag == "initspeedrandrange": initspeedrandrange = float(parameter.inside) elif parameter.tag == "initdirectionrandrange": initdirectionrandrange = float(parameter.inside) elif parameter.tag == "particlesperframe": particlesperframe = int(parameter.inside) elif parameter.tag == "particlelife": particlelife = int(parameter.inside) elif parameter.tag == "genspacing": genspacing = int(parameter.inside) elif parameter.tag == "drawtype": drawtype = self.GetStringAsDrawtype(parameter.inside) elif parameter.tag == "colour": colour = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "radius": radius = float(parameter.inside) elif parameter.tag == "length": length = float(parameter.inside) elif parameter.tag == "image": imagepath = float(parameter.inside) elif parameter.tag == "keyframes": keyframes = parameter.children elif parameter.tag == "particlekeyframes": particlekeyframes = parameter.children newsource = self.CreateSource(pos, initspeed, initdirection, initspeedrandrange, initdirectionrandrange, particlesperframe, particlelife, genspacing, drawtype, colour, radius, length, imagepath) for keyframe in keyframes: frame = int(keyframe.meta['frame']) variables = {} for variable in keyframe.children: if variable.tag == "pos_x" and variable.inside != "None": variables['pos_x'] = int(variable.inside) elif variable.tag == "pos_y" and variable.inside != "None": variables['pos_y'] = int(variable.inside) elif variable.tag == "initspeed" and variable.inside != "None": variables['initspeed'] = float(variable.inside) elif variable.tag == "initdirection" and variable.inside != "None": variables['initdirection'] = float(variable.inside) elif variable.tag == "initspeedrandrange" and variable.inside != "None": variables['initspeedrandrange'] = float( variable.inside) elif variable.tag == "initdirectionrandrange" and variable.inside != "None": variables['initdirectionrandrange'] = float( variable.inside) elif variable.tag == "particlesperframe" and variable.inside != "None": variables['particlesperframe'] = int( variable.inside) elif variable.tag == "genspacing" and variable.inside != "None": variables['genspacing'] = int(variable.inside) elif variable.tag == "interpolationtype" and variable.inside != "None": variables[ 'interpolationtype'] = self.GetStringAsInterpolationtype( variable.inside) newframe = newsource.CreateKeyframe(frame=frame) newframe.variables = variables for keyframe in particlekeyframes: frame = int(keyframe.meta['frame']) variables = {} for variable in keyframe.children: if variable.tag == "colour_r" and variable.inside != "None": variables['colour_r'] = int(variable.inside) elif variable.tag == "colour_g" and variable.inside != "None": variables['colour_g'] = int(variable.inside) elif variable.tag == "colour_b" and variable.inside != "None": variables['colour_b'] = int(variable.inside) elif variable.tag == "radius" and variable.inside != "None": variables['radius'] = float(variable.inside) elif variable.tag == "length" and variable.inside != "None": variables['length'] = float(variable.inside) elif variable.tag == "interpolationtype" and variable.inside != "None": variables[ 'interpolationtype'] = self.GetStringAsInterpolationtype( variable.inside) newframe = newsource.CreateParticleKeyframe(frame=frame) newframe.variables = variables newsource.PreCalculateParticles() elif child.tag == "directedgravity": strength = 0.0 strengthrandrange = 0.0 direction = [0, 0] keyframes = None for parameter in child.children: if parameter.tag == "strength": strength = float(parameter.inside) elif parameter.tag == "strengthrandrange": strengthrandrange = float(parameter.inside) elif parameter.tag == "direction": direction = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "keyframes": keyframes = parameter.children newgrav = self.CreateDirectedGravity(strength, strengthrandrange, direction) for keyframe in keyframes: frame = int(keyframe.meta['frame']) variables = {} for variable in keyframe.children: if variable.tag == "strength" and variable.inside != "None": variables['strength'] = float(variable.inside) elif variable.tag == "strengthrandrange" and variable.inside != "None": variables['strengthrandrange'] = float( variable.inside) elif variable.tag == "direction_x" and variable.inside != "None": variables['direction_x'] = float(variable.inside) elif variable.tag == "direction_y" and variable.inside != "None": variables['direction_y'] = float(variable.inside) elif variable.tag == "interpolationtype" and variable.inside != "None": variables[ 'interpolationtype'] = self.GetStringAsInterpolationtype( variable.inside) newframe = newgrav.CreateKeyframe(frame=frame) newframe.variables = variables elif child.tag == "pointgravity": strength = 0.0 strengthrandrange = 0.0 pos = (0, 0) keyframes = None for parameter in child.children: if parameter.tag == "strength": strength = float(parameter.inside) elif parameter.tag == "strengthrandrange": strengthrandrange = float(parameter.inside) elif parameter.tag == "pos": pos = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "keyframes": keyframes = parameter.children newgrav = self.CreatePointGravity(strength, strengthrandrange, pos) for keyframe in keyframes: frame = int(keyframe.meta['frame']) variables = {} for variable in keyframe.children: if variable.tag == "strength" and variable.inside != "None": variables['strength'] = float(variable.inside) elif variable.tag == "strengthrandrange" and variable.inside != "None": variables['strengthrandrange'] = float( variable.inside) elif variable.tag == "pos_x" and variable.inside != "None": variables['pos_x'] = int(variable.inside) elif variable.tag == "pos_y" and variable.inside != "None": variables['pos_y'] = int(variable.inside) elif variable.tag == "interpolationtype" and variable.inside != "None": variables[ 'interpolationtype'] = self.GetStringAsInterpolationtype( variable.inside) newframe = newgrav.CreateKeyframe(frame=frame) newframe.variables = variables elif child.tag == "vortexgravity": strength = 0.0 strengthrandrange = 0.0 pos = (0, 0) keyframes = None for parameter in child.children: if parameter.tag == "strength": strength = float(parameter.inside) elif parameter.tag == "strengthrandrange": strengthrandrange = float(parameter.inside) elif parameter.tag == "pos": direction = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "keyframes": keyframes = parameter.children newgrav = self.CreateVortexGravity(strength, strengthrandrange, pos) for keyframe in keyframes: frame = int(keyframe.meta['frame']) variables = {} for variable in keyframe.children: if variable.tag == "strength" and variable.inside != "None": variables['strength'] = float(variable.inside) elif variable.tag == "strengthrandrange" and variable.inside != "None": variables['strengthrandrange'] = float( variable.inside) elif variable.tag == "pos_x" and variable.inside != "None": variables['pos_x'] = int(variable.inside) elif variable.tag == "pos_y" and variable.inside != "None": variables['pos_y'] = int(variable.inside) elif variable.tag == "interpolationtype" and variable.inside != "None": variables[ 'interpolationtype'] = self.GetStringAsInterpolationtype( variable.inside) newframe = newgrav.CreateKeyframe(frame=frame) newframe.variables = variables elif child.tag == "circle": pos = (0, 0) colour = (0, 0, 0) bounce = 0.0 radius = 0.0 keyframes = None for parameter in child.children: if parameter.tag == "pos": pos = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "colour": colour = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "bounce": bounce = float(parameter.inside) elif parameter.tag == "radius": radius = float(parameter.inside) elif parameter.tag == "keyframes": keyframes = parameter.children newobstacle = self.CreateCircle(pos, colour, bounce, radius) for keyframe in keyframes: frame = int(keyframe.meta['frame']) variables = {} for variable in keyframe.children: if variable.tag == "pos_x" and variable.inside != "None": variables['pos_x'] = int(variable.inside) elif variable.tag == "pos_y" and variable.inside != "None": variables['pos_y'] = int(variable.inside) elif variable.tag == "colour_r" and variable.inside != "None": variables['colour_r'] = int(variable.inside) elif variable.tag == "colour_g" and variable.inside != "None": variables['colour_g'] = int(variable.inside) elif variable.tag == "colour_b" and variable.inside != "None": variables['colour_b'] = int(variable.inside) elif variable.tag == "bounce" and variable.inside != "None": variables['bounce'] = float(variable.inside) elif variable.tag == "radius" and variable.inside != "None": variables['radius'] = float(variable.inside) elif variable.tag == "interpolationtype" and variable.inside != "None": variables[ 'interpolationtype'] = self.GetStringAsInterpolationtype( variable.inside) newframe = newobstacle.CreateKeyframe(frame=frame) newframe.variables = variables elif child.tag == "rectangle": pos = (0, 0) colour = (0, 0, 0) bounce = 0.0 width = 0.0 height = 0.0 keyframes = None for parameter in child.children: if parameter.tag == "pos": pos = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "colour": colour = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "bounce": bounce = float(parameter.inside) elif parameter.tag == "width": width = float(parameter.inside) elif parameter.tag == "height": height = float(parameter.inside) elif parameter.tag == "keyframes": keyframes = parameter.children newobstacle = self.CreateRectangle(pos, colour, bounce, width, height) for keyframe in keyframes: frame = int(keyframe.meta['frame']) variables = {} for variable in keyframe.children: if variable.tag == "pos_x" and variable.inside != "None": variables['pos_x'] = int(variable.inside) elif variable.tag == "pos_y" and variable.inside != "None": variables['pos_y'] = int(variable.inside) elif variable.tag == "colour_r" and variable.inside != "None": variables['colour_r'] = int(variable.inside) elif variable.tag == "colour_g" and variable.inside != "None": variables['colour_g'] = int(variable.inside) elif variable.tag == "colour_b" and variable.inside != "None": variables['colour_b'] = int(variable.inside) elif variable.tag == "bounce" and variable.inside != "None": variables['bounce'] = float(variable.inside) elif variable.tag == "width" and variable.inside != "None": variables['width'] = float(variable.inside) elif variable.tag == "height" and variable.inside != "None": variables['height'] = float(variable.inside) elif variable.tag == "interpolationtype" and variable.inside != "None": variables[ 'interpolationtype'] = self.GetStringAsInterpolationtype( variable.inside) newframe = newobstacle.CreateKeyframe(frame=frame) newframe.variables = variables elif child.tag == "boundaryline": pos = (0, 0) colour = (0, 0, 0) bounce = 0.0 direction = [0.0, 0.0] keyframes = None for parameter in child.children: if parameter.tag == "pos": pos = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "colour": colour = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "bounce": bounce = float(parameter.inside) elif parameter.tag == "normal": normal = self.ConvertXMLTuple(parameter.inside) elif parameter.tag == "keyframes": keyframes = parameter.children newobstacle = self.CreateBoundaryLine(pos, colour, bounce, normal) for keyframe in keyframes: frame = int(keyframe.meta['frame']) variables = {} for variable in keyframe.children: if variable.tag == "pos_x" and variable.inside != "None": variables['pos_x'] = int(variable.inside) elif variable.tag == "pos_y" and variable.inside != "None": variables['pos_y'] = int(variable.inside) elif variable.tag == "colour_r" and variable.inside != "None": variables['colour_r'] = int(variable.inside) elif variable.tag == "colour_g" and variable.inside != "None": variables['colour_g'] = int(variable.inside) elif variable.tag == "colour_b" and variable.inside != "None": variables['colour_b'] = int(variable.inside) elif variable.tag == "bounce" and variable.inside != "None": variables['bounce'] = float(variable.inside) elif variable.tag == "normal_x" and variable.inside != "None": variables['normal_x'] = float(variable.inside) elif variable.tag == "normal_y" and variable.inside != "None": variables['normal_y'] = float(variable.inside) elif variable.tag == "interpolationtype" and variable.inside != "None": variables[ 'interpolationtype'] = self.GetStringAsInterpolationtype( variable.inside) newframe = newobstacle.CreateKeyframe(frame=frame) newframe.variables = variables