Dear all,
I have a window with several textctrl. I am trying to intercept the mouse click in each control, open a filedialog and set the value of the specific control with the selected file.
The problem is that I would like to avoid creating hundreds of similar functions for each control, so I would like to bind one single function to all of them.
What I got so far is the following

def onSecond(self, event):
    focus = wx.TextCtrl.FindFocus()
        if focus.GetValue()=="":
            focus.SetValue("loading...")
            dlg = wx.FileDialog(self, message="Choose the first image (base image)",wildcard = filters, style = wx.MULTIPLE)

            if dlg.ShowModal() == wx.ID_OK:
                focus.SetValue(dlg.GetDirectory()+"; "+", ".join(str(fl[len(dlg.GetDirectory())+1:]) for fl in dlg.GetPaths()))

                #print dlg.GetDirectory()+"; "+", ".join(str(fl[len(dlg.GetDirectory())+1:]) for fl in dlg.GetPaths())


            dlg.Destroy()  

The above works if the specific textctrl is empty (focus.GetValue()==""). What should I do if I want to popup the filedialog regardless of the contect of the specific control?
If I get rid of if focus.GetValue()=="": I will get into an endless loop.
Where am I wrong and how should I proceed?
Thanks,
Gianluca

Are your indentations a mixture of tabs and spaces?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.