literate-dotfiles/inkscape.org

88 lines
2.7 KiB
Org Mode
Raw Normal View History

2020-11-03 11:30:27 +01:00
#+TITLE: Inkscape
2021-01-01 20:12:34 +01:00
#+SETUPFILE: ./setup/org-setup-file.org
2020-11-03 11:30:27 +01:00
#+PROPERTY: header-args :comments no
#+PROPERTY: header-args+ :mkdirp yes
* Save Selection to SVG extension
** =ink= file
#+begin_src xml :tangle ~/.config/inkscape/extensions/save_selection/save_selection.inx
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<!-- _name must have same name as .py file but capitalise it. Shows on Menu this way-->
<_name>Save Selection</_name>
<!-- id should be unique. Associates entered values with this menu -->
<id>org.inkscape.save_selection</id>
<!-- mention a dependency here and will check for existence (optional)-->
<dependency type="executable" location="inx">save_selection.py</dependency>
<!-- start notebook -->
<param name="param" type="float" min="0.1" max="1000.0" precision="5" _gui-text="A floating value">1.0</param>
<param name="achoice" type="bool" _gui-text="A boolean value">false</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu _name="Save Selection"/>
</effects-menu>
</effect>
<!-- py file again -->
<script>
<command location="inx" interpreter="python">save_selection.py</command>
</script>
</inkscape-extension>
#+end_src
** =py= file
:PROPERTIES:
:header-args: :shebang "#!/usr/bin/env python"
:header-args+: :comments both :mkdirp yes
:header-args+: :tangle ~/.config/inkscape/extensions/save_selection/save_selection.py
:END:
#+begin_src python
import os
import inkex
import inkex.command
class SaveSelection(inkex.OutputExtension): # choose a better name
def add_arguments(self, pars):
pars.add_argument("--param", type=float, dest="param", default=1.0)
pars.add_argument("-x", "--achoice", type=inkex.Boolean, dest="achoice", default=False)
def save(self, stream):
# param2 = self.options.param
# choice = self.options.achoice
# inkex.command.inkscape_command(self.svg, verbs=['EditInvert']);
# inkex.command.inkscape_command(self.svg, verbs=['EditDelete']);
# filename = os.popen('rofi -dmenu -p "Filename"')
# print(filename)
# inkex.debug(self.svg.selected.svg)
self.document.write(self.svg.selected)
# Get selected objects
# selection = self.svg.selected
# selection = inkex.load_svg(
# inkex.command.inkscape_command(
# self.svg, verbs=['FitCanvasToDrawing']))
# # Create a Canvas ovject
# # Write File
# # stream.write(b''.join(self.svg.selected.tostring()))
# inkex.command.write_svg(selection, "/home/thomas/", "test.svg")
if __name__ == '__main__':
SaveSelection().run()
#+end_src