def SaveFile(self, fileName=''):
"""Saves the file to the type specified in the extension. If no file
name is specified a dialog box is provided. Returns True if sucessful,
otherwise False.
.bmp Save a Windows bitmap file.
.xbm Save an X bitmap file.
.xpm Save an XPM bitmap file.
.png Save a Portable Network Graphics file.
.jpg Save a Joint Photographic Experts Group file.
"""
extensions = {
"bmp": wx.BITMAP_TYPE_BMP, # Save a Windows bitmap file.
"xbm": wx.BITMAP_TYPE_XBM, # Save an X bitmap file.
"xpm": wx.BITMAP_TYPE_XPM, # Save an XPM bitmap file.
"jpg": wx.BITMAP_TYPE_JPEG, # Save a JPG file.
"png": wx.BITMAP_TYPE_PNG, # Save a PNG file.
}
fType = _string.lower(fileName[-3:])
dlg1 = None
while fType not in extensions:
if dlg1: # FileDialog exists: Check for extension
dlg2 = wx.MessageDialog(self, 'File name extension\n'
'must be one of\nbmp, xbm, xpm, png, or jpg',
'File Name Error', wx.OK | wx.ICON_ERROR)
try:
dlg2.ShowModal()
finally:
dlg2.Destroy()
# FileDialog doesn't exist: just check one
else:
dlg1 = wx.FileDialog(
self,
"Choose a file with extension bmp, gif, xbm, xpm, png, or jpg", ".", "",
"BMP files (*.bmp)|*.bmp|XBM files (*.xbm)|*.xbm|XPM file (*.xpm)|*.xpm|PNG files (*.png)|*.png|JPG files (*.jpg)|*.jpg",
wx.SAVE | wx.OVERWRITE_PROMPT
)
if dlg1.ShowModal() == wx.ID_OK:
fileName = dlg1.GetPath()
fType = _string.lower(fileName[-3:])
else: # exit without saving
dlg1.Destroy()
return False
if dlg1:
dlg1.Destroy()
# Save Bitmap
res = self._Buffer.SaveFile(fileName, extensions[fType])
return res
评论列表
文章目录