Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhroom committed Oct 4, 2024
1 parent 13e6ab6 commit 847007b
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 35 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "rascal2"
version = "0.0.0"
dynamic = ["version"]
dependencies = [
"RATapi",
"PyQt6",
Expand All @@ -17,6 +17,9 @@ license = {file = "LICENSE"}
Documentation = "https://rascalsoftware.github.io/RAT/master/index.html"
Repository = "https://github.com/RascalSoftware/RasCAL-2"

[tool.setuptools.dynamic]
version = {attr = "rascal2.RASCAL2_VERSION"}

[tool.ruff]
line-length = 120

Expand Down
1 change: 0 additions & 1 deletion rascal2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from os import PathLike

from rascal2.core import Settings, get_global_settings
from rascal2.widgets import TerminalWidget

SOURCE_PATH = pathlib.Path(__file__).parent
STATIC_PATH = SOURCE_PATH / "static"
Expand Down
10 changes: 2 additions & 8 deletions rascal2/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<<<<<<< HEAD
from rascal2.core.settings import Settings, get_global_settings

__all__ = ["Settings", "get_global_settings"]
=======
from rascal2.core.runner import RATRunner
from rascal2.core.settings import Settings
from rascal2.core.settings import Settings, get_global_settings

__all__ = ["RATRunner", "Settings"]
>>>>>>> 958f1a7 (working runner using processes)
__all__ = ["RATRunner", "get_global_settings", "Settings"]
2 changes: 0 additions & 2 deletions rascal2/core/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def check_queue(self):
self.error = item
self.stopped.emit()
else: # else, assume item is an event
if isinstance(item, str):
item.rstrip()
self.events.append(item)
self.event_received.emit()

Expand Down
12 changes: 8 additions & 4 deletions rascal2/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SettingsGroups(StrEnum):

General = "General"
Logging = "Logging"
Terminal = "Terminal"
Windows = "Windows"


Expand Down Expand Up @@ -105,11 +106,14 @@ 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)
terminal_fontsize: int = Field(default=12, title=SettingsGroups.General, description="Terminal Font Size", gt=0)

log_path: str = Field(default="logs/rascal.log", title="logging", description="Path to Log File")
log_level: LogLevels = Field(default=LogLevels.Info, title="logging", description="Minimum Log Level")
clear_terminal: bool = Field(default=True, title="logging", description="Clear Terminal when Run Starts")
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")

clear_terminal: bool = Field(
default=True, title=SettingsGroups.Terminal, description="Clear Terminal when Run Starts"
)
terminal_fontsize: int = Field(default=12, title=SettingsGroups.Terminal, description="Terminal Font Size", gt=0)

mdi_defaults: MDIGeometries = Field(
default=None, title=SettingsGroups.Windows, description="Default Window Geometries"
Expand Down
2 changes: 1 addition & 1 deletion rascal2/ui/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def handle_interrupt(self):
self.view.logging.info("RAT run interrupted!")
else:
self.view.logging.error(f"RAT run failed with exception:\n{self.runner.error}")
self.view.end_run()
self.view.reset_widgets()

def handle_event(self):
"""Handle event data produced by the RAT run."""
Expand Down
4 changes: 2 additions & 2 deletions rascal2/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ def enable_elements(self):

def handle_results(self, results):
"""Handle the results of a RAT run."""
self.end_run()
self.reset_widgets()
self.controls_widget.chi_squared.setText(f"{results.calculationResults.sumChi:.6g}")

def end_run(self):
def reset_widgets(self):
"""Reset widgets after a run."""
self.controls_widget.run_button.setChecked(False)
18 changes: 7 additions & 11 deletions rascal2/widgets/terminal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Widget for terminal display."""

import logging

from PyQt6 import QtGui, QtWidgets

from rascal2 import RASCAL2_VERSION
Expand All @@ -21,14 +19,9 @@ def __init__(self, parent=None):
self.text_area.setFont(font)
self.text_area.setLineWrapMode(self.text_area.LineWrapMode.NoWrap)

self.logger = logging.getLogger("log")

widget_layout = QtWidgets.QVBoxLayout()

self.scroll_text = QtWidgets.QScrollArea()
self.scroll_text.setWidget(self.text_area)
self.scroll_text.setWidgetResizable(True)
widget_layout.addWidget(self.scroll_text)
widget_layout.addWidget(self.text_area)

self.progress_bar = QtWidgets.QProgressBar()
self.progress_bar.setMaximumHeight(15)
Expand All @@ -53,7 +46,10 @@ def __init__(self, parent=None):
░░░░░ ░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░░░
"""
)
self.write_html(f"<b>RasCAL-2:</b> software for neutron reflectivity calculations <b>v{RASCAL2_VERSION}</b>")
self.write_html(f"\n<b>RasCAL-2:</b> software for neutron reflectivity calculations <b>v{RASCAL2_VERSION}</b>")

# set text area to be scrolled to the left at start
self.text_area.moveCursor(QtGui.QTextCursor.MoveOperation.StartOfLine, QtGui.QTextCursor.MoveMode.MoveAnchor)

def write(self, text: str):
"""Append plain text to the terminal.
Expand All @@ -64,7 +60,7 @@ def write(self, text: str):
The text to append.
"""
self.text_area.appendPlainText(text)
self.text_area.appendPlainText(text.rstrip())

def write_html(self, text: str):
"""Append HTML text to the terminal.
Expand All @@ -75,7 +71,7 @@ def write_html(self, text: str):
The HTML to append.
"""
self.text_area.appendHtml(text)
self.text_area.appendHtml(text.rstrip())

def clear(self):
"""Clear the text in the terminal."""
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MockGlobalSettings:
"""A mock of the global settings."""

def __init__(self):
self.settings = {"General/editor_fontsize": 15, "General/terminal_fontsize": 28}
self.settings = {"General/editor_fontsize": 15, "Terminal/terminal_fontsize": 28}

def value(self, key):
return self.settings[key]
Expand Down Expand Up @@ -87,4 +87,4 @@ def test_set_global(mock):
settings = Settings(editor_fontsize=18, terminal_fontsize=3)
settings.set_global_settings()
mock.assert_any_call("General/editor_fontsize", 18)
mock.assert_any_call("General/terminal_fontsize", 3)
mock.assert_any_call("Terminal/terminal_fontsize", 3)
2 changes: 1 addition & 1 deletion tests/test_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def test_settings_dialog_reset_button(settings_dialog_with_parent):
@pytest.mark.parametrize(
"tab_group, settings_labels",
[
(SettingsGroups.General, ["Style", "Editor Fontsize", "Terminal Fontsize"]),
(SettingsGroups.General, ["Style", "Editor Fontsize"]),
],
)
def test_settings_dialog_tabs(settings_dialog_with_parent, tab_group, settings_labels):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self):
self.controls_widget = MagicMock()
self.terminal_widget = MagicMock()
self.handle_results = MagicMock()
self.end_run = MagicMock()
self.reset_widgets = MagicMock()
self.logging = MagicMock()
self.settings = MagicMock()

Expand Down Expand Up @@ -94,7 +94,7 @@ def test_stop_run(presenter):
presenter.runner.error = None
presenter.handle_interrupt()
presenter.view.logging.info.assert_called_once_with("RAT run interrupted!")
presenter.view.end_run.assert_called_once()
presenter.view.reset_widgets.assert_called_once()


def test_run_error(presenter):
Expand Down

0 comments on commit 847007b

Please sign in to comment.