Hi,
I’m using ProgressWindow with style=wx.PD_AUTO_HIDE.
In spite of that, when the processing is finished (see extract_with_progress below), the ProgressWindow does not disappear.
In the below code I tried various places (in blue) to coerce the ProgressWindow to destroy itself, to no avail.
Could anyone look at the code and suggest what changes are needed so that the ProgressWindow will disappear before the program terminates ?
Thanks,
Ron.
#!/usr/bin/env python
-- coding: utf-8 --
“”"
“”"
import glob
import os, os.path
import sys
import tarfile
import wx
import ProgressWindow
def get_tgz_save_states():
“”"
“”"
directories = []
message=“Which ‘save_state’ tgz files do you want to use ?”
defaultDir=""
wildcard=“tar gzip files (.tgz)|.tgz|all files (.)|.”
style=wx.FD_OPEN | wx.FD_MULTIPLE
dialog = wx.FileDialog(None,message=message, defaultDir=defaultDir, wildcard=wildcard, style=style)
if dialog.ShowModal() == wx.ID_OK:
directories.append(dialog.GetPaths())
dialog.Destroy()
if len(directories):
return(directories[0])
else:
return([])
def get_save_states():
“”"
Will ask user for save_statetgz files.
If they exist, will check if in same path there’s a directory of the unzipped save_state.
If such unzipped directory exists, will give a message to the screen (the does not requre
a user interaction) and will return the opened directories paths.
If not, will unzip the save_stategz and will return the opened direcories paths.
“”"
app = wx.App(redirect=False)
tgz_save_states_paths = get_tgz_save_states()
dialog = wx.MessageDialog(None, "Choose another 'save state' file ?", caption="Another 'save state' ?",
style=wx.YES_NO, pos=wx.DefaultPosition)
while dialog.ShowModal() == wx.ID_YES:
for path in get_tgz_save_states():
tgz_save_states_paths.append(path)
save_state_directories = un_tgz(app,tgz_save_states_paths)
app.update()
return(save_state_directories)
def un_tgz(app,tgz_save_states_paths):
“”"
Will return an untarred save_state directories.
If save_state sub-dir already exists in same directory as tgz_dir,
will not unzip tgz_name, but give appropriate message.
“”"
save_states_directories = []
for path in tgz_save_states_paths:
if (path.endswith(".tgz")):
tgz_dir = os.path.dirname(path)
tgz_name = os.path.basename(path)
(tgz_name_without_extension, extension) = os.path.splitext(tgz_name)
save_state_name = os.path.join(tgz_dir,tgz_name_without_extension)
save_states_directories.append(save_state_name)
if glob.glob(save_state_name): # save_state dir already exists ?
msg = “Directory ‘%s’ already exists in ‘%s’. ‘%s’ will not be untarred!” % (tgz_name_without_extension,
tgz_dir, tgz_name)
wx.MilliSleep(200)
wx.SafeYield()
else:
msg = “Untarring ‘%s’ into ‘%s’.” % (tgz_name,tgz_dir)
wx.MilliSleep(200)
wx.SafeYield()
tar = tarfile.open(path)
# See http://www.wxpython.org/docs/api/wx.ProgressDialog-class.html for styles.
progress = ProgressWindow.ProgressWindow(None,“Creating %s” % tgz_name_without_extension,"%s",
size=(600,-1), style=wx.PD_SMOOTH|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_ELAPSED_TIME)
callback = progress.update
try:
extract_with_progress(tar, tgz_dir, progress_callback=callback, dialog=progress)
finally:
progress.destroy()
tar.close()
return(save_states_directories)
def default_progress_callback(stage, step, total):
print “%s (Step %d of %d)” % (stage, step, total)
def extract_with_progress(tarfile, extract_to, dialog, progress_callback=default_progress_callback):
members = tarfile.getmembers()
for i, member in enumerate(members):
progress_callback(member.name, i + 1, len(members))
tarfile.extract(member, extract_to)
dialog.destroy()
if name == ‘main’:
“”"
Get list of save_states directoris to work on,
from a tgz list.
If directories do not exist, untar the tgz files.
“”"
save_states_directories = get_save_states()