9
9
import inkex
10
10
from time import sleep
11
11
import warnings
12
+ import io
12
13
13
- __version__ = '1.1.0 '
14
+ __version__ = '1.6.1 '
14
15
15
16
def atoi (text ):
16
17
return int (text ) if text .isdigit () else text
@@ -60,6 +61,9 @@ def do_png(self):
60
61
os .system (command )
61
62
62
63
def do_bundle (self ):
64
+ if not self .has_7zip ():
65
+ inkex .utils .errormsg ("Please install and add 7-Zip directory to Environment Variable" )
66
+ return
63
67
file_export = '"' + self .options .output_dir + '"'
64
68
command = "start inkporter bundle {0} {1} {2} {3} {4}" .format (
65
69
self .myfile , self .options .id_pattern , file_export , self .options .dpi , self .options .bg_color )
@@ -68,7 +72,7 @@ def do_bundle(self):
68
72
def do_jpg (self ):
69
73
file_export = '"' + self .options .output_dir + '"'
70
74
if not self .has_imagemagick ():
71
- inkex .utils .errormsg ("Please install and add ImageMagick directory to Environment Variable" )
75
+ inkex .utils .errormsg ("Please install and add ImageMagick directory to PATH Environment Variable" )
72
76
return
73
77
if self .options .with_cmyk :
74
78
options = "CMYK"
@@ -84,10 +88,13 @@ def do_jpg(self):
84
88
def do_pdf (self ):
85
89
file_export = '"' + self .options .output_dir + '"'
86
90
if self .options .with_cmyk :
91
+ if not self .has_gs32 ():
92
+ inkex .utils .errormsg ("Please Install and add Ghostscript 32 bit directory to PATH environment variable to export PDF-CMYK" )
93
+ return
87
94
command = "start inkporter pdf_cmyk {0} {1} {2}" .format (
88
95
self .myfile , self .options .id_pattern , file_export )
89
96
os .system (command )
90
- else :
97
+ else :
91
98
command = "start inkporter pdf {0} {1} {2}" .format (
92
99
self .myfile , self .options .id_pattern , file_export )
93
100
os .system (command )
@@ -108,6 +115,10 @@ def do_eps(self):
108
115
os .close (self .tmplog_fd )
109
116
110
117
def do_booklet (self ):
118
+ if not self .has_gs32 ():
119
+ inkex .utils .errormsg ("Please Install and add Ghostscript 32 bit directory to PATH environment variable to export Booklet (PDF)" )
120
+ return
121
+
111
122
if self .options .with_cmyk :
112
123
file_export = '"' + self .options .output_dir + '"'
113
124
command = "start inkporter booklet_cmyk {0} {1} {2}" .format (
@@ -123,6 +134,9 @@ def do_booklet(self):
123
134
124
135
def do_webp (self ):
125
136
file_export = '"' + self .options .output_dir + '"'
137
+ if not self .has_webp ():
138
+ inkex .utils .errormsg ("Please Download and add libwebp directory to PATH environment variable to export WEBP" )
139
+ return
126
140
command = "start inkporter webp {0} {1} {2} {3}" .format (
127
141
self .myfile , self .options .id_pattern , file_export , self .options .dpi )
128
142
os .system (command )
@@ -131,10 +145,22 @@ def do_webp(self):
131
145
def has_imagemagick (self ):
132
146
status , output = self .get_cmd_output ('magick --version' )
133
147
return status == 0 and 'ImageMagick' in output
148
+
149
+ def has_gs32 (self ):
150
+ status , output = self .get_cmd_output ('gswin32c --help' )
151
+ return status == 0 and 'Ghostscript' in output
152
+
153
+ def has_webp (self ):
154
+ status , output = self .get_cmd_output ('cwebp' )
155
+ return status == 0 and 'cwebp' in output
156
+
157
+ def has_7zip (self ):
158
+ status , output = self .get_cmd_output ('7z' )
159
+ return status == 0 and '7-Zip' in output
134
160
135
161
def make_tmp_file (self , file_format ):
136
162
handler , self .myfile = tempfile .mkstemp (suffix = ".svg" ,prefix = "inkporter-%s-" % file_format )
137
- with open (handler , "w" ) as f :
163
+ with io . open (handler , "w" , encoding = "utf-8 " ) as f :
138
164
f .write (etree .tostring (self .document , encoding = "utf-8" ,xml_declaration = True ).decode ("utf-8" ))
139
165
self .tmpout .append (self .myfile )
140
166
@@ -151,28 +177,16 @@ def get_cmd_output(self, cmd):
151
177
text = text [:- 1 ]
152
178
return sts , text
153
179
154
- def do_cleanup (self ):
155
- # for item in self.tmpout:
156
- # if os.path.exists(os.path.abspath(item)):
157
- # os.remove(os.path.abspath(item))
158
- # if os.path.isdir(self.tmpdir):
159
- # os.rmdir(self.tmpdir)
160
- print ("hai" )
180
+ def quit_inkporter (self ):
181
+ warnings .filterwarnings ("ignore" )
182
+ exit ()
161
183
162
184
# called when extension is running
163
185
def effect (self ):
164
- if len (self .options .id_pattern ) > 0 :
165
- new_nss = inkex .utils .NSS
166
- new_nss [u're' ] = u'http://exslt.org/regular-expressions'
167
- path_to_compile = "//*[re:match(@id,'(%s)','g')]" % self .options .id_pattern
168
- self .id_to_process = self .document .xpath (path_to_compile , namespaces = new_nss )
169
- self .svg .selected = {}
170
- for item in self .id_to_process :
171
- self .svg .selected [item .attrib ['id' ]] = item
172
- if len (self .svg .selected ) < 1 :
186
+ if not self .options .id_pattern :
173
187
inkex .utils .errormsg (
174
- "Please select at least 1 object or fill ID Pattern to use this extension!" )
175
- exit ()
188
+ "Please fill ID Pattern to use this extension!" )
189
+ self . quit_inkporter ()
176
190
try :
177
191
if not os .path .isdir (os .path .expandvars (self .options .output_dir )):
178
192
os .mkdir (os .path .expandvars (self .options .output_dir ))
@@ -193,14 +207,12 @@ def effect(self):
193
207
self .do_webp ()
194
208
elif self .options .format == "bundle" :
195
209
self .do_bundle ()
196
- self .do_cleanup ()
197
210
except Exception as e :
198
211
inkex .utils .errormsg (e )
199
212
import traceback
200
213
inkex .utils .errormsg (traceback .print_exc ())
201
- print ("hai" )
202
214
203
- warnings . filterwarnings ( "ignore" )
215
+ self . quit_inkporter ( )
204
216
205
217
206
218
if __name__ == '__main__' :
0 commit comments