inkstitch/lib/extensions/object_commands.py

40 wiersze
1.2 KiB
Python
Czysty Zwykły widok Historia

2021-03-12 04:17:19 +00:00
# Authors: see git history
#
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
2018-08-17 02:50:34 +00:00
import inkex
from ..commands import OBJECT_COMMANDS, add_commands
2018-08-17 02:50:34 +00:00
from ..i18n import _
from .commands import CommandsExtension
2018-08-17 02:50:34 +00:00
class ObjectCommands(CommandsExtension):
COMMANDS = OBJECT_COMMANDS
2018-08-17 02:50:34 +00:00
def effect(self):
if not self.get_elements():
return
if not self.svg.selection:
2018-08-17 02:50:34 +00:00
inkex.errormsg(_("Please select one or more objects to which to attach commands."))
return
self.svg = self.document.getroot()
commands = [command for command in self.COMMANDS if getattr(self.options, command)]
if not commands:
inkex.errormsg(_("Please choose one or more commands to attach."))
return
# Each object (node) in the SVG may correspond to multiple Elements of different
# types (e.g. stroke + fill). We only want to process each one once.
seen_nodes = set()
for element in self.elements:
2022-05-20 17:06:40 +00:00
if element.node not in seen_nodes and element.shape:
add_commands(element, commands)
2018-08-17 02:50:34 +00:00
seen_nodes.add(element.node)