/
main.py
920 lines (664 loc) · 30 KB
/
main.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
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.Qt import Qt
import sys
import scipy
from UI import MainWindow
from UI import VNA_addr_dialog
from UI import MainWidget
from dialogs import pairNameDialog
from dialogs.connectDialog import ConnectDialog
from dialogs.vna_test import VNATestDialog
from print2console import EmittingStream
from widgets.ParameterWidget import ParameterWidget
from widgets.EmbeddingWidget import EmbeddingWidget
from widgets.AlienWidget import AlienWidget
from widgets.PlugWidget import PlugWidget
from widgets.ConsoleWidget import ConsoleWidget
from limits.LimitDialog import LimitDialog
from Communication import Communication
import matplotlib.figure
import matplotlib.backends.backend_qt5
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.pyplot import cm
import os
import time
import random
import pylab
from skrf import Network as rf
from settings import Settings
from snpAnalyze import SNPManipulations
import os
from os.path import splitext
import time
from Sample import Sample
import numpy as np
import threading
import multiprocessing
#import thread
from Project import Project
from calWizard import CalibrationWizard
from decimal import Decimal
import pickle
import matplotlib.ticker
from tabThread import TabThread
from multiprocessing.dummy import Pool as ThreadPool
from genericworker import GenericWorker
class BeldenSNPApp(QtWidgets.QMainWindow, MainWindow.Ui_MainWindow, QtWidgets.QAction, QtWidgets.QFileDialog, QtWidgets.QListView, QtWidgets.QDialog, QtCore.Qt):
'''
This class handles all of the user sent commands from the GUI.
'''
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
fileMenu = self.actionImport_SnP
newProject = self.actionNew_Project
#Initialize sample sample Table
self.sampleTable.setColumnCount(4)
self.sampleTable.setHorizontalHeaderLabels([None, "Name","Date", "Limit"])
self.sampleTable.setSortingEnabled(True)
self.sampleTable.setContextMenuPolicy(self.CustomContextMenu)
self.sampleTable.customContextMenuRequested.connect(self.tableContextMenu)
self.selected = []
#Initialize Tab widget for sample info
#self.sampleTable.customContextMenuRequested.connect(self.tableContextMenu)
#New Project
self.Project = Project()
#Initialize plot parameters
self.activeParameter = "Main" #We want the the first sample tab to display to be the Main tab.
nav = NavigationToolbar(self.graphicsView, self) #Sets up the menu at the bottom of the GUI which lets us interact with the matplotlib plots
self.verticalLayout_3.addWidget(nav)
#Here, we process any arguments that might be sent the program from outside of the interface.
#In other words, when ever a user right click on an SNP files, rather than opening them in Notepad, it would be opened in this interface.
arguments = sys.argv[1:]
if len(arguments):
self.Project.importSNP(arguments)
self.displaySamplesInTable()
self.comm = Communication()
self.settings = Settings()
self.threadpool = QtCore.QThreadPool()
self.poolMutex = QtCore.QMutex()
self.paramWidgetList = []
# Comment out this line to get messanges to appear in terminal instead of in app.
self.setupConsole()
#@QtCore.pyqtSlot()
def addPlug(self):
testName, result = QtWidgets.QInputDialog.getText(self, "Add a Plug Sample",
"Please enter a plug name")
if result and len(testName) > 0 and not testName.isspace():
print("%s!" % testName)
self.Project.addPlug(testName)
self.displaySamplesInTable()
else:
return
def addEmbed(self):
testName, result = QtWidgets.QInputDialog.getText(self, "Add an Embedded Sample",
"Please enter a sample name")
if result and len(testName) > 0 and not testName.isspace():
print("%s!" % testName)
self.Project.addEmbed(testName)
self.displaySamplesInTable()
else:
return
def addAlien(self):
testName, result = QtWidgets.QInputDialog.getText(self, "Add an Alien Test",
"Please enter a Test name")
if result and len(testName) > 0 and not testName.isspace():
print("%s!" % testName)
self.Project.addAlien(testName)
self.displaySamplesInTable()
else:
return
def newProject(self):
self.Project = Project()
self.sampleTable.setRowCount(0)
def deleteSample(self):
self.Project.delete(self.selected)
self.displaySamplesInTable()
self.setActiveSample()
def setLimit(self):
type = None
if self.selected[0].__repr__() == "Embed" or self.selected[0].__repr__() == "Plug" :
type = "Embedding"
limitDialog = LimitDialog(type = type)
result = limitDialog.showDialog()
if result:
item = limitDialog.getSelection().internalPointer().standard
for limit in item.limits.values():
if not (limit == ""):
for function in limit.functions:
for symbol in function.free_symbols:
if not (str(symbol) == 'f'):
ret = QtWidgets.QInputDialog.getDouble(self, "Enter the parameter value", "Please enter the value for the parameter "+ str(symbol) +" : ")
limit.setParamValue(symbol, ret[0])
for sample in self.selected:
worker = GenericWorker(sample.setStandard , standard=item)
worker.signals.finished.connect(self.displaySamplesInTable)
self.threadpool.start(worker)
def setActiveSample(self):
self.plot(None, None)
self.selected = []
for i in self.sampleTable.selectionModel().selectedRows():
self.selected.append(self.sampleTable.item(i.row(),0).data(Qt.UserRole))
#print self.selected
if len(self.selected) >= 1:
self.Project.activeSample = self.selected
if len(self.selected) == 1: #Since only one sample can be displayed at a time
if self.selected[0].__repr__() == "Alien":
self.setupAlien()
elif self.selected[0].__repr__() == "Embed":
self.setupEmbed()
elif self.selected[0].__repr__() == "Plug":
self.setupPlug()
elif self.selected[0].__repr__() == "SNP":
self.displaySampleParams(self.selected)
elif len(self.selected) > 1 or len(self.selected) < 1:
self.displaySampleParams(None)
def displaySamplesInTable(self):
#self.blockSignals( False )
print("Finished TREAD !")
self.blockSignals(False)
measurementCount = len(self.Project.measurements)
self.sampleTable.setRowCount(measurementCount)
for i, measurement in enumerate(self.Project.measurements):
#Column 0 (type)
type = measurement.__repr__()[0]
self.sampleTable.setItem(i, 0, QtWidgets.QTableWidgetItem(type))
self.sampleTable.item(i, 0).setData(Qt.UserRole, measurement)
#Column 1 (name)
self.sampleTable.setItem(i, 1, QtWidgets.QTableWidgetItem(measurement.name))
self.sampleTable.item(i, 1).setData(Qt.UserRole, measurement)
#Column 2 (date)
self.sampleTable.setItem(i, 2, QtWidgets.QTableWidgetItem(measurement.date))
self.sampleTable.item(i, 2).setData(Qt.UserRole, measurement)
#Column 3 (standard)
if measurement.standard is not None:
self.sampleTable.setItem(i, 3, QtWidgets.QTableWidgetItem(measurement.standard.name))
self.sampleTable.item(i, 3).setData(Qt.UserRole, measurement)
self.sampleTable.resizeColumnsToContents()
self.setActiveSample()
def setupEmbed(self):
self.param_tabs.clear()
self.embeddingWidget = EmbeddingWidget(self.param_tabs, sample = self.selected[0], graph=self.graphicsView, comm = self.comm, project=self.Project)
self.embeddingWidget.proc_addPlug.connect(self.addPlug)
self.embeddingWidget.proc_importPlug.connect(self.importPlug)
#self.param_tabs.addTab(self.embeddingWidget.widget, "Embedding Main")
def setupPlug(self):
self.param_tabs.clear()
self.plugWidget = PlugWidget(self.param_tabs, sample = self.selected[0], graph=self.graphicsView, comm = self.comm)
#self.param_tabs.addTab(self.embeddingWidget.widget, "Embedding Main")
def setupAlien(self):
self.param_tabs.clear()
self.alienWidget = AlienWidget(self.param_tabs, sample = self.selected[0], graph=self.graphicsView, comm = self.comm)
#self.param_tabs.addTab(self.embeddingWidget.widget, "Embedding Main")
def importSnp(self):
#Whenever the user clicks on the import SNP button, it opens a file dialog
options = self.Options()
options |= self.DontUseNativeDialog
files, _ = self.getOpenFileNames(self, "Select SNP(s)", "","sNp Files (*.s*p)", options=options)
#print files
print(files)
#This needs to be in thread Look into this : https://realpython.com/python-pyqt-qthread/
#for file in files:
#self.blockSignals( True )
self.blockSignals(True)
worker = GenericWorker(function= self.Project.importSNP, files = files)
worker.signals.finished.connect(self.displaySamplesInTable)
self.threadpool.start(worker)
#self.my_worker.start.connect(self.my_worker.run)
'''self.threadPool.append(my_thread)
self.my_worker = my_worker
self.importSNPTask = self.Project.importSNP(samples = files)
self.importSNPTask.notifyFinished.connect(self.displaySamplesInTable)
self.importSNPTask.started.connect(self.startImport)
self.importSNPTask.start.emit()'''
#self.Project.importSNP(files)
#print(self.rs.RL.items())
#self.plot(self.rs.NEXT) USE THIS !!!!!!!
#self.displaySamplesInTable()
def startImport(self):
print("START IMPORT THREAD : ", int(QtCore.QThread.currentThreadId()))
def plot(self, x=None, param_dict=None, limit = None, unit = "Mhz", avgLimit = None):
self.graphicsView.figure.clear()
#ax.set_xlim(300*(10**3), 10**9)
#self.ax.semilogx(x, self.pitch, '.-', label=label, c=color)
if x is not None or param_dict is not None:
ax=self.graphicsView.figure.add_subplot(111)
#print param_dict.keys()
color=iter(cm.rainbow(np.linspace(0,1,len(param_dict.keys()))))
for key in sorted(param_dict.keys()):
c = next(color)
#print key
#a = scipy.signal.decimate(x, 10)
if len(x) == len(param_dict[key]):
ax.semilogx(x, param_dict[key], label=key, c = c)
#print key
ax.xaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
#self.figure.tight_layout()
ax.grid(which="both")
ax.set_xlabel('Freq ({})'.format(unit))
ax.set_ylabel('dB')
ax.set_title(self.activeParameter)
if self.activeParameter.replace(" ", "") == "PropagationDelay":
ax.set_ylabel('nSec')
if limit is not None:
ax.semilogx(*zip(*limit), linestyle = '--', label="limit", c = c)
if avgLimit is not None:
ax.semilogx(*zip(*avgLimit), linestyle = '--', label="average limit", c = c)
ax.legend(loc='upper left', ncol = 1 if len(param_dict.keys()) <= 8 else 2 )
#self.ax.legend()
self.graphicsView.draw()
def pairRename(self):
pair_names = self.settings.pairNames
num_pairs = self.settings.numPairs
try:
names = pairNameDialog.PairNameDialog(pair_names, num_pairs).getPairNames()
self.settings.pairNames = names
except Exception as e:
print(e)
def pairRenameAlien(self):
pair_names = self.settings.pairNamesAlien
num_pairs = self.settings.numPairs
try:
names = pairNameDialog.PairNameDialog(pair_names, num_pairs).getPairNames()
self.settings.pairNamesAlien = names
except Exception as e:
print(e)
def setPairNumberAlien(self):
sample = self.selected[0]
pair_names = sample.port_name
num_pairs = sample.numPairs
try:
names = pairNameDialog.PairNameDialog(pair_names, num_pairs).getPairNames()
#self.settings.pairNamesAlien = names
sample.port_rename(names)
if len(self.selected) == 1: #Since only one sample can be displayed at a time
self.setupAlien()
except Exception as e:
print(e)
def setPairNumber(self):
sample = self.selected[0]
if sample.__repr__() == "Alien":
self.setPairNumberAlien()
return
snp = sample.snpFile
sided = sample.one_sided
standard = sample.standard
pair_names = sample.port_name
try:
names = pairNameDialog.PairNameDialog(pair_names, sample.num_ports_dd).getPairNames()
#self.settings.pairNames = names
sample.__init__(snp, sided, standard, pair_names = names)
sample.getParameters()
sample.setStandard(standard)
self.Project.activeSample = self.selected
#print self.selected
if len(self.selected) == 1: #Since only one sample can be displayed at a time
self.displaySampleParams(self.selected)
except Exception as e:
print(e)
def tableContextMenu(self, pos):
#print self.selected
try:
if len(self.selected) > 0 and all("SNP" in sample.__repr__() for sample in self.selected):
#Start by getting info on the sample. (If they're all the same type or not)
menu = QtWidgets.QMenu()
setLimit = menu.addAction("Set Limit")
if len(self.selected) == 1:
setPairNumber = menu.addAction("Renumber Pairs")
test_type = menu.addMenu("Set Test Type") #Set the sub menu to select the different types of matrixes
one_sided = test_type.addAction("One Sided")
end_end = test_type.addAction("End to End")
one_sided.setCheckable(True)
end_end.setCheckable(True)
exportExcel = menu.addAction("Export To Excel")
exportPDF = menu.addAction("Export To PDF")
delete = menu.addAction("Delete")
#get test type for samples. If theyre all one sided, all
#end-end or all different.
#To start get the test type of the first sample
_one_sided = self.selected[0].one_sided
print(_one_sided)
for sample in self.selected:
if _one_sided != sample.one_sided:
_one_sided = None
break
if _one_sided == True:
one_sided.setChecked(True)
end_end.setChecked(False)
elif _one_sided == False:
one_sided.setChecked(False)
end_end.setChecked(True)
else:
one_sided.setChecked(False)
end_end.setChecked(False)
action = menu.exec_(QtGui.QCursor.pos())
if action == one_sided:
for sample in self.selected:
sample.reCalc(one_sided = True)
self.Project.activeSample = self.selected
#print self.selected
if len(self.selected) == 1: #Since only one sample can be displayed at a time
self.displaySampleParams(self.selected)
elif len(self.selected) > 1:
self.displaySampleParams(None)
elif action == end_end:
for sample in self.selected:
sample.reCalc(one_sided = False)
if len(self.selected) == 1: #Since only one sample can be displayed at a time
self.displaySampleParams(self.selected)
elif len(self.selected) > 1:
self.displaySampleParams(None)
elif action == exportExcel:
print(self.selected)
self.generateExcel()
elif action == exportPDF:
print(self.selected)
self.generatePDF()
elif action == delete:
self.deleteSample()
elif action == setLimit:
self.setLimit()
#self.Project.activeMeasurements = selected
elif action == setPairNumber and len(self.selected) == 1:
self.setPairNumber()
return 1
elif len(self.selected) > 0 and not all("SNP" in sample.__repr__() for sample in self.selected):
menu = QtWidgets.QMenu()
setLimit = menu.addAction("Set Limit")
if len(self.selected) == 1:
setPairNumber = menu.addAction("Renumber Pairs")
if self.selected[0].__repr__() == "Embed":
saveDeembed = menu.addAction("Save Embedding Measurement")
exportExcel = menu.addAction("Export To Excel")
exportPDF = menu.addAction("Export To PDF")
delete = menu.addAction("Delete")
#get test type for samples. If theyre all one sided, all
#end-end or all different.
#To start get the test type of the first sample
action = menu.exec_(QtGui.QCursor.pos())
if action == exportExcel:
print(self.selected)
self.generateExcel()
elif action == exportPDF:
print(self.selected)
self.generatePDF()
elif action == delete:
self.deleteSample()
elif action == setLimit:
self.setLimit()
elif action == saveDeembed:
self.saveDeembedding()
elif action == setPairNumber and len(self.selected) == 1:
self.setPairNumber()
#self.Project.activeMeasurements = selected
return 1
menu = QtWidgets.QMenu()
addSNP = menu.addAction("Add Sample")
addAlien = menu.addAction("Add Alien Sample")
addEmbed = menu.addAction("Add Emdedding Sample")
addPlug = menu.addAction("Add Plug Sample")
selectAll = menu.addAction("Select All")
action = menu.exec_(QtGui.QCursor.pos())
if action == selectAll:
self.sampleTable.selectAll()
elif action == addSNP:
self.importSnp()
elif action == addAlien:
self.addAlien()
elif action == addEmbed:
self.addEmbed()
elif action == addPlug:
self.addPlug()
except Exception as e:
print(e)
def generateExcel(self):
#file, _ = self.getSaveFileName(self,"Export Excel Repport", "","Excel File (*.xlsx)")
if len(self.selected) == 0:
samples = self.Project.measurements
else:
samples = self.selected
print(samples)
self.Project.generateExcelReport(samples)
def generatePDF(self):
#file, _ = self.getSaveFileName(self,"Export Excel Repport", "","Excel File (*.xlsx)")
if len(self.selected) == 0:
samples = self.Project.measurements
else:
samples = self.selected
self.Project.generatePDFReport(samples)
def displaySampleParams(self, sample):
currentTab = self.activeParameter
if sample == None:
self.param_tabs.clear()
return
self.param_tabs.clear()
#print sample
self.sample = sample[0]
#print self.sample
#Create a tab widget containing a main tab and all the parameters
#Start off by creating the home tab
self.mainTab = QtWidgets.QWidget()
self.mainTabWidget = MainWidget.Ui_MainWidget()
self.mainTabWidget.setupUi(self.mainTab)
self.setupMainTab()
self.param_tabs.addTab(self.mainTab, "Main")
self.tab_list = []
self.tab_list.append(self.mainTab)
self.paramWidgetList = []
self.paramWidgetList.append(None)
#values = self.calculateErrors(pool=os.cpu_count())
allPass = True
failedParams = []
self.blockSignals(True)
for param in self.sample.parameters:
self.new_tab = ParameterWidget(param.replace(" ", ''), self.sample , graph = self.graphicsView) #, values[param.replace(" ","")])
self.paramWidgetList.append(self.new_tab)
self.tab_list.append(self.new_tab.widget)
self.param_tabs.addTab(self.new_tab.widget, param)
allPass = allPass and self.new_tab.hasPassed
if not self.new_tab.hasPassed:
failedParams.append(param)
if allPass:
self.mainTabWidget.passLabel.setText("Pass")
else:
self.mainTabWidget.passLabel.setText("Fail")
self.mainTabWidget.failsLabel.setText(str(failedParams))
for i in range(0,self.param_tabs.count()):
if self.param_tabs.tabText(i) == currentTab:
index = i
break
else:
index = 0
self.blockSignals(False)
self.param_tabs.setCurrentIndex(index)
self.tabChange(index)
def tabChange(self, index):
#This function is called whenever a parameter
self.tab_index = index #self.param_tabs.currentIndex()
self.activeParameter = self.param_tabs.tabText(self.tab_index)
print("Active Parameter = ", self.activeParameter)
if self.selected:
sample = self.selected[0]
else:
return
#print index
if self.tab_index >= 1:
if sample.__repr__() == "Embed":
tab_index = self.param_tabs.currentIndex()
activeParameter = self.param_tabs.tabText(self.tab_index)
self.embeddingWidget.embedPlotUpdate(activeParameter)
if sample.__repr__() == "Plug":
tab_index = self.param_tabs.currentIndex()
activeParameter = self.param_tabs.tabText(self.tab_index)
self.plugWidget.plugPlotUpdate(activeParameter)
elif sample.__repr__() == "Alien":
try:
self.alienWidget
except AttributeError:
self.alienWidget = None
if self.alienWidget is None:
self.setupAlien()
self.alienWidget.alienPlotUpdate()
elif sample.__repr__() == "SNP":
currentParamWidget = self.paramWidgetList[self.tab_index]
currentParamWidget.plotUpdate(sample, self.activeParameter)
#print(self.sample.frequency.unit)
#worstValue = sample.getWorstValue(self.activeParameter)
#print(worstValue)
else:
self.plot(None, None)
def setupMainTab(self):
self.mainTabWidget.testNameLabel.setText(self.sample.name+" : ")
self.mainTabWidget.dateLabel.setText(self.sample.date.__str__())
self.mainTabWidget.limitLabel.setText(self.sample.standard.__str__())
def importPlug(self):
options = self.Options()
options |= self.DontUseNativeDialog
file, _ = self.getOpenFileName(self, "Select Plug", "", "Plug (*.plug)", options=options)
#print files
print(file)
p = self.Project.addPlug(" ")
p.deserialize(file)
self.displaySamplesInTable()
def importDeembedding(self):
options = self.Options()
options |= self.DontUseNativeDialog
file, _ = self.getOpenFileName(self, "Select Deembeding", "", "Deembedding (*.mbed)", options=options)
#print files
print(file)
f = open(file, 'rb')
temp = pickle.load(f)
f.close()
plug = temp.plug
self.Project.measurements.append(plug)
d = self.Project.addEmbed(" ")
d.deserialize(file)
self.displaySamplesInTable()
def saveDeembedding(self):
if len(self.selected) == 1:
sample = self.selected[0]
outputFile, _ = self.getSaveFileName(self, "Save Deembedding", "","Deembedding file (*.mbed)")
sample.serialize(file = outputFile)
def saveProject(self):
pass
def openProject(self):
pass
def connect(self):
connectDialog = ConnectDialog(self.comm)
res=connectDialog.showDialog()
if res and self.comm._connected:
if connectDialog.calib is False:
self.comm.setCal(connectDialog.newDial.typeBox.currentIndex())
self.actionWho_am_I.setEnabled(True)
self.actionCalibrate.setEnabled(True)
self.actionCalibrate_2.setEnabled(True)
self.actionDisconnect.setEnabled(True)
self.actionConnect.setEnabled(False)
self.actionMeasure.setEnabled(True)
self.actionRun.setEnabled(True)
def disconnect(self):
self.comm.disconnect()
self.actionMeasure.setEnabled(False)
self.actionWho_am_I.setEnabled(False)
self.actionCalibrate.setEnabled(False)
self.actionCalibrate_2.setEnabled(False)
self.actionDisconnect.setEnabled(False)
self.actionRun.setEnabled(False)
self.actionConnect.setEnabled(True)
def whoAmI(self):
self.comm.whoAmI()
def aquire(self):
try:
vnaDialog = VNATestDialog()
res = vnaDialog.exec_()
if res:
name = vnaDialog.getSampleName()
ports = vnaDialog.getPorts()
sample_file = self.comm.acquire(name, ports, vnaDialog.getVNACOnfiguration())
print(sample_file)
self.Project.importSNP([sample_file])
self.displaySamplesInTable()
except Exception as e:
print(e)
'''try:
if file:=self.comm.aquireInterface():
self.Project.importSNP([file])
self.displaySamplesInTable()
except Exception as e:
print(e)'''
def simpleAquire(self):
pass
def reject(self):
pass
def calibrate(self):
print("CALIBRATE")
self.comm.calibrate()
def setupConsole(self):
self.consoleWidget = ConsoleWidget(parent = self.console_widget)
sys.stdout = EmittingStream(textWritten=self.consoleWidget.writeToConsole) # test
def __del__(self): # test
# Restore sys.stdout
sys.stdout = sys.__stdout__
class Addr_Dialog:
def getAddr(self):
self.comm = Communication()
dialog = QtWidgets.QDialog()
addr_dialog = VNA_addr_dialog.Ui_Addr_Dialog()
addr_dialog.setupUi(dialog)
addr_dialog.plainTextEdit.setPlainText(self.comm.VNAAddress)
result = dialog.exec_()
print("here")
if not result:
return 0
if result:
addr = addr_dialog.plainTextEdit.toPlainText()
print("sent")
if len(addr) < 1:
return 0
return addr
'''from UI import port_renumber
class Port_Renumbering:
def getPortNumbering(self, fromPort):
dialog = QtWidgets.QDialog()
pr = port_renumber.Ui_Dialog()
pr.setupUi(dialog)
result = dialog.exec_()
_from = None
_to = None
if not result:
return None, None
if result:
_from = pr.fromLineEdit.text()
_to = pr.toLineEdit.text()
print("sent")
if len(_from) < 1 or len(_to) < 1:
return None, None
return _from, _to'''
def main():
app = QtWidgets.QApplication(sys.argv) # A new instance of QApplication
app.setStyle('fusion')
app.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
screen_resolution = app.desktop().screenGeometry()
width, height = screen_resolution.width(), screen_resolution.height()
#pixmap = QtGui.QPixmap("splash.jpeg")
#splash = QtWidgets.QSplashScreen(pixmap)
#splash.show()
#time.sleep(10)
form = BeldenSNPApp() # We set the form to be our ExampleApp (design)
#form.show() # Show the form
form.showMaximized()
print("Starting")
print(sys.argv)
'''sys._excepthook = sys.excepthook
def exception_hook(exctype, value, traceback):
print(exctype, value, traceback)
sys._excepthook(exctype, value, traceback)
sys.exit(1)
sys.excepthook = exception_hook
#splash.finish(form)
sys.exit(app.exec_())'''
app.exec_()
app.deleteLater()
if __name__ == '__main__': # if we're running file directly and not importing it
main() # run the main function