I've seen this question that explains how to restrict a gtk FileChooserDialog so that only directories are allowed.
I would like to place a further restriction so that only directories whose name match a certain pattern are allowed. I tried using a gtk.FileFilter()
but it did not work:
self.logFileBrowseDialog = gtk.FileChooserDialog(title="Select Log Directory",
action=gtk.FILE_CHOOSER_ACTION_SAVE,
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN,gtk.RESPONSE_OK))
self.logFileBrowseDialog.set_current_folder('/path/to/default/log/dir');
logDirFilter = gtk.FileFilter()
logDirFilter.set_name("Log Directory")
logDirFilter.add_pattern("[0-1][0-9]-[0-3][0-9]-[0-9][0-9][0-9][0-9]-[0-2][0-9]-[0-5][0-9]-[0-5][0-9].[0-9][0-9][0-9]_GMT_Logs")
self.logFileBrowseDialog.add_filter(logDirFilter)
self.logFileBrowseDialog.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
Is it possible to only permit directories of a certain name? I realize that the user still needs a way to navigate away from an non-permitted directory to a permitted one. Ideally the "Open" button would be disabled if the current location does not meet the name criteria.