ProgressWindow with style=wx.PD_AUTO_HIDE does not disappear

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_state
gz 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()

Hi Ron,

If you're still using ProgressWindow as I originally wrote it, you may
want to look at these lines in update:

        # We want our value to be between 0 and 1
        if max_value is not None:
            value = float(value) / max_value
            
        # The progress dialog is expecting values between 0 and 100
        value = int(value * 100)
        if value >= 100:
            value = 99 # wx seems to block when val == 100

Ie. I never actually pass a value greater than 99 to the progress
window. This was because (at the time) I had problems when I passed 100,
and rather than find the root cause, I just never let it go above 99 (I
never use the PD_AUTO_HIDE style). You could try allowing that to go to
100 and see if it makes a difference.

However, be aware that the PD_AUTO_HIDE will only hide the dialog; it
won't destroy it. You must call 'destroy' to actually release the
memory.

I'm surprised that the "finally: progress.destroy()" line doesn't work
though.

Simon

···

-----Original Message-----
From: wxpython-users-bounces@lists.wxwidgets.org
[mailto:wxpython-users-bounces@lists.wxwidgets.org] On Behalf
Of Barak, Ron
Sent: 04 February 2009 16:24
To: wxpython-users@lists.wxwidgets.org
Subject: [wxpython-users] ProgressWindow with
style=wx.PD_AUTO_HIDE does notdisappear

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.

Hi Simon,

Commenting out as follows does allow the wx.PD_AUTO_HIDE to function:

def update(self, message, value, max_value=None):
    """
    Update the progress dialog with a new message and value. If max_value
    is not provided, 'value' should be between 0 and 1.
    """
    if self.dialog is None:
        self._create_dialog()

    # We want our value to be between 0 and 1
    if max_value is not None:
        value = float(value) / max_value
       
    # The progress dialog is expecting values between 0 and 100
    value = int(value * 100)
    """
    if value >= 100:
        value = 99 # wx seems to block when val == 100
        """
       
    message = self.format_string % message
    self.dialog.Update(value, newmsg=message)

For completeness sake, I’m attaching ProgressDialog.py (that supports setting of styles) and my ProgressDialog demo.

Thanks for all your help,
Ron.

ProgressWindow.py (2.79 KB)

ProgressWindow_demo1.py (3.97 KB)

···

-----Original Message-----
From: King Simon-NFHD78 [mailto:simon.king@motorola.com]
Sent: Wednesday, February 04, 2009 19:04
To: wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users] ProgressWindow with style=wx.PD_AUTO_HIDE does notdisappear

-----Original Message-----
From: wxpython-users-bounces@lists.wxwidgets.org
[mailto:wxpython-users-bounces@lists.wxwidgets.org] On Behalf Of
Barak, Ron
Sent: 04 February 2009 16:24
To: wxpython-users@lists.wxwidgets.org
Subject: [wxpython-users] ProgressWindow with style=wx.PD_AUTO_HIDE
does notdisappear

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.

Hi Ron,

If you’re still using ProgressWindow as I originally wrote it, you may want to look at these lines in update:

    # We want our value to be between 0 and 1
    if max_value is not None:
        value = float(value) / max_value
       
    # The progress dialog is expecting values between 0 and 100
    value = int(value * 100)
    if value >= 100:
        value = 99 # wx seems to block when val == 100

Ie. I never actually pass a value greater than 99 to the progress window. This was because (at the time) I had problems when I passed 100, and rather than find the root cause, I just never let it go above 99 (I never use the PD_AUTO_HIDE style). You could try allowing that to go to 100 and see if it makes a difference.

However, be aware that the PD_AUTO_HIDE will only hide the dialog; it won’t destroy it. You must call ‘destroy’ to actually release the memory.

I’m surprised that the “finally: progress.destroy()” line doesn’t work though.

Simon