Inkscape.org
Creating New Extensions This extension appears to hang Inkscape on exit. Why?
  1. #1
    observing observing @observing

    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()
    

    linetoy2.inx follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
      <name>Line Toy 2</name>
      <id>org.inkscape.linetoy2</id>
      <effect>
        <effects-menu>
          <submenu name="Effect"/>
        </effects-menu>
      </effect>
      <script>
        <command location="inx" interpreter="python">linetoy2.py</command>
      </script>
    </inkscape-extension>
    

     

  2. #2
    inklinea inklinea @inklinea⛰️

    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.

  3. #3
    observing observing @observing

    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.

  4. #4
    inklinea inklinea @inklinea⛰️

    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()
  5. #5
    observing observing @observing

    That's a good idea. I've used the logging module a lot in other Python programs.

  6. #6
    Patrick Storz Patrick Storz @Ede_123
    *

    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?

Inkscape Inkscape.org Inkscape Forum Creating New Extensions This extension appears to hang Inkscape on exit. Why?