literate-dotfiles/docs/inkscape.html

131 lines
12 KiB
HTML

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2021-01-01 ven. 20:09 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Inkscape</title>
<meta name="generator" content="Org mode" />
<meta name="author" content="Dehaeze Thomas" />
<link rel="stylesheet" type="text/css" href="./dist/style.css"/>
<script type="text/javascript" src="./dist/script.js"></script>
</head>
<body>
<div id="org-div-home-and-up">
<a accesskey="h" href="./index.html"> UP </a>
|
<a accesskey="H" href="./index.html"> HOME </a>
</div><div id="content">
<h1 class="title">Inkscape</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#orge5e47be">Save Selection to SVG extension</a>
<ul>
<li><a href="#org74c03e7"><code>ink</code> file</a></li>
<li><a href="#org7f93603"><code>py</code> file</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-orge5e47be" class="outline-2">
<h2 id="orge5e47be">Save Selection to SVG extension</h2>
<div class="outline-text-2" id="text-orge5e47be">
</div>
<div id="outline-container-org74c03e7" class="outline-3">
<h3 id="org74c03e7"><code>ink</code> file</h3>
<div class="outline-text-3" id="text-org74c03e7">
<div class="org-src-container">
<pre class="src src-xml"><span class="org-nxml-processing-instruction-delimiter">&lt;?</span><span class="org-nxml-processing-instruction-target">xml</span> <span class="org-nxml-processing-instruction-content">version="1.0" encoding="utf-8"</span><span class="org-nxml-processing-instruction-delimiter">?&gt;</span>
<span class="org-nxml-processing-instruction-delimiter">&lt;?</span><span class="org-nxml-processing-instruction-target">xml</span> <span class="org-nxml-processing-instruction-content">version="1.0" encoding="UTF-8"</span><span class="org-nxml-processing-instruction-delimiter">?&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">inkscape-extension</span> <span class="org-nxml-namespace-attribute-xmlns">xmlns</span>=<span class="org-string">"http://www.inkscape.org/namespace/inkscape/extension"</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-comment-delimiter">&lt;!-- </span><span class="org-comment">_name must have same name as .py file but capitalise it. Shows on Menu this way</span><span class="org-comment-delimiter">--&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">_name</span><span class="org-nxml-tag-delimiter">&gt;</span><span class="org-nxml-text">Save Selection</span><span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-element-local-name">_name</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-comment-delimiter">&lt;!-- </span><span class="org-comment">id should be unique. Associates entered values with this menu </span><span class="org-comment-delimiter">--&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">id</span><span class="org-nxml-tag-delimiter">&gt;</span><span class="org-nxml-text">org.inkscape.save_selection</span><span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-element-local-name">id</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-comment-delimiter">&lt;!-- </span><span class="org-comment">mention a dependency here and will check for existence (optional)</span><span class="org-comment-delimiter">--&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">dependency</span> <span class="org-nxml-attribute-local-name">type</span>=<span class="org-string">"executable"</span> <span class="org-nxml-attribute-local-name">location</span>=<span class="org-string">"inx"</span><span class="org-nxml-tag-delimiter">&gt;</span><span class="org-nxml-text">save_selection.py</span><span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-element-local-name">dependency</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-comment-delimiter">&lt;!-- </span><span class="org-comment">start notebook </span><span class="org-comment-delimiter">--&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">param</span> <span class="org-nxml-attribute-local-name">name</span>=<span class="org-string">"param"</span> <span class="org-nxml-attribute-local-name">type</span>=<span class="org-string">"float"</span> <span class="org-nxml-attribute-local-name">min</span>=<span class="org-string">"0.1"</span> <span class="org-nxml-attribute-local-name">max</span>=<span class="org-string">"1000.0"</span> <span class="org-nxml-attribute-local-name">precision</span>=<span class="org-string">"5"</span> <span class="org-nxml-attribute-local-name">_gui-text</span>=<span class="org-string">"A floating value"</span><span class="org-nxml-tag-delimiter">&gt;</span><span class="org-nxml-text">1.0</span><span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-element-local-name">param</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">param</span> <span class="org-nxml-attribute-local-name">name</span>=<span class="org-string">"achoice"</span> <span class="org-nxml-attribute-local-name">type</span>=<span class="org-string">"bool"</span> <span class="org-nxml-attribute-local-name">_gui-text</span>=<span class="org-string">"A boolean value"</span><span class="org-nxml-tag-delimiter">&gt;</span><span class="org-nxml-text">false</span><span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-element-local-name">param</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">effect</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">object-type</span><span class="org-nxml-tag-delimiter">&gt;</span><span class="org-nxml-text">all</span><span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-element-local-name">object-type</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">effects-menu</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">submenu</span> <span class="org-nxml-attribute-local-name">_name</span>=<span class="org-string">"Save Selection"</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-element-local-name">effects-menu</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-element-local-name">effect</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-comment-delimiter">&lt;!-- </span><span class="org-comment">py file again </span><span class="org-comment-delimiter">--&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">script</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-element-local-name">command</span> <span class="org-nxml-attribute-local-name">location</span>=<span class="org-string">"inx"</span> <span class="org-nxml-attribute-local-name">interpreter</span>=<span class="org-string">"python"</span><span class="org-nxml-tag-delimiter">&gt;</span><span class="org-nxml-text">save_selection.py</span><span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-element-local-name">command</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-element-local-name">script</span><span class="org-nxml-tag-delimiter">&gt;</span>
<span class="org-nxml-tag-delimiter">&lt;</span><span class="org-nxml-tag-slash">/</span><span class="org-nxml-element-local-name">inkscape-extension</span><span class="org-nxml-tag-delimiter">&gt;</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org7f93603" class="outline-3">
<h3 id="org7f93603"><code>py</code> file</h3>
<div class="outline-text-3" id="text-org7f93603">
<div class="org-src-container">
<pre class="src src-python"><span class="org-keyword">import</span> os
<span class="org-keyword">import</span> inkex
<span class="org-keyword">import</span> inkex.command
<span class="org-keyword">class</span> <span class="org-type">SaveSelection</span>(inkex.OutputExtension): <span class="org-comment-delimiter"># </span><span class="org-comment">choose a better name</span>
<span class="org-keyword">def</span> <span class="org-function-name">add_arguments</span>(<span class="org-keyword">self</span>, pars):
pars.add_argument(<span class="org-string">"--param"</span>, <span class="org-builtin">type</span>=<span class="org-builtin">float</span>, dest=<span class="org-string">"param"</span>, default=<span class="org-highlight-numbers-number">1.0</span>)
pars.add_argument(<span class="org-string">"-x"</span>, <span class="org-string">"--achoice"</span>, <span class="org-builtin">type</span>=inkex.Boolean, dest=<span class="org-string">"achoice"</span>, default=<span class="org-constant">False</span>)
<span class="org-keyword">def</span> <span class="org-function-name">save</span>(<span class="org-keyword">self</span>, stream):
<span class="org-comment-delimiter"># </span><span class="org-comment">param2 = self.options.param</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">choice = self.options.achoice</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">inkex.command.inkscape_command(self.svg, verbs=['EditInvert']);</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">inkex.command.inkscape_command(self.svg, verbs=['EditDelete']);</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">filename = os.popen('rofi -dmenu -p "Filename"')</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">print(filename)</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">inkex.debug(self.svg.selected.svg)</span>
<span class="org-keyword">self</span>.document.write(<span class="org-keyword">self</span>.svg.selected)
<span class="org-comment-delimiter"># </span><span class="org-comment">Get selected objects</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">selection = self.svg.selected</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">selection = inkex.load_svg(</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">inkex.command.inkscape_command(</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">self.svg, verbs=['FitCanvasToDrawing']))</span>
<span class="org-comment-delimiter"># </span><span class="org-comment"># Create a Canvas ovject</span>
<span class="org-comment-delimiter"># </span><span class="org-comment"># Write File</span>
<span class="org-comment-delimiter"># </span><span class="org-comment"># stream.write(b''.join(self.svg.selected.tostring()))</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">inkex.command.write_svg(selection, "/home/thomas/", "test.svg")</span>
<span class="org-keyword">if</span> <span class="org-builtin">__name__</span> == <span class="org-string">'__main__'</span>:
SaveSelection().run()
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: Dehaeze Thomas</p>
<p class="date">Created: 2021-01-01 ven. 20:09</p>
</div>
</body>
</html>