1

手動で変更できる wx.dirPicker コントロールを備えた Python アプリケーションがあり、コードを実行する前に、選択したパスが存在することを確認する必要があります。そのために、私はこれを使用しています:

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()   

パスが存在するかどうかを検出して、正常に動作します。

しかし、パスが存在しないとメッセージダイアログが表示されるのですが、OKボタンを押しても閉じることができず、原因がわかりません。

ありがとうございました。

4

2 に答える 2

1

私の最初のアプローチは: 誰かが wx.dirpicker パスを手動で変更するたびに、アプリケーションがレポート ファイルをそのパスにエクスポートするため、パスが存在することを確認する必要があります。

後で、誰かが「レポートの作成」ボタンを押したときにのみパスを確認することにしました。そのために、次のコードを使用します。

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 
于 2013-02-07T15:58:09.333 に答える
0

「self.Destroy()」の前に「dlg.Destroy()」を呼び出す必要があると思います。

result = dlg.ShowModal()    
dlg.Destroy()
if result == 0:
    self.Destroy() 
于 2013-02-05T16:00:00.920 に答える