From 70925b5332ac57832452af31b178876d06062421 Mon Sep 17 00:00:00 2001 From: Dominik Gresch Date: Tue, 11 Apr 2023 14:37:45 +0200 Subject: [PATCH] Fix logic for selecting action in file dialog (#2003) The `FileDialog.action` can have values `open`, `open files`, or `save as`, see https://github.com/enthought/pyface/blob/a9bf0264cb2afe9d05ce8856de650fd6efbc2684/pyface/ui/wx/file_dialog.py#L37 and https://github.com/enthought/pyface/blob/a9bf0264cb2afe9d05ce8856de650fd6efbc2684/pyface/ui/qt/file_dialog.py#L36. The `dialog_style` on the other hand can have values `open` and `save`, see https://github.com/enthought/traitsui/blob/c08f891c19e5464e308cb9c6c14e77599e11b132/traitsui/editors/file_editor.py#L77-L78 As such, the logic for converting from `dialog_style` to `action` was the wrong way around. As a result, the file dialog would always open in "open" mode. --- traitsui/qt/file_editor.py | 2 +- traitsui/wx/file_editor.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/traitsui/qt/file_editor.py b/traitsui/qt/file_editor.py index 4301d49a8..2f2d55b9f 100644 --- a/traitsui/qt/file_editor.py +++ b/traitsui/qt/file_editor.py @@ -138,7 +138,7 @@ def _create_file_dialog(self): dlg = FileDialog( parent=self.get_control_widget(), default_path=self._file_name.text(), - action="save" if self.factory.dialog_style == "save as" else "open", + action="save as" if self.factory.dialog_style == "save" else "open", wildcard=wildcard, ) return dlg diff --git a/traitsui/wx/file_editor.py b/traitsui/wx/file_editor.py index 396a08b34..7ac95a1a6 100644 --- a/traitsui/wx/file_editor.py +++ b/traitsui/wx/file_editor.py @@ -207,7 +207,7 @@ def _create_file_dialog(self): dlg = FileDialog( parent=self.get_control_widget(), default_path=self._file_name.GetValue(), - action="save" if self.factory.dialog_style == "save as" else "open", + action="save as" if self.factory.dialog_style == "save" else "open", wildcard=wildcard, ) return dlg