Partial method opens multiple wxFileDialog

Hello everyone,

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[0])) + ‘/’ + str(file)**
** print(fileDir)**
** 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:**
** return**
** pathname = fileDialog.GetPath()**
** try:**
** with open(pathname, “rb”) as file:**
** mainPath.append(pathname)**
** wx.TextCtrl.SetValue(self.m_tc1, str(mainPath[0]))**
** xmlParser(str(pathname))**
** 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.

Thank you,

I would suggest that you:

  • try calling event.Skip()
  • state your platform and versions
  • attach a runnable sample
  • try a different event type, e.g. EVT_LEFT_DOWN

Regards,
Dietmar

1 Like

Hi Dietmar!

EVT_LEFT_DOWN worked perfectly and everything is fixed. It’s a bit weirdI couldn’t find that this event is also available for TextCtrl.

Thank you very much!
Horia