Commit 2055ba5c authored by Duggan, John's avatar Duggan, John
Browse files

Set up matplotlib

parent d2cf1632
Loading
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ from pathlib import Path
from typing import Any, Dict, List

from blinker import signal
from matplotlib.figure import Figure
from nova.common.signals import Signal, ToolCommand, get_signal_id
from nova.mvvm.interface import BindingInterface
from pydantic import BaseModel, Field, ValidationError
@@ -26,12 +27,16 @@ class MainViewModel:
        self.model = model
        self.view_state = ViewState()

        self.figure = Figure(figsize=(8.0, 4.0))
        self.ax = self.figure.subplots(1, 1)

        # here we create a bind that connects ViewModel with View. It returns a communicator object,
        # that allows to update View from ViewModel (by calling update_view).
        # self.model will be updated automatically on changes of connected fields in View,
        # but one also can provide a callback function if they want to react to those events
        # and/or process errors.
        self.config_bind = binding.new_bind()
        self.figure_bind = binding.new_bind()
        self.slurm_params_bind = binding.new_bind(
            self.model.slurm_params, callback_after_update=self.on_change_slurm_params
        )
@@ -43,6 +48,9 @@ class MainViewModel:
        self.completion_signal = signal("ips_fastran_complete")
        self.completion_signal.connect(self.on_completion, weak=False)

    def get_figure(self) -> Figure:
        return self.figure

    def init_view(self) -> None:
        self.config_bind.update_in_view(self.model.config.model_dump_json(indent=2))

@@ -71,6 +79,8 @@ class MainViewModel:
            pass

    def on_completion(self, _sender: Any, output_path: Path) -> None:
        self.update_figure()

        self.view_state.results_disabled = False
        self.view_state_bind.update_in_view(self.view_state)

@@ -79,3 +89,7 @@ class MainViewModel:
            self.view_state.results_disabled = True
            self.view_state.active_tab = 2
            self.view_state_bind.update_in_view(self.view_state)

    def update_figure(self) -> None:
        # TODO: draw the rest of the owl
        self.figure_bind.update_in_view(None)
+1 −1
Original line number Diff line number Diff line
@@ -31,4 +31,4 @@ class TabContentPanel:
                        with vuetify.VWindowItem(value=2):
                            ExecutionTab()
                        with vuetify.VWindowItem(value=3):
                            ResultsTab()
                            ResultsTab(self.view_model)
+13 −4
Original line number Diff line number Diff line
"""Module for the Slurm tab."""

from nova.trame.view.components import InputField
from nova.trame.view.layouts import GridLayout
from typing import Any

from nova.trame.view.components.visualization import MatplotlibFigure

from ips_fastran_gui.app.view_models.main_view_model import MainViewModel


class ResultsTab:
    """Slurm view class."""

    def __init__(self) -> None:
    def __init__(self, view_model: MainViewModel) -> None:
        self.view_model = view_model
        self.view_model.figure_bind.connect(self.update)

        self.create_ui()

    def create_ui(self) -> None:
        pass
        self.figure_view = MatplotlibFigure(self.view_model.get_figure())

    def update(self, _: Any = None) -> None:
        self.figure_view.update()