参数树不考虑用户输入的数据
Data entered by the user are not taken into account by the parameter tree
我希望你能帮助我,我的问题会很清楚。
我正在使用 PyQT5 制作 GUI 来配置舞台电机。在 GUI 中,用户可以通过更改参数树中的值来更改舞台的位置等。
之前,没有 class MainWindow,所以树就在主窗口中,并且运行良好(我必须创建 class MainWindow 才能使用 closeEvent)。
现在用户可以编辑值,但程序不会考虑更改,因此阶段的参数不会更改。我不知道我应该在 Change 函数或其他地方修改什么,以便从主窗口过渡到 MainWindow class 工作
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow,self).__init__()
self.initUI()
def initUI(self):
######### Parameters of the Parameter tree #########
params = [
{'name': 'Parameters', 'type': 'group', 'children': [
{'name': 'Center Position', 'type': 'float', 'value': CenterPos , 'step': 0.001,'siPrefix': True, 'suffix': 'm'},
{'name': 'Range', 'type': 'float', 'value': Range, 'limits':(0,24),'step': 0.001,'siPrefix': True, 'suffix': 'm'},
{'name': 'Step Size', 'type': 'float', 'value': StepSize,'siPrefix': True,'suffix': 'm','readonly': True},
{'name': 'Points', 'type': 'int', 'value': int(Points), 'limits': (1, 256), 'step': 1},
]},
]
p = Parameter.create(name='params', type='group', children=params)
t = ParameterTree()
t.setParameters(p, showTop=False)
t.setWindowTitle('pyqtgraph example: Parameter Tree')
def change(param, changes):
global p,StartingPoint,ArrivingPoint,CenterPos,Range,Points,StepSize
for param, data in changes:
path = p.childPath(param)
if path[0]=='Stage Parameters':
if path[1]=='Center Position':
CenterPos = data*1E3
StartingPoint=data*1E3-Range/2.0
ArrivingPoint=data*1E3+Range/2.0
StepSize = (ArrivingPoint-StartingPoint)/Points
p.param('arameters','Step Size').setValue(StepSize)
if path[1]=='Range':
Range=data*1E3
StartingPoint=CenterPos-Range/2.0
ArrivingPoint=CenterPos+Range/2.0
StepSize = (ArrivingPoint-StartingPoint)/Points
p.param('Parameters','Step Size').setValue(StepSize)
if path[1]=='Points':
Points=data
StepSize=Range/data
p.param('Parameters','Step Size').setValue(StepSize)
p.sigTreeStateChanged.connect(change)
w = MainWindow()
使用参数树的示例代码:http://www.pyqtgraph.org/downloads/0.10.0/pyqtgraph-0.10.0-deb/pyqtgraph-0.10.0/examples/parametertree.py 我能够以更合适的方式重写我的参数树。使用带有子函数的 class 可以实现相互依赖变量的更新,例如上面 link 中示例的 "ComplexParameter" class。
用户输入的数据现在在 class ComplexParameter 中正确使用全局变量。
我希望你能帮助我,我的问题会很清楚。 我正在使用 PyQT5 制作 GUI 来配置舞台电机。在 GUI 中,用户可以通过更改参数树中的值来更改舞台的位置等。 之前,没有 class MainWindow,所以树就在主窗口中,并且运行良好(我必须创建 class MainWindow 才能使用 closeEvent)。
现在用户可以编辑值,但程序不会考虑更改,因此阶段的参数不会更改。我不知道我应该在 Change 函数或其他地方修改什么,以便从主窗口过渡到 MainWindow class 工作
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow,self).__init__()
self.initUI()
def initUI(self):
######### Parameters of the Parameter tree #########
params = [
{'name': 'Parameters', 'type': 'group', 'children': [
{'name': 'Center Position', 'type': 'float', 'value': CenterPos , 'step': 0.001,'siPrefix': True, 'suffix': 'm'},
{'name': 'Range', 'type': 'float', 'value': Range, 'limits':(0,24),'step': 0.001,'siPrefix': True, 'suffix': 'm'},
{'name': 'Step Size', 'type': 'float', 'value': StepSize,'siPrefix': True,'suffix': 'm','readonly': True},
{'name': 'Points', 'type': 'int', 'value': int(Points), 'limits': (1, 256), 'step': 1},
]},
]
p = Parameter.create(name='params', type='group', children=params)
t = ParameterTree()
t.setParameters(p, showTop=False)
t.setWindowTitle('pyqtgraph example: Parameter Tree')
def change(param, changes):
global p,StartingPoint,ArrivingPoint,CenterPos,Range,Points,StepSize
for param, data in changes:
path = p.childPath(param)
if path[0]=='Stage Parameters':
if path[1]=='Center Position':
CenterPos = data*1E3
StartingPoint=data*1E3-Range/2.0
ArrivingPoint=data*1E3+Range/2.0
StepSize = (ArrivingPoint-StartingPoint)/Points
p.param('arameters','Step Size').setValue(StepSize)
if path[1]=='Range':
Range=data*1E3
StartingPoint=CenterPos-Range/2.0
ArrivingPoint=CenterPos+Range/2.0
StepSize = (ArrivingPoint-StartingPoint)/Points
p.param('Parameters','Step Size').setValue(StepSize)
if path[1]=='Points':
Points=data
StepSize=Range/data
p.param('Parameters','Step Size').setValue(StepSize)
p.sigTreeStateChanged.connect(change)
w = MainWindow()
使用参数树的示例代码:http://www.pyqtgraph.org/downloads/0.10.0/pyqtgraph-0.10.0-deb/pyqtgraph-0.10.0/examples/parametertree.py 我能够以更合适的方式重写我的参数树。使用带有子函数的 class 可以实现相互依赖变量的更新,例如上面 link 中示例的 "ComplexParameter" class。
用户输入的数据现在在 class ComplexParameter 中正确使用全局变量。