bugfix migrator

This commit is contained in:
Mario Voigt 2024-01-26 16:43:34 +01:00
parent 0e306c045f
commit ff8dc882ba

View File

@ -8,7 +8,7 @@ This extension parses the selection and will put all elements into one single gr
Author: Mario Voigt / FabLab Chemnitz Author: Mario Voigt / FabLab Chemnitz
Mail: mario.voigt@stadtfabrikanten.org Mail: mario.voigt@stadtfabrikanten.org
Date: 13.08.2020 Date: 13.08.2020
Last Patch: 24.01.2024 Last Patch: 26.01.2024
License: GNU GPL v3 License: GNU GPL v3
""" """
@ -88,21 +88,23 @@ class UngrouperAndElementMigratorFilter(inkex.EffectExtension):
docroot = self.document.getroot() docroot = self.document.getroot()
#remove comments #remove comments
if so.comments is True: if so.comments is False:
for element in docroot.iter(): for element in docroot.iter(tag=etree.Comment):
if "cyfunction Comment" in str(element.tag): #inkex.utils.debug("Comment: <!-- {} -->".format(element.text))
self.allDrops.append(element) self.allDrops.append(element)
element.getparent().remove(element)
#remove newlines (tails of elements) #remove newlines (tails of elements)
if so.tails is True: if so.tails is False:
parser = etree.XMLParser(remove_blank_text=True) tails = 0
for element in docroot.iter('*'): for element in docroot.iter('*'):
if element.text is not None: if element.text is not None:
element.text = element.text.strip() element.text = element.text.strip()
tails += 1
if element.tail is not None: if element.tail is not None:
element.tail = element.tail.strip() element.tail = element.tail.strip()
tails += 1
if tails > 0:
self.msg("{} tails/texts were removed during nodes while migration.".format(tails))
namespace = [] #a list of selected types we are going to process for filtering (dropping items) namespace = [] #a list of selected types we are going to process for filtering (dropping items)
#namespace.append("{http://www.w3.org/2000/svg}sodipodi") if so.sodipodi else "" #do not do this. it will crash InkScape #namespace.append("{http://www.w3.org/2000/svg}sodipodi") if so.sodipodi else "" #do not do this. it will crash InkScape
@ -239,7 +241,7 @@ class UngrouperAndElementMigratorFilter(inkex.EffectExtension):
# show a list with items to delete. For ungroup mode it does not apply because we are not going to remove anything # show a list with items to delete. For ungroup mode it does not apply because we are not going to remove anything
if so.operationmode == "filter_only" or so.operationmode == "ungroup_and_filter": if so.operationmode == "filter_only" or so.operationmode == "ungroup_and_filter":
if so.showdroplist: if so.showdroplist:
self.msg(str(len(self.allDrops)) + " elements were removed during nodes while migration.") self.msg("{} elements were removed during nodes while migration.".format(len(self.allDrops)))
if len(self.allDrops) > 100: #if we print too much to the output stream we will freeze InkScape forever wihtout any visual error message. So we write to file instead if len(self.allDrops) > 100: #if we print too much to the output stream we will freeze InkScape forever wihtout any visual error message. So we write to file instead
migrate_log_file = open('migrategroups.log', 'w') migrate_log_file = open('migrategroups.log', 'w')
else: else: