def get_original(self): """Here, we try to find inktex objects among the selected svg elements when the dialog was opened.""" src_attrib = Converter.add_ns('src', ns=u'inktex') g_tag = Converter.add_ns('g', ns=u'svg') for i in self.options.ids: node = self.selected[i] if node.tag == g_tag and src_attrib in node.attrib: return node, \ node.attrib.get(src_attrib, '').decode('string-escape') return None, None
def store_settings(self, settings): """Store a dict of inktex settings in the svg tree""" # find or create svg/metadata/inktex:settings try: inktex_settings = self.document.xpath('//inktex:settings', namespaces=Converter.namespaces)[0] except: metadata = self.xpathSingle('//svg:metadata') inktex_settings = inkex.etree.SubElement(metadata, Converter.add_ns('settings', ns=u'inktex')) # small helper function to store settings def store_setting(name, value): inktex_settings.attrib[Converter.add_ns(name, ns=u'inktex')] = str(value) # store settings for key, value in settings.iteritems(): store_setting(key, value)
def store_settings(self, settings): """Store a dict of inktex settings in the svg tree""" # find or create svg/metadata/inktex:settings try: inktex_settings = self.document.xpath( '//inktex:settings', namespaces=Converter.namespaces)[0] except: metadata = self.xpathSingle('//svg:metadata') inktex_settings = inkex.etree.SubElement( metadata, Converter.add_ns('settings', ns=u'inktex')) # small helper function to store settings def store_setting(name, value): inktex_settings.attrib[Converter.add_ns(name, ns=u'inktex')] = str(value) # store settings for key, value in settings.iteritems(): store_setting(key, value)
def copy_styles(self): """Copy the styles and transforms if we edited an old element. This can be extended further, to include colors etc.""" transform_attrib = 'transform' transform_attrib_ns = Converter.add_ns('transform', ns=u'svg') style_attrib = 'style' if self.orig is None: return if transform_attrib in self.orig.attrib: self.new.attrib[transform_attrib] = \ self.orig.attrib[transform_attrib] if transform_attrib_ns in self.orig.attrib: self.new.attrib[transform_attrib] = \ self.orig.attrib[transform_attrib_ns] if style_attrib in self.orig.attrib: self.new.attrib[style_attrib] = self.orig.attrib[style_attrib]
def store_src_information(self): """Store the LaTeX source in the top level element.""" self.new.attrib[Converter.add_ns('src', ns=u'inktex')] = \ self.new_src.encode('string-escape')
def store_setting(name, value): inktex_settings.attrib[Converter.add_ns(name, ns=u'inktex')] = str(value)