-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import threading | ||
import time | ||
from ..models.main import ModelStatus | ||
|
||
|
||
class ModelStatusController: | ||
""" Tracks if the model is running and updates the view to reflect the status. """ | ||
def __init__(self, model, view): | ||
""" | ||
Constructor | ||
@In, model, Model, the model | ||
@In, view, View, the view | ||
""" | ||
self.model = model | ||
self.view = view | ||
self._model_has_run = False # Flag to indicate the model has already been run | ||
self.check_model_status() | ||
|
||
def check_model_status(self): | ||
""" | ||
Check the status of the model and update the view | ||
@In, None | ||
@Out, None | ||
""" | ||
def _check_status(): | ||
""" | ||
Local helper function for checking the status of the model in a separate thread | ||
@In, None | ||
@Out, None | ||
""" | ||
current_status = self.model.status | ||
while True: | ||
if current_status != self.model.status: | ||
current_status = self.model.status | ||
self.view.set_status(self.model.status) | ||
time.sleep(0.5) | ||
|
||
thread = threading.Thread(target=_check_status) | ||
thread.daemon = True | ||
thread.name = "ModelStatusChecker" | ||
thread.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from typing import Optional, Callable | ||
import os | ||
import tkinter as tk | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import tkinter as tk | ||
from ..models.main import ModelStatus as ModelStatusEnum | ||
|
||
|
||
class ModelStatus(tk.Frame): | ||
""" A widget for displaying the status of the model. """ | ||
def __init__(self, master: tk.Widget, **kwargs): | ||
""" | ||
Constructor | ||
@In, master, tk.Widget, the parent widget | ||
@In, kwargs, dict, keyword arguments | ||
@Out, None | ||
""" | ||
super().__init__(master, **kwargs) | ||
self.status = tk.StringVar() | ||
self.status.set("Model not yet run") | ||
self.status_label = tk.Label(self, textvariable=self.status, bg="white", anchor='w', padx=10, pady=3) | ||
self.status_label.pack(side='left') | ||
self.grid_columnconfigure(0, weight=1) | ||
|
||
def set_status(self, new_status: ModelStatusEnum): | ||
""" | ||
Set the status label | ||
@In, new_status, ModelStatusEnum, the new status | ||
@Out, None | ||
""" | ||
self.status.set(new_status.value) | ||
# Change the color of the label based on the status | ||
if new_status == ModelStatusEnum.FINISHED: | ||
self.status_label.config(fg='green') | ||
elif new_status == ModelStatusEnum.ERROR: | ||
self.status_label.config(fg='red') | ||
else: | ||
self.status_label.config(fg='black') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters