Question

Looks like there's no built-in option to disable/remove the InputBox/TextCtrl part in wx.lib.filebrowsebutton.FileBrowseButton, well I did come up with a workaround which is simply set labelText to blank and then size it down to fit only the button itself, this way visually you can tell no difference from a normal button, but I don't think it's nice enough to go with.

So is there a way to fully disable/remove the InputBox part? Or maybe a way to bind normal button with file browser function?

Was it helpful?

Solution

If you don't need a textctrl, then you don't really need wx.lib.FileBrowseButton. You can just have a normal wx.Button that launches a wx.FileDialog instance. In fact, that's all that wx.lib.FileBrowsBbutton does. Here's the relevant source code, the whole thing can be viewed here: https://github.com/wxWidgets/wxPython/blob/master/wx/lib/filebrowsebutton.py

def OnBrowse (self, event = None):
        """ Going to browse for file... """
        current = self.GetValue()
        directory = os.path.split(current)
        if os.path.isdir( current):
            directory = current
            current = ''
        elif directory and os.path.isdir( directory[0] ):
            current = directory[1]
            directory = directory [0]
        else:
            directory = self.startDirectory
            current = ''
        dlg = wx.FileDialog(self, self.dialogTitle, directory, current,
                            self.fileMask, self.fileMode)

        if dlg.ShowModal() == wx.ID_OK:
            self.SetValue(dlg.GetPath())
        dlg.Destroy()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top