From 173a22b75f631017a9ac8f2869f9acdd6983ce58 Mon Sep 17 00:00:00 2001 From: Scott Pakin Date: Sun, 27 Aug 2023 22:36:37 -0600 Subject: [PATCH] Impose a deterministic order on new_sis_objs --- simpinkscr/simple_inkscape_scripting.py | 8 +++++++- tests/data/refs/sis__8d48a6c75ad0f6ab2782880662940307.out | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/simpinkscr/simple_inkscape_scripting.py b/simpinkscr/simple_inkscape_scripting.py index 0701144..db83e51 100644 --- a/simpinkscr/simple_inkscape_scripting.py +++ b/simpinkscr/simple_inkscape_scripting.py @@ -3265,6 +3265,12 @@ def apply_action(action, obj=None): # Object type is not recognized by Simple Inkscape Scripting. pass + # Sort new_sis_objs by the underlying inkex objects' order in the SVG + # file. + svg_order = {iobj: num + for iobj, num in zip(svg_root.iter(), range(2**31))} + new_sis_objs.sort(key=lambda k: svg_order[k.get_inkex_object()]) + # Assign a parent to each created object. iobj2obj = {o.get_inkex_object(): o for o in all_objs + new_sis_objs} for obj in new_sis_objs: @@ -3284,7 +3290,7 @@ def apply_action(action, obj=None): # nothing and hope for the best. pass - # Return the set of newly created objects. + # Return the list of newly created objects. return new_sis_objs diff --git a/tests/data/refs/sis__8d48a6c75ad0f6ab2782880662940307.out b/tests/data/refs/sis__8d48a6c75ad0f6ab2782880662940307.out index 44930b8..978174e 100644 --- a/tests/data/refs/sis__8d48a6c75ad0f6ab2782880662940307.out +++ b/tests/data/refs/sis__8d48a6c75ad0f6ab2782880662940307.out @@ -11,8 +11,8 @@ + - - + \ No newline at end of file