From 00d7f50a7eb71626eb2958dfb07dbd3ff2d635a8 Mon Sep 17 00:00:00 2001 From: Scott Pakin Date: Wed, 10 Jan 2024 20:18:02 -0700 Subject: [PATCH] Define __repr__ on SimpleMetadata --- simpinkscr/simple_inkscape_scripting.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/simpinkscr/simple_inkscape_scripting.py b/simpinkscr/simple_inkscape_scripting.py index a52fb36..e219b78 100644 --- a/simpinkscr/simple_inkscape_scripting.py +++ b/simpinkscr/simple_inkscape_scripting.py @@ -2149,7 +2149,7 @@ class RectangularForeignObject(inkex.ForeignObject, pass -class SimpleMetadata(): +class SimpleMetadata(GenericReprMixin): 'Provide a simple interface to document metadata.' def __init__(self): @@ -2329,12 +2329,19 @@ def __init__(self): } self._licenses['Open Font License'] = self._licenses['OFL'] + def get_inkex_object(self): + '''Return the SimpleMetadata's underlying inkex object. + Regrettably, this exhibits the side effect of creating a + tag if one does not already exist (tested with + Inkscape 1.3.2.''' + global _simple_top + return _simple_top.svg_root.metadata + def _search_hierarchy(self, *args): '''Search an XML hierarchy given tuples of (namespace, tag). is the implicit first element of the hierarchy. This method returns the final node.''' - global _simple_top - elt = _simple_top.svg_root.metadata + elt = self.get_inkex_object() for ns_tag in [(self.rdf, 'RDF')] + list(args): child = elt.find('./{%s}%s' % ns_tag) if child is None: @@ -2346,8 +2353,7 @@ def _create_hierarchy(self, *args): '''Create an XML hierarchy given tuples of (namespace, tag). is the implicit first element of the hierarchy. This method returns the final node.''' - global _simple_top - elt = _simple_top.svg_root.metadata + elt = self.get_inkex_object() for ns_tag in [(self.rdf, 'RDF')] + list(args): child = elt.find('./{%s}%s' % ns_tag) if child is None: