If user selects a folder to which he has no access rights an WindowsError exception is thrown (on Win Vista).
This happens on wxPython 2.8.7.1-msw-ansi and as I work around I put the offending line 668 in lib.imagebrowser.py in the class FindFiles into a try/except as follows:
try:
for i in os.listdir(dir):
if i == "." or i == "..":
continue
etc etc
except WindowsError:
message = traceback.format_exc()
dlg = wx.MessageDialog(None, message,
'Windows error occurred', wx.ICON_EXCLAMATION)
try:
dlg.ShowModal()
finally:
dlg.Destroy()
pass
I am used the MessageDialog as there is no statuslist. But this is not ideal as it pops up for each sub-folder and shows a very technical error message.
Anyone has a nicer solution to this problem?
I.e. how could one just catch access rights exception and put the folder name into a list and then show the message dialog after the try/except is done.
Werner
P.S.
here the full exception generated on a German OS:
Traceback (most recent call last):
File "wx\lib\imagebrowser.pyo", line 652, in OnOk
File "wx\lib\imagebrowser.pyo", line 597, in ResetFiles
File "wx\lib\imagebrowser.pyo", line 517, in GetFiles
File "wx\lib\imagebrowser.pyo", line 668, in __init__
WindowsError: [Error 5] Zugriff verweigert: 'C:\\Dokumente und Einstellungen/*.*'
If user selects a folder to which he has no access rights an WindowsError exception is thrown (on Win Vista).
This happens on wxPython 2.8.7.1-msw-ansi and as I work around I put the offending line 668 in lib.imagebrowser.py in the class FindFiles into a try/except as follows:
try:
for i in os.listdir(dir):
if i == "." or i == "..":
continue
etc etc
except WindowsError:
message = traceback.format_exc()
dlg = wx.MessageDialog(None, message,
'Windows error occurred', wx.ICON_EXCLAMATION)
try:
dlg.ShowModal()
finally:
dlg.Destroy()
pass
I am used the MessageDialog as there is no statuslist. But this is not ideal as it pops up for each sub-folder and shows a very technical error message.
Anyone has a nicer solution to this problem?
I.e. how could one just catch access rights exception and put the folder name into a list and then show the message dialog after the try/except is done.
Werner
P.S.
here the full exception generated on a German OS:
Traceback (most recent call last):
File "wx\lib\imagebrowser.pyo", line 652, in OnOk
File "wx\lib\imagebrowser.pyo", line 597, in ResetFiles
File "wx\lib\imagebrowser.pyo", line 517, in GetFiles
File "wx\lib\imagebrowser.pyo", line 668, in __init__
WindowsError: [Error 5] Zugriff verweigert: 'C:\\Dokumente und Einstellungen/*.*'
I'm not sure if this is what you want or not, but here's what I came up with:
If user selects a folder to which he has no access rights an WindowsError exception is thrown (on Win Vista).
This happens on wxPython 2.8.7.1-msw-ansi and as I work around I put the offending line 668 in lib.imagebrowser.py in the class FindFiles into a try/except as follows:
try:
for i in os.listdir(dir):
if i == "." or i == "..":
continue
etc etc
except WindowsError:
message = traceback.format_exc()
dlg = wx.MessageDialog(None, message,
'Windows error occurred', wx.ICON_EXCLAMATION)
try:
dlg.ShowModal()
finally:
dlg.Destroy()
pass
Changed exception to just do:
except WindowsError, extraInfo:
# no access right
if extraInfo[0] == 5:
pass
else:
traceback.print_exc()
Doing a message dialog was no nice as it is shown for each image type one is interested in.
Maybe lib.imagebrowser could be enhanced to return a list/dir of folders one could not access and then application programmer can do with it what he wants.
You could also write the errors to a file and then display it when you're done iterating. Anyway, I hope that this will give you some ideas at least.
Mike, thanks for that.
Will wait and see how Robin would like to deal with this as it is wx.lib.imagebrowser and not in my own code. Would then try to work out a patch which hopefully would get included into the next release.
You could also write the errors to a file and then display it when you're done iterating. Anyway, I hope that this will give you some ideas at least.
Mike, thanks for that.
Will wait and see how Robin would like to deal with this as it is wx.lib.imagebrowser and not in my own code. Would then try to work out a patch which hopefully would get included into the next release.
Werner
Yeah. That's a good idea. Robin seems pretty busy of late.
If user selects a folder to which he has no access rights an WindowsError exception is thrown (on Win Vista).
This happens on wxPython 2.8.7.1-msw-ansi and as I work around I put the offending line 668 in lib.imagebrowser.py in the class FindFiles into a try/except as follows:
try:
for i in os.listdir(dir):
if i == "." or i == "..":
continue
etc etc
except WindowsError:
message = traceback.format_exc()
dlg = wx.MessageDialog(None, message,
'Windows error occurred', wx.ICON_EXCLAMATION)
try:
dlg.ShowModal()
finally:
dlg.Destroy()
pass
Changed exception to just do:
except WindowsError, extraInfo:
# no access right
if extraInfo[0] == 5:
pass
else:
traceback.print_exc()
Doing a message dialog was no nice as it is shown for each image type one is interested in.
You could raise another exception after showing the dialog which will then cause the iteration of the other image types to be stopped.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
You could also write the errors to a file and then display it when you're done iterating. Anyway, I hope that this will give you some ideas at least.
Mike, thanks for that.
Will wait and see how Robin would like to deal with this as it is wx.lib.imagebrowser and not in my own code. Would then try to work out a patch which hopefully would get included into the next release.
What should be done in wx.lib.imagebrowser?
I did just the following which gives the user an empty directory listing, but no error. Would be nice to give some feedback but I am not sure how best to do this. Had a MessageDialog in there but that pops up for each file extension, not very nice.
try:
for i in os.listdir(dir):
if i == "." or i == "..":
continue
path = os.path.join(dir, i)
if os.path.isdir(path):
dirlist.append(i)
continue
path = path.upper()
value = i.upper()
if pattern.match(value) != None:
filelist.append(i)
except WindowsError, extraInfo:
# no access right
if extraInfo[0] == 5:
pass
else:
traceback.print_exc()