Handle other cancels gracefully

This commit is contained in:
Skyler Lehmkuhl 2013-01-18 13:37:34 -05:00
parent ec0a4a5d4b
commit 5925ca7dc2
1 changed files with 15 additions and 4 deletions

View File

@ -539,7 +539,11 @@ def open_file(widget=None):
global root global root
MainWindow.stage.delete(root) MainWindow.stage.delete(root)
shutil.rmtree(svlgui.SECURETEMPDIR) shutil.rmtree(svlgui.SECURETEMPDIR)
try:
thetarfile = tarfile.open(fileobj=svlgui.file_dialog("open").open("rb"),mode="r:gz") thetarfile = tarfile.open(fileobj=svlgui.file_dialog("open").open("rb"),mode="r:gz")
except AttributeError:
# User cancelled
return
basefile = thetarfile.extractfile("basefile") basefile = thetarfile.extractfile("basefile")
root, svlgui.Library = pickle.load(basefile) root, svlgui.Library = pickle.load(basefile)
svlgui.SECURETEMPDIR = tempfile.mkdtemp() svlgui.SECURETEMPDIR = tempfile.mkdtemp()
@ -566,8 +570,11 @@ def save_file(widget=None):
tarinfo = tarfile.TarInfo('basefile') tarinfo = tarfile.TarInfo('basefile')
tarinfo.size = len(data) tarinfo.size = len(data)
if svlgui.FILE.name.startswith(svlgui.TEMPDIR): if svlgui.FILE.name.startswith(svlgui.TEMPDIR):
try:
thetarfile = tarfile.open(fileobj=svlgui.file_dialog("save", name="untitled.beam").open('wb'),mode="w:gz") thetarfile = tarfile.open(fileobj=svlgui.file_dialog("save", name="untitled.beam").open('wb'),mode="w:gz")
print thetarfile.name except AttributeError:
# User cancelled
return
else: else:
thetarfile = tarfile.open(svlgui.FILE.name,mode="w:gz") thetarfile = tarfile.open(svlgui.FILE.name,mode="w:gz")
thetarfile.addfile(tarinfo, StringIO.StringIO(data)) thetarfile.addfile(tarinfo, StringIO.StringIO(data))
@ -607,7 +614,11 @@ def save_file_as(widget=None):
data = pickle.dumps((root,svlgui.Library)) data = pickle.dumps((root,svlgui.Library))
tarinfo = tarfile.TarInfo('basefile') tarinfo = tarfile.TarInfo('basefile')
tarinfo.size = len(data) tarinfo.size = len(data)
try:
thetarfile = tarfile.open(fileobj=svlgui.file_dialog("save", name="untitled.beam").open('wb'),mode="w:gz") thetarfile = tarfile.open(fileobj=svlgui.file_dialog("save", name="untitled.beam").open('wb'),mode="w:gz")
except AttributeError:
# User cancelled
return
thetarfile.addfile(tarinfo, StringIO.StringIO(data)) thetarfile.addfile(tarinfo, StringIO.StringIO(data))
#Save the path so we can come back here #Save the path so we can come back here
lastpath = os.path.abspath(".") lastpath = os.path.abspath(".")