15
15
import shutil
16
16
import subprocess
17
17
import sys
18
- import tempfile
19
18
from shlex import quote
20
19
21
20
from PIL import Image
@@ -147,16 +146,15 @@ def get_command(self, file, **options):
147
146
148
147
def show_file (self , file , ** options ):
149
148
"""Display given file"""
150
- fd , path = tempfile .mkstemp ()
151
- with os .fdopen (fd , "w" ) as f :
152
- f .write (file )
153
- with open (path ) as f :
154
- subprocess .Popen (
155
- ["im=$(cat); open -a Preview.app $im; sleep 20; rm -f $im" ],
156
- shell = True ,
157
- stdin = f ,
158
- )
159
- os .remove (path )
149
+ subprocess .call (["open" , "-a" , "Preview.app" , file ])
150
+ subprocess .Popen (
151
+ [
152
+ sys .executable ,
153
+ "-c" ,
154
+ "import os, sys, time;time.sleep(20);os.remove(sys.argv[1])" ,
155
+ file ,
156
+ ]
157
+ )
160
158
return 1
161
159
162
160
@@ -172,19 +170,6 @@ def get_command(self, file, **options):
172
170
command = self .get_command_ex (file , ** options )[0 ]
173
171
return f"({ command } { quote (file )} ; rm -f { quote (file )} )&"
174
172
175
- def show_file (self , file , ** options ):
176
- """Display given file"""
177
- fd , path = tempfile .mkstemp ()
178
- with os .fdopen (fd , "w" ) as f :
179
- f .write (file )
180
- with open (path ) as f :
181
- command = self .get_command_ex (file , ** options )[0 ]
182
- subprocess .Popen (
183
- ["im=$(cat);" + command + " $im; rm -f $im" ], shell = True , stdin = f
184
- )
185
- os .remove (path )
186
- return 1
187
-
188
173
189
174
class XDGViewer (UnixViewer ):
190
175
"""
@@ -195,6 +180,11 @@ def get_command_ex(self, file, **options):
195
180
command = executable = "xdg-open"
196
181
return command , executable
197
182
183
+ def show_file (self , file , ** options ):
184
+ subprocess .Popen (["xdg-open" , file ])
185
+ os .remove (file )
186
+ return 1
187
+
198
188
199
189
class DisplayViewer (UnixViewer ):
200
190
"""
@@ -208,6 +198,16 @@ def get_command_ex(self, file, title=None, **options):
208
198
command += f" -name { quote (title )} "
209
199
return command , executable
210
200
201
+ def show_file (self , file , ** options ):
202
+ args = ["display" ]
203
+ if "title" in options :
204
+ args += ["-name" , options ["title" ]]
205
+ args .append (file )
206
+
207
+ subprocess .Popen (args )
208
+ os .remove (file )
209
+ return 1
210
+
211
211
212
212
class GmDisplayViewer (UnixViewer ):
213
213
"""The GraphicsMagick ``gm display`` command."""
@@ -217,6 +217,11 @@ def get_command_ex(self, file, **options):
217
217
command = "gm display"
218
218
return command , executable
219
219
220
+ def show_file (self , file , ** options ):
221
+ subprocess .Popen (["gm" , "display" , file ])
222
+ os .remove (file )
223
+ return 1
224
+
220
225
221
226
class EogViewer (UnixViewer ):
222
227
"""The GNOME Image Viewer ``eog`` command."""
@@ -226,6 +231,11 @@ def get_command_ex(self, file, **options):
226
231
command = "eog -n"
227
232
return command , executable
228
233
234
+ def show_file (self , file , ** options ):
235
+ subprocess .Popen (["eog" , "-n" , file ])
236
+ os .remove (file )
237
+ return 1
238
+
229
239
230
240
class XVViewer (UnixViewer ):
231
241
"""
@@ -241,6 +251,16 @@ def get_command_ex(self, file, title=None, **options):
241
251
command += f" -name { quote (title )} "
242
252
return command , executable
243
253
254
+ def show_file (self , file , ** options ):
255
+ args = ["xv" ]
256
+ if "title" in options :
257
+ args += ["-name" , options ["title" ]]
258
+ args .append (file )
259
+
260
+ subprocess .Popen (args )
261
+ os .remove (file )
262
+ return 1
263
+
244
264
245
265
if sys .platform not in ("win32" , "darwin" ): # unixoids
246
266
if shutil .which ("xdg-open" ):
0 commit comments