The toy extension below, whose code I extracted from a larger one I've been developing, appears to hang inkscape 1.1 after it exits. When the variable "cntr" is set to a value greater than 108, inkscape hangs with a blank dialog box displayed. Note that, if the AbortExtension statement on line 30 is not commented out, inkscape doesn't hang, but the dashed line isn't drawn on the document. I'm not aware of any limits that I'm exceeding, so I would greatly appreciate any insights that others may have as to why this is happening
linetoy2.py follows:
#!/usr/bin/env python
# coding=utf-8
#
#
"""
Draws a dashed line
"""
import inkex
class LineToy2(inkex.EffectExtension):
def effect(self):
layer = self.svg.get_current_layer()
dprop = ''
cntr = 108
coord = 10.0
for i in range(cntr): # Hangs inkscape on cntr > 108
dprop = dprop+" M {0},{1} L {2},{3}".format(coord,coord,coord+.4,coord+.4)
coord += .8
dprop = dprop[1:]
inkex.utils.debug(dprop)
inkex.utils.debug("dprop = {0} characters".format(len(dprop)))
dline = inkex.PathElement()
dline.set('stroke-width','1.0')
dline.set ('stroke','black')
dline.set('fill','none')
dline.set('d',dprop)
layer.append(dline)
inkex.utils.debug("Finished")
#raise inkex.AbortExtension("Aborted at end of effect")
if __name__ == '__main__':
LineToy2().run()
Well, I wouldn't have guessed that one, but you are indeed correct. This is definitely going to make debugging my larger extension a challenge. Many thanks for your quick response.
I'm just a beginner in python, but most of the simple things beginners need are included as standard library modules in the python distribution, ie they all ship with Inkscape 1.1 + anyway and excluding GTK3 , 1.0.1 as well.
The logging module creates a small file in the extensions folder called 'example.log'. You can change the path - it's not recommended to write to the extensions folder though.
#!/usr/bin/env python
# coding=utf-8
#
#
"""
Draws a dashed line
"""
import logging
import datetime
import inkex
logging.basicConfig(filename='example.log', format='%(message)s', level=logging.DEBUG)
class LineToy2(inkex.EffectExtension):
def effect(self):
layer = self.svg.get_current_layer()
dprop = ''
cntr = 250
coord = 10.0
for i in range(cntr): # Hangs inkscape on cntr > 108
dprop = dprop+" M {0},{1} L {2},{3}".format(coord,coord,coord+.4,coord+.4)
coord += .8
dprop = dprop[1:]
logging.info(f'\n----------------*{datetime.datetime.now()}*----------------')
logging.info(f'cntr : {cntr}\n')
logging.info(f'coord : {coord}\n')
logging.info(f'dprop : {dprop}\n')
logging.info("dprop = {0} characters".format(len(dprop)))
#inkex.utils.debug("dprop = {0} characters".format(len(dprop)))
dline = inkex.PathElement()
dline.set('stroke-width','1.0')
dline.set ('stroke','black')
dline.set('fill','none')
dline.set('d',dprop)
layer.append(dline)
#inkex.utils.debug("Finished")
#raise inkex.AbortExtension("Aborted at end of effect")
if __name__ == '__main__':
LineToy2().run()
The toy extension below, whose code I extracted from a larger one I've been developing, appears to hang inkscape 1.1 after it exits. When the variable "cntr" is set to a value greater than 108, inkscape hangs with a blank dialog box displayed. Note that, if the AbortExtension statement on line 30 is not commented out, inkscape doesn't hang, but the dashed line isn't drawn on the document. I'm not aware of any limits that I'm exceeding, so I would greatly appreciate any insights that others may have as to why this is happening
linetoy2.py follows:
linetoy2.inx follows:
Try commenting out the
inkex.util.debug
lines.Sometimes flooding inkex.erromsg() or debug can hang it.
I just set cntr to 1200, ran no problems.
Well, I wouldn't have guessed that one, but you are indeed correct. This is definitely going to make debugging my larger extension a challenge. Many thanks for your quick response.
I'm just a beginner in python, but most of the simple things beginners need are included as standard library modules in the python distribution, ie they all ship with Inkscape 1.1 + anyway and excluding GTK3 , 1.0.1 as well.
The logging module creates a small file in the extensions folder called 'example.log'. You can change the path - it's not recommended to write to the extensions folder though.
That's a good idea. I've used the logging module a lot in other Python programs.
It would be interesting to know why
inkex.utils.debug()
fails though!If you can replicate the issue consistently and/or provide a minimal example please file a report at https://inkscape.org/report so this can be fixed.
Edit: As a first text, does
inkex.errormsg()
work?