myParam.py 4.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# -*- coding: utf-8 -*-
"""
This example demonstrates the use of pyqtgraph's parametertree system. This provides
a simple way to generate user interfaces that control sets of parameters. The example
demonstrates a variety of different parameter types (int, float, list, etc.)
as well as some customized parameter types

"""


import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui


app = QtGui.QApplication([])

from pyqtgraph.parametertree import Parameter, ParameterTree, registerParameterType
18
from ADoutputs import daq_AO, daq_DO
19 20 21


params = [
22 23
    {'name': 'laser_parameters_397', 'type': 'group', 'title': '397 laser parameters', 'children': [
        {'name': 'piezoA', 'type': 'float', 'value': 0, 'step': 0.2, 'limits': (-10, 10), 'siPrefix': True, 'suffix': 'V'},
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
        {'name': 'piezoB', 'type': 'float', 'value': 0, 'step': 0.05, 'limits': (-1, 1), 'siPrefix': True, 'suffix': 'V'},
        {'name': 'shutter1', 'type': 'bool', 'value': True, 'tip': "This is a checkbox"},
        {'name': 'shutter2', 'type': 'bool', 'value': True, 'tip': "This is a checkbox"},
       
    ]},
    {'name': '866 laser parameters', 'type': 'group', 'children': [
        {'name': 'piezoA', 'type': 'float', 'value': 0, 'step': 0.05, 'limits': (-1, 1), 'siPrefix': True, 'suffix': 'V'},
        {'name': 'piezoB', 'type': 'float', 'value': 0, 'step': 0.05, 'limits': (-1, 1), 'siPrefix': True, 'suffix': 'V'},
        {'name': 'shutter1', 'type': 'bool', 'value': True, 'tip': "This is a checkbox"},
        {'name': 'shutter2', 'type': 'bool', 'value': True, 'tip': "This is a checkbox"},
    ]},
    {'name': '423 laser parameters', 'type': 'group', 'children': [
        {'name': 'piezo', 'type': 'float', 'value': 0, 'step': 0.05, 'limits': (-1, 1), 'siPrefix': True, 'suffix': 'V'},
        {'name': 'shutter1', 'type': 'bool', 'value': True, 'tip': "This is a checkbox"},
    ]},
    {'name': 'Save/Restore functionality', 'type': 'group', 'children': [
        {'name': 'Save State', 'type': 'action'},
        {'name': 'Restore State', 'type': 'action', 'children': [
            {'name': 'Add missing items', 'type': 'bool', 'value': True},
            {'name': 'Remove extra items', 'type': 'bool', 'value': True},
        ]},
    ]},
]

## Create tree of Parameter objects
p = Parameter.create(name='params', type='group', children=params)

51 52 53


"""
54 55 56 57 58 59
## If anything changes in the tree, print a message
def change(param, changes):
    print("tree changes:")
    for param, change, data in changes:
        path = p.childPath(param)
        if path is not None:
60
            childName = '_'.join(path)
61 62
        else:
            childName = param.name()
63 64 65 66 67 68 69
        #print('  parameter: %s'% childName)
        #print('  change:    %s'% change)
        #print('  data:      %s'% str(data))
        #print(path)
        myDict[childName].set_analog_out(data)
        #print('  ----------')
        
70 71 72 73 74
p.sigTreeStateChanged.connect(change)

def valueChanging(param, value):
    print("Value changing (not finalized): %s %s" % (param, value))
    
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"""

def valueChanging(box):
    #print(box.name())
    #print(box.value())
    laser_parameters_397_piezoA.set_analog_out(box.value())
    


p.children()[0].children()[0].sigValueChanging.connect(valueChanging)


laser_parameters_397_piezoA = daq_AO(0)
myDict = {'laser_parameters_397_piezoA': laser_parameters_397_piezoA}


#def whenChange(sb):
#    analog0.set_analog_out(sb.value())
    
#spin.sigValueChanging.connect(whenChange)





100 101 102 103 104 105 106 107 108 109 110 111 112 113

def save():
    global state
    state = p.saveState()
    
def restore():
    global state
    add = p['Save/Restore functionality', 'Restore State', 'Add missing items']
    rem = p['Save/Restore functionality', 'Restore State', 'Remove extra items']
    p.restoreState(state, addChildren=add, removeChildren=rem)
p.param('Save/Restore functionality', 'Save State').sigActivated.connect(save)
p.param('Save/Restore functionality', 'Restore State').sigActivated.connect(restore)


114
## Create  ParameterTree widgets
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
t = ParameterTree()
t.setParameters(p, showTop=False)
t.setWindowTitle('pyqtgraph example: Parameter Tree')


win = QtGui.QWidget()
layout = QtGui.QGridLayout()
win.setLayout(layout)
layout.addWidget(QtGui.QLabel("These are two views of the same data. They should always display the same values."), 0,  0, 1, 2)
layout.addWidget(t, 1, 0, 1, 1)

win.show()
win.resize(800,800)

## test save/restore
s = p.saveState()
p.restoreState(s)


134

135 136 137 138 139
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()