0

I have written a simple ArcGIS python script tool that takes only one input, a file, and displays a "Yes/No" message box when the script is run.

The script runs, but the message box pops up behind the Geoprocessing window and does not obtain focus. Sliding the Geoprocessing window to the side to reveal the message box, and clicking either "Yes" or "No", has no effect: the script appears frozen. To unfreeze, i must press "Cancel" in the Geoprocessing window and then press either "Yes" or "No" in the message box. The script then cancels/aborts.

The script code is:

import arcpy
import ctypes

inFile = arcpy.GetParameterAsText(0)
arcpy.AddMessage("\nInput file: {0}\n".format(inFile))

# Yes/No mbox = 4, return code Yes = 6, return code No = 7
mBox = ctypes.windll.user32.MessageBoxW
result = mBox(None, u"Just checking...", u"File Check", 4)

if result == 6:
    arcpy.AddMessage("User pressed Yes\n")
elif result == 7:
    arcpy.AddMessage("User pressed No\n")
else:
    arcpy.AddMessage("Unknown return code\n")

arcpy.AddMessage("Complete.\n")

I realize using a message box in this context is a bit of a no-no. But if my transgression of best practice might be overlooked for a moment, can anyone help me understand the technical reason of this message box freeze behavior?

I think it might be to do with the window handle parameter of the message box (currently set to None), and that creating it with the window handle of the Geoprocessing window might solve it - allowing the Geoprocessing window to release focus to the message box. However, i am still trying to figure out how to the get the window handle of the Geoprocessing window.

Using ArcGIS 10.5, python 2.7, Win 7

4
  • Are you using background geoprocessing?
    – Fezter
    Apr 23, 2018 at 1:29
  • No, that's disabled, definitely in the foreground - that's the "Geoprocessing" window i refer to, the window that shows the progress bar and any messages etc as the script is running.
    – Rovsom
    Apr 23, 2018 at 1:45
  • I've experimented with GUI python objects inside of ArcGIS and it crashes everytime. I'm not sure about the technical side, but I think there is a conflict with ownership of different windows. Not sure if this will work but their pythonaddins library includes a messagebox: desktop.arcgis.com/en/arcmap/latest/analyze/python-addins/…. I don't know if it will run inside a geoprocessing window though.
    – dslamb
    Apr 23, 2018 at 13:29
  • @dslamb Yes, nice one! This seems to work. I just used: result = pythonaddins.MessageBox("Just Checking...", "File check", 4) No issues for my little test script tool. Submit your comment as answer if you like, and i'll accept it.
    – Rovsom
    Apr 23, 2018 at 22:42

1 Answer 1

0

The solution to this was to use the pythonaddins library.

Moved from a comment: I've experimented with GUI python objects inside of ArcGIS and it crashes everytime. I'm not sure about the technical side, but I think there is a conflict with ownership of different windows. Not sure if this will work but their pythonaddins library includes a messagebox: desktop.arcgis.com/en/arcmap/latest/analyze/python-addins/…. I don't know if it will run inside a geoprocessing window though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.