forked from mnesarco/inkscape-parametric
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparametric_editor.py
More file actions
executable file
·63 lines (53 loc) · 2.41 KB
/
Copy pathparametric_editor.py
File metadata and controls
executable file
·63 lines (53 loc) · 2.41 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /usr/bin/python
'''
Copyright (C) 2019 Frank Martinez, mnesarco <at> gmail.com
This file is part of inkscape-parametric.
inkscape-parametric is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
inkscape-parametric is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with inkscape-parametric. If not, see <https://www.gnu.org/licenses/>.
'''
import inkex, simplestyle, simplepath, math, copy, sys, subprocess, tempfile, os
import parametric
class ParametricEditor(parametric.Parametric):
"""
This extension Opens a Scintilla Editor and load parametric script content.
"""
def __init__(self):
parametric.Parametric.__init__(self)
def effect(self):
root = self.getroot()
script = root.find('.//{%s}script' % self.namespace)
if script != None:
if script.text == None:
code = '""" Write Python code Here """'
else:
code = script.text
codeFile = tempfile.NamedTemporaryFile(mode="w+", suffix=".py", delete=False)
codeFile.write(code)
codeFileName = codeFile.name
codeFile.close()
# if you have troubles on your windows system, you can comment out the SciTE line
# and uncomment the notepad.exe line. If this works and launches notepad then
# it is likely an issue with SciTE not being in the system PATH.
subprocess.call(['SciTE', codeFileName])
#subprocess.call(['notepad.exe', codeFileName])
codeStream = open(codeFileName, 'r')
code = codeStream.read()
codeStream.close()
os.unlink(codeFileName)
script.text = code
try:
parametric.Parametric.effect(self)
except Exception as e:
inkex.errormsg(str(e))
if __name__ == '__main__':
e = ParametricEditor()
e.run()
# vim: expandtab shiftwidth=4 tabstop=4 softtabstop=4 fileencoding=utf-8 textwidth=99