View Module

src/view/gui.py PLASMAG GUI module

class src.view.gui.AboutDialog(parent=None, version='')

Bases: QDialog

open_documentation()
class src.view.gui.CalculationThread(controller, params_dict=None)

Bases: QThread

A QThread subclass for running calculations in a separate thread to avoid blocking the main GUI thread.

calculation_failed
calculation_finished
run()

Runs the calculation process in a separate thread. :return:

class src.view.gui.ClickableLabel(*args, **kwargs)

Bases: QLabel

clicked
mousePressEvent(self, ev: QMouseEvent | None)
class src.view.gui.EnlargedImageDialog(pixmap, parent=None)

Bases: QDialog

closeEvent(self, a0: QCloseEvent | None)
eventFilter(self, a0: QObject | None, a1: QEvent | None) bool
class src.view.gui.MainGUI(config_dict=None, version='')

Bases: QMainWindow

Main Graphical User Interface window

The MainGUI class is responsible for creating and managing the graphical user interface of the PLASMAG application. It sets up input fields for parameters, sliders for adjustments, a plotting area for visualization, and initiates calculations.

Attributes:
  • currently_selected_input (tuple): A tuple containing the currently selected QLineEdit and its parameter name.

  • central_widget (QWidget): The central widget of the QMainWindow.

  • main_layout (QVBoxLayout): The main layout containing all widgets.

  • inputs (dict): Dictionary mapping parameter names to their respective QLineEdit widgets.

  • global_slider_coarse (QSlider): The slider for coarse adjustments of parameter values.

  • global_slider_fine (QSlider): The slider for fine adjustments of parameter values.

  • calculate_btn (QPushButton): The button to trigger the calculation process.

  • canvas (MplCanvas): The matplotlib canvas for plotting calculation results.

  • controller (CalculationController): The controller handling the calculation logic.

adjust_slider_properties(parameter)

Adjusts the properties (minimum, maximum, and current value) of the global sliders based on the selected parameter. This method is crucial for ensuring that the sliders provide a meaningful and constrained range of adjustment for the parameter’s value.

Args:

parameter (str): The name of the parameter for which to adjust the slider properties.

Note:

The coarse slider is adjusted to cover the entire range of the parameter, allowing for broad adjustments. The fine slider is designed to fine-tune the parameter value, focusing on the decimal part for precise control.

adjust_spice_splitter(show)
adjust_splitter_for_spice_hidden()
adjust_splitter_for_spice_visible()
apply_flicker_data_to_parameters(specific_data)

Applies the flicker loaded data to the input parameters fields in the UI. :param specific_data: dict containing the flicker parameters to apply :return:

bind_slider_to_input(line_edit, parameter)

Binds the coarse and fine sliders to a selected input field, allowing for parameter adjustment. It sets the sliders’ ranges based on the parameter’s defined range and adjusts them to reflect the input’s current value.

Args:

line_edit (QLineEdit): The QLineEdit widget representing the input field for the parameter. parameter (str): The name of the parameter associated with the input field.

This method calculates the initial positions of both sliders based on the current value of the input field and adjusts the sliders to reflect both the integral and decimal parts of this value.

calculate()

Gathers the current parameter values from the input fields, initiates the calculation process through the controller, and triggers the plotting of the results. Uses unit conversion for parameters requiring it.

calculate_slider_value(value, min_val, max_val)

Converts the parameter value to a slider position, considering the parameter’s range. For linear parameters, it returns the value itself. For logarithmic scaling, still need to adjust this method to calculate the slider position appropriately.

change_plot_count()
clear_plot_layout()
clear_saved_results()
delayed_calculate()

Performs calculation after a delay to avoid UI lag during slider adjustments. This method is triggered by the calculation_timer’s timeout signal.

display_error(error_message)

Triggered when an error occurs during the calculation process. :param error_message: :return:

display_graph(clustering_type='degree')

Opens an HTML file in the default system web browser.

Args:

file_path (str): The path to the HTML file to open.

display_graph_community()
display_graph_degree()
display_graph_distance()
export_CLTF_NEMI()
export_dependency_tree()
export_parameters_to_json()

Exports the current input parameters to a JSON file. The user is prompted to select a file location for the export. Exported parameters can be imported back into the application. :return:

export_results()

Exports the latest calculation results to a CSV file. The user is prompted to select a file location for the export. :return: None

import_flicker_data_from_json()

Imports specific data from a JSON. The json file should be exported from the Flicker tuning module :return:

import_parameters_from_json(need_filename=True, path=None, data=None)

