diff --git a/rascal2/ui/view.py b/rascal2/ui/view.py index 19a98ac..1b55068 100644 --- a/rascal2/ui/view.py +++ b/rascal2/ui/view.py @@ -23,11 +23,6 @@ def __init__(self): self.presenter = MainWindowPresenter(self) - # TODO Remove this when the startup windows are added! just here to 'bootstrap' controls creation for the widget - from RATapi import Controls # noqa - - self.presenter.model.controls = Controls() - self.mdi = QtWidgets.QMdiArea() # TODO replace the widgets below self.plotting_widget = QtWidgets.QWidget() @@ -98,6 +93,7 @@ def setupMDI(self): "Terminal": self.terminal_widget, "Fitting Controls": self.controls_widget, } + self.controls_widget.setup_controls() for title, widget in reversed(widgets.items()): widget.setWindowTitle(title) diff --git a/rascal2/widgets/controls.py b/rascal2/widgets/controls.py index 4572783..94a7ab8 100644 --- a/rascal2/widgets/controls.py +++ b/rascal2/widgets/controls.py @@ -20,20 +20,10 @@ def __init__(self, parent): # create fit settings view and setup connection to model self.fit_settings_layout = QtWidgets.QStackedLayout() - for procedure in Procedures: - proc_settings = [f for f in fields.get(procedure, []) if f != "procedure"] - proc_settings.remove("resampleParams") # FIXME remove when merged - just for testing - fit_set = FitSettingsWidget(self, proc_settings, self.presenter) - self.fit_settings_layout.addWidget(fit_set) - self.fit_settings = QtWidgets.QWidget() self.fit_settings.setLayout(self.fit_settings_layout) self.fit_settings.setBackgroundRole(QtGui.QPalette.ColorRole.Base) - # set initial procedure to whatever is in the Controls object - init_procedure = [p.value for p in Procedures].index(self.presenter.model.controls.procedure) - self.set_procedure(init_procedure) - # create run and stop buttons self.run_button = QtWidgets.QPushButton(icon=QtGui.QIcon(path_for("play.png")), text="Run") self.run_button.toggled.connect(self.toggle_run_button) @@ -67,7 +57,6 @@ def __init__(self, parent): procedure_layout.addWidget(QtWidgets.QLabel("Procedure:")) self.procedure_dropdown = QtWidgets.QComboBox() self.procedure_dropdown.addItems([p.value for p in Procedures]) - self.procedure_dropdown.setCurrentIndex(init_procedure) self.procedure_dropdown.currentIndexChanged.connect(self.set_procedure) procedure_layout.addWidget(self.procedure_dropdown) @@ -96,6 +85,21 @@ def __init__(self, parent): self.setLayout(widget_layout) + def setup_controls(self): + """Setup the parts of the widget which depend on the Controls object.""" + + # add fit settings for each procedure + for procedure in Procedures: + proc_settings = [f for f in fields.get(procedure, []) if f != "procedure"] + proc_settings.remove("resampleParams") # FIXME remove when merged - just for testing + fit_set = FitSettingsWidget(self, proc_settings, self.presenter) + self.fit_settings_layout.addWidget(fit_set) + + # set initial procedure to whatever is in the Controls object + init_procedure = [p.value for p in Procedures].index(self.presenter.model.controls.procedure) + self.set_procedure(init_procedure) + self.procedure_dropdown.setCurrentIndex(init_procedure) + def toggle_fit_settings(self, toggled: bool): """Toggle whether the fit settings table is visible. diff --git a/tests/test_controls.py b/tests/test_controls.py index 9f2fdc3..c6e9030 100644 --- a/tests/test_controls.py +++ b/tests/test_controls.py @@ -27,6 +27,7 @@ def __init__(self): def controls_widget() -> ControlsWidget: def _widget(): widget = ControlsWidget(view) + widget.setup_controls() return widget return _widget diff --git a/tests/test_ui.py b/tests/test_ui.py index 088e545..85aff39 100644 --- a/tests/test_ui.py +++ b/tests/test_ui.py @@ -35,6 +35,10 @@ def test_integration(qt_application, make_main_window): _ = qt_application window = make_main_window() window.show() + # TODO replace with startup project creation when implemented + from RATapi import Controls # noqa + + window.presenter.model.controls = Controls() window.setupMDI() names = [win.windowTitle() for win in window.mdi.subWindowList()]