swingutils.dialogs.filechooser

Contains helpers for JFileChooser related functionality.

class swingutils.dialogs.filechooser.SimpleFileFilter(suffixes, preferred=None, description=None)

A simple FileFilter class, suitable for use with the showSaveDialog() function, and of course Java’s JFileChooser class.

swingutils.dialogs.filechooser.createFileChooserDialog(filters, filename, prefs, prefkey, multiselect)

Creates a file chooser dialog that remembers its last directory.

swingutils.dialogs.filechooser.showOpenDialog(filters, filename=None, parent=None, prefs=None, prefkey=None, multiselect=False)

Shows a save dialog that remembers the last directory based on the given preferences key. If the selected file filter has a ‘suffix’ attribute, it will be appended to the selected file name if it’s missing.

Parameters:
  • filters (javax.swing.filechooser.FileFilter) – a FileFilter (or several of them in an iterable)
  • filename (str) – default name for the new file
  • parent – parent component to attach to
  • prefs (java.util.prefs.Preferences) – a Preferences object to use for remembering the save directory
  • prefkey (str) – key to use for saving/loading last save directory
  • multiselectTrue to allow multiple files to be selected
Returns:

list of selected files (if multiselect=True), else the selected file

Return type:

java.io.File

swingutils.dialogs.filechooser.showSaveDialog(filters, filename=None, parent=None, prefs=None, prefkey=None)

Shows a save dialog that remembers the last directory based on the given preferences key. If the selected file filter has a ‘suffix’ attribute, it will be appended to the selected file names if it’s missing.

Parameters:
  • filters (javax.swing.filechooser.FileFilter) – a FileFilter (or several of them in an iterable)
  • filename (str) – default name for the new file
  • parent – parent component to attach to
  • prefs (java.util.prefs.Preferences) – a Preferences object to use for remembering the save directory
  • prefkey (str) – key to use for saving/loading last save directory
Returns:

the selected file

Return type:

java.io.File