def __init__(self, parent: QWidget = None): """Initializes the ModelFittingDataSelectorView.""" super(ModelFittingDataSelectorView, self).__init__(parent) self.setupUi(self) self.result_table_selector = CyclicDataSelectorView(self) self.result_table_selector.set_data_combo_box_label("Results table") self.result_table_selector_layout.addWidget(self.result_table_selector)
def __init__(self, parent=None): super().__init__(parent=parent) self._selectors_layout = QtWidgets.QHBoxLayout() self._data_selector = CyclicDataSelectorView(self) self._data_selector.set_data_combo_box_label("Display:") self._data_selector.set_data_combo_box_label_width(300) self._selectors_layout.addWidget(self._data_selector) self._selectors_layout.setSpacing(100) self.verticalLayout.insertItem(1, self._selectors_layout)
def __init__(self, parent: QWidget = None): """Initialize the BasicFittingView and create the FitControlsView and a FitFunctionOptionsView.""" super(BasicFittingView, self).__init__(parent) self.setupUi(self) self.fit_controls = FitControlsView(self) self.workspace_selector = CyclicDataSelectorView(self) self.fit_function_options = FitFunctionOptionsView(self) self.fit_controls_layout.addWidget(self.fit_controls) self.workspace_selector_layout.addWidget(self.workspace_selector) self.fit_function_options_layout.addWidget(self.fit_function_options) self.disable_tab_observer = GenericObserver(self.disable_view) self.enable_tab_observer = GenericObserver(self.enable_view) self.disable_view()
def __init__(self, parent: QWidget = None): """Initializes the CorrectionsView.""" super(CorrectionsView, self).__init__(parent) self.setupUi(self) self.parent = parent self.run_selector = CyclicDataSelectorView(self) self.run_selector.set_data_combo_box_label("Runs :") self.run_selector.set_data_combo_box_label_width(50) self.corrections_layout.addWidget(self.run_selector, 1) self.dead_time_corrections_view = DeadTimeCorrectionsView(self) self.corrections_layout.addWidget(self.dead_time_corrections_view, 1) self.background_corrections_view = BackgroundCorrectionsView(self) self.corrections_layout.addWidget(self.background_corrections_view, 10) self.disable_tab_observer = GenericObserver(self.disable_view) self.enable_tab_observer = GenericObserver(self.enable_view) self.disable_view()
class DualPlotMaxentPaneView(BasePaneView): def __init__(self, parent=None): super().__init__(parent=parent) self._selectors_layout = QtWidgets.QHBoxLayout() self._data_selector = CyclicDataSelectorView(self) self._data_selector.set_data_combo_box_label("Display:") self._data_selector.set_data_combo_box_label_width(300) self._selectors_layout.addWidget(self._data_selector) self._selectors_layout.setSpacing(100) self.verticalLayout.insertItem(1, self._selectors_layout) def set_slot_for_selection_changed(self, slot): self._data_selector.set_slot_for_dataset_changed(slot) def update_selection(self, selections) -> None: self._data_selector.update_dataset_name_combo_box(selections) @property def get_selection_for_plot(self): return self._data_selector.current_dataset_name
class ModelFittingDataSelectorView(ui_form, base_widget): """ The ModelFittingDataSelectorView includes the cyclic results table data selector, and two combo boxes to select X and Y data. """ def __init__(self, parent: QWidget = None): """Initializes the ModelFittingDataSelectorView.""" super(ModelFittingDataSelectorView, self).__init__(parent) self.setupUi(self) self.result_table_selector = CyclicDataSelectorView(self) self.result_table_selector.set_data_combo_box_label("Results table") self.result_table_selector_layout.addWidget(self.result_table_selector) def set_slot_for_results_table_changed(self, slot) -> None: """Connect the slot for the result tables combo box being changed.""" self.result_table_selector.set_slot_for_dataset_changed(slot) def set_slot_for_selected_x_changed(self, slot) -> None: """Connect the slot for when the selected X changes.""" self.x_selector.currentIndexChanged.connect(slot) def set_slot_for_selected_y_changed(self, slot) -> None: """Connect the slot for when the selected Y changes.""" self.y_selector.currentIndexChanged.connect(slot) def result_table_names(self) -> list: """Returns a list of result table names currently loaded into model fitting.""" return self.result_table_selector.dataset_names def add_results_table_name(self, results_table_name: str) -> None: """Add a results table to the results table combo box.""" self.result_table_selector.add_dataset_name(results_table_name) def update_result_table_names(self, table_names: list) -> None: """Update the data in the parameter display combo box.""" self.result_table_selector.update_dataset_name_combo_box(table_names) def update_x_parameters(self, x_parameters: list, emit_signal: bool = False) -> None: """Update the available X parameters.""" old_x_parameter = self.x_selector.currentText() self.x_selector.blockSignals(True) self.x_selector.clear() self.x_selector.addItems(x_parameters) self.x_selector.blockSignals(False) new_index = self.set_selected_x_parameter(old_x_parameter) if emit_signal: # Signal is emitted manually in case the index has not changed (but the loaded parameter may be different) self.x_selector.currentIndexChanged.emit(new_index) def update_y_parameters(self, y_parameters: list, emit_signal: bool = False) -> None: """Update the available Y parameters.""" old_y_parameter = self.y_selector.currentText() self.y_selector.blockSignals(True) self.y_selector.clear() self.y_selector.addItems(y_parameters) self.y_selector.blockSignals(False) new_index = self.set_selected_y_parameter(old_y_parameter) if emit_signal: # Signal is emitted manually in case the index has not changed (but the loaded parameter may be different) self.y_selector.currentIndexChanged.emit(new_index) def set_selected_x_parameter(self, x_parameter: str) -> int: """Sets the selected X parameter.""" new_index = self.x_selector.findText(x_parameter) self.x_selector.blockSignals(True) self.x_selector.setCurrentIndex(new_index if new_index != -1 else 0) self.x_selector.blockSignals(False) return new_index def set_selected_y_parameter(self, y_parameter: str) -> int: """Sets the selected Y parameter.""" new_index = self.y_selector.findText(y_parameter) self.y_selector.blockSignals(True) self.y_selector.setCurrentIndex(new_index if new_index != -1 else 0) self.y_selector.blockSignals(False) return new_index def number_of_result_tables(self) -> int: """Returns the number of result tables loaded into the widget.""" return self.result_table_selector.number_of_datasets() @property def current_result_table_index(self) -> str: """Returns the index of the currently displayed result table.""" return self.result_table_selector.current_dataset_index @property def x_parameter(self) -> str: """Returns the selected X parameter name.""" return str(self.x_selector.currentText()) @property def y_parameter(self) -> str: """Returns the selected Y parameter name.""" return str(self.y_selector.currentText())
class CorrectionsView(widget, ui_form): """ The CorrectionsView contains widgets allowing a Dead Time correction and Background correction. """ def __init__(self, parent: QWidget = None): """Initializes the CorrectionsView.""" super(CorrectionsView, self).__init__(parent) self.setupUi(self) self.parent = parent self.run_selector = CyclicDataSelectorView(self) self.run_selector.set_data_combo_box_label("Runs :") self.run_selector.set_data_combo_box_label_width(50) self.corrections_layout.addWidget(self.run_selector, 1) self.dead_time_corrections_view = DeadTimeCorrectionsView(self) self.corrections_layout.addWidget(self.dead_time_corrections_view, 1) self.background_corrections_view = BackgroundCorrectionsView(self) self.corrections_layout.addWidget(self.background_corrections_view, 10) self.disable_tab_observer = GenericObserver(self.disable_view) self.enable_tab_observer = GenericObserver(self.enable_view) self.disable_view() @property def dead_time_view(self) -> DeadTimeCorrectionsView: """Returns the dead time corrections view.""" return self.dead_time_corrections_view @property def background_view(self) -> BackgroundCorrectionsView: """Returns the background corrections view.""" return self.background_corrections_view def set_tab_warning(self, message: str) -> None: """Sets a warning message as the tooltip of the corrections tab.""" if self.parent is not None: self.parent.set_tab_warning("Corrections", message) def set_slot_for_run_selector_changed(self, slot) -> None: """Connect the slot for the Run Selector combobox""" self.run_selector.set_slot_for_dataset_changed(slot) def update_run_selector_combo_box(self, runs: list) -> None: """Update the data in the run selector combo box.""" self.run_selector.update_dataset_name_combo_box(runs) def current_run_string(self) -> int: """Returns the currently displayed run number string.""" return self.run_selector.current_dataset_name def warning_popup(self, message: str) -> None: """Displays a warning message.""" warning(message, parent=self) def disable_view(self) -> None: """Disable all widgets in this corrections view.""" self.setEnabled(False) def enable_view(self) -> None: """Enable all widgets in this corrections view.""" self.setEnabled(self.run_selector.number_of_datasets() != 0)
def setUp(self): self.view = CyclicDataSelectorView() self.view.show() self.assert_widget_created()
class CyclicDataSelectorViewTest(unittest.TestCase, QtWidgetFinder): def setUp(self): self.view = CyclicDataSelectorView() self.view.show() self.assert_widget_created() def tearDown(self): self.assertTrue(self.view.close()) QApplication.sendPostedEvents() def test_that_update_dataset_name_combo_box_will_set_the_names_in_the_dataset_name_combobox( self): dataset_names = ["Name1", "Name2", "Name3"] self.view.update_dataset_name_combo_box(dataset_names) data = [ self.view.dataset_name_combo_box.itemText(i) for i in range(self.view.dataset_name_combo_box.count()) ] self.assertTrue(data, dataset_names) def test_that_update_dataset_name_combo_box_will_select_the_previously_selected_item_if_it_still_exists( self): selected_dataset = "Name3" dataset_names = ["Name1", "Name2", selected_dataset] self.view.update_dataset_name_combo_box(dataset_names) self.view.dataset_name_combo_box.setCurrentIndex(2) new_dataset_names = ["Name4", selected_dataset, "Name5"] self.view.update_dataset_name_combo_box(new_dataset_names) self.assertTrue(self.view.current_dataset_name, selected_dataset) def test_that_increment_dataset_name_combo_box_will_increment_the_dataset_which_is_selected( self): dataset_names = ["Name1", "Name2", "Name3"] self.view.update_dataset_name_combo_box(dataset_names) self.view.dataset_name_combo_box.setCurrentIndex(2) self.assertTrue(self.view.current_dataset_name, "Name3") self.view.increment_dataset_name_combo_box() self.assertTrue(self.view.current_dataset_name, "Name1") def test_that_decrement_dataset_name_combo_box_will_decrement_the_dataset_which_is_selected( self): dataset_names = ["Name1", "Name2", "Name3"] self.view.update_dataset_name_combo_box(dataset_names) self.view.dataset_name_combo_box.setCurrentIndex(2) self.assertTrue(self.view.current_dataset_name, "Name1") self.view.decrement_dataset_name_combo_box() self.assertTrue(self.view.current_dataset_name, "Name3") def test_that_the_current_dataset_name_can_be_set_as_expected(self): selected_dataset = "Name2" dataset_names = ["Name1", selected_dataset, "Name3"] self.view.update_dataset_name_combo_box(dataset_names) self.assertEqual(self.view.current_dataset_name, "Name1") self.view.current_dataset_name = selected_dataset self.assertEqual(self.view.current_dataset_name, selected_dataset) def test_that_the_current_dataset_name_will_not_change_the_selected_dataset_if_the_provided_dataset_does_not_exist( self): selected_dataset = "Name3" dataset_names = ["Name1", "Name2", selected_dataset] self.view.update_dataset_name_combo_box(dataset_names) self.view.current_dataset_name = selected_dataset self.assertEqual(self.view.current_dataset_name, selected_dataset) self.view.current_dataset_name = "Does not exist" self.assertEqual(self.view.current_dataset_name, selected_dataset) def test_that_add_dataset_name_will_add_a_name_to_the_end_of_the_datasets( self): dataset_names = ["Name1", "Name2", "Name3"] self.view.update_dataset_name_combo_box(dataset_names) self.assertEqual(self.view.number_of_datasets(), 3) self.view.add_dataset_name("Name4") self.assertEqual(self.view.number_of_datasets(), 4) def test_that_number_of_datasets_will_return_the_expected_number_of_datasets( self): dataset_names = ["Name1", "Name2", "Name3"] self.view.update_dataset_name_combo_box(dataset_names) self.assertEqual(self.view.number_of_datasets(), len(dataset_names)) def test_that_current_dataset_index_will_return_the_expected_dataset_index( self): dataset_names = ["Name1", "Name2", "Name3"] self.view.update_dataset_name_combo_box(dataset_names) self.view.current_dataset_name = "Name2" self.assertEqual(self.view.current_dataset_index, 1) def test_that_current_dataset_index_will_return_none_when_there_is_nothing_selected_in_the_combobox( self): self.assertEqual(self.view.current_dataset_index, None)
class BasicFittingView(ui_form, base_widget): """ The BasicFittingView has a FitControlsView and a FitFunctionOptionsView. It can be used for Single Fitting. """ def __init__(self, parent: QWidget = None): """Initialize the BasicFittingView and create the FitControlsView and a FitFunctionOptionsView.""" super(BasicFittingView, self).__init__(parent) self.setupUi(self) self.fit_controls = FitControlsView(self) self.workspace_selector = CyclicDataSelectorView(self) self.fit_function_options = FitFunctionOptionsView(self) self.fit_controls_layout.addWidget(self.fit_controls) self.workspace_selector_layout.addWidget(self.workspace_selector) self.fit_function_options_layout.addWidget(self.fit_function_options) self.disable_tab_observer = GenericObserver(self.disable_view) self.enable_tab_observer = GenericObserver(self.enable_view) self.disable_view() def set_slot_for_fit_generator_clicked(self, slot) -> None: """Connect the slot for the Fit Generator button.""" self.fit_controls.set_slot_for_fit_generator_clicked(slot) def set_slot_for_fit_button_clicked(self, slot) -> None: """Connect the slot for the Fit button.""" self.fit_controls.set_slot_for_fit_button_clicked(slot) def set_slot_for_undo_fit_clicked(self, slot) -> None: """Connect the slot for the Undo Fit button.""" self.fit_controls.set_slot_for_undo_fit_clicked(slot) def set_slot_for_plot_guess_changed(self, slot) -> None: """Connect the slot for the Plot Guess checkbox.""" self.fit_controls.set_slot_for_plot_guess_changed(slot) def set_slot_for_dataset_changed(self, slot) -> None: """Connect the slot for the display workspace combo box being changed.""" self.workspace_selector.set_slot_for_dataset_changed(slot) def set_slot_for_covariance_matrix_clicked(self, slot) -> None: """Connect the slot for the Covariance Matrix button being clicked.""" self.fit_function_options.set_slot_for_covariance_matrix_clicked(slot) def set_slot_for_fit_name_changed(self, slot) -> None: """Connect the slot for the fit name being changed by the user.""" self.fit_function_options.set_slot_for_fit_name_changed(slot) def set_slot_for_function_structure_changed(self, slot) -> None: """Connect the slot for the function structure changing.""" self.fit_function_options.set_slot_for_function_structure_changed(slot) def set_slot_for_function_parameter_changed(self, slot) -> None: """Connect the slot for a function parameter changing.""" self.fit_function_options.set_slot_for_function_parameter_changed(slot) def set_slot_for_function_attribute_changed(self, slot) -> None: """Connect the slot for a function attribute changing.""" self.fit_function_options.set_slot_for_function_attribute_changed(slot) def set_slot_for_start_x_updated(self, slot) -> None: """Connect the slot for the start x option.""" self.fit_function_options.set_slot_for_start_x_updated(slot) def set_slot_for_end_x_updated(self, slot) -> None: """Connect the slot for the end x option.""" self.fit_function_options.set_slot_for_end_x_updated(slot) def set_slot_for_exclude_range_state_changed(self, slot) -> None: """Connect the slot for the exclude range checkbox.""" self.fit_function_options.set_slot_for_exclude_range_state_changed(slot) def set_slot_for_exclude_start_x_updated(self, slot) -> None: """Connect the slot for the exclude start x option.""" self.fit_function_options.set_slot_for_exclude_start_x_updated(slot) def set_slot_for_exclude_end_x_updated(self, slot) -> None: """Connect the slot for the exclude end x option.""" self.fit_function_options.set_slot_for_exclude_end_x_updated(slot) def set_slot_for_minimizer_changed(self, slot) -> None: """Connect the slot for changing the Minimizer.""" self.fit_function_options.set_slot_for_minimizer_changed(slot) def set_slot_for_evaluation_type_changed(self, slot) -> None: """Connect the slot for changing the Evaluation type.""" self.fit_function_options.set_slot_for_evaluation_type_changed(slot) def set_slot_for_use_raw_changed(self, slot) -> None: """Connect the slot for the Use raw option.""" self.fit_function_options.set_slot_for_use_raw_changed(slot) def set_workspace_combo_box_label(self, text: str) -> None: """Sets the label text next to the workspace selector combobox.""" self.workspace_selector.set_data_combo_box_label(text) def set_datasets_in_function_browser(self, dataset_names: list) -> None: """Sets the datasets stored in the FunctionBrowser.""" self.fit_function_options.set_datasets_in_function_browser(dataset_names) def set_current_dataset_index(self, dataset_index: int) -> None: """Sets the index of the current dataset.""" if dataset_index is not None: self.fit_function_options.set_current_dataset_index(dataset_index) def set_number_of_undos(self, number_of_undos: int) -> None: """Sets the allowed number of 'Undo Fit' events.""" self.fit_controls.set_number_of_undos(number_of_undos) def update_dataset_name_combo_box(self, dataset_names: list, emit_signal: bool = True) -> None: """Update the data in the parameter display combo box.""" self.workspace_selector.update_dataset_name_combo_box(dataset_names, emit_signal) def update_local_fit_status_and_chi_squared(self, fit_status: str, chi_squared: float) -> None: """Updates the view to show the status and results from a fit.""" if fit_status is not None: self.fit_function_options.update_fit_status_labels(fit_status, chi_squared) else: self.fit_function_options.clear_fit_status() def update_global_fit_status(self, fit_statuses: list, _: int = None) -> None: """Updates the global fit status label.""" self.fit_controls.update_global_fit_status_label([status == "success" for status in fit_statuses if status]) def update_fit_function(self, fit_function: IFunction) -> None: """Updates the parameters of a fit function shown in the view.""" self.fit_function_options.update_function_browser_parameters(False, fit_function) @property def current_dataset_name(self) -> str: """Returns the selected dataset name.""" return self.workspace_selector.current_dataset_name @current_dataset_name.setter def current_dataset_name(self, dataset_name: str) -> None: """Sets the currently selected dataset name.""" self.workspace_selector.current_dataset_name = dataset_name def number_of_datasets(self) -> int: """Returns the number of dataset names loaded into the widget.""" return self.workspace_selector.number_of_datasets() @property def current_dataset_index(self) -> int: """Returns the index of the currently displayed dataset.""" return self.workspace_selector.current_dataset_index @property def fit_object(self) -> IFunction: """Returns the global fitting function.""" return self.fit_function_options.fit_object def current_fit_function(self) -> IFunction: """Returns the current fitting function in the view.""" return self.fit_function_options.current_fit_function() @property def minimizer(self) -> str: """Returns the selected minimizer.""" return self.fit_function_options.minimizer @property def start_x(self) -> float: """Returns the selected start X.""" return self.fit_function_options.start_x @start_x.setter def start_x(self, value: float) -> None: """Sets the selected start X.""" self.fit_function_options.start_x = value @property def end_x(self) -> float: """Returns the selected end X.""" return self.fit_function_options.end_x @end_x.setter def end_x(self, value: float) -> None: """Sets the selected end X.""" self.fit_function_options.end_x = value @property def exclude_range(self) -> bool: """Returns true if the Exclude Range option is ticked.""" return self.fit_function_options.exclude_range @property def exclude_start_x(self) -> float: """Returns the start X for the excluded region.""" return self.fit_function_options.exclude_start_x @exclude_start_x.setter def exclude_start_x(self, value: float) -> None: """Sets the selected exclude start X.""" self.fit_function_options.exclude_start_x = value @property def exclude_end_x(self) -> float: """Returns the end X for the excluded region.""" return self.fit_function_options.exclude_end_x @exclude_end_x.setter def exclude_end_x(self, value: float) -> None: """Sets the selected exclude end X.""" self.fit_function_options.exclude_end_x = value @property def evaluation_type(self) -> str: """Returns the selected evaluation type.""" return self.fit_function_options.evaluation_type @property def fit_to_raw(self) -> bool: """Returns whether or not fitting to raw data is ticked.""" return self.fit_function_options.fit_to_raw @fit_to_raw.setter def fit_to_raw(self, check: bool) -> None: """Sets whether or not you are fitting to raw data.""" self.fit_function_options.fit_to_raw = check @property def plot_guess(self) -> bool: """Returns true if plot guess is ticked.""" return self.fit_controls.plot_guess @plot_guess.setter def plot_guess(self, check: bool) -> None: """Sets whether or not plot guess is ticked.""" self.fit_controls.plot_guess = check @property def function_name(self) -> str: """Returns the function name being used.""" return self.fit_function_options.function_name @function_name.setter def function_name(self, function_name: str) -> None: """Sets the function name being used.""" self.fit_function_options.function_name = function_name def warning_popup(self, message: str) -> None: """Displays a warning message.""" warning(message, parent=self) @property def global_parameters(self) -> list: """Returns a list of global parameters.""" return self.fit_function_options.global_parameters def parameter_value(self, full_parameter: str) -> float: """Returns the value of the specified parameter.""" return self.fit_function_options.parameter_value(full_parameter) def attribute_value(self, full_attribute: str): """Returns the value of the specified attribute.""" return self.fit_function_options.attribute_value(full_attribute) def switch_to_simultaneous(self) -> None: """Switches the view to simultaneous fit mode.""" self.fit_function_options.switch_to_simultaneous() def switch_to_single(self) -> None: """Switches the view to single fit mode.""" self.fit_function_options.switch_to_single() def hide_exclude_range_checkbox(self) -> None: """Hides the Exclude Range checkbox in the fitting options.""" self.fit_function_options.hide_exclude_range_checkbox() def hide_fit_raw_checkbox(self) -> None: """Hides the Fit Raw checkbox in the fitting options.""" self.fit_function_options.hide_fit_raw_checkbox() def hide_evaluate_function_as_checkbox(self) -> None: """Hides the Evaluate Function as checkbox in the fitting options.""" self.fit_function_options.hide_evaluate_function_as_checkbox() def set_start_and_end_x_labels(self, start_x_label: str, end_x_label: str) -> None: """Sets the labels to use for the start and end X labels in the fit options table.""" self.fit_function_options.set_start_and_end_x_labels(start_x_label, end_x_label) def set_exclude_start_and_end_x_visible(self, visible: bool) -> None: """Sets whether the exclude start and end x options are visible.""" self.fit_function_options.set_exclude_start_and_end_x_visible(visible) def set_covariance_button_enabled(self, enabled: bool) -> None: """Sets whether the Covariance Matrix button is enabled or not.""" self.fit_function_options.set_covariance_button_enabled(enabled) def show_normalised_covariance_matrix(self, covariance_ws: ITableWorkspace, workspace_name: str) -> None: """Shows the normalised covariance matrix in a separate table display window.""" self.fit_function_options.show_normalised_covariance_matrix(covariance_ws, workspace_name) def disable_view(self) -> None: """Disable all widgets in this fitting widget.""" self.setEnabled(False) def enable_view(self) -> None: """Enable all widgets in this fitting widget.""" self.setEnabled(self.workspace_selector.number_of_datasets() != 0)
def __init__(self, parent=None): super(MaxEntView, self).__init__(parent) self.grid = QtWidgets.QVBoxLayout(self) self._runs_selector = CyclicDataSelectorView(self) self._runs_selector.set_data_combo_box_label("Runs:") self._runs_selector.set_data_combo_box_label_width(50) self._period_selector = CyclicDataSelectorView(self) self._period_selector.set_data_combo_box_label("Period:") self._period_selector.set_data_combo_box_label_width(50) # add splitter for resizing splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical) self.run = None # make table self.table = QtWidgets.QTableWidget(self) self.table.resize(800, 800) self.table.setRowCount(7) self.table.setColumnCount(2) self.table.setColumnWidth(0, 300) self.table.setColumnWidth(1, 300) self.table.verticalHeader().setVisible(False) self.table.horizontalHeader().setStretchLastSection(True) self.table.setHorizontalHeaderLabels( ("MaxEnt Property;Value").split(";")) table_utils.setTableHeaders(self.table) # populate table options = [] table_utils.setRowName(self.table, 0, "Calculate by") self.method = table_utils.addComboToTable(self.table, 0, options) table_utils.setRowName(self.table, 1, "Phase Table") self.phase_table_combo = table_utils.addComboToTable(self.table, 1, options) table_utils.setRowName(self.table, 2, "Fit dead times") self.dead_box = table_utils.addCheckBoxToTable(self.table, True, 2) table_utils.setRowName(self.table, 3, "Output phase table") self.output_phase_box = table_utils.addCheckBoxToTable( self.table, False, 3) table_utils.setRowName(self.table, 4, "Output deadtimes") self.output_dead_box = table_utils.addCheckBoxToTable( self.table, False, 4) table_utils.setRowName(self.table, 5, "Output reconstructed data") self.output_data_box = table_utils.addCheckBoxToTable( self.table, False, 5) table_utils.setRowName(self.table, 6, "Output phase convergence") self.output_phase_evo_box = table_utils.addCheckBoxToTable( self.table, False, 6) self.table.resizeRowsToContents() # advanced options table self.advancedLabel = QtWidgets.QLabel("\n Advanced Options") # make table self.tableA = QtWidgets.QTableWidget(self) self.tableA.resize(800, 800) self.tableA.setRowCount(7) self.tableA.setColumnCount(2) self.tableA.setColumnWidth(0, 300) self.tableA.setColumnWidth(1, 300) self.tableA.verticalHeader().setVisible(False) self.tableA.horizontalHeader().setStretchLastSection(True) self.tableA.setHorizontalHeaderLabels( ("Advanced Property;Value").split(";")) table_utils.setTableHeaders(self.tableA) table_utils.setRowName(self.tableA, 0, "Maximum entropy constant (A)") self.AConst, _ = table_utils.addDoubleToTable(self.tableA, 0.1, 0) table_utils.setRowName(self.tableA, 1, "Lagrange multiplier for chi^2") self.factor, _ = table_utils.addDoubleToTable(self.tableA, 1.04, 1) table_utils.setRowName(self.tableA, 2, "Inner Iterations") self.inner_loop = table_utils.addSpinBoxToTable(self.tableA, 10, 2) table_utils.setRowName(self.tableA, 3, "Outer Iterations") self.outer_loop = table_utils.addSpinBoxToTable(self.tableA, 10, 3) table_utils.setRowName(self.tableA, 4, "Double pulse data") self.double_pulse_box = table_utils.addCheckBoxToTable( self.tableA, False, 4) table_utils.setRowName(self.tableA, 5, "Number of data points") self.N_points = table_utils.addComboToTable(self.tableA, 5, options) table_utils.setRowName(self.tableA, 6, "Maximum Field ") self.max_field, _ = table_utils.addDoubleToTable(self.tableA, 1000.0, 6) # layout # this is if complex data is unhidden self.table.setMinimumSize(40, 203) self.tableA.setMinimumSize(40, 207) # make buttons self.button = QtWidgets.QPushButton('Calculate MaxEnt', self) self.button.setStyleSheet("background-color:lightgrey") self.cancel = QtWidgets.QPushButton('Cancel', self) self.cancel.setStyleSheet("background-color:lightgrey") self.cancel.setEnabled(False) # connects self.button.clicked.connect(self.MaxEntButtonClick) self.cancel.clicked.connect(self.cancelClick) # button layout self.buttonLayout = QtWidgets.QHBoxLayout() self.buttonLayout.addWidget(self.button) self.buttonLayout.addWidget(self.cancel) # add to layout self.grid.addWidget(self._runs_selector) self.grid.addWidget(self._period_selector) splitter.addWidget(self.table) splitter.addWidget(self.advancedLabel) splitter.addWidget(self.tableA) self.grid.addWidget(splitter) self.grid.addLayout(self.buttonLayout)
class MaxEntView(QtWidgets.QWidget): """ The view for the MaxEnt widget. This creates the look of the widget """ # signals maxEntButtonSignal = QtCore.Signal() cancelSignal = QtCore.Signal() def __init__(self, parent=None): super(MaxEntView, self).__init__(parent) self.grid = QtWidgets.QVBoxLayout(self) self._runs_selector = CyclicDataSelectorView(self) self._runs_selector.set_data_combo_box_label("Runs:") self._runs_selector.set_data_combo_box_label_width(50) self._period_selector = CyclicDataSelectorView(self) self._period_selector.set_data_combo_box_label("Period:") self._period_selector.set_data_combo_box_label_width(50) # add splitter for resizing splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical) self.run = None # make table self.table = QtWidgets.QTableWidget(self) self.table.resize(800, 800) self.table.setRowCount(7) self.table.setColumnCount(2) self.table.setColumnWidth(0, 300) self.table.setColumnWidth(1, 300) self.table.verticalHeader().setVisible(False) self.table.horizontalHeader().setStretchLastSection(True) self.table.setHorizontalHeaderLabels( ("MaxEnt Property;Value").split(";")) table_utils.setTableHeaders(self.table) # populate table options = [] table_utils.setRowName(self.table, 0, "Calculate by") self.method = table_utils.addComboToTable(self.table, 0, options) table_utils.setRowName(self.table, 1, "Phase Table") self.phase_table_combo = table_utils.addComboToTable(self.table, 1, options) table_utils.setRowName(self.table, 2, "Fit dead times") self.dead_box = table_utils.addCheckBoxToTable(self.table, True, 2) table_utils.setRowName(self.table, 3, "Output phase table") self.output_phase_box = table_utils.addCheckBoxToTable( self.table, False, 3) table_utils.setRowName(self.table, 4, "Output deadtimes") self.output_dead_box = table_utils.addCheckBoxToTable( self.table, False, 4) table_utils.setRowName(self.table, 5, "Output reconstructed data") self.output_data_box = table_utils.addCheckBoxToTable( self.table, False, 5) table_utils.setRowName(self.table, 6, "Output phase convergence") self.output_phase_evo_box = table_utils.addCheckBoxToTable( self.table, False, 6) self.table.resizeRowsToContents() # advanced options table self.advancedLabel = QtWidgets.QLabel("\n Advanced Options") # make table self.tableA = QtWidgets.QTableWidget(self) self.tableA.resize(800, 800) self.tableA.setRowCount(7) self.tableA.setColumnCount(2) self.tableA.setColumnWidth(0, 300) self.tableA.setColumnWidth(1, 300) self.tableA.verticalHeader().setVisible(False) self.tableA.horizontalHeader().setStretchLastSection(True) self.tableA.setHorizontalHeaderLabels( ("Advanced Property;Value").split(";")) table_utils.setTableHeaders(self.tableA) table_utils.setRowName(self.tableA, 0, "Maximum entropy constant (A)") self.AConst, _ = table_utils.addDoubleToTable(self.tableA, 0.1, 0) table_utils.setRowName(self.tableA, 1, "Lagrange multiplier for chi^2") self.factor, _ = table_utils.addDoubleToTable(self.tableA, 1.04, 1) table_utils.setRowName(self.tableA, 2, "Inner Iterations") self.inner_loop = table_utils.addSpinBoxToTable(self.tableA, 10, 2) table_utils.setRowName(self.tableA, 3, "Outer Iterations") self.outer_loop = table_utils.addSpinBoxToTable(self.tableA, 10, 3) table_utils.setRowName(self.tableA, 4, "Double pulse data") self.double_pulse_box = table_utils.addCheckBoxToTable( self.tableA, False, 4) table_utils.setRowName(self.tableA, 5, "Number of data points") self.N_points = table_utils.addComboToTable(self.tableA, 5, options) table_utils.setRowName(self.tableA, 6, "Maximum Field ") self.max_field, _ = table_utils.addDoubleToTable(self.tableA, 1000.0, 6) # layout # this is if complex data is unhidden self.table.setMinimumSize(40, 203) self.tableA.setMinimumSize(40, 207) # make buttons self.button = QtWidgets.QPushButton('Calculate MaxEnt', self) self.button.setStyleSheet("background-color:lightgrey") self.cancel = QtWidgets.QPushButton('Cancel', self) self.cancel.setStyleSheet("background-color:lightgrey") self.cancel.setEnabled(False) # connects self.button.clicked.connect(self.MaxEntButtonClick) self.cancel.clicked.connect(self.cancelClick) # button layout self.buttonLayout = QtWidgets.QHBoxLayout() self.buttonLayout.addWidget(self.button) self.buttonLayout.addWidget(self.cancel) # add to layout self.grid.addWidget(self._runs_selector) self.grid.addWidget(self._period_selector) splitter.addWidget(self.table) splitter.addWidget(self.advancedLabel) splitter.addWidget(self.tableA) self.grid.addWidget(splitter) self.grid.addLayout(self.buttonLayout) def getLayout(self): return self.grid # add data to view def addRuns(self, runs): self._runs_selector.update_dataset_name_combo_box(runs) def add_periods(self, periods): self._period_selector.update_dataset_name_combo_box(periods) def set_methods(self, options): self.method.clear() self.method.addItems(options) def addNPoints(self, options): self.N_points.clear() self.N_points.addItems(options) # send signal def MaxEntButtonClick(self): self.maxEntButtonSignal.emit() def cancelClick(self): self.cancelSignal.emit() def warning_popup(self, message): warning(message, parent=self) def activateCalculateButton(self): self.button.setEnabled(True) self._period_selector.setEnabled(True) self._runs_selector.setEnabled(True) self.cancel.setEnabled(False) def deactivateCalculateButton(self): self.button.setEnabled(False) self._period_selector.setEnabled(False) self._runs_selector.setEnabled(False) self.cancel.setEnabled(True) def update_phase_table_combo(self, phase_table_list): name = self.phase_table_combo.currentText() self.phase_table_combo.clear() self.phase_table_combo.addItems(phase_table_list) index = self.phase_table_combo.findText(name) if index != -1: self.phase_table_combo.setCurrentIndex(index) else: self.phase_table_combo.setCurrentIndex(0) # slots def run_changed_slot(self, slot): self._runs_selector.set_slot_for_dataset_changed(slot) def method_changed_slot(self, slot): self.method.currentIndexChanged.connect(slot) def period_changed_slot(self, slot): self._period_selector.set_slot_for_dataset_changed(slot) @property def get_run(self): return str(self._runs_selector.current_dataset_name) @property def num_periods(self): return len(self._period_selector.dataset_names) @property def get_period(self): return str(self._period_selector.current_dataset_name) @property def get_method(self): return str(self.method.currentText()) @property def num_points(self): return int(self.N_points.currentText()) @property def maximum_field(self): return float(self.max_field.text()) @property def fit_dead_times(self): return self.dead_box.checkState() == QtCore.Qt.Checked @property def double_pulse(self): return self.double_pulse_box.checkState() == QtCore.Qt.Checked @property def outer_iterations(self): return int(self.outer_loop.text()) @property def inner_iterations(self): return int(self.inner_loop.text()) @property def maximum_entropy_constant(self): return float(self.AConst.text()) @property def lagrange_multiplier(self): return float(self.factor.text()) @property def phase_table(self): return str(self.phase_table_combo.currentText()) @property def output_phase_table(self): return self.output_phase_box.checkState() == QtCore.Qt.Checked @property def output_dead_times(self): return self.output_dead_box.checkState() == QtCore.Qt.Checked @property def output_phase_convergence(self): return self.output_phase_evo_box.checkState() == QtCore.Qt.Checked @property def output_reconstructed_spectra(self): return self.output_data_box.checkState() == QtCore.Qt.Checked
class RawPaneView(BasePaneView): def __init__(self, parent=None): super().__init__(parent=parent) self._selectors_layout = QtWidgets.QHBoxLayout() self._runs_selector = CyclicDataSelectorView(self) self._runs_selector.set_data_combo_box_label("Runs:") self._runs_selector.set_data_combo_box_label_width(50) self._selectors_layout.addWidget(self._runs_selector) self._selectors_layout.setSpacing(100) self._detectors_selector = CyclicDataSelectorView(self) self._detectors_selector.set_data_combo_box_label("Detectors:") self._detectors_selector.set_data_combo_box_label_width(50) self._selectors_layout.addWidget(self._detectors_selector) self.verticalLayout.insertItem(1, self._selectors_layout) def set_slot_for_detectors_changed(self, slot): self._detectors_selector.set_slot_for_dataset_changed(slot) def update_detectors(self, detectors: list) -> None: self._detectors_selector.update_dataset_name_combo_box(detectors) @property def get_detectors(self): return self._detectors_selector.current_dataset_name self._runs_selector.set_data_combo_box_label_width(50) self.verticalLayout.insertWidget(1, self._runs_selector) def set_slot_for_runs_changed(self, slot): self._runs_selector.set_slot_for_dataset_changed(slot) def update_runs(self, detectors: list) -> None: self._runs_selector.update_dataset_name_combo_box(detectors) @property def get_run(self): return self._runs_selector.current_dataset_name