Is there a way to have the script dialog box have the radio button that says "Close this dialog when completed successfully" unchecked for any user who runs the script tool? Is there configuration somewhere to do this?
3 Answers 3
Based upon your comments in other responses, it sounds like you really just want to alert the user about things that have occurred during the operation of your script, rather than necessarily keep the script dialog box open.
A couple of alternative approaches could be:
- Write the pertinent information back to the ArcGIS GP console by adding messages, warnings, and errors calls to your script. If the user simply unchecks the "Close this dialog when completed successfully", you pass all the info you want into the text box.
- Write all the pertinent information to a log file. You could add a checkbox to your script to "View Log File" (checked on by default) that would open the log file after the process completes (to success or failure) using "os.startfile(your_log_file)", which would open the log file in it's default application.
-
Your right, my question is more like you stated. Thanks for the answer as it answers my real question.Justin– Justin2012年01月26日 16:36:09 +00:00Commented Jan 26, 2012 at 16:36
-
+1 for logging, it's so easy to do with the logging module and log files take up so little space, there's no reason not to do it.Chad Cooper– Chad Cooper2012年01月26日 18:05:24 +00:00Commented Jan 26, 2012 at 18:05
-
Since he won't mention it himself, @ChadCooper wrote an article about ArcPy and logging that was posted in ArcUser back in 2008.RyanKDalton– RyanKDalton2012年05月07日 20:01:47 +00:00Commented May 7, 2012 at 20:01
ArcGIS stores a great deal of a user's preferences in the Windows Registry, which is partially documented in "ArcGIS Desktop Advanced Settings Registry Keys.doc", found in the Utilities folder of your ArcGIS installation. You can browse these settings with the Registry Editor (run regedit
), and look into the keys from HKEY_CURRENT_USER\Software\ESRI
.
This particular feature asked in the question can be modified using Python (at your own risk!):
import _winreg as reg
# Get registry key for ArcToolbox processing dialog (ATPD):
ATPD_key = reg.OpenKey(reg.HKEY_CURRENT_USER,\
r'Software\ESRI\ArcToolbox\ATProgressDialog', 0, reg.KEY_ALL_ACCESS)
# Get current status of AutoClose
autoclose_before = bool(reg.QueryValueEx(ATPD_key, 'AutoClose')[0])
print('AutoClose before: ' + str(autoclose_before))
if autoclose_before:
print('Turning off AutoClose')
reg.SetValueEx(ATPD_key, 'AutoClose', 0, reg.REG_DWORD, int(False))
You can place snippets of this in def __init__(self)
of the script validation, which runs before the toolbox progress dialog. However, if a user actually prefers to have the AutoClose checked, I'm not sure how to set it back after the script has finished, unless you store autoclose_before
somewhere in the registry and do a similar post-set in your geoprocessing script. But you've been warned, this is Python hackery!
A clean, no fuss alternative would be to display your log file in a simple Tkinter window at the end of your script. While the registry option is workable, there may be forces beyond your control, admin privileges, etc.
if showLog:
import Tkinter
#read the log data
log = open(r'logfile.txt').read()
#create a tkinter window with a text box
root = Tkinter.Tk('Geoprocessing Log File')
txt = Tkinter.Text(root)
txt.pack()
btn = Tkinter.Button(root,text='Close',command=root.destroy)
btn.pack()
txt.insert(Tkinter.END,log)
root.mainloop()