gui_combine_window.py
- class ScenarioGUI.gui_classes.gui_combine_window.JsonDict
Bases:
TypedDict
- class ScenarioGUI.gui_classes.gui_combine_window.MainWindow(dialog: QtW.QMainWindow, app: QtW.QApplication, gui_structure: Type[GuiStructureType], translations: type[Translations], *, result_creating_class: type[ResultsClass], data_2_results_function: Callable[[DataStorage], tuple[object, ft_partial[None]] | tuple[object, Callable[[], None]]])
Bases:
QMainWindow,BaseUIThis class contains the general functionalities of the GUI (e.g. the handling of creating new scenarios, saving documents etc.)
- Parameters
- dialogQtW.QWidget
Q widget as main window where everything is happening
- appQtW.QApplication
The widget for the application itself
- result_creating_class: Object with from_dict and to_dict function
results creating class
- data_2_results_functionCallable
function to create the results class and a function to be called in the thread
- Returns
- MainWindow
- activate_load_as_new_scenarios() None
activates the possibility to load files as new scenarios and append them to the current scenario list Returns ——-
None
- add_other_export_function(file_extension: str, func: Callable[[str | Path, JsonDict], None])
adds an export behaviour for a different file type. Parameters ———- file_extension: str
file type like (*.csv)
- func: Callable[[str | Path, JsonDict], None]
function which get the path to the file and the json dict as input and creates and saves the new file.
- Returns
- None
- add_other_import_function(file_extension: str, func: Callable[[str | Path], JsonDict])
adds an import behaviour for a different file type. Parameters ———- file_extension: str
file type like (*.csv)
- func: Callable[[str | Path], JsonDict]
function which get the path to the file as input and creates a dict of results like the json format does.
- Returns
- None
- add_other_version_import_function(version: str, func: Callable[[JsonDict], JsonDict])
adds an import behaviour for a previous version of the gui. Parameters ———- version: str
version for which the behaviour is added
- func: Callable[[str | Path], JsonDict]
function which get the path to the file as input and creates a dict of results like the json format does.
- Returns
- None
- add_scenario() None
Function to add a scenario.
- Returns
- None
- auto_save() None
This function automatically saves data in the backup file.
- Returns
- None
- change() None
This function checks if there are changes to a scenario or a file save happened. If there were changes, an * is added to the current scenario. This function is only active when self.started is True (this is the case when the application is running) and self.checking is True (this can temporarily be disabled by some other function).
- Returns
- None
- change_language() None
This function changes the language on the different labels and buttons in the gui.
- Returns
- None
- change_page_button_layout(button: QPushButton, big: bool = False, name: str = '') None
This function changes the layout of the page button, by adding/removing the text and icon.
- Parameters
- buttonQtW.QPushButton
Button for which the layout has to be changed
- bigbool
True if the expanded version of the button is needed, False otherwise
- namestr
Name of the icon for the relevant button
- Returns
- None
- change_scenario(idx: int) None
Updates the gui to the correct data from the datastorage with the selected index idx.
- Parameters
- idxint
Index of the selected scenario
- Returns
- None
- change_window_title() None
This function changes the window title to the filename and marks it with an * if unsaved changes exist
- Returns
- None
- check_page_button_layout(mouse_over: bool) None
This function checks if the layout of the page button should be changed. When the mouse_over is True, the page button is expanded to include text and icon. When mouse_over is False, the page button is again ‘closed’.
- Parameters
- mouse_overbool
True if the mouse is over a PushButton and it should be expanded
- Returns
- None
- check_results() None
This function checks if there are results and if so, it will display them. It checks this by checking if there exists a results attribute in the datastorage object that differs from None.
- Returns
- None
- check_values() bool
This function checks if all the options in the gui are given correct values. If not, it will print an error message on the status bar.
- Returns
- None
- closeEvent(event) None
This function is called when the gui is closed. It will prompt a window asking if potential changes need to be saved.
- Parameters
- event
closing event
- Returns
- None
- delete_backup()
This function deletes the backup file link (not the actual backup file) if it exists.
- Returns
- None
- delete_scenario() None
This function deletes the selected scenario and selects the scenario above it.
- Returns
- None
- display_results() None
This function displays the results (of the selected scenario) on the results page.
- Returns
- None
- eventFilter(obj: QObject, event) bool
This function checks the mouse over event. It overwrites the eventFilter object in QObject.
- Parameters
- objQtW.QObject
- eventevent
Event for which it is check if the mouse is entering or leaving
- Returns
- bool
True to check if the function has worked correctly. (implemented for test cases)
- fun_load() None
This function sets the filename by opening a QFileDialog box. Afterwards, it runs fun_load_known_filename() to open this file.
- Returns
- None
- fun_load_known_filename() None
This function loads a previously stored project based on the self.filename attribute. This attribute is set by the function fun_load(). When no such file exists, a message is printed in the status bar.
- Returns
- None
- fun_new() None
This function creates a new project and resets the GUI.
- Returns
- None
- fun_rename_scenario(name: str = '') None
Function to rename the current scenario with a dialog box to ask for a new name
- Parameters
- namestr
Name of the scenario (only for testing purposes
- Returns
- None
- fun_save(filename: Optional[tuple[str, str]] = None) bool
This function saves all the scenarios in a JSON formatted *.{FILE_EXTENSION} file.
Parameters
- filename: tuple[str, str] | None
name of file
- Returns
- bool
True if the saving was successful.
- fun_save_as() bool
This function sets the filename to a default value and calls the fun_save() function.
- Returns
- bool
- load_add_scenarios() None
This function sets the filename by opening a QFileDialog box. Afterwards, it runs fun_load_known_filename() to open this file.
- Returns
- None
- load_backup() None
This function tries to open the backup file and load its values.
- Returns
- None
- remove_previous_calculated_results()
This function removes previously calculated results by removing the results attribute and closing all the figures in the DataStorage.
- Returns
- None
- resizeEvent(event: QResizeEvent) None
update push buttons sizes
- Parameters
- event: QtG.QResizeEvent
- Returns
- None
- save_scenario() bool
This function saves the current scenario in the backup.
- Returns
- None
- scenario_is_changed(new_row_item: QListWidgetItem, old_row_item: QListWidgetItem) None
This function handles the changing of scenarios. If the auto-save ButtonBox is set to auto-save, the previous scenario is changed an the new item is selected. If not, a messagebox is shown to ask if the ‘old’ scenario should be saved.
- Parameters
- new_row_itemQtW.QListWidgetItem
New selected item in the scenario listbox
- old_row_itemQtW.QListWidgetItem
Old selected item in the scenario listbox
- Returns
- None
- set_event_filter() None
This function sets the event filter for the page buttons so it can be detected when there is a mouse over event.
- Returns
- None
- set_links() None
This function connects all the buttons to their relevant actions. All interactions between front and back-end are implemented here.
- Returns
- None
- set_name(name: str) str
set the text of the item and checks for the appearens in the current scenario names Parameters ———- name: str
scenario name
- Returns
- str
- static set_push_button_icon(button: QPushButton, icon_name: str) None
This function sets the icon in the QPushButton.
- Parameters
- buttonQtW.QPushButton
Button to which the icon should be set
- icon_namestr
Icon name
- Returns
- None
- start_current_scenario_calculation() None
This function starts the calculation of the selected/current scenario, when check_values() is True.
- Returns
- None
- start_multiple_scenarios_calculation() None
This function starts the calculation of all the scenarios that do not have a results attribute in their DS, when check_values() is True.
- Returns
- None
- thread_function(results: CalcProblem) None
This function closes the thread of the old calculation and stores it results. It increments the number of calculated scenarios, and calls to update the progress bar. Afterwards, it starts the new thread for the following calculation.
- Parameters
- resultsTuple[DataStorage, int]
Tuple with the DS object of the current thread and its corresponding index
- Returns
- None
- update_bar(val: int | float) None
This function updates the status bar or hides them if it is no longer needed. It displays the percentage of calculated scenarios.
- Parameters
- valint | float
Number of successfully calculated scenarios
- Returns
- None