1

I have an Python application with a wx.dirPicker control that can be manually changed and I need to be sure that the chosen path exists before running my code. To do that I'm using this:

def m_dirPicker1OnUpdateUI( self, event ):
        src_directory = self.m_dirPicker1.GetTextCtrlValue()
        if os.path.exists(src_directory)==False:
                      dlg = wx.MessageDialog( self, "The specified path doesn't exist", "Warning", wx.ICON_ERROR | wx.ICON_EXCLAMATION )
                      dlg.ShowModal()    
                      #print(dlg.GetReturnCode())
                      if dlg.GetReturnCode() == 0:
                          self.Destroy()   

It works fine, detecting if the path exists.

However, when the path doesn't exist the message dialog appears but I can't close it after pressing the OK button, and I don't understand why.

Thank you.

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
TMoover
  • 620
  • 1
  • 7
  • 22

2 Answers2

1

My first approach was: Every time someone changes wx.dirpicker path manually, I need to be sure that path exists since my application will export a report file to that path.

Later I decided to check the path only when someone press "Create Report" button. To do that I use the following code:

try: 
    if src_directory = self.m_dirPicker1.GetTextCtrlValue():
         if os.path.exists(src_directory)==False:
         dlg = wx.MessageDialog( self, "The specified path doesn't exist", "Warning", wx.ICON_EXCLAMATION)
         dlg.ShowModal()
    else:
         #run my code to create report file in src_directory path 

except:
     create report_error file 
TMoover
  • 620
  • 1
  • 7
  • 22
iroupa
  • 11
  • 1
0

I think you should call "dlg.Destroy()" before "self.Destroy()":

result = dlg.ShowModal()    
dlg.Destroy()
if result == 0:
    self.Destroy() 
furins
  • 4,979
  • 1
  • 39
  • 57
  • I did used your code but it doesn't work either. I solved the problem changing the way I was dealing with the problem – TMoover Feb 05 '13 at 23:55
  • @TMoover: I'm glad to know that you solved the problem! :) It may be nice for future readers if you can add an answer/comment to your own question giving some details on how you managed to work on this problem. – furins Feb 07 '13 at 14:48