【发布时间】: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