参数树不考虑用户输入的数据



我希望你能帮助我,我的问题会足够清楚。 我正在使用 PyQT5 制作一个 GUI 来配置舞台电机。在GUI中,用户可以更改位置等...通过更改参数树中的值来更改阶段。 以前,没有类 MainWindow,所以树只是在 main 中并且运行良好(我必须创建类 MainWindow 才能使用 closeEvent(。

现在,用户可以编辑值,但程序不会考虑更改,因此舞台的参数不会更改。我不知道我应该在 Change 函数或其他地方修改什么,以便从 main 类到 MainWindow 类的过渡工作

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 我能够以更合适的方式重写我的参数树。相互依赖变量的更新可以使用具有子函数的类来实现,例如上面链接中示例的"ComplexParameter"类。

现在,用户输入的数据正在考虑在内,并在类 ComplexParameter 中正确使用全局变量。

最新更新