добавлены ~стиль~ и сохранение настроек в json

This commit is contained in:
Andrew 2024-11-11 14:28:21 +03:00
parent ac502c5fdf
commit dc4c74471f
11 changed files with 53 additions and 32 deletions

View File

@ -1,19 +1,19 @@
{
"a_max_1" : 5.41,
"v_max_1" : 0.108,
"a_max_2" : 35.81,
"v_max_2" : 0.678,
"mass_1" : 257,
"mass_2" : 1,
"k_hardness_1" : 1759291,
"k_hardness_2" : 0,
"torque_max_1" : 20,
"torque_max_2" : 0,
"transmission_ratio_1" : 0.00125,
"transmission_ratio_2" : 1,
"position_start_1" : 0.080,
"position_start_2" : 0.080,
"k_prop" : 0.05,
"time_capture" : 100000,
"a_max_1": 5.41,
"v_max_1": 0.108,
"a_max_2": 35.81,
"v_max_2": 0.678,
"mass_1": 257,
"mass_2": 1,
"k_hardness_1": 1759291,
"k_hardness_2": 0,
"torque_max_1": 20,
"torque_max_2": 0,
"transmission_ratio_1": 0.00125,
"transmission_ratio_2": 1,
"position_start_1": 0.08,
"position_start_2": 0.08,
"k_prop": 0.05,
"time_capture": 100000,
"UML_time_scaler": 1000
}
}

View File

@ -16,6 +16,7 @@ class app:
self.sysSettings = settingsWindow("params\system_params.json", 'System', self._update_settings)
self._load_preset()
def _get_ideal_timings(self, opt: OptAlgorithm) -> list[float]:
data = opt.Ts
@ -37,7 +38,8 @@ class app:
system_config=self.system_params,
opt=self.opt_algorithm,
bool_dict=self.bool_dict,
float_dict=self.float_dict)
float_dict=self.float_dict,
show_settings_func=self._show_settings)
self.uml_creator = UMLCreator(system_config=self.system_params,
request_generator=self.request_generator,
@ -63,6 +65,10 @@ class app:
opt=self.opt_algorithm,
bool_dict=self.bool_dict,
float_dict=self.float_dict)
def _show_settings(self):
self.operSettings.show()
self.sysSettings.show()
if __name__ == '__main__':

View File

@ -1,4 +1,5 @@
import pyqtgraph as pg
from pyqtgraph.Qt import QtWidgets
import numpy as np
from src.gui import qt_settings as qts
@ -12,7 +13,7 @@ class PlotWindow:
operator_config: dict,
opt: OptAlgorithm,
bool_dict: dict,
float_dict: dict):
float_dict: dict, show_settings_func):
pg.setConfigOptions(antialias=True)
self.opt = opt
self.bool_dict = bool_dict
@ -22,7 +23,8 @@ class PlotWindow:
self.alpha = 100 #[0-255 прозрачность фона]
self._getIdealTimings()
self._init_app()
self._init_ui()
self.settings_button.clicked.connect(show_settings_func)
def update_data(self,
@ -39,11 +41,20 @@ class PlotWindow:
self._getIdealTimings()
self._updatePlots()
def _init_app(self):
def _init_ui(self):
self.widget = QtWidgets.QWidget()
layout = QtWidgets.QVBoxLayout()
self.widget.setLayout(layout)
self.win = pg.GraphicsLayoutWidget(show=True, title="")
self.win.resize(1000,600)
self.win.setWindowTitle('')
layout.addWidget(self.win)
self.settings_button = QtWidgets.QPushButton("Show settings")
self.settings_button.setFixedWidth(160)
layout.addWidget(self.settings_button)
self.p11, self.l11 = self._init_graph('Electrode force, closure', 'Force', 'N', 'Time', 'ms')
#self.p21, _ = self._init_graph('Electrode force, compression', 'Force', 'N', 'Time', 'ms')
#self.p31, _ = self._init_graph('Electrode force, compression', 'Force', 'N', 'Time', 'ms')
@ -63,8 +74,9 @@ class PlotWindow:
self.p11.setAutoVisible(x=False, y=True)
self.p12.setAutoVisible(x=False, y=True)
self.p13.setAutoVisible(x=False, y=True)
self._updatePlots()
self.widget.setStyleSheet(qts.dark_style)
self.widget.show()
def _init_graph(self, title, Yname, Yunits, Xname, Xunits):
plot = self.win.addPlot(title = title)
@ -82,7 +94,7 @@ class PlotWindow:
self.l12.clear()
self.p13.clear()
self.l13.clear()
self._plotRealData()
times = np.arange(20000)/10
self._plotIdealData(times)

View File

@ -57,7 +57,7 @@ QRadioButton {
"""
dark_style = """
QMainWindow {
QWidget {
background-color: #0D1117; /* Тёмный, современный цвет для фона */
font-family: "Segoe UI", sans-serif;
font-size: 14px;

View File

@ -3,6 +3,7 @@ from pyqtgraph.Qt import QtWidgets
from pyqtgraph.parametertree import Parameter, ParameterTree
from src.utils.json_tools import read_json, write_json
from src.gui import qt_settings as qts
class settingsWindow(QtWidgets.QWidget):
def __init__(self, path: str, name: str, upd_func):
@ -20,32 +21,34 @@ class settingsWindow(QtWidgets.QWidget):
self.data = read_json(self.settingsPath)
def write_settings(self):
self.getParams()
write_json(self.settingsPath, self.data)
def _getTreeStructure(self) -> list:
params = []
for key, value in self.data.items():
params.append({'name': str(key), 'type': type(value).__name__, 'value': value})
params.append({'name': 'Save', 'type': 'action'})
return params
def _init_ui(self):
temp = self._getTreeStructure()
self.params = Parameter.create(name='params', type='group', children=temp)
self.params = Parameter.create(name=self.name, type='group', children=temp)
self.params.param('Save').sigActivated.connect(self.write_settings)
ParamsTree = ParameterTree()
ParamsTree.setParameters(self.params)
ParamsTree.setWindowTitle('Settings ,f,f')
ParamsTree.setParameters(self.params, showTop=True)
layout = QtWidgets.QGridLayout()
layout.addWidget(ParamsTree, 0,0)
self.setLayout(layout)
self.show()
self.setStyleSheet(qts.white_style)
# self.show()
def getParams(self) -> dict:
self.data = {}
for p in self.params:
self.data[p.name()] = p.value()
if p.name() != 'Save':
self.data[p.name()] = p.value()
return self.data
if __name__ == '__main__':

View File

@ -16,6 +16,6 @@ def write_json(filepath: str, data: dict):
try:
with open(filepath, 'w') as json_file:
json.dump(data, json_file)
json.dump(data, json_file, indent=4)
except Exception as e:
raise e