Skip to content

Commit

Permalink
moved controls-dependent setup and removed workaround from view
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhroom committed Aug 29, 2024
1 parent b9a6ab7 commit ee2b5c6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
6 changes: 1 addition & 5 deletions rascal2/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 15 additions & 11 deletions rascal2/widgets/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions tests/test_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self):
def controls_widget() -> ControlsWidget:
def _widget():
widget = ControlsWidget(view)
widget.setup_controls()
return widget

return _widget
Expand Down
4 changes: 4 additions & 0 deletions tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down

0 comments on commit ee2b5c6

Please sign in to comment.