pypeit.setup_gui.dialog_helpers module
Utilities for creating and displaying dialogs in Qt.
- class pypeit.setup_gui.dialog_helpers.DialogResponses(*values)[source]
Bases:
EnumEnum 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, caption, file_mode, file_type=None, default_file=None, history=None, save=False, ask_for_all=False)[source]
Bases:
objectOpens 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 (
QWidget) – Parent of the dialog widget.caption (
str) – Caption for the dialog.file_mode (
FileMode) – The file mode for the dialog.filter – The filter to use for files in the file dialog. For example: “PypeIt input files (*.pypeit)”
history (
Optional[QStringListModel]) – The list of paths to populate the history of the dialog. New paths selected are added to this history.save (
bool) – Whether the dialog is a save dialog. If False it is treated as an open dialog. Defaults to False.ask_for_all (
bool) – Whether the dialog should present a “Use this location for everything” option when saving. Defaults to False.
- classmethod create_open_file_dialog(parent, caption, file_type, history_group='OpenFile')[source]
Creates a dialog to prompt the user for an existing file.
- Parameters:
parent (
QWidget) – The parent widget of the pop-up dialogcaption (
str) – A caption for the dialogfilter – A QFileDialog filter for a file to open. For example: “Text Files (*.txt)”
history_group (
str) – 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, config_name, prompt_for_all=False, history_group='OutputDirectory')[source]
Creates a dialog requesting the user select a location to save a file. A history is maintained.
- Parameters:
parent (
QWidget) – The parent widget of the pop-up dialogconfig_name (
str) – The name of the configuration being saved to a pypeit file.prompt_for_all (
bool) – 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”
- Return type:
- 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.
- class pypeit.setup_gui.dialog_helpers.PersistentStringListModel(settings_group, settings_value_name)[source]
Bases:
QStringListModelChild 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, message)[source]
Display an error message pop up dialog to the user.
- pypeit.setup_gui.dialog_helpers.prompt_to_save(parent)[source]
Prompt the user if they want to save any unsaved data.
- Parameters:
parent (
QWidget) – The parent widget of the pop-up dialog- Returns:
SAVEif the user wants to save,ACCEPTif they want to continue without saving,CANCELif they want to cancel the current operation and to not lose any data.- Return type: