I have a problem that I couldn’t fix for some time now.
I have a dynamic generated GUI , and in this GUI I have multiple wxTextCtrl 's . For each wxTextCtrl I have an event with a partial method attached to it.
The problem is, when I run the event on the wxTextCtrl it opens as many filedialogs as I have wxTextCtrl’s .
Here are some snipest from my code. I hope you guys can help me.
and here is my method :
def onDoubleClick(self, event, buttonName):
** file = (str(buttonName).split(’/’)[-1])**
** fileDir = (os.path.dirname(mainPath)) + ‘/’ + str(file)**
** with wx.FileDialog(self, “Open i3d map file”, wildcard=“i3d files (.i3d)|.i3d”,**
** style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:**
** if fileDialog.ShowModal() == wx.ID_CANCEL:**
** pathname = fileDialog.GetPath()**
** with open(pathname, “rb”) as file:**
** wx.TextCtrl.SetValue(self.m_tc1, str(mainPath))**
** except IOError:**
** wx.LogError(“Cannot open file ‘%s’.” % file)**
to be a bit more clear, I bind the event in here:
self.tcTmp.Bind(wx.EVT_SET_FOCUS, partial(self.onDoubleClick, buttonName=self.tmpFilename))
and everything goes smooth until the print(fileDir) and the first wxFileDialog. Afterwards it opens multiple fileDialogs. If I delete the whole fileDialog code and leave just what I have until print(fileDir), everything works as expected. Everytime I click on my textCtrl, it prints just once.