Question

I'm creating a file dialog that allows the user to save a file after editing it in my app. I want to add a checkbox to the dialog so the user can make some choices about what format the file is saved in. I think I need to make some new class that inherits from FileDialog and inserts a checkbox into the frame created by the filedialog, but I don't really know how to do that. Can anyone help me out?

(I also want to create an analogous file dialog for opening a file, but I assume that will just mean replacing the SAVE style with the OPEN style.)

Was it helpful?

Solution

I think you are going the wrong way about this. In general extra widgets aren't ment to be added to the standard dialogs (they wouldn't really be standard if you could).

If you wish to add wx.CheckBox's or the like the you going to have to create your own custom dialog by subclassing wx.Dialog.

If all you need to do is to provide the user with a means of filtering by file-types to be opened or select which file-type the file is to be saved as, then this functionality is all ready provided by wx.FileDialog.

By using the wildcard paramater when creating an instance of your fileDialog you can supply a group of file-types for the user to choose from.

Here's a snippet from the wxPython Demo and a screenshot to illustrate. The wxPython Demo is very usefull application which provides demos of most of the widgets included with wxPython, a worthwhile download if you don't already have it.

wildcard = "Python source (*.py)|*.py|"     \
           "Compiled Python (*.pyc)|*.pyc|" \
           "SPAM files (*.spam)|*.spam|"    \
           "Egg file (*.egg)|*.egg|"        \
           "All files (*.*)|*.*"

alt text

wx.FileDialog Documentation:

http://wxpython.org/docs/api/wx.FileDialog-class.html

http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.FileDialog.html

OTHER TIPS

In wxWidgets 2.9 custom controls can be added to file dialogs using wxFileDialog::SetExtraControlCreator(). It's implemented for GTK, MSW and generic dialogs.

Alternatively, you may use the wxFileCtrl class. It has native implementation only in wxGTK.

I don't know if these features is available from Python wrappers, though.

I agree with volting. If you need a custom (NOT native) dialog, subclass wx.Dialog. Otherwise, use the standard dialogs the way they're supposed to be used. See also:

http://www.blog.pythonlibrary.org/2010/06/26/the-dialogs-of-wxpython-part-1-of-2/

http://www.blog.pythonlibrary.org/2010/07/10/the-dialogs-of-wxpython-part-2-of-2/

I have to disagree with the sentiment that you should use standard dialogs only how they were designed.

I take another view and would rather look at using subclassing the way that subclassing was intended. And to me, it is to add additional functionality/specialization to a class.

So it is not changing the behavior of the standard dialog. It is creating a new dialog BASED ON the standard dialog with a little additional functionality.

In my case, I want to add two buttons to the wx.MultiChoiceDialog to provide a Select All and/or Unselect All functions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top