pypeit.setup_gui.dialog_helpers module
Utilities for creating and displaying dialogs in Qt.
- class pypeit.setup_gui.dialog_helpers.DialogResponses(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
Enum
Enum for the responses from a dialog.
- ACCEPT = 1
The user accepted the dialog. This could have been from an “Accept”, “Ok”, “Continue” or similar button.
- ACCEPT_FOR_ALL = 2
The user accepted the dialog for this and any subsequent requests. For example, a Save All that should save everthing to the same path.
- CANCEL = 4
The user canceled the dialog.
- SAVE = 3
The user requested to save any unchanged data before continuing with an operation.
- class pypeit.setup_gui.dialog_helpers.FileDialog(parent: QWidget, caption: str, file_mode: FileMode, file_type: FileType | None = None, default_file: str | Path | None = None, history: QStringListModel | None = None, save: bool = False, ask_for_all: bool = False)[source]
Bases:
object
Opens a file dialog for either opening or saving files. This encapsulates the logic to use QFileDialog in a way that can be used by the view or controller and can be easilly patched by unit tests.
- Parameters:
parent – Parent of the dialog widget.
caption – Caption for the dialog.
file_mode – The file mode for the dialog.
filter – The filter to use for files in the file dialog. For example: “PypeIt input files (*.pypeit)”
history – The list of paths to populate the history of the dialog. New paths selected are added to this history.
save – Whether the dialog is a save dialog. If False it is treated as an open dialog. Defaults to False.
ask_for_all – Whether the dialog should present a “Use this location for everything” option when saving. Defaults to False.
- classmethod create_open_file_dialog(parent: QWidget, caption: str, file_type: FileType, history_group: str = 'OpenFile') FileDialog [source]
Creates a dialog to prompt the user for an existing file.
- Parameters:
parent – The parent widget of the pop-up dialog
caption – A caption for the dialog
filter – A QFileDialog filter for a file to open. For example: “Text Files (*.txt)”
history_group – The group in the applications persistent settings to persist the history. Defaults to “OpenFile”
- Returns:
The created file dialog.
- Return type:
- classmethod create_save_location_dialog(parent: QWidget, config_name: str, prompt_for_all: bool = False, history_group='OutputDirectory') FileDialog [source]
Creates a dialog requesting the user select a location to save a file. A history is maintained.
- Parameters:
parent – The parent widget of the pop-up dialog
config_name – The name of the configuration being saved to a pypeit file.
prompt_for_all – Whether to prompt the user if this save location should apply to all subsequent files in the operation.
history_group – The group in the applications persistent settings to persist the history. Defaults to “OutputDirectory”
- Returns:
The FileDialog object used to prompt the user. It’s response attribute will be either CANCEL, ACCEPT, or ACCEPT_FOR_ALL. It’s selected_path members will be set to the chosen path or None of the dialog was canceled.
- show() DialogResponses [source]
Show a modal file dialog. If the dialog is accepted, the results will be saved in the selected_path and response attributes.
- Returns:
CANCEL, ACCEPT_FOR_ALL, or ACCEPT.
- Return type:
- class pypeit.setup_gui.dialog_helpers.FileType(name: 'str', extension: 'str')[source]
Bases:
object
- class pypeit.setup_gui.dialog_helpers.PersistentStringListModel(settings_group, settings_value_name)[source]
Bases:
QStringListModel
Child class of QStringListModel that persists it’s contents to QSettings.
- Parameters:
- save(topLeft=None, bottomRight=None, roles=None)[source]
Saves the data persisted in this PersistentStringListModel.
- Parameters:
topLeft (QModelIndex) – The top left index of the data changhed. This is not and defaults to None.
bottomRight (QModelIndex) – The bottom right index of the data changed. This is not and defaults to None.
roles (list) – List of roles changed. This is not and defaults to None.
- pypeit.setup_gui.dialog_helpers.display_error(parent: QWidget, message: str) None [source]
Display an error message pop up dialog to the user.
- Parameters:
parent – The parent widget of the pop-up dialog
message – The message to display.
- pypeit.setup_gui.dialog_helpers.prompt_to_save(parent: QWidget) DialogResponses [source]
Prompt the user if they want to save any unsaved data.
- Parameters:
parent – The parent widget of the pop-up dialog
- Returns:
SAVE
if the user wants to save,ACCEPT
if they want to continue without saving,CANCEL
if they want to cancel the current operation and to not lose any data.- Return type: