-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathset_css_class.py
More file actions
47 lines (36 loc) · 1.49 KB
/
set_css_class.py
File metadata and controls
47 lines (36 loc) · 1.49 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
"""
Sets a css class on selected elements, while optionally removing the elements' styling.
If inline styles are not removed, the css class might not have effect.
Inspired by MergeStyles (and best used together with it).
"""
__author__ = "Mois Moshev"
__email__ = "mois@monomon.me"
__copyright__ = "Copyright (C) 2017 Mois Moshev"
__license__ = "GPL"
import inkex
import sys
class SetCSSClass(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.arg_parser.add_argument("-n", "--name",
type=str,
dest="name", default="",
help="Name of css class to apply")
self.arg_parser.add_argument("-c", "--clear_styles",
type=inkex.Boolean,
dest="clear_styles", default=True,
help="Name of css class to apply")
def effect(self):
newclass = self.options.name
elements = self.svg.selected.values()
for el in elements:
current_classes = el.attrib.has_key("class") and el.attrib["class"].split() or []
if newclass not in current_classes:
current_classes.append(newclass)
if self.options.clear_styles:
el.attrib.pop("style", None)
el.attrib["class"] = " ".join(current_classes)
if __name__ == "__main__":
e = SetCSSClass()
e.run()