def set_weedline(self,enabled): """ If enabled a box is drawn around the graphic. Returns None.""" assert type(enabled) == bool, "enabled must be a bool" if enabled != self.get_weedline_status(): # a change needs made x,y = self.get_position() if enabled: # add it to the data # bbox should not include padding since the weedline is not yet enabled minx,maxx,miny,maxy = self.get_bounding_box() p = self.get_weedline_padding() d = "M%f,%f V%f H%f V%f Z" % (minx-p,miny-p,maxy+p,maxx+p,miny-p) self._data.extend(simplepath.parsePath(d)) else: # remove it from the data for i in range(0,5): # remove the 5 commands added self._data.pop() self._properties['weedline'] = enabled self.set_position(x,y) self._properties['changed'] = True self._update()
def set_weedline(self, enabled): """ If enabled a box is drawn around the graphic. Returns None.""" assert type(enabled) == bool, "enabled must be a bool" if enabled != self.get_weedline_status(): # a change needs made x, y = self.get_position() if enabled: # add it to the data # bbox should not include padding since the weedline is not yet enabled minx, maxx, miny, maxy = self.get_bounding_box() p = self.get_weedline_padding() d = "M%f,%f V%f H%f V%f Z" % (minx - p, miny - p, maxy + p, maxx + p, miny - p) self._data.extend(simplepath.parsePath(d)) else: # remove it from the data for i in range(0, 5): # remove the 5 commands added self._data.pop() self._properties['weedline'] = enabled self.set_position(x, y) self._properties['changed'] = True self._update()
def _to_simplepaths(self,nodes): """ Takes in a list of etree._Elements and returns a list of simplepaths. """ if type(nodes) != type(list): nodes = list(nodes) spl = [] for node in nodes: if node.tag in [ inkex.addNS('path','svg'), 'path' ]: spl.extend(simplepath.parsePath(node.get("d"))) elif node.tag in [ inkex.addNS('rect','svg'), 'rect' ]: # TODO: Convert rect to path log.warn("Cannot handle '%s' objects, covert to rect's to path first."%(node.tag)) elif node.tag in [ inkex.addNS('g','svg'), 'g' ]: if node.get("transform"): # This doesn't work! #simpletransform.applyTransformToPath(node.get("transform"),node) pass spl.extend(self._to_simplepaths(list(node))) else: log.warn("Cannot handle tag '%s'"%(node.tag)) return spl
def _to_simplepaths(self, nodes): """ Takes in a list of etree._Elements and returns a list of simplepaths. """ if type(nodes) != type(list): nodes = list(nodes) spl = [] for node in nodes: if node.tag in [inkex.addNS('path', 'svg'), 'path']: spl.extend(simplepath.parsePath(node.get("d"))) elif node.tag in [inkex.addNS('rect', 'svg'), 'rect']: # TODO: Convert rect to path log.warn( "Cannot handle '%s' objects, covert to rect's to path first." % (node.tag)) elif node.tag in [inkex.addNS('g', 'svg'), 'g']: if node.get("transform"): # This doesn't work! #simpletransform.applyTransformToPath(node.get("transform"),node) pass spl.extend(self._to_simplepaths(list(node))) else: log.warn("Cannot handle tag '%s'" % (node.tag)) return spl