fix: окна настроек теперь отображаются корректно и обновляют все графики

This commit is contained in:
Andrew 2024-11-13 11:13:31 +03:00
parent 844aa4a78a
commit 7c09dde2d1
6 changed files with 60 additions and 48 deletions

Binary file not shown.

View File

@ -1,3 +1,3 @@
from .plot_window import Plotter
from .settings_window import settingsWindow
from .app import graphWindow
from .app import tabWidgetGenerator

View File

@ -6,63 +6,68 @@ from src.OptAlgorithm import OptAlgorithm
from src.gui import Plotter, settingsWindow
class graphWindow:
def __init__(self, path = None):
self.path = path
self._load_preset()
class tabWidgetGenerator:
def __init__(self):
self.UMLgenerator = Request(server_url='http://www.plantuml.com/plantuml/svg/')
self.uml_creator = UMLCreator(request_generator=self.UMLgenerator)
self.operator_params = read_json("params/operator_params.json")
self.system_params = read_json("params/system_params.json")
self.operSettings = settingsWindow("params\operator_params.json", 'Operator', self._update)
self.sysSettings = settingsWindow("params\system_params.json", 'System', self._update)
def get_widget(self):
return self.plotter.widget
self.paths = []
self.plotters = []
self.bool_dicts = []
self.float_dicts = []
self.timings_dicts = []
self.modes = []
def get_widget(self, path):
self.paths.append(path)
self.plotters.append(Plotter(show_settings_func=self._show_settings))
self._getParsedData(path)
self._update()
return self.plotters[-1].widget
def _get_ideal_timings(self, opt: OptAlgorithm) -> list[float]:
data = opt.Ts
ideal_time = [data['tclose'], data['tgrow'], opt.getMarkOpen(), data["tmovement"]]
return ideal_time
def _load_preset(self):
self.operator_params = read_json("params/operator_params.json")
self.system_params = read_json("params/system_params.json")
generator = Request(server_url='http://www.plantuml.com/plantuml/svg/')
self.uml_creator = UMLCreator(request_generator=generator)
self.operSettings = settingsWindow("params\operator_params.json", 'Operator', self._update_settings)
self.sysSettings = settingsWindow("params\system_params.json", 'System', self._update_settings)
self.plotter = Plotter(show_settings_func=self._show_settings)
self.parser = DiagramParser(system_config=self.system_params)
self.parser.setData(self.path)
self.bool_dict = self.parser.getBoolDict()
self.float_dict = self.parser.getFloatDict()
self.timings_dict = self.parser.getRealTimings()
self.mode = self.parser.getMode()
self._update_settings()
def _getParsedData(self, path):
parser = DiagramParser(system_config=self.system_params)
parser.setData(path)
self.bool_dicts.append(parser.getBoolDict())
self.float_dicts.append(parser.getFloatDict())
self.timings_dicts.append(parser.getRealTimings())
self.modes.append(parser.getMode())
def _update_settings(self, _ = None):
def _update(self, _ = None):
self.operator_params = self.operSettings.getParams()
self.system_params = self.sysSettings.getParams()
self.opt_algorithm = OptAlgorithm(operator_config=self.operator_params, system_config=self.system_params)
self.ideal_times = self._get_ideal_timings(self.opt_algorithm)
opt_algorithm = OptAlgorithm(operator_config=self.operator_params, system_config=self.system_params)
ideal_times = self._get_ideal_timings(opt_algorithm)
for i in range (len(self.plotters)):
self.plotters[i].update_data(operator_config=self.operator_params,
system_config=self.system_params,
opt=opt_algorithm,
bool_dict=self.bool_dicts[i],
ideal_time=ideal_times,
float_dict=self.float_dicts[i],
mode = self.modes[i],
timings_dict=self.timings_dicts[i])
self.uml_creator.update_uml(operator_config=self.operator_params,
system_config=self.system_params,
ideal_time=self.ideal_times,
bool_dict=self.bool_dict,
float_dict=self.float_dict,
mode = self.mode,
timings_dict=self.timings_dict)
ideal_time=ideal_times,
bool_dict=self.bool_dicts[i],
float_dict=self.float_dicts[i],
mode = self.modes[i],
timings_dict=self.timings_dicts[i])
self.plotter.update_data(operator_config=self.operator_params,
system_config=self.system_params,
opt=self.opt_algorithm,
bool_dict=self.bool_dict,
ideal_time=self.ideal_times,
float_dict=self.float_dict,
mode = self.mode,
timings_dict=self.timings_dict)
def _show_settings(self):
self.operSettings.show()
@ -71,5 +76,7 @@ class graphWindow:
if __name__ == '__main__':
pg.mkQApp("Plotting")
temp = graphWindow("trace_samples/2024_11_08-19_30_49.csv")
temp = tabWidgetGenerator()
widget = temp.get_widget("trace_samples/2024_11_08-19_30_49.csv")
widget.show()
pg.exec()

View File

@ -11,11 +11,12 @@ from PyQt5.QtWidgets import (
)
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QObject, QFileSystemWatcher
from PyQt5.QtGui import QIcon
from src.gui import qt_settings as qts
# Импортируйте ваш класс `app` здесь
# Предполагается, что класс `app` предоставляет интерфейс для отображения данных
# Если `app` не предоставляет виджет, возможно, потребуется его модифицировать
from src.gui.app import graphWindow
from src.gui.app import tabWidgetGenerator
class DirectoryWatcher(QObject):
@ -30,6 +31,7 @@ class DirectoryWatcher(QObject):
self.existing_files = set(os.listdir(self.directory_path))
self.watcher.directoryChanged.connect(self.on_directory_changed)
def on_directory_changed(self, _):
try:
current_files = set(os.listdir(self.directory_path))
@ -50,11 +52,14 @@ class MainWindow(QMainWindow):
self.setGeometry(100, 100, 800, 600)
self.tabs = QTabWidget()
self.tabs.setStyleSheet(qts.dark_style)
self.tabGen = tabWidgetGenerator()
self.setCentralWidget(self.tabs)
# self.setWindowIcon(QIcon("path_to_icon.png"))
self.start_directory_watcher(directory_to_watch)
def start_directory_watcher(self, directory_path):
self.watcher_thread = QThread()
self.watcher = DirectoryWatcher(directory_path)
@ -66,14 +71,14 @@ class MainWindow(QMainWindow):
self.watcher_thread.start()
def handle_new_file(self, file_path):
time.sleep(0.2)
file_name = os.path.basename(file_path)
app_instance = graphWindow(path=file_path)
tab_widget = self.tabGen.get_widget(path=file_path)
tab = QWidget()
layout = QVBoxLayout()
app_widget = app_instance.get_widget()
layout.addWidget(app_widget)
layout.addWidget(tab_widget)
label = QLabel(f"{file_name}")
label.setAlignment(Qt.AlignCenter)