Skip to content

Adds live recalculate option #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rascal2/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Settings(BaseModel, validate_assignment=True, arbitrary_types_allowed=True
Notes
-----
For each system setting, the model field `title` contains the setting group,
and the model field `description` gives an English name for the setting.
and the model field `description` gives a description for the setting.
The model fields for a setting can be accessed via Settings.model_fields[setting].

"""
Expand All @@ -106,6 +106,9 @@ class Settings(BaseModel, validate_assignment=True, arbitrary_types_allowed=True
# The global settings are read and written via this object using `set_global_settings`.
style: Styles = Field(default=Styles.Light, title=SettingsGroups.General, description="Style")
editor_fontsize: int = Field(default=12, title=SettingsGroups.General, description="Editor Font Size", gt=0)
live_recalculate: bool = Field(
default=True, title=SettingsGroups.General, description="Auto-run simulation when parameter values change."
)

log_path: str = Field(default="logs/rascal.log", title=SettingsGroups.Logging, description="Path to Log File")
log_level: LogLevels = Field(default=LogLevels.Info, title=SettingsGroups.Logging, description="Minimum Log Level")
Expand Down
20 changes: 18 additions & 2 deletions rascal2/ui/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,27 @@ def interrupt_terminal(self):
"""Sends an interrupt signal to the RAT runner."""
self.runner.interrupt()

def run(self):
"""Run RAT."""
def run(self, procedure: RAT.utils.enums.Procedures = None):
"""Run RAT.

Parameters
----------
procedure : Procedures, optional
What procedure to run with. If None, will use the procedure
from the model controls.

"""
# reset terminal
self.view.terminal_widget.progress_bar.setVisible(False)
if self.view.settings.clear_terminal:
self.view.terminal_widget.clear()

# saving the old procedure, changing it, and setting it back at the end
# is cheaper than copying controls if procedure is not None
old_procedure = self.model.controls.procedure
if procedure is not None:
self.model.controls.procedure = procedure

rat_inputs = RAT.inputs.make_input(self.model.project, self.model.controls)
display_on = self.model.controls.display != RAT.utils.enums.Display.Off

Expand All @@ -152,6 +166,8 @@ def run(self):
self.runner.event_received.connect(self.handle_event)
self.runner.start()

self.model.controls.procedure = old_procedure

def handle_results(self):
"""Handle a RAT run being finished."""
self.view.undo_stack.push(
Expand Down
16 changes: 13 additions & 3 deletions rascal2/widgets/project/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def setData(self, index, value, role=QtCore.Qt.ItemDataRole.EditRole) -> bool:
except pydantic.ValidationError:
return False
if not self.edit_mode:
self.parent.update_project()
# recalculate plots if value was changed
recalculate = self.index_header(index) == "value"
self.parent.update_project(recalculate)
self.dataChanged.emit(index, index)
return True
return False
Expand Down Expand Up @@ -237,10 +239,18 @@ def make_delete_button(self, index):

return button

def update_project(self):
"""Update the field in the parent Project."""
def update_project(self, recalculate: bool):
"""Update the field in the parent Project.

Parameters
----------
recalculate : bool
Whether to recalculate the plots when the project updates.
"""
presenter = self.parent.parent.parent.presenter
presenter.edit_project({self.field: self.model.classlist})
if recalculate and presenter.view.settings.live_recalculate:
presenter.run("calculate")


class ParametersModel(ClassListModel):
Expand Down