【问题标题】:Data entered by the user are not taken into account by the parameter tree参数树不考虑用户输入的数据
【发布时间】:2018-11-20 14:26:12
【问题描述】:

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

【问题讨论】:

    标签: python parameters pyqt qtgui pyqtgraph


    【解决方案1】:

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

    现在通过在类 ComplexParameter 中正确使用全局变量来考虑用户输入的数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      • 2020-03-22
      相关资源
      最近更新 更多