добавлены ~стиль~ и сохранение настроек в json
This commit is contained in:
parent
ac502c5fdf
commit
dc4c74471f
@ -1,19 +1,19 @@
|
|||||||
{
|
{
|
||||||
"a_max_1" : 5.41,
|
"a_max_1": 5.41,
|
||||||
"v_max_1" : 0.108,
|
"v_max_1": 0.108,
|
||||||
"a_max_2" : 35.81,
|
"a_max_2": 35.81,
|
||||||
"v_max_2" : 0.678,
|
"v_max_2": 0.678,
|
||||||
"mass_1" : 257,
|
"mass_1": 257,
|
||||||
"mass_2" : 1,
|
"mass_2": 1,
|
||||||
"k_hardness_1" : 1759291,
|
"k_hardness_1": 1759291,
|
||||||
"k_hardness_2" : 0,
|
"k_hardness_2": 0,
|
||||||
"torque_max_1" : 20,
|
"torque_max_1": 20,
|
||||||
"torque_max_2" : 0,
|
"torque_max_2": 0,
|
||||||
"transmission_ratio_1" : 0.00125,
|
"transmission_ratio_1": 0.00125,
|
||||||
"transmission_ratio_2" : 1,
|
"transmission_ratio_2": 1,
|
||||||
"position_start_1" : 0.080,
|
"position_start_1": 0.08,
|
||||||
"position_start_2" : 0.080,
|
"position_start_2": 0.08,
|
||||||
"k_prop" : 0.05,
|
"k_prop": 0.05,
|
||||||
"time_capture" : 100000,
|
"time_capture": 100000,
|
||||||
"UML_time_scaler": 1000
|
"UML_time_scaler": 1000
|
||||||
}
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -16,6 +16,7 @@ class app:
|
|||||||
self.sysSettings = settingsWindow("params\system_params.json", 'System', self._update_settings)
|
self.sysSettings = settingsWindow("params\system_params.json", 'System', self._update_settings)
|
||||||
|
|
||||||
self._load_preset()
|
self._load_preset()
|
||||||
|
|
||||||
|
|
||||||
def _get_ideal_timings(self, opt: OptAlgorithm) -> list[float]:
|
def _get_ideal_timings(self, opt: OptAlgorithm) -> list[float]:
|
||||||
data = opt.Ts
|
data = opt.Ts
|
||||||
@ -37,7 +38,8 @@ class app:
|
|||||||
system_config=self.system_params,
|
system_config=self.system_params,
|
||||||
opt=self.opt_algorithm,
|
opt=self.opt_algorithm,
|
||||||
bool_dict=self.bool_dict,
|
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,
|
self.uml_creator = UMLCreator(system_config=self.system_params,
|
||||||
request_generator=self.request_generator,
|
request_generator=self.request_generator,
|
||||||
@ -63,6 +65,10 @@ class app:
|
|||||||
opt=self.opt_algorithm,
|
opt=self.opt_algorithm,
|
||||||
bool_dict=self.bool_dict,
|
bool_dict=self.bool_dict,
|
||||||
float_dict=self.float_dict)
|
float_dict=self.float_dict)
|
||||||
|
|
||||||
|
def _show_settings(self):
|
||||||
|
self.operSettings.show()
|
||||||
|
self.sysSettings.show()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
from pyqtgraph.Qt import QtWidgets
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from src.gui import qt_settings as qts
|
from src.gui import qt_settings as qts
|
||||||
@ -12,7 +13,7 @@ class PlotWindow:
|
|||||||
operator_config: dict,
|
operator_config: dict,
|
||||||
opt: OptAlgorithm,
|
opt: OptAlgorithm,
|
||||||
bool_dict: dict,
|
bool_dict: dict,
|
||||||
float_dict: dict):
|
float_dict: dict, show_settings_func):
|
||||||
pg.setConfigOptions(antialias=True)
|
pg.setConfigOptions(antialias=True)
|
||||||
self.opt = opt
|
self.opt = opt
|
||||||
self.bool_dict = bool_dict
|
self.bool_dict = bool_dict
|
||||||
@ -22,7 +23,8 @@ class PlotWindow:
|
|||||||
self.alpha = 100 #[0-255 прозрачность фона]
|
self.alpha = 100 #[0-255 прозрачность фона]
|
||||||
|
|
||||||
self._getIdealTimings()
|
self._getIdealTimings()
|
||||||
self._init_app()
|
self._init_ui()
|
||||||
|
self.settings_button.clicked.connect(show_settings_func)
|
||||||
|
|
||||||
|
|
||||||
def update_data(self,
|
def update_data(self,
|
||||||
@ -39,11 +41,20 @@ class PlotWindow:
|
|||||||
self._getIdealTimings()
|
self._getIdealTimings()
|
||||||
self._updatePlots()
|
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 = pg.GraphicsLayoutWidget(show=True, title="")
|
||||||
self.win.resize(1000,600)
|
self.win.resize(1000,600)
|
||||||
self.win.setWindowTitle('')
|
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.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.p21, _ = self._init_graph('Electrode force, compression', 'Force', 'N', 'Time', 'ms')
|
||||||
#self.p31, _ = 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.p11.setAutoVisible(x=False, y=True)
|
||||||
self.p12.setAutoVisible(x=False, y=True)
|
self.p12.setAutoVisible(x=False, y=True)
|
||||||
self.p13.setAutoVisible(x=False, y=True)
|
self.p13.setAutoVisible(x=False, y=True)
|
||||||
|
|
||||||
self._updatePlots()
|
self._updatePlots()
|
||||||
|
self.widget.setStyleSheet(qts.dark_style)
|
||||||
|
self.widget.show()
|
||||||
|
|
||||||
def _init_graph(self, title, Yname, Yunits, Xname, Xunits):
|
def _init_graph(self, title, Yname, Yunits, Xname, Xunits):
|
||||||
plot = self.win.addPlot(title = title)
|
plot = self.win.addPlot(title = title)
|
||||||
@ -82,7 +94,7 @@ class PlotWindow:
|
|||||||
self.l12.clear()
|
self.l12.clear()
|
||||||
self.p13.clear()
|
self.p13.clear()
|
||||||
self.l13.clear()
|
self.l13.clear()
|
||||||
|
|
||||||
self._plotRealData()
|
self._plotRealData()
|
||||||
times = np.arange(20000)/10
|
times = np.arange(20000)/10
|
||||||
self._plotIdealData(times)
|
self._plotIdealData(times)
|
||||||
|
@ -57,7 +57,7 @@ QRadioButton {
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
dark_style = """
|
dark_style = """
|
||||||
QMainWindow {
|
QWidget {
|
||||||
background-color: #0D1117; /* Тёмный, современный цвет для фона */
|
background-color: #0D1117; /* Тёмный, современный цвет для фона */
|
||||||
font-family: "Segoe UI", sans-serif;
|
font-family: "Segoe UI", sans-serif;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
@ -3,6 +3,7 @@ from pyqtgraph.Qt import QtWidgets
|
|||||||
from pyqtgraph.parametertree import Parameter, ParameterTree
|
from pyqtgraph.parametertree import Parameter, ParameterTree
|
||||||
|
|
||||||
from src.utils.json_tools import read_json, write_json
|
from src.utils.json_tools import read_json, write_json
|
||||||
|
from src.gui import qt_settings as qts
|
||||||
|
|
||||||
class settingsWindow(QtWidgets.QWidget):
|
class settingsWindow(QtWidgets.QWidget):
|
||||||
def __init__(self, path: str, name: str, upd_func):
|
def __init__(self, path: str, name: str, upd_func):
|
||||||
@ -20,32 +21,34 @@ class settingsWindow(QtWidgets.QWidget):
|
|||||||
self.data = read_json(self.settingsPath)
|
self.data = read_json(self.settingsPath)
|
||||||
|
|
||||||
def write_settings(self):
|
def write_settings(self):
|
||||||
|
self.getParams()
|
||||||
write_json(self.settingsPath, self.data)
|
write_json(self.settingsPath, self.data)
|
||||||
|
|
||||||
def _getTreeStructure(self) -> list:
|
def _getTreeStructure(self) -> list:
|
||||||
params = []
|
params = []
|
||||||
for key, value in self.data.items():
|
for key, value in self.data.items():
|
||||||
params.append({'name': str(key), 'type': type(value).__name__, 'value': value})
|
params.append({'name': str(key), 'type': type(value).__name__, 'value': value})
|
||||||
|
params.append({'name': 'Save', 'type': 'action'})
|
||||||
return params
|
return params
|
||||||
|
|
||||||
def _init_ui(self):
|
def _init_ui(self):
|
||||||
temp = self._getTreeStructure()
|
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 = ParameterTree()
|
||||||
ParamsTree.setParameters(self.params)
|
ParamsTree.setParameters(self.params, showTop=True)
|
||||||
ParamsTree.setWindowTitle('Settings ,f,f')
|
|
||||||
layout = QtWidgets.QGridLayout()
|
layout = QtWidgets.QGridLayout()
|
||||||
layout.addWidget(ParamsTree, 0,0)
|
layout.addWidget(ParamsTree, 0,0)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
self.setStyleSheet(qts.white_style)
|
||||||
self.show()
|
# self.show()
|
||||||
|
|
||||||
def getParams(self) -> dict:
|
def getParams(self) -> dict:
|
||||||
self.data = {}
|
self.data = {}
|
||||||
for p in self.params:
|
for p in self.params:
|
||||||
self.data[p.name()] = p.value()
|
if p.name() != 'Save':
|
||||||
|
self.data[p.name()] = p.value()
|
||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Binary file not shown.
@ -16,6 +16,6 @@ def write_json(filepath: str, data: dict):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with open(filepath, 'w') as json_file:
|
with open(filepath, 'w') as json_file:
|
||||||
json.dump(data, json_file)
|
json.dump(data, json_file, indent=4)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
Loading…
Reference in New Issue
Block a user