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

2024-04-25 13:05:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望你能帮助我,我的问题会很清楚。 我正在使用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()

Tags: pathnameselfdataparamvaluetyperange
1条回答
网友
1楼 · 发布于 2024-04-25 13:05:19

使用这个参数树的示例代码:http://www.pyqtgraph.org/downloads/0.10.0/pyqtgraph-0.10.0-deb/pyqtgraph-0.10.0/examples/parametertree.py我能够以更合适的方式重写我的参数树。相互依赖变量的更新可以通过使用一个具有子函数的类来实现,比如上面链接中示例的“ComplexParameter”类。你知道吗

通过在ComplexParameter类中正确使用全局变量,现在可以考虑用户输入的数据。你知道吗

相关问题 更多 >

    热门问题