I’m looking for some help to solve this type of issue.
While processing files, I have a progress panel displayed off of my main window. However, if I need user interaction (like choosing a new file destination), there is a default “cancel” button. If the user chooses to “cancel”, then the dialog goes away, but there is no code to stop the progress panel, and now the application is locked up.
I tried to use a “dialog ends” component, so that when the dialog is closed, the application can figure out what was chosen and either stop the panel, or continue on. However, this doesn’t work. It seems the only time this function is called is after the dialog that says “all done” at the end of the processing. Shouldn’t it be called whenever any dialog closes?
To solve this, I added code before calling for the “open” panel to first stop the progress panel. I’m trying to avoid peppering my code with these statements.
While I can pepper my code, I’m also concerned that should an Applescript error occur -perhaps a timeout waiting for user interaction- the same situation happens. You enter “OK” to close the error dialog, but the progress panel will not stop.
When the progress panel is “always running”, you of course can’t quit the application and have to force quit it.
Anything I can do to centralize the “stopping” of the panel so that I can call it anytime a dialog returns with “cancel” of is an Applescript error dialog?
A slightly clearer description of what your problem is would help. Are you saying that you have both a dialog and a panel displayed.
The whole issue of panels and their threadedness is quite difficult.
I assume that you are using the on panel ended handler. If you call close panel within the on panel ended it should get rid of the panel thread.
I use a fairly ugly method to stop processing files if the cancel button in the progress panel was clicked. I have a property that is set when the cancel button is clicked and at the end of my files processing repeat loop I will exit the repeat loop if the flag is set.
I’ll look more into the interaction with the “panel ended” function that I have coded already.
Hopefully the following details will better explain my problem:
I have a main window that has a progress panel as a sheet when the user starts to process the files. This progress panel does not have a cancel or any interaction with the user beyond giving the user feedback that the application is running (progress bar) and text (it has a status line that says when it’s starting up, cleaning up, and how many files processed so far). This panel appears and closes normally when the application runs through without error.
One place in my code that asks for user input is if the u ser has not already designated where to store the processed files. An “open” dialog appears and this is my first challenge. If the user selects a destination, the program (and progress panel) continue through without error. If the user hits the cancel button, the open dialog goes away, but my progress panel remains with nothing to do since the application pretty much stops now. I have coded around this by stopping the progress panel before displaying the open dialog and then starting it again if the user selects a destination. If they hit “cancel” no issues since the panel was already stopped.
This works OK, and I can pepper my code that before any dialog appears the panel is closed, BUT - if an AppleScript error were to occur (timeout, destination fills etc.) the panel will still be around.
Will the “panel ended” code run when an Applescript error dalog box appears as well?
Trying to find a way to stop (and restart maybe) the panel when one of many issues may appear. This solution would work for expected user interactions for errors I can check for in “try” blocks, or unexpected errors happen just when running.
Hope these details explain further what I’m trying to do, and I appreciate the advise so far.
Why not ask for the destination before your even open the panel? If the user then cancels, the panel never even opens. Also, add a try handler to your script within the loop that the progress panel is indicating. In the “on error” part of the block, close the panel and display the error via dialog (if desired).