From 90c210c58bcc1a94eca37833ced18861bc540ed4 Mon Sep 17 00:00:00 2001 From: matham Date: Wed, 4 Nov 2020 16:04:52 -0500 Subject: [PATCH] Some APIs are only available for open panels. --- plyer/platforms/macosx/filechooser.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/plyer/platforms/macosx/filechooser.py b/plyer/platforms/macosx/filechooser.py index 386a58647..7dd65c32f 100644 --- a/plyer/platforms/macosx/filechooser.py +++ b/plyer/platforms/macosx/filechooser.py @@ -55,23 +55,25 @@ def _handle_selection(selection): def run(self): panel = None - if self.mode in ("open", "dir"): + if self.mode in ("open", "dir", "dir_and_files"): panel = NSOpenPanel.openPanel() - else: + + panel.setCanChooseDirectories_(self.mode != "open") + panel.setCanChooseFiles_(self.mode != "dir") + + if self.multiple: + panel.setAllowsMultipleSelection_(True) + elif self.mode == "save": panel = NSSavePanel.savePanel() + else: + assert False, self.mode panel.setCanCreateDirectories_(True) - - panel.setCanChooseDirectories_(self.mode == "dir") - panel.setCanChooseFiles_(self.mode != "dir") panel.setShowsHiddenFiles_(self.show_hidden) if self.title: panel.setTitle_(objc_str(self.title)) - if self.mode != "save" and self.multiple: - panel.setAllowsMultipleSelection_(True) - # Mac OS X does not support wildcards unlike the other platforms. # This tries to convert wildcards to "extensions" when possible, # ans sets the panel to also allow other file types, just to be safe. @@ -88,6 +90,7 @@ def run(self): filthies.append(objc_str(pystr)) ftypes_arr = objc_arr(*filthies) + # todo: switch to allowedContentTypes panel.setAllowedFileTypes_(ftypes_arr) panel.setAllowsOtherFileTypes_(not self.use_extensions)