Imports input parameters from a JSON file. The user is prompted to select a file to import the parameters from. The imported parameters are then used to update the UI. :return:

init_canvas(number_of_plots=3, number_of_buttons=3)

Initializes the matplotlib canvas for plotting the calculation results. Creates three separate canvases for different plots and adds them to the main layout. :return:

init_controller(backups_count=3)

Initializes the CalculationController for handling the calculation logic. :return:

init_menu()

Initializes the menu bar with options for exporting and importing parameters. :return:

init_parameters_input()

Initializes the input fields for the parameters based on the loaded input parameters. Iterates over the input parameters dictionary and creates a QLabel and QLineEdit for each parameter in each section. The input fields are organized in a scrollable area for better visibility and usability.

init_sliders()

Initializes the global sliders for frequency, coarse and fine adjustments of parameter values. The sliders are set up with appropriate ranges and connected to the update methods for parameter values.

init_spice_settings()
init_strategy_selection()
init_timer(timer_value=50)

Initializes the calculation timer with a delay of XX milliseconds. Used to trigger the calculation process after a delay to avoid lag during slider adjustments. :return:

init_ui()

Initializes the graphical user interface by setting up the main layout, input fields, sliders, and plotting area. :return:

linear_scale(log_value, min_val, max_val, min_log, max_log)

Converts a logarithmic frequency value back to a linear slider value.

load_and_normalize_curve(file_path)

Loads a curve from a CSV file and return x and y data. :param file_path: FULL path to the CSV file :return: x_data, y_data

load_background_curve(canvas_index)
load_default_parameters(reload=True)

Loads the default input parameters from the ‘data/default.json’ file. :return:

load_spice_configs()
load_strategy(strategies_info) dict
log_scale(value, min_val, max_val, min_log, max_log)

Converts a linear slider value to a logarithmic frequency value.

merge_spice_parameters(selected_circuit_name)
on_calculation_finished(calculation_results)

Callback method for handling the completion of the calculation process. :param calculation_results: :return:

open_documentation()
plot_results(calculation_results)

Plots the calculation results on the canvas based on the selected key from the combo box a nd the state of the ‘Show Old Curve’ checkbox. :param calculation_results: :return:

post_init_setup()
reload_pixmap()
reset_background_curve(canvas_index)
reset_parameters(reload=True)

Resets all input fields to their default values and adjusts the sliders to reflect these defaults. This method iterates through all parameters across categories, reverting any changes made by the user to the default state.

retrieve_parameters()
save_results(index, button)
set_labels(data_meta, canvas)

Set labels and scales based on data type.

show_about_dialog()
show_enlarged_image(pixmap)
toggle_spice_visibility()
update_canvas_count(num_plots)
update_frequency_range(value)

Updates the frequency range values based on the slider position. :param value: :return:

update_node_strategy(node_name, strategy_class)
update_plot(index)
update_selected_input_value(slider_type)

Updates the value of the currently selected input field based on the slider movement. This method ensures that changes made using the sliders are immediately reflected in the input field, providing a responsive and interactive experience for adjusting parameters.

Args:

slider_type (str): Indicates whether the adjustment is made with the ‘coarse’ or ‘fine’ slider.

Depending on the slider type, this method calculates the new value for the input field by combining the integral part from the coarse slider and the decimal part from the fine slider, maintaining precision.

update_spice_parameters_ui(index)
validate_input(line_edit, parameter)

Validates the input of a QLineEdit widget, ensuring it’s a valid number within the specified range for the given parameter. Adjusts the input value to the nearest valid value if it falls outside the allowed range and visually indicates invalid inputs.

class src.view.gui.MplCanvas

Bases: FigureCanvasQTAgg

A custom matplotlib canvas for displaying plots in the GUI.

add_curve(x_data, y_data, label=None)

Adds a curve to the plot with the given x and y data. :param x_data: :param y_data: :param label: :return:

class src.view.gui.ResizableImageLabel(pixmap, parent=None)

Bases: QLabel

clicked
get_pixmap()
mousePressEvent(self, ev: QMouseEvent | None)
resizeEvent(self, a0: QResizeEvent | None)
setPixmap(self, a0: QPixmap)
class src.view.gui.ToolTipLineEdit(default_value='', tooltip_text='', *args, **kwargs)

Bases: QLineEdit

src.view.gui.convert_unit(value, from_unit, to_unit)

Converts the given value from one unit to another using Pint.

Args:

value (float): The value to convert. from_unit (str): The unit of the input value. to_unit (str): The target unit for the conversion.

Returns:

float: The converted value.