I have created a dialog to select a file with wxpython and FileBrowseButton with this code.

fbb = wxfbb.FileBrowseButton(panel,labelText="Select an image file:", fileMask=mask, fileMode=wx.OPEN, size=(800,30))
markFile = fbb.GetValue()

I need to use the selected file for further actions. How can I do it? I have tried

return markFile

but I get this error

TypeError: __init__() should return None, not 'unicode'

Can anyone help?


Here is an example that Henri left somewhere ...

# exploring wxPython's
# wx.lib.filebrowsebutton.FileBrowseButton()

import wx
import wx.lib.filebrowsebutton

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle):
        wx.Frame.__init__(self, parent, -1, mytitle, size=(500,100))
        panel = wx.Panel(self)

        self.fbb = wx.lib.filebrowsebutton.FileBrowseButton(panel,
            labelText="Select a WAVE file:", fileMask="*.wav")
        play_button = wx.Button(panel, -1, ">>  Play")
        self.Bind(wx.EVT_BUTTON, self.onPlay, play_button)

        # setup the layout with sizers
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.Add(self.fbb, 1, wx.ALIGN_CENTER_VERTICAL)
        hsizer.Add(play_button, 0, wx.ALIGN_CENTER_VERTICAL)
        # create a border space
        border = wx.BoxSizer(wx.VERTICAL)
        border.Add(hsizer, 0, wx.EXPAND|wx.ALL, 15)

    def onPlay(self, evt):
        filename = self.fbb.GetValue()
        self.sound = wx.Sound(filename)
        # error handling ...
        if self.sound.IsOk():
            wx.MessageBox("Missing or invalid sound file", "Error")

app = wx.App(0)
# create a MyFrame instance and show the frame
caption = "wx.lib.filebrowsebutton.FileBrowseButton()"
MyFrame(None, caption).Show()

I have played a little bit with the example by Henri, and I think that I got it. However, I have a problem.
This is my button that opens a dialog to browse for a directory

self.picsFolder = wx.lib.filebrowsebutton.DirBrowseButton(panel,labelText="Select your pictures directory:", size=(800,30))

Then, this is a piece of a defined function, which gets the path to the directory stored in self.picsFolder and tried to set the current directory to this path

def WaterMark(self, event):
	px = self.px.GetValue()
	markFile = self.markFile.GetValue()
	picsFolder = self.picsFolder.GetValue()

The problem is that when I run it, the screen turns grey and, after a long time, the process gets killed. Do you know where the problem is? I have attached a file with the whole code in case you need to check it.


It sounds like either the screensaver or the wxPython time out (for certain types of widgets). I don't use timeout so am not familiar with it other than seeing it in the docs. Your program should allow the user a certain amount of time to choose a file, and if they haven't made a decision in say 2 or 3 minutes, exit. And you should print picsFolder for your own information to see if it contains the complete path or just the file name. Also, it is better IMHO to use the complete path instead of os.chdir() as it can get confusing as to which directory you are actually in. Finally, it is bad form to use the same name for a variable and a class, i.e.
picsFolder = self.picsFolder.GetValue()

picsFolder = ClassInstance()  ## variable is a class instance
picsFolder = self.picsFolder.GetValue()  ## picsFolder is now a variable (the class instance is gone) 
## In Python CamelCase is used for class instances and 
## lower_case is used for variables and we don't get mixed up
## The style guide is here, http://www.python.org/dev/peps/pep-0008
## if you are interested

I'm running Ubuntu Lucid Lynx 64 bits. If I remove the "os.chdir(picsFolder)" it does not turn grey.