> I'm trying to understand how to detect a user pressing Escape, or > clicking on Cancel when win32gui.GetOpenFileNameW() is called. > > When I press escape when the FileOpen dialogue is present, I see the > following error with Python2.5/PWin32 Build 210 > > error: (0, 'GetOpenFileNameW', 'No error message is available') > > Would someone explain what this means, or how to detect the > above situations? > > My call looks like this > > > filter='Patches' > customfilter='All Files' > unicodeFilenames=None > unicodeFilenames, customfilter, flags = > win32gui.GetOpenFileNameW(Filter=filter, > CustomFilter=customfilter, > FilterIndex=1, > File='*.pch', > InitialDir=os.getcwd(), > Title='Select Input Files', > Flags=win32con.OFN_ALLOWMULTISELECT|win32con.OFN_EXPLORER, > DefExt='.pch')
As currently implemented, you must detect cancel by trapping win32gui.error, and checking the hresult is zero. While this is slightly ugly, it is more convenient than returning None, as in the usual case there are 3 return values. Returning (None, None, None) might have been possible, but was not implemented, and I'm reluctant to change the semantics of the return value in this case. I'll document this. Mark _______________________________________________ Python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
