summaryrefslogtreecommitdiff
path: root/lib/extensions/reorder.py
blob: 933c1d70d091bd8dda78bcc9f0cf89288e4cf7b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Authors: see git history
#
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later.  See the file LICENSE for details.

from .base import InkstitchExtension


class Reorder(InkstitchExtension):
    # Remove selected objects from the document and readd them in the order they
    # were selected.

    def effect(self):
        objects = self.get_selected_in_order()

        for obj in objects[1:]:
            obj.getparent().remove(obj)

        insert_parent = objects[0].getparent()
        insert_pos = insert_parent.index(objects[0])

        insert_parent.remove(objects[0])

        insert_parent[insert_pos:insert_pos] = objects


if __name__ == '__main__':
    e = Reorder()
    e.affect()