mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2025-12-16 01:30:07 +01:00
Merge pull request #1576 from pbrod/Fix_issue1570_use_of_tempfile
Fixes issue #1570:
This commit is contained in:
@@ -34,7 +34,6 @@
|
||||
#
|
||||
|
||||
|
||||
|
||||
"""
|
||||
img2py.py -- Convert an image to PNG format and embed it in a Python
|
||||
module with appropriate code so it can be loaded into
|
||||
@@ -81,7 +80,6 @@ function. See its docstring for more info.
|
||||
|
||||
import base64
|
||||
import getopt
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@@ -120,10 +118,8 @@ def convert(fileName, maskClr, outputDir, outputName, outType, outExt):
|
||||
with open(newname, "wb") as f_out:
|
||||
with open(fileName, "rb") as f_in:
|
||||
f_out.write(f_in.read())
|
||||
return 1, "ok"
|
||||
|
||||
else:
|
||||
return img2img.convert(fileName, maskClr, outputDir, outputName, outType, outExt)
|
||||
return True, "ok"
|
||||
return img2img.convert(fileName, maskClr, outputDir, outputName, outType, outExt)
|
||||
|
||||
|
||||
def _replace_non_alphanumeric_with_underscore(imgName):
|
||||
@@ -187,7 +183,9 @@ def img2py(image_file, python_file,
|
||||
app = wx.App(0)
|
||||
|
||||
# convert the image file to a temporary file
|
||||
tfname = tempfile.mktemp()
|
||||
with tempfile.NamedTemporaryFile(delete=False) as fid:
|
||||
tfname = fid.name
|
||||
|
||||
try:
|
||||
ok, msg = convert(image_file, maskClr, None, tfname, wx.BITMAP_TYPE_PNG, ".png")
|
||||
if not ok:
|
||||
@@ -260,7 +258,6 @@ def img2py(image_file, python_file,
|
||||
|
||||
print("Embedded %s%s into %s%s" % (image_file, n_msg, python_file, m_msg))
|
||||
|
||||
|
||||
def main(args=None):
|
||||
if not args:
|
||||
args = sys.argv[1:]
|
||||
|
||||
Reference in New Issue
Block a user