-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcustom_widgets.py
More file actions
489 lines (395 loc) · 17.4 KB
/
custom_widgets.py
File metadata and controls
489 lines (395 loc) · 17.4 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
from PyQt5.QtWidgets import (QPushButton,QFormLayout,QWidget,
QLineEdit,QVBoxLayout,QSizePolicy,
QGroupBox,QHBoxLayout,QComboBox,QFrame,
QLabel,QSpacerItem, QStatusBar)
from PyQt5.QtGui import (QValidator,QDoubleValidator,QIntValidator)
#from PyQt5.qtc import ()
from sys import float_info, maxsize
class MyDoubleValidator(QDoubleValidator):
"""
Fix for strange behavior of default QDoubleValidator used in
CurrentSourceWidget
http://learnwithhelvin.blogspot.com/2010/01/qdoublevalidator.html
(needed some tweaking)
"""
def __init__(self, bottom: float = float_info.min,
top:float = float_info.max,
decimals:int = float_info.dig, parent: QWidget = None):
super().__init__(bottom, top, decimals, parent)
def validate(self, input_value : str, pos : int) -> tuple:
state, char, pos = super().validate(input_value, pos)
if input_value == '' or input_value == '.':
return QValidator.Intermediate,char, pos
if state != QValidator.State.Acceptable:
return QValidator.Invalid,char, pos
return QValidator.Acceptable,char, pos
class ColoredButton(QPushButton):
"""the default button to be used in the program
(makes it easy to change the color of all buttons and so on)"""
def __init__(self, *args, rgb: tuple = (64, 137, 255), **kwargs):
super().__init__(*args, **kwargs)
color = 'rgb' + str(rgb)
self.setStyleSheet("""
QPushButton{
background-color: """ + color + """;\n
font: 18px;
min-width: 2em;
padding: 6px;
}""")
class MyGroupBox(QGroupBox):
"""custom groupbox to make the border darker and make
further style sheet changes easier"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setStyleSheet("""QGroupBox {
border: 1px solid black;
margin-top: 4px;
}
QGroupBox:title{
top: -8px;
left: 10px;
padding-top: 2px;
}""")
class FieldControllerWidget(MyGroupBox):
"""Widget for displaying the fieldController controls"""
def __init__(self,*args,**kwargs):
super().__init__(*args, **kwargs)
layout = QFormLayout()
self.fieldInput = QLineEdit('5000')
self.fieldInput.setValidator(QIntValidator())
layout.addRow('Field (Gauss)',self.fieldInput)
self.delayInput = QLineEdit('10')
self.delayInput.setValidator(QDoubleValidator())
layout.addRow('Field Delay (sec)',self.delayInput)
self.setMaximumSize(350,400)
self.setLayout(layout)
class CurrentSourceWidget(MyGroupBox):
"""Widget for displaying the current controls"""
def __init__(self,*args,**kwargs):
super().__init__(*args, **kwargs)
layout = QFormLayout()
self.currentInput = QLineEdit('1e-6')
self.currentInput.setValidator(QDoubleValidator())
layout.addRow('Current (A)',self.currentInput)
self.vLimitInput = QLineEdit('10')
self.vLimitInput.setValidator(QDoubleValidator())
layout.addRow('V-Limit', self.vLimitInput)
self.setMaximumSize(350,400)
self.setLayout(layout)
class VoltmeterWidget(MyGroupBox):
"""Widget for displaying the voltmeter controls"""
def __init__(self,*args,**kwargs):
super().__init__(*args, **kwargs)
layout = QFormLayout()
self.integratingInput = QComboBox()
self.integratingInput.addItem('~2s')
self.integratingInput.addItem('~5s')
self.integratingInput.addItem('~10s')
self.integratingInput.addItem('~20s')
self.integratingInput.setCurrentIndex(1)
layout.addRow('Integrating Time',self.integratingInput)
self.RangeInput = QComboBox()
self.RangeInput.addItem('Enable Auto-Range')
self.RangeInput.addItem('3mV Range')
self.RangeInput.addItem('30mV Range')
self.RangeInput.addItem('300mV Range')
self.RangeInput.addItem('3V Range')
self.RangeInput.addItem('30V Range')
self.RangeInput.addItem('Disable Auto-Range')
layout.addRow('Range Control',self.RangeInput)
self.setMaximumSize(350,400)
self.setLayout(layout)
class SampleInfoWidget(MyGroupBox):
"""Widget for sample inforamtion inputs"""
def __init__(self,*args,**kwargs):
super().__init__(*args, **kwargs)
layout = QFormLayout()
self.sampleIDInput = QLineEdit()
layout.addRow('Sample ID',self.sampleIDInput)
self.tempInput = QLineEdit('293')
self.tempInput.setValidator(MyDoubleValidator(0))
layout.addRow('Temp',self.tempInput)
self.setLayout(layout)
self.thicknessInput = QLineEdit('1')
self.thicknessInput.setValidator(MyDoubleValidator(0))
layout.addRow('Thickness (um)', self.thicknessInput)
self.dataPointsInput = QLineEdit('10')
#this is the max value the validator will take
self.dataPointsInput.setValidator(QIntValidator(0,2147483647))
layout.addRow('# of data points',self.dataPointsInput)
self.setMaximumSize(350,400)
self.setLayout(layout)
class Inputs(QWidget):
"""column1 of the Hall tab"""
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
#make the first column
layout = QVBoxLayout()
#UI section for sample information
self.sampleInfoWidget = SampleInfoWidget('Sample Information')
layout.addWidget(self.sampleInfoWidget)
#UI section for fieldController
self.fieldControllerWidget = FieldControllerWidget('Field Controller B-H 15')
layout.addWidget(self.fieldControllerWidget)
#UI section for Voltmeter
self.voltmeterWidget = VoltmeterWidget('Voltmeter controls - Keithley 182')
layout.addWidget(self.voltmeterWidget)
#UI section for current
self.currentWidget = CurrentSourceWidget('Current Source - Keithley 220')
layout.addWidget(self.currentWidget)
#add the buttons
self.goBtn = ColoredButton('GO')
self.goBtn.setMinimumSize(400,55)
layout.addWidget(self.goBtn)
self.abortBtn = ColoredButton('Abort', rgb = (255,0,0))
self.abortBtn.setEnabled(False)
self.abortBtn.setMinimumSize(400,55)
layout.addWidget(self.abortBtn)
#add a spacer on the bottom
spacer = QSpacerItem(100,100, hPolicy = QSizePolicy.Preferred,
vPolicy = QSizePolicy.Expanding)
layout.addItem(spacer)
subLayout = QHBoxLayout()
self.backupBtn = ColoredButton('Backup Data')
subLayout.addWidget(self.backupBtn)
self.repeatBtn = ColoredButton('repeat')
self.repeatBtn.setCheckable(True)
subLayout.addWidget(self.repeatBtn)
layout.addLayout(subLayout)
self.setSizePolicy(QSizePolicy.Maximum,QSizePolicy.Expanding)
self.setLayout(layout)
def textDict(self) -> dict:
"""return a dictionary of the inputs"""
dict = {'temp': self.sampleInfoWidget.tempInput.text(),
'sampleID': self.sampleInfoWidget.sampleIDInput.text(),
'thickness': float(self.sampleInfoWidget.thicknessInput.text()),
'dataPoints': int(self.sampleInfoWidget.dataPointsInput.text()),
'field': float(self.fieldControllerWidget.fieldInput.text()),
'fieldDelay': float(self.fieldControllerWidget.delayInput.text()),
'current': float(self.currentWidget.currentInput.text()),
'vLim': float(self.currentWidget.vLimitInput.text()),
'intgrtTime': self.voltmeterWidget.integratingInput.currentText(),
'rangeCtrl': self.voltmeterWidget.RangeInput.currentText()}
return dict
class FitResults1(QFrame):
"""widget to display the results, located on the right side"""
def __init__(self,*args,**kwargs):
super().__init__(*args, **kwargs)
self.setFrameShape(QFrame.Box)
self.setFrameShadow(QFrame.Plain)
self.setLineWidth(1)
layout = QVBoxLayout()
layout = QVBoxLayout()
self.SheetRes1Lbl = QLabel('Sheet Res 1 (Ohm)')
layout.addWidget(self.SheetRes1Lbl)
self.SheetRes1Display = QLineEdit()
self.SheetRes1Display.setReadOnly(True)
layout.addWidget(self.SheetRes1Display)
self.SheetRes2Lbl = QLabel('Sheet Res 2 (Ohm)')
layout.addWidget(self.SheetRes2Lbl)
self.SheetRes2Display = QLineEdit()
self.SheetRes2Display.setReadOnly(True)
layout.addWidget(self.SheetRes2Display)
self.Rxy1Lbl = QLabel('Rxy1 (Ohm)')
layout.addWidget(self.Rxy1Lbl)
self.Rxy1Display = QLineEdit()
self.Rxy1Display.setReadOnly(True)
layout.addWidget(self.Rxy1Display)
self.Rxy2Lbl = QLabel('Rxy2 (Ohm)')
layout.addWidget(self.Rxy2Lbl)
self.Rxy2Display = QLineEdit()
self.Rxy2Display.setReadOnly(True)
layout.addWidget(self.Rxy2Display)
self.q1Lbl = QLabel('q1')
layout.addWidget(self.q1Lbl)
self.q1Display = QLineEdit()
self.q1Display.setReadOnly(True)
layout.addWidget(self.q1Display)
self.q2Lbl = QLabel('q2')
layout.addWidget(self.q2Lbl)
self.q2Display = QLineEdit()
self.q2Display.setReadOnly(True)
layout.addWidget(self.q2Display)
self.FfactorLbl = QLabel('Ffactor')
layout.addWidget(self.FfactorLbl)
self.FfactorDisplay = QLineEdit()
self.FfactorDisplay.setReadOnly(True)
layout.addWidget(self.FfactorDisplay)
self.HallRatioLbl = QLabel('HallRatio')
layout.addWidget(self.HallRatioLbl)
self.HallRatioDisplay = QLineEdit()
self.HallRatioDisplay.setReadOnly(True)
layout.addWidget(self.HallRatioDisplay)
spacer = QSpacerItem(100,100, hPolicy = QSizePolicy.Preferred,
vPolicy = QSizePolicy.Expanding)
layout.addItem(spacer)
self.setLayout(layout)
self.setMinimumSize(120,500)
self.setMaximumSize(300,1000)
class FitResults2(QFrame):
"""widget to display the results, located on the right side"""
def __init__(self,*args,**kwargs):
super().__init__(*args, **kwargs)
self.setFrameShape(QFrame.Box)
self.setFrameShadow(QFrame.Plain)
self.setLineWidth(1)
layout = QVBoxLayout()
layout = QVBoxLayout()
self.AvgSheetResLbl = QLabel('Avg Sheet Res (Ohm)')
layout.addWidget(self.AvgSheetResLbl)
self.AvgSheetResDisplay = QLineEdit()
self.AvgSheetResDisplay.setReadOnly(True)
layout.addWidget(self.AvgSheetResDisplay)
self.AvgTransResLbl = QLabel('Avg Trans Res (Ohm)')
layout.addWidget(self.AvgTransResLbl)
self.AvgTransResDisplay = QLineEdit()
self.AvgTransResDisplay.setReadOnly(True)
layout.addWidget(self.AvgTransResDisplay)
self.AvgResLbl = QLabel('Avg Res (Ohm-cm)')
layout.addWidget(self.AvgResLbl)
self.AvgResDisplay = QLineEdit()
self.AvgResDisplay.setReadOnly(True)
layout.addWidget(self.AvgResDisplay)
self.SheetConcLbl = QLabel('Sheet Conc (cm-2)')
layout.addWidget(self.SheetConcLbl)
self.SheetConcDisplay = QLineEdit()
self.SheetConcDisplay.setReadOnly(True)
layout.addWidget(self.SheetConcDisplay)
self.BulkConcLbl = QLabel('Bulk Conc (cm-3)')
layout.addWidget(self.BulkConcLbl)
self.BulkConcDisplay = QLineEdit()
self.BulkConcDisplay.setReadOnly(True)
layout.addWidget(self.BulkConcDisplay)
self.HallCoefLbl = QLabel('Hall Coef (cm3/C)')
layout.addWidget(self.HallCoefLbl)
self.HallCoefDisplay = QLineEdit()
self.HallCoefDisplay.setReadOnly(True)
layout.addWidget(self.HallCoefDisplay)
self.HallMobilityLbl = QLabel('Hall Mobility (cm2/Vs)')
layout.addWidget(self.HallMobilityLbl)
self.HallMobilityDisplay = QLineEdit()
self.HallMobilityDisplay.setReadOnly(True)
layout.addWidget(self.HallMobilityDisplay)
spacer = QSpacerItem(100,100, hPolicy = QSizePolicy.Preferred,
vPolicy = QSizePolicy.Expanding)
layout.addItem(spacer)
self.setLayout(layout)
self.setMaximumSize(200,1000)
class BelowGraphWidget(QWidget):
"""widget placed below the graph"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
layout = QVBoxLayout()
self.pathLbl = QLabel('Output File Path')
layout.addWidget(self.pathLbl)
self.pathInput = QLineEdit('C:/Users/lw5968/Documents/Hall Data/test.txt')
layout.addWidget(self.pathInput)
self.rSqrLbl = QLabel('R-Square Value')
layout.addWidget(self.rSqrLbl)
self.rContainer = QFrame()
self.rContainer.setFrameShape(QFrame.Box)
self.rContainer.setFrameShadow(QFrame.Plain)
self.rContainer.setLineWidth(1)
frameLayout = QHBoxLayout()
self.box1 = QLineEdit()
self.box1.setReadOnly(True)
frameLayout.addWidget(self.box1)
self.box2 = QLineEdit()
self.box2.setReadOnly(True)
frameLayout.addWidget(self.box2)
self.box3 = QLineEdit()
self.box3.setReadOnly(True)
frameLayout.addWidget(self.box3)
self.box4 = QLineEdit()
self.box4.setReadOnly(True)
frameLayout.addWidget(self.box4)
self.box5 = QLineEdit()
self.box5.setReadOnly(True)
frameLayout.addWidget(self.box5)
self.box6 = QLineEdit()
self.box6.setReadOnly(True)
frameLayout.addWidget(self.box6)
self.box7 = QLineEdit()
self.box7.setReadOnly(True)
frameLayout.addWidget(self.box7)
self.box8 = QLineEdit()
self.box8.setReadOnly(True)
frameLayout.addWidget(self.box8)
self.rContainer.setLayout(frameLayout)
layout.addWidget(self.rContainer)
self.setLayout(layout)
def textDict(self) -> dict:
"""returns a dictionary of all the text in this widget for ease of access later"""
dict = {'box1': self.box1.text(), 'box2': self.box2.text(),
'box3': self.box3.text(), 'box4': self.box4.text(),
'box5': self.box5.text(), 'box6': self.box6.text(),
'box7': self.box7.text(), 'box8': self.box8.text(),
'path': self.pathInput.text()}
return dict
class IVColumn1(QWidget):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
layout = QVBoxLayout()
self.currentLbl = QLabel('Current (A)')
layout.addWidget(self.currentLbl)
self.currentInput = QLineEdit('1e-6')
layout.addWidget(self.currentInput)
self.integratingLbl = QLabel('Voltmeter Integrating Time (s)')
layout.addWidget(self.integratingLbl)
self.integratingInput = QComboBox()
self.integratingInput.addItem('~2s')
self.integratingInput.addItem('~5s')
self.integratingInput.addItem('~10s')
self.integratingInput.addItem('~20s')
self.integratingInput.setCurrentIndex(1)
layout.addWidget(self.integratingInput)
self.voltLimitLbl = QLabel('Voltage Limit (V)')
layout.addWidget(self.voltLimitLbl)
self.voltLimitInput = QLineEdit('10')
layout.addWidget(self.voltLimitInput)
self.resistanceLbl = QLabel('Resistance (ohms)')
layout.addWidget(self.resistanceLbl)
self.resistanceDisplay = QLineEdit('0')
self.resistanceDisplay.setReadOnly(True)
layout.addWidget(self.resistanceDisplay)
self.switchLbl = QLabel('Switch Number')
layout.addWidget(self.switchLbl)
self.switches = QComboBox()
for i in range(6):
self.switches.addItem(str(i + 1))
layout.addWidget(self.switches)
self.goBtn = ColoredButton('Go')
self.goBtn.setMinimumSize(400,55)
layout.addWidget(self.goBtn)
self.abortBtn = ColoredButton('Abort', rgb = (255,0,0))
self.abortBtn.setEnabled(False)
self.abortBtn.setMinimumSize(400,55)
layout.addWidget(self.abortBtn)
spacer = QSpacerItem(100,100, hPolicy = QSizePolicy.Preferred,
vPolicy = QSizePolicy.Expanding)
layout.addItem(spacer)
self.setLayout(layout)
self.setMaximumSize(200,1000)
def textDict(self) -> dict:
dict = {'current': float(self.currentInput.text()),
'switchNumber': self.switches.currentText(),
'intgrtTime': self.integratingInput.currentText(),
'voltLim': float(self.voltLimitInput.text())}
return dict
class status(QStatusBar):
"""status bar at the bottom of the application to display useful information"""
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.setStyleSheet('QStatusBar::item {border: None;}')
self.switchLbl = QLabel('switch: n/a')
self.fieldLbl = QLabel('field: Off')
self.stateLbl = QLabel("state: Idle")
spacer = QWidget()
spacer.setFixedWidth(50)
spacer2 = QWidget()
spacer2.setFixedWidth(50)
self.addPermanentWidget(self.stateLbl)
self.addPermanentWidget(spacer)
self.addPermanentWidget(self.fieldLbl)
self.addPermanentWidget(spacer2)
self.addPermanentWidget(self.switchLbl)