50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
![]() |
from PySide6.QtCore import Signal
|
||
|
from PySide6.QtWidgets import QMenu
|
||
|
from PySide6.QtGui import QAction
|
||
|
from sqlitedict import SqliteDict
|
||
|
|
||
|
from communication.param_manager import ParamManager
|
||
|
from components.common.custom_widget import CustomWidget
|
||
|
from env import PARAMS_DB_PATH
|
||
|
|
||
|
|
||
|
class WidgetMenu(QMenu):
|
||
|
signal_input_accept = Signal(dict)
|
||
|
def __init__(self, param_name, _param_idx, parent=None):
|
||
|
super(WidgetMenu, self).__init__(parent)
|
||
|
self.action_edit = QAction("Edit", self)
|
||
|
self.action_refresh = QAction("Refresh", self)
|
||
|
self.addAction(self.action_edit)
|
||
|
self.addAction(self.action_refresh)
|
||
|
self.dialog = CustomWidget()
|
||
|
self.param_name = param_name
|
||
|
self.param_idx = _param_idx
|
||
|
|
||
|
self.param_manager = ParamManager()
|
||
|
|
||
|
_param_indicator = f'设定参数:{self.param_name}'
|
||
|
_param_indicator += '' if _param_idx=='' else f'[{_param_idx}]'
|
||
|
|
||
|
self.dialog.setWindowTitle(_param_indicator)
|
||
|
|
||
|
self.action_edit.triggered.connect(self.open_input_dialog)
|
||
|
|
||
|
def open_input_dialog(self):
|
||
|
self.config_input_dialog(self.pos())
|
||
|
if self.dialog.exec():
|
||
|
_val = self.dialog.get_input_val()
|
||
|
self.signal_input_accept.emit({
|
||
|
"name": self.param_name,
|
||
|
"index": self.param_idx,
|
||
|
"value": _val
|
||
|
})
|
||
|
|
||
|
def config_input_dialog(self, pos):
|
||
|
# 创建一个 QLineEdit 输入框
|
||
|
self.dialog.move(pos.x(), pos.y() + 55)
|
||
|
|
||
|
val = self.param_manager.get(self.param_name).values()[self.param_idx]
|
||
|
# 从数据库中读取变量的值
|
||
|
self.dialog.line_edit.setText(str(round(val, 10)))
|
||
|
# 输入框默认选取全部
|
||
|
self.dialog.line_edit.selectAll()
|