added set_css_class extension
This commit is contained in:
parent
3901479ab2
commit
b7ac64c308
@ -34,7 +34,9 @@
|
|||||||
<effect>
|
<effect>
|
||||||
<object-type>all</object-type>
|
<object-type>all</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
<submenu name="Laser Tools" />
|
<submenu name="FabLab Chemnitz">
|
||||||
|
<submenu name="Finger-jointed/Tabbed Boxes"/>
|
||||||
|
</submenu>
|
||||||
</effects-menu>
|
</effects-menu>
|
||||||
</effect>
|
</effect>
|
||||||
<script>
|
<script>
|
||||||
|
20
extensions/fablabchemnitz/set_css_class/meta.json
Normal file
20
extensions/fablabchemnitz/set_css_class/meta.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Set CSS Class On Elements",
|
||||||
|
"id": "fablabchemnitz.de.set_css_class",
|
||||||
|
"path": "set_css_class",
|
||||||
|
"original_name": "Set CSS class on elements",
|
||||||
|
"original_id": "org.inkscape.stylesheet.set",
|
||||||
|
"license": "GNU GPL",
|
||||||
|
"license_url": "https://github.com/monomon/inkscape-set-css-class/blob/master/set_css_class.py",
|
||||||
|
"comment": "",
|
||||||
|
"source_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X/src/branch/master/extensions/fablabchemnitz/set_css_class",
|
||||||
|
"fork_url": "https://github.com/monomon/inkscape-set-css-class",
|
||||||
|
"documentation_url": "https://stadtfabrikanten.org/display/IFM/Set+CSS+Class+On+Elements",
|
||||||
|
"inkscape_gallery_url": null,
|
||||||
|
"main_authors": [
|
||||||
|
"github.com/monomon",
|
||||||
|
"github.com/vmario89"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
19
extensions/fablabchemnitz/set_css_class/set_css_class.inx
Normal file
19
extensions/fablabchemnitz/set_css_class/set_css_class.inx
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
|
<name>Set CSS Class On Elements</name>
|
||||||
|
<id>fablabchemnitz.de.set_css_class</id>
|
||||||
|
<label>Set a CSS class on the selected elements. Their current inline styles will be removed.</label>
|
||||||
|
<param name="name" type="string" gui-text="CSS class name:">class1</param>
|
||||||
|
<param name="clear_styles" type="bool" gui-text="clear inline styling">true</param>
|
||||||
|
<effect needs-live-preview="false">
|
||||||
|
<object-type>all</object-type>
|
||||||
|
<effects-menu>
|
||||||
|
<submenu name="FabLab Chemnitz">
|
||||||
|
<submenu name="Various"/>
|
||||||
|
</submenu>
|
||||||
|
</effects-menu>
|
||||||
|
</effect>
|
||||||
|
<script>
|
||||||
|
<command location="inx" interpreter="python">set_css_class.py</command>
|
||||||
|
</script>
|
||||||
|
</inkscape-extension>
|
40
extensions/fablabchemnitz/set_css_class/set_css_class.py
Normal file
40
extensions/fablabchemnitz/set_css_class/set_css_class.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
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.EffectExtension):
|
||||||
|
|
||||||
|
def add_arguments(self, pars):
|
||||||
|
pars.add_argument("--name", help="Name of css class to apply")
|
||||||
|
pars.add_argument("--clear_styles", type=inkex.Boolean, 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["style"] = ""
|
||||||
|
|
||||||
|
el.attrib["class"] = " ".join(current_classes)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
SetCSSClass().run()
|
Reference in New Issue
Block a user