def effectHook(self): if len(self.selected) != 1: log.outMsg("You have to only select the object whose you want \ to copy the Xmoto parameters.") return False node = self.selected[self.options.ids[0]] label = node.get(addNS('xmoto_label', 'xmoto')) if label is None: log.outMsg("The selected object has no Xmoto properties to copy.") return False node = self.svg.getAndCreateMetadataNode() node.set(addNS('saved_xmoto_label', 'xmoto'), label) return False
def effectLoadHook(self): def setSublayerAttrs(): self.node = convertToXmNode(self.node, self.svg) self.circle = self.node.getCircleChild() self.isBitmap = True self.nodeId = self.circle.get('id', '') if len(self.selected) != 1: log.outMsg("You have to only select the object whose you want to \ change the id.") return (True, False) # this extension exists to handle the case when you want to # change an entity id self.isBitmap = False self.node = self.selected[self.options.ids[0]] if self.node.tag == addNS('g', 'svg'): if self.node.get(addNS('xmoto_label', 'xmoto')) is None: # if someone group a single sprite, and then try to # change it's id, it will spit this on his face : log.outMsg("You have to only select the object whose you want \ to change the id.") return (True, False) else: setSublayerAttrs() elif self.node.tag in [addNS('use', 'svg'), addNS('image', 'svg')]: if self.node.getparent().tag != addNS('g', 'svg'): log.outMsg("You have selected an image which is not part of a \ sublayer entity.\nStop doing that.") return (True, False) else: self.node = self.node.getparent() setSublayerAttrs() else: self.nodeId = self.node.get('id', '') return (False, False)
def effectUnloadHook(self): nodeNewId = self.get('objectId').get_text() if checkVarId(nodeNewId) == False: log.outMsg("You can only use alphanumerical characters and the \ underscore for the id.\nThe id can't begin with a number.") return False if nodeNewId != self.nodeId: if self.isBitmap == True: self.circle.set('id', nodeNewId) self.node.set('id', 'g_' + nodeNewId) image = self.node.find(addNS('image', 'svg')) if image is not None: image.set('id', 'image_' + nodeNewId) else: self.node.set('id', nodeNewId) return False
def effectHook(self): if len(self.selected) == 0: log.outMsg("You have to select the objects whose you want to \ paste the Xmoto parameters.") return False descNode = self.svg.getMetaDataNode() if descNode is None: log.outMsg("You have to copy the Xmoto properties of an \ object first.") return False self.label = descNode.get(addNS('saved_xmoto_label', 'xmoto')) if self.label is None: log.outMsg("You have to copy the Xmoto properties of an \ object first.") return False applyOnElements(self, self.selected, self.setLabel) # we want to update the nodes shapes with their new style return True
def setLabel(self, node): node.set(addNS('xmoto_label', 'xmoto'), self.label)
def effectHook(self): #read svg information, find selected path to use in the line. if len(self.selected) != 1: log.outMsg("You have to select only one object.") return False for node in self.selected.values(): if node.tag not in [addNS('path', 'svg'), addNS('rect', 'svg')]: log.outMsg("You need to select path and rectangle only.") return False # there's only one selected object node = self.selected.values()[0] self.jointType = self.options.joint self.space = self.options.space self.numBlocks = self.options.blocks # is it a physic block? node = convertToXmNode(node, self.svg) label = node.getParsedLabel() createIfAbsent(label, 'position') if 'physics' not in label['position']: log.outMsg("The selected object has to be an Xmoto physics block.") return False # we need uniq ids idPrefix = node.get('id') blockPrefix = idPrefix + 'jl_block' jointPrefix = idPrefix + 'jl_joint' # TODO::if called different times on the same object node.set('id', blockPrefix + '0') aabb = node.getAABB() offset = self.space + aabb.width() jointHeight = 10 if jointHeight > aabb.height() / 2.0: jointHeight = aabb.height() / 2.0 ex = AddJoint(self.jointType) for no in xrange(1, self.numBlocks + 1): node = node.duplicate(blockPrefix + str(no)) node.translate(offset, 0) if no < self.numBlocks + 1: newJoint = None if self.jointType == 'pin': jointX = aabb.x() - aabb.width() / 2.0 - self.space jointY = aabb.y() + aabb.height() / 2.0 - jointHeight / 2.0 jointWidth = aabb.width() + self.space newJoint = etree.Element(addNS('rect', 'svg')) newJoint.set('x', str(jointX)) newJoint.set('y', str(jointY)) newJoint.set('width', str(jointWidth)) newJoint.set('height', str(jointHeight)) elif self.jointType == 'pivot': jointX = aabb.x() - self.space / 2.0 jointY = aabb.cy() newJoint = etree.Element(addNS('path', 'svg')) newJoint.set( 'd', getCenteredCircleSvgPath(jointX, jointY, jointHeight / 2.0)) node.getparent().append(newJoint) newJoint.set('id', jointPrefix + str(no)) transform = node.get('transform') if transform is not None: newJoint.set('transform', transform) label, style = ex.getLabelAndStyle(blockPrefix + str(no - 1), blockPrefix + str(no)) ex.updateNodeSvgAttributes(newJoint, label, style) return False