RUNTIME在wx.FileDialog小部件中更改文件时出错

时间:2017-08-16 12:56:23

标签: python c++ runtime wxpython

我有一个GUI,要求用户从3个wx.FileDialog窗口打开3个xlsx文件。程序运行正常,但如果我尝试更改文件,我会得到RuntimeError: wrapped C/C++ object of type FileDialog has been deleted。例如,在returnsReport fileDialog上,如果我打开错误的文件并去更改它,那就是我得到的错误。下面是代码片段,对此错误的任何帮助都会很棒。

class MainFrame(wx.Frame):
    def __init__(self):
        frame = wx.Frame.__init__(self, None, wx.ID_ANY, "Returns", size = (625,250))
        self.Center()
        panel = wx.Panel(self,wx.ID_ANY)

        box = wx.BoxSizer(wx.HORIZONTAL)
        menubar = wx.MenuBar()
        helpMenu = wx.Menu()                    ######MENUBAR
        fileMenu = wx.Menu()
        helpItem = helpMenu.Append(wx.ID_ANY, 'Help',"Help")
        fileItem = fileMenu.Append(wx.ID_EXIT, 'Quit', 'Quit application')

        menubar.Append(fileMenu, '&File')
        menubar.Append(helpMenu, '&Help')





        self.returnsReport = wx.FileDialog(panel, 'Open Returns Report', "", "", "Excel Files (*.xlsx)|*.xlsx", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        self.returnsButton = wx.Button(panel, pos = (430,25), id=wx.ID_ANY, label="Returns Report")
        self.returnsButton.myname = "Returns"
        self.returnsButton.Bind(wx.EVT_BUTTON, self.findReturns)

        self.ser02Report = wx.FileDialog(panel, 'Open SER02', "", "", "Excel Files (*.xlsx)|*.xlsx", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        self.ser02Button = wx.Button(panel, pos = (430,75), id=wx.ID_ANY, label="SER02 Report")
        self.ser02Button.myname = "SER02"
        self.ser02Button.Bind(wx.EVT_BUTTON, self.findReturns)

        self.objkReport = wx.FileDialog(panel, 'Open OBJK', "", "", "Excel Files (*.xlsx)|*.xlsx", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        self.objkButton = wx.Button(panel, pos = (430,125), id=wx.ID_ANY, label="OBJK Report")
        self.objkButton.myname = "OBJK"
        self.objkButton.Bind(wx.EVT_BUTTON, self.findReturns)

        self.runButton = wx.Button(panel, pos = (500,175), id=wx.ID_ANY, label="Run Report")
        self.runButton.myname = "Run"
        self.runButton.Bind(wx.EVT_BUTTON, self.runReport)


        buttons = [self.returnsButton, self.ser02Button, self.objkButton]
        self.returnsFile = wx.TextCtrl(panel, pos = (60,25), size = (350,-1))
        self.ser02File = wx.TextCtrl(panel, pos = (60,75), size = (350,-1))
        self.objkFile = wx.TextCtrl(panel, pos = (60,125), size = (350,-1))

        self.Bind(wx.EVT_CLOSE, self.OnQuit)



        #box.Add(self.lst,0,wx.EXPAND)
        panel.SetSizer(box) 
        panel.Fit()


    def findReturns(self, event):


        button = event.GetEventObject().myname
        if button == 'Returns':
            self.returnsReport.ShowModal()
            self.returnsFile.SetValue(self.returnsReport.GetPath())

            self.returnsReport.Destroy()
        elif button == 'SER02':
            self.ser02Report.ShowModal()
            self.ser02File.SetValue(self.ser02Report.GetPath())
            self.ser02Report.Destroy()
        else:
            self.objkReport.ShowModal()
            self.objkFile.SetValue(self.objkReport.GetPath())
            self.objkReport.Destroy()   

0 个答案:

没有答案