-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConnectPanel.py
125 lines (96 loc) · 3.78 KB
/
ConnectPanel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from PyQt5 import QtCore
from PyQt5.QtCore import Qt
from PyQt5 import QtGui
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QWidget
from PyQt5 import uic
from LabJackPython import deviceCount, listAll
from labjack import MyU3
Form, Base = uic.loadUiType('connect.ui')
class ConnectPanel(Base, Form):
childNames = ['deviceComboBox', 'propertyViewer']
deviceType = 3
deviceOpened = QtCore.pyqtSignal(MyU3)
deviceDisconnected = QtCore.pyqtSignal()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# self.groupButtons()
self.setupUi(self)
self.gatherChildren()
self.setupComboBox()
self.propertyViewer.setColumnCount(2)
self.propertyViewer.setHorizontalHeaderItem(0, QtWidgets.QTableWidgetItem('Property'))
self.propertyViewer.setHorizontalHeaderItem(1, QtWidgets.QTableWidgetItem('Value'))
self.propertyViewer.horizontalHeader().setStretchLastSection(True)
self.connectButtons()
def gatherChildren(self):
for name in self.childNames:
child = self.findChild(QtCore.QObject, name)
if child is not None:
setattr(self, name, child)
else:
print("Child '{}' not found!".format(name))
def setupComboBox(self):
self.deviceComboBox.addItem('Select a device...')
self.deviceComboBox.insertSeparator(1)
self.deviceComboBox.addItem('Refresh list')
self.deviceComboBox.insertSeparator(3)
self.deviceComboBox.currentIndexChanged.connect(self.comboBoxCallback)
self.comboBoxCallback(2)
def comboBoxCallback(self, newIndex):
if newIndex == 0:
pass
elif newIndex == 2:
self.refreshDeviceList()
self.deviceComboBox.setCurrentIndex(0)
elif newIndex >= 4:
self.selectDevice(newIndex - 4)
def clearDevices(self):
self.propertyViewer.clearContents()
self.propertyViewer.setRowCount(0)
MyU3.close_all()
self.deviceDisconnected.emit()
for i in range(self.deviceComboBox.count(), 3, -1):
self.deviceComboBox.removeItem(i)
def refreshDeviceList(self):
self.clearDevices()
devices = listAll(self.deviceType)
self.deviceList = []
for key in devices.keys():
self.deviceComboBox.addItem(devices[key]['deviceName'])
self.deviceList.append(devices[key])
def selectDevice(self, index):
dev = self.deviceList[index]
sn = dev['serialNumber']
self.myu3instance = MyU3(False, sn)
self.displayProperties()
def displayProperties(self):
self.updatePropertyViewer()
self.deviceOpened.emit(self.myu3instance)
def updatePropertyViewer(self):
prop = self.myu3instance.configU3()
ioprops = self.myu3instance.configIO()
prop['FIOAnalog'] = ioprops['FIOAnalog']
prop['EIOAnalog'] = ioprops['EIOAnalog']
self.propertyViewer.setRowCount(len(prop))
for i, (key, val) in enumerate(prop.items()):
self.propertyViewer.setItem(i, 0, QtWidgets.QTableWidgetItem(key))
self.propertyViewer.setItem(i, 1, QtWidgets.QTableWidgetItem(str(val)))
def groupButtons(self, buttons, tag):
if not hasattr(self, 'buttonGroups'):
self.buttonGroups = {}
group = QtWidgets.QButtonGroup()
for i, b in enumerate(buttons):
b.setCheckable(True)
b.setChecked(i == 0)
group.addButton(b)
group.setId(b, i)
group.setExclusive(True)
self.buttonGroups[tag] = group
def connectButtons(self):
pass
if __name__ == '__main__':
app = QtWidgets.QApplication([])
panel = ConnectPanel()
panel.show()
app.exec_()