4

Can a gtk.FileChooserDialog/gtk.FileChooserButton be set to only allow users to select a folder/directory?

Maybe I add a directory filter to achieve this? How can I make it so the user can only select a folder?

email_dialog    = gtk.FileChooserDialog(title="Select folder",
                                        buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
email_filter = gtk.FileFilter()
email_filter.set_name("Folder")
email_filter.add_pattern("*")  # whats the pattern for a folder
email_dialog.add_filter(email_filter)
sazr
  • 24,984
  • 66
  • 194
  • 362
  • Possible duplicate http://stackoverflow.com/questions/3170962/enable-gtkfilechooserdialog-to-select-files-or-folders – coder Jun 03 '12 at 05:51
  • @coder, That's not a duplicate; the question you linked is about allowing selection of a file OR a folder, not a folder exclusively. – ptomato Jun 03 '12 at 10:17

1 Answers1

8
email_dialog.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)

Documentation here.

ptomato
  • 56,175
  • 13
  • 112
  • 165