-
Notifications
You must be signed in to change notification settings - Fork 3
/
gui.py
2316 lines (1982 loc) · 81.5 KB
/
gui.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
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
############################################################################
#
# gui.py - Rev 1.0
# Copyright (C) 2021-4 by Joseph B. Attili, aa2il AT arrl DOT net
#
# GUI-related functions for pySDR
#
############################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
############################################################################
import sys
import functools
import time
import inspect
import types
from pprint import pprint
from Tables import *
from rig_control import *
from Plotting import *
from receiver import *
from rig_io.ft_tables import *
from rig_io.presets import *
#from rtty import * # Disabled until we get a chance to bring it up to date
from widgets_qt import *
import collections
from utils import show_threads
from utilities import freq2band
try:
if True:
from PyQt6.QtCore import QTimer,qVersion
else:
from PySide6.QtCore import QTimer,qVersion
except ImportError:
from PyQt5.QtCore import QTimer,qVersion
############################################################################
# Structure to hold a bandmap spot
class SPOT:
def __init__(self,call,freq,color):
self.call=call
self.freq=freq
self.color=color
############################################################################
# The GUI
class SDR_GUI(QMainWindow):
def __init__(self,P,parent=None):
super(SDR_GUI, self).__init__(parent)
# Init
self.P=P
print('QT Version=',qVersion())
# Put up splash screen
self.P = P
self.parent=parent
self.splash=SPLASH_SCREEN(P.app,'splash.png')
self.status_bar = self.splash.status_bar
# Function that actually constructs the gui
def construct_gui(self):
# Init
P=self.P
self.gui_closed=False
self.prev_group=''
# Splash will close when main window of gui is open
self.splash.splash.finish(P.gui)
# Wait for SDR to start up
print('\npySDR_GUI: Init GUI ...\n')
if P.MP_SCHEME==1:
while not P.sdr:
print('pySDR_GUI: Waiting for SDR to startup ...')
time.sleep(1)
elif P.MP_SCHEME==2:
msg = P.pipe.recv()
print('msg1=',msg)
elif P.MP_SCHEME==3:
print('pySDR_GUI: Waiting for SDR to startup ...')
while P.nchunks<2:
time.sleep(1)
else:
print('GUI - Unknown MP SCHEME',P.MP_SCHEME)
sys.exit(0)
# Init
self.P=P
self.last_psd_update = time.time()
self.ShowParams()
self.SHOW_BASEBAND_PLOTS=False
self.itune_cnt=0
self.P.AF_FILTER_NUM = None
self.P.audio_playback = False
# Start by putting up the root window
self.win = QWidget()
self.setCentralWidget(self.win)
self.setWindowTitle('pySDR by AA2IL')
# We use a simple grid to layout controls
self.grid = QGridLayout()
self.win.setLayout(self.grid)
nrows=15
ncols=11
# Status bar
self.status_bar = StatusBar(self,nrows+1)
# Create wideband RTTY window
if self.P.ENABLE_RTTY:
self.rtty=RTTY_GUI(P)
################################################################################
# Add top row buttons
# Start & stop rx processing - don't use this much so its disabled
col=-1
if False:
col+=1
self.btn1 = QPushButton('Start RX')
self.btn1.setToolTip('Start/stop receiver')
self.btn1.setCheckable(True)
self.btn1.clicked.connect(self.StartStopRX)
self.grid.addWidget(self.btn1,0,col)
else:
self.btn1 = None
self.btn1state=True
# Start & stop RF PSD
col+=1
self.btn2 = QPushButton('Start RF PSD')
self.btn2.setToolTip('Start/stop RF PSD')
self.btn2.setCheckable(True)
self.btn2.clicked.connect(self.StartStopRF_PSD)
self.grid.addWidget(self.btn2,0,col)
# Start & stop Baseband PSD
col+=1
self.btn4 = QPushButton('Start IQ PSD')
self.btn4.setToolTip('Start/stop Baseband IQ PSD')
self.btn4.setCheckable(True)
self.btn4.clicked.connect(self.StartStopBaseband_PSD)
self.grid.addWidget(self.btn4,0,col)
# Start & stop AF PSD
col+=1
self.btn3 = QPushButton('Start AF PSD')
self.btn3.setToolTip('Start/stop AF PSD')
self.btn3.setCheckable(True)
self.btn3.clicked.connect(self.StartStopAF_PSD)
self.grid.addWidget(self.btn3,0,col)
# Select Sub RX to control
col+=1
self.sub_rx_ctrl = QComboBox()
for i in range(P.NUM_RX):
self.sub_rx_ctrl.addItem('RX '+str(i))
self.grid.addWidget(self.sub_rx_ctrl,0,col)
self.sub_rx_ctrl.currentIndexChanged.connect(self.SelectPlotRX)
# Start & stop saving raw IQ data
col+=1
self.btn5 = QPushButton('Save Raw IQ')
self.btn5.setToolTip('Start/stop saving data')
self.btn5.setCheckable(True)
self.btn5.clicked.connect(self.StartStopSave_RawIQ)
self.grid.addWidget(self.btn5,0,col)
# Start & stop saving baseband IQ data
col+=1
self.btn6 = QPushButton('Save BB IQ')
self.btn6.setToolTip('Start/stop saving data')
self.btn6.setCheckable(True)
self.btn6.clicked.connect(self.StartStopSave_BasebandIQ)
self.grid.addWidget(self.btn6,0,col)
# Start & stop saving demod data
col+=1
self.btn7 = QPushButton('Save Demod')
self.btn7.setToolTip('Start/stop saving data')
self.btn7.setCheckable(True)
self.btn7.clicked.connect(self.StartStopSave_Demod)
self.grid.addWidget(self.btn7,0,col)
# Start & stop auto muting
col+=1
self.btn8 = QPushButton('Auto Mute')
self.btn8.setToolTip('Mute Big Sigs')
self.btn8.setCheckable(True)
self.btn8.clicked.connect(self.StartStop_AutoMute)
self.grid.addWidget(self.btn8,0,col)
col+=1
self.btn9 = LED('','lime')
#self.grid.addWidget(self.btn9,0,col)
self.grid.addWidget(self.btn9,nrows+1,ncols)
# Debug - show settings
if False:
b = QPushButton('Params')
b.setToolTip('Show params')
b.clicked.connect(self.ShowParams)
self.grid.addWidget(b,0,ncols-1)
# Turn audio on and off
b = QPushButton('Audio Out')
b.setToolTip('Turn Audio On/Off')
b.clicked.connect(self.AudioOnOff)
b.setCheckable(True)
self.grid.addWidget(b,0,ncols-1)
self.AudioPlayBackBtn=b
self.AudioOnOff(-1)
# Hook to exit app
b = QPushButton('Quit')
b.setToolTip('Click to quit!')
b.clicked.connect( self.closeEvent )
self.grid.addWidget(b,0,ncols)
################################################################################
# Left side relates to the SDRplay
row=1
# Add Antenna Selector
if self.P.SDR_TYPE=='sdrplay':
self.Antennas=['Ant A','Ant B','Hi-Z']
lb=QLabel("Antenna:")
self.Ant_cb = QComboBox()
self.Ant_cb.addItems(self.Antennas)
self.Ant_cb.currentIndexChanged.connect(self.AntSelect)
#self.AntSelect(-1)
row+=1
self.grid.addWidget(lb,row,0)
self.grid.addWidget(self.Ant_cb,row,1)
# Add control for BCB band notch
if self.P.SDR_TYPE=='sdrplay':
lb=QLabel("BCD Notch:")
self.BCB_btn = QPushButton('Enable')
self.BCB_btn.setToolTip('Enable/disable AM/FM BCB notch filter')
self.BCB_btn.clicked.connect(self.EnableBCBnotch)
row+=1
self.grid.addWidget(lb,row,0)
self.grid.addWidget(self.BCB_btn,row,1)
# Add front-end gain control (aka LNA)
if self.P.SDR_TYPE=='sdrplay':
self.RFgains=[str(i) for i in range(8)]
#print 'Available RF gains=',self.RFgains
lb=QLabel("RF Gain:")
self.RFgain_cb = QComboBox()
self.RFgain_cb.addItems(self.RFgains)
self.RFgain_cb.currentIndexChanged.connect(self.LNASelect)
#self.LNASelect(-1)
row+=1
self.grid.addWidget(lb,row,0)
self.grid.addWidget(self.RFgain_cb,row,1)
# Add front-end gain control (aka LNA)
if self.P.SDR_TYPE=='rtlsdr':
self.direct=[str(i) for i in range(3)]
lb=QLabel("Direct Sampling:")
self.direct_cb = QComboBox()
self.direct_cb.addItems(self.direct)
self.direct_cb.currentIndexChanged.connect(self.DirectSelect)
self.DirectSelect(self.P.DIRECT_SAMP)
row+=1
self.grid.addWidget(lb,row,0)
self.grid.addWidget(self.direct_cb,row,1)
# Add IF sampling rate control
if not self.P.REPLAY_MODE:
if self.P.MP_SCHEME==2:
RATEs = self.mp_comm('listSampleRates')
else:
RATEs = self.P.sdr.listSampleRates(SOAPY_SDR_RX, 0)
else:
RATEs = [self.P.SRATE]
self.srates=[]
for rate in RATEs:
if rate>=1e6:
rate2 = rate/1e6
tag=' MHz'
else:
rate2 = rate/1e3
tag=' KHz'
if rate2==int(rate2):
rate2=int(rate2)
self.srates.append( str(rate2) + tag )
print('SAMPLING RATEs=',RATEs)
print('SAMPLING RATEs=',self.srates)
lb=QLabel("Sampling Rate:")
self.srate_cb = QComboBox()
self.srate_cb.addItems(self.srates)
self.srate_cb.currentIndexChanged.connect(self.SrateSelect)
#self.SrateSelect(-1)
row+=1
self.grid.addWidget(lb,row,0)
self.grid.addWidget(self.srate_cb,row,1)
# Add IF bandwidth selection - this is tightly coupled to sample rate
# selection so is not of much use
if self.P.SDR_TYPE=='sdrplay':
if self.P.MP_SCHEME==2:
BWs=self.mp_comm('listBandwidths')
else:
BWs=self.P.sdr.listBandwidths(SOAPY_SDR_RX, 0)
# print "Available Bandwidths=",self.BWs
self.bws=[]
for bw in BWs:
if bw>=1e6:
bw2 = bw/1e6
tag=' MHz'
else:
bw2 = bw/1e3
tag=' KHz'
if bw2==int(bw2):
bw2=int(bw2)
self.bws.append( str(bw2) + tag )
lb=QLabel("IF Bandwidth:")
self.BW_cb = QComboBox()
self.BW_cb.addItems(self.bws)
self.BW_cb.currentIndexChanged.connect(self.IF_BWSelect)
#self.IF_BWSelect(-1)
row+=1
self.grid.addWidget(lb,row,0)
self.grid.addWidget(self.BW_cb,row,1)
# Add IF freq control
self.IFs=['0 KHz','450 KHz','1620 KHz','2048 KHz']
lb=QLabel("IF:")
self.IF_cb = QComboBox()
self.IF_cb.addItems(self.IFs)
self.IF_cb.currentIndexChanged.connect(self.IFSelect)
#self.IFSelect(-1)
row+=1
self.grid.addWidget(lb,row,0)
self.grid.addWidget(self.IF_cb,row,1)
# Add IF Gain control
if P.REPLAY_MODE:
self.IFgains=['1']
else:
if self.P.SDR_TYPE=='sdrplay':
stage='IFGR'
elif self.P.SDR_TYPE=='rtlsdr':
stage='TUNER'
if self.P.MP_SCHEME==2:
rr = self.mp_comm('getGainRange',stage)
else:
r = self.P.sdr.getGainRange(SOAPY_SDR_RX, 0,stage)
if type(r)==list:
rr=r
else:
print("\nr=",r,type(r),r.minimum(),r.maximum(),r.step())
rr = [r.minimum(),r.maximum(),r.step()]
self.dgain = rr[2]
if self.dgain==0:
self.dgain = rr[1]/10.
if self.P.SDR_TYPE=='sdrplay':
self.IFgains=[str(i) for i in range(int(rr[0]),int(rr[1]+0.5))]
else:
self.IFgains=[str(i) for i in np.arange(rr[0],rr[1]+self.dgain/2.,self.dgain)]
print(self.IFgains)
lb=QLabel("IF Gain:")
self.IFgain_cb = QComboBox()
self.IFgain_cb.addItems(self.IFgains)
self.IFgain_cb.currentIndexChanged.connect(self.IFGainSelect)
#self.IFGainSelect(-1)
row+=1
self.grid.addWidget(lb,row,0)
self.grid.addWidget(self.IFgain_cb,row,1)
# Add text boxes to show freq of each rx
self.rx_frq_box = []
for i in range(P.NUM_RX):
lb=QLabel("RX"+str(i)+":")
self.rx_frq_box.append( QLineEdit() )
row+=1
self.grid.addWidget(lb,row,0)
self.grid.addWidget(self.rx_frq_box[i],row,1)
self.rx_frq_box[i].setText( "{0:,.1f} KHz".format(P.FC[i]/1000.) )
# Add button to force a hop
row+=1
self.Hop_btn = QPushButton('Force a Hop')
self.Hop_btn.setToolTip('Force a Hop')
self.grid.addWidget(self.Hop_btn,row,0,1,2)
if P.HOPPER:
self.Hop_btn.clicked.connect(self.P.hopper.Hopper)
else:
self.Hop_btn.setEnabled(False)
################################################################################
# The middle relates to tuning - start by adding freq readout
self.lcd = MyLCDNumber(None,7,1,ival=.001*P.FC[0],wheelCB=self.FreqSelect)
self.grid.addWidget(self.lcd,1,2,5,ncols-3)
self.SelectPlotRX(0)
# Add tabs to hold buttons for presets
self.tabs = QTabWidget()
self.grid.addWidget(self.tabs,6,2,nrows-6,ncols-3)
# Add tab for rig control
if P.sock and P.sock.connection!='NONE' and P.RIG_CONTROL_MENU:
self.rig = RIG_CONTROL(self.tabs,P)
# Add presets
ncols2=6
presets = read_presets2(None,'Presets')
for line in presets:
grp=line['Group']
if grp=='Sats':
continue # Skip this group
elif grp=='HAM':
for b in ['160m','80m','40m','20m','15m','10m']:
ham_band=make_ham_presets2(b,bands,P.PAN_BW,P.RIG_IF)
for sub_band in ham_band:
self.create_presets2('Ham 1',sub_band,ncols2)
for b in ['60m','30m','17m','12m','6m','2m','1.25m','70cm','33cm','23cm']:
ham_band=make_ham_presets2(b,bands,P.PAN_BW,P.RIG_IF)
for sub_band in ham_band:
self.create_presets2('Ham 2',sub_band,ncols2)
else:
self.create_presets2(grp,line,ncols2)
# Volume control
lb=QLabel("AF Gain:")
self.grid.addWidget(lb,nrows,1)
self.afgain = QSlider(Qt.Orientation.Horizontal)
# sld.setFocusPolicy(Qt.NoFocus)
self.afgain.setMinimum(0)
self.afgain.setMaximum(100)
self.afgain.setValue(int(P.VOL))
self.afgain.valueChanged.connect(self.VolumeControl)
self.afgain.setTickPosition(QSlider.TickPosition.TicksBelow)
self.afgain.setTickInterval(10)
self.grid.addWidget(self.afgain,nrows,2,1,ncols-3)
self.VolumeControl()
# Mute Buttons
self.Mute_btns = [None]*P.MAX_RX
irow=nrows-2
icol=ncols-1
for i in range(P.MAX_RX):
self.Mute_btns[i] = QPushButton('Mute RX'+str(i+1))
self.Mute_btns[i].setToolTip('Click to Mute/Unmute Audio')
self.Mute_btns[i].clicked.connect( functools.partial( self.MuteCB,i )) # Clicking button toggles mute state
self.Mute_btns[i].setCheckable(True)
if i>=P.NUM_RX:
self.Mute_btns[i].setEnabled(False)
self.MuteCB(i,True) # Start out muted
self.grid.addWidget(self.Mute_btns[i],irow,icol)
icol=icol+1
if icol>ncols:
irow+=1
icol=ncols-1
################################################################################
# Right side (mostly) relates to demodulation/info extraction
# Add Tuning step
row=2
self.steps=["10 Hz","100 Hz","1 KHz","5 KHz","10 KHz","25 KHz","50 KHz",\
"100 KHz","200 KHz","1 MHz","10 MHz","100 MHz","1 GHz"]
lb=QLabel("Tuning Step:")
self.grid.addWidget(lb,row,ncols-1)
self.step_cb = QComboBox()
self.step_cb.addItems(self.steps)
self.step_cb.currentIndexChanged.connect(self.StepSelect)
self.step_cb.setCurrentIndex(4)
self.grid.addWidget(self.step_cb,row,ncols)
# Add Mode selector
row+=1
self.modes = MODES
lb=QLabel("Demodulator:")
self.grid.addWidget(lb,row,ncols-1)
self.mode_cb = QComboBox()
self.mode_cb.addItems(self.modes)
self.mode_cb.currentIndexChanged.connect(self.ModeSelect)
self.grid.addWidget(self.mode_cb,row,ncols)
#self.ModeSelect(-1)
# Add vidio bandwidth selector
row+=1
self.video_bws = VIDEO_BWs
lb=QLabel("Video Bandwidth:")
self.grid.addWidget(lb,row,ncols-1)
self.vidbw_cb = QComboBox()
self.vidbw_cb.addItems(self.video_bws)
self.vidbw_cb.currentIndexChanged.connect(self.Video_BWSelect)
self.grid.addWidget(self.vidbw_cb,row,ncols)
#self.Video_BWSelect(-1)
# Add audio bandwidth selector
row+=1
self.af_bws = AF_BWs
lb=QLabel("AF Bandwidth:")
self.grid.addWidget(lb,row,ncols-1)
self.afbw_cb = QComboBox()
self.afbw_cb.addItems(self.af_bws)
self.afbw_cb.currentIndexChanged.connect(self.AF_BWSelect)
self.grid.addWidget(self.afbw_cb,row,ncols)
#self.AF_BWSelect(-1)
################################################################################
# Add buttons to control pan-adaptor
# Checkbox to turn it on and off
row+=1
self.pan_cb = QCheckBox("Pan-adaptor Mode")
self.pan_cb.setChecked(True)
self.grid.addWidget(self.pan_cb,row,ncols-1)
# Scroll box to control direction of Pan adaptor
self.PanDirs=['Up/Down','Up','Down']
self.PanDir_cb = QComboBox()
self.PanDir_cb.addItems(self.PanDirs)
self.PanDir_cb.currentIndexChanged.connect(self.PanDirSelect)
self.PanDirSelect(0)
self.grid.addWidget(self.PanDir_cb,row,ncols)
# Scroll box to select display bandwidth
row+=1
self.PanBWs=PAN_BWs
lb=QLabel("Pan BW:")
self.PanBW_cb = QComboBox()
self.PanBW_cb.addItems(self.PanBWs)
self.PanBW_cb.currentIndexChanged.connect(self.PanBWSelect)
print('----------------- PAN BW=',P.PAN_BW)
#self.PanBWSelect(-1)
self.grid.addWidget(lb,row,ncols-1)
self.grid.addWidget(self.PanBW_cb,row,ncols)
# Scroll box to select dynamic range
row+=1
self.PanDRs=[str(i) for i in range(10,100,10)]
lb=QLabel("Dynamic Range:")
self.PanDR_cb = QComboBox()
self.PanDR_cb.addItems(self.PanDRs)
self.PanDR_cb.currentIndexChanged.connect(self.PanDRSelect)
#self.PanDRSelect(-1)
self.grid.addWidget(lb,row,ncols-1)
self.grid.addWidget(self.PanDR_cb,row,ncols)
# Scroll box to select min peak distance
row+=1
self.PeakDists=['100 Hz','1 KHz','10 KHz']
lb=QLabel("Min Peak Distance:")
self.PeakDist_cb = QComboBox()
self.PeakDist_cb.addItems(self.PeakDists)
self.PeakDist_cb.currentIndexChanged.connect(self.PeakDistSelect)
#self.PeakDistSelect(-1)
self.grid.addWidget(lb,row,ncols-1)
self.grid.addWidget(self.PeakDist_cb,row,ncols)
# Check box to use peaks for tuning
row+=1
self.Use_Peaks_cb = QCheckBox("Use Peaks for Tuning")
self.Use_Peaks_cb.setChecked(False)
self.grid.addWidget(self.Use_Peaks_cb,row,ncols-1)
# Check box to add offset for digi modes
self.DIGI_OFFSET=1000*1e-3
self.digi_cb = QCheckBox("Add Digi Offset")
self.digi_cb.setChecked(self.P.DIGI_OFFSET)
self.grid.addWidget(self.digi_cb,row,ncols)
# Check boxes to follow center freq of transceiver
row+=1
self.follow_freq_cb = QCheckBox("Follow RIG Freq")
self.follow_freq_cb.setChecked(self.P.FOLLOW_FREQ)
self.grid.addWidget(self.follow_freq_cb,row,ncols-1)
self.follow_band_cb = QCheckBox("Follow RIG Band")
self.follow_band_cb.setChecked(self.P.FOLLOW_BAND)
self.grid.addWidget(self.follow_band_cb,row,ncols)
row+=1
self.split_cb = QCheckBox("CLAR Follows SDR Freq")
self.split_cb.setChecked(False)
self.grid.addWidget(self.split_cb,row,ncols-1)
self.so2v_cb = QCheckBox("VFO-B Follows SDR Freq")
self.so2v_cb.setChecked(self.P.SO2V)
self.grid.addWidget(self.so2v_cb,row,ncols)
################################################################################
# Setup timer to make sure we don't hang
self.timer1 = QTimer()
self.timer1.timeout.connect(self.TicToc)
self.timer1.start(5000)
################################################################################
# Open plotting windows
#title="pySDR by AA2IL"
self.plots_rf=three_box_plot(P,"RF - AA2IL","RF Time Series","RF PSD", \
P.SRATE/1000.,P.FOFFSET/1000.,P.IN_CHUNK_SIZE,
2*P.IN_CHUNK_SIZE,0.,self.MouseClickRF,P.TRANSPOSE)
self.plots_rf.hide()
OVERLAP = 0.5 # 0.75
self.plots_af=three_box_plot(P,"Demod Audio - AA2IL","AF Time Series","AF PSD", \
P.FS_OUT/1000.,0,4*P.OUT_CHUNK_SIZE,
8*P.OUT_CHUNK_SIZE,OVERLAP,self.MouseClickRF,P.TRANSPOSE)
self.plots_af.hide()
self.plots_bb=three_box_plot(P,"Baseband IQ - AA2IL","Baseband Time Series", \
"Baseband PSD", P.FS_OUT/1000.,0,P.IN_CHUNK_SIZE,
2*P.IN_CHUNK_SIZE,0.,self.MouseClickRF,P.TRANSPOSE)
self.plots_bb.hide()
# Finally, we're ready to show the gui
print('------------------------- And Away We Go !!!!!!!!!!!!!!!!!!!!!!')
self.show()
# Move to lower left corner of screen
#screen_resolution = self.P.app.desktop().screenGeometry()
screen_resolution = self.P.app.primaryScreen().size()
self.screen_width = screen_resolution.width()
self.screen_height = screen_resolution.height()
if P.GEO==None:
widget = self.geometry()
print("Screen Res:",screen_resolution,self.screen_width, self.screen_height)
self.move(0, self.screen_height - widget.height() )
else:
# WWWxHHH+XXX+YYY
# pySDR.py -geo 1100x530+5+540
print('geo=',P.GEO)
geo2=P.GEO.split('+')
print('geo2=',geo2)
geo3=geo2[0].split('x')
print('geo3=',geo3)
w=int( geo3[0] )
h=int( geo3[1] )
x=int( geo2[1] )
y=int( geo2[2] )
print('geo=',P.GEO,'\tx=',x,'\ty=',y,'\tw=',w,'\th=',h)
self.setGeometry(x,y,w,h)
if P.DESKTOP!=None:
cmd1='wmctrl -r "'+self.windowTitle()+'" -t '+str(P.DESKTOP)
print('cmd1=',cmd1)
os.system(cmd1)
"""
cmd2='wmctrl -r "'+self.plots_rf.pwin.windowTitle()+'" -t '+str(P.DESKTOP)
print('cmd2=',cmd2)
os.system(cmd2)
cmd3='wmctrl -r "'+self.plots_af.pwin.windowTitle()+'" -t '+str(P.DESKTOP)
print('cmd3=',cmd3)
os.system(cmd3)
cmd4='wmctrl -r "'+self.plots_bb.pwin.windowTitle()+'" -t '+str(P.DESKTOP)
print('cmd4=',cmd4)
os.system(cmd4)
"""
################################################################################
# Callback to show current params
def AudioOnOff(self,opt):
P=self.P
if opt==-1:
P.audio_playback = False
else:
P.audio_playback = not P.audio_playback
print('\nAUDIO ON/OFF: Audio playback is',P.audio_playback)
print('opt=',opt)
# Manage the button
if P.audio_playback:
self.AudioPlayBackBtn.setText('Stop Audio')
"""
self.AudioPlayBackBtn.setStyleSheet('QPushButton { \
background-color: red; \
border :1px inset ; \
border-radius: 5px; \
border-color: gray; \
font: bold 14px; \
padding: 4px; \
}')
"""
else:
self.AudioPlayBackBtn.setText('Start Audio')
"""
self.AudioPlayBackBtn.setStyleSheet('QPushButton { \
background-color: limegreen; \
border :1px outset ; \
border-radius: 5px; \
border-color: gray; \
font: bold 14px; \
padding: 4px; \
}')
"""
# Manage the audio player(s)
for irx in range(P.NUM_PLAYERS):
player=P.players[irx]
print(irx,player.active)
if P.audio_playback and player.active:
print('Resuming audio playback for RX',irx)
player.resume()
elif not P.audio_playback and player.active:
print('Pausing audio playback for RX',irx)
player.pause()
################################################################################
def TicToc(self):
#print('Tic Toc ...')
if self.P.Stopper.is_set():
print('Tic Toc - Triggering closeEvent ...')
self.closeEvent()
################################################################################
# Routine to start the GUI
def StartGUI(self):
P=self.P
# Set various gui checkboxes, etc.
self.SrateSelect(-1)
self.IFSelect(-1)
self.IFGainSelect(-1)
self.ModeSelect(-1)
self.Video_BWSelect(-1)
self.AF_BWSelect(-1)
self.PanBWSelect(-1)
self.PanDRSelect(-1)
self.PeakDistSelect(-1)
if self.P.SDR_TYPE=='sdrplay':
self.AntSelect(-1)
self.LNASelect(-1)
self.IF_BWSelect(-1)
# Activate various options
if P.PANADAPTOR:
self.StartStopAF_PSD()
if P.FOLLOW_FREQ:
self.follow_freq_cb.setChecked(True)
# Make sure rig settings are reasonable
P.sock.set_vfo('A','A')
P.sock.set_vfo(op='A->B')
P.sock.set_sub_dial(func='CLAR')
self.rig_retune()
if False:
# Not sure why I thought we needed to do this
# It sets all the rx's to the same freq
fc = self.lcd.get()
print('BURP1: FC=',fc,P.FC)
for i in range(1,P.NUM_RX):
P.FC[i]=1000*fc
print('BURP2: FC=',fc,P.FC)
self.FreqSelect(fc,False)
if P.ENABLE_RTTY:
if self.rtty.active:
self.rtty.raise_()
print('pySDR: GUI ready ... ')
if P.MP_SCHEME==2:
self.mp_comm('GUIready')
################################################################################
# Routine to close down gracefully
def closeEvent(self, event=None):
print('CloseEvent ...')
# This seems to get called twice so trap second call
if self.gui_closed:
return
else:
self.gui_closed=True
# Close plotting windows
if self.P.SHOW_RF_PSD:
# self.plots_rf.pwin.close()
self.StartStopRF_PSD()
if self.P.SHOW_AF_PSD:
self.StartStopAF_PSD()
if self.P.SHOW_BASEBAND_PSD:
self.StartStopBaseband_PSD()
print('\n--------------------------------------------------------------------------')
print('closeEvent: Stopping timers...')
self.P.PSDtimer.stop()
print("--- PSD timer stopped")
#self.P.monitor.timer.stop()
print("--- WatchDog timer stopped")
time.sleep(1)
if self.P.MP_SCHEME==2:
print('closeEvent: Closing down RX ...')
self.mp_comm('Shutdown')
print('--- Waiting for RX to join...')
self.P.mp_proc.terminate()
self.P.mp_proc.join()
self.P.pipe=None
print('--- RX joined.')
if self.P.MP_SCHEME==3:
print('closeEvent: Closing down RX ...')
self.mp_comm('Shutdown')
if self.P.ENABLE_RTTY:
if self.rtty.active:
self.rtty.wrap_up()
print('Waiting for RTTY to exit...')
while self.rtty.active and True:
time.sleep(1)
self.P.app.processEvents()
if self.P.UDP_CLIENT and self.P.udp_client:
#self.P.udp_client.Close()
self.P.udp_client.Stopper.set()
# Loop through all the threads and close (join) them
print("Waiting for threads to quit...")
show_threads()
for th in self.P.threads:
print('\tWaiting for thread to quit -',th.getName(),' ...')
if self.P.Stopper:
self.P.Stopper.set()
th.join(5.0)
print('\t... Thread quit -',th.getName())
print("Closing down gui ...")
#if self.P.SHOW_RF_PSD:
# self.plots_rf.pwin.close()
# print "Closing down gui - RF PSD closed"
#self.plots_af.close()
app = QApplication.instance()
app.quitOnLastWindowClosed=False
print("Closing down gui - Closing all windows ...")
app.closeAllWindows()
print("Closing down gui - All windows closed")
time.sleep(1)
self.win.destroy()
print("Closing down gui - Main window closed")
print("\nThat's all folks!\n")
show_threads()
sys.exit(0)
# Function to create preset push buttons
def create_presets(self,tag,station_list,ncols):
#print 'CREATE_PRESETS:',tag,station_list
# Add a tab
tab1 = QWidget()
self.tabs.addTab(tab1,tag)
grid = QGridLayout()
tab1.setLayout(grid)
# Add a grid of buttons
i=0
j=0
for s in station_list:
#print 'CREATE PRESETS:',s,'\n',station_list[s]
b = QPushButton(s)
f1=station_list[s][0] # Freq 1
m=station_list[s][1] # Mode
if len(station_list[s])>2:
f2=station_list[s][2] # Freq 2
else:
f2=f1
f=(f1+f2)/2 # Tune to center of band
# Set tool tip to show freq(s)
fthresh=30e3 # Above 30 MHz, show MHz instead of KHz
if f1!=f2:
if f>fthresh:
tip="{:,} - {:,} MHz".format(.001*f1,.001*f2)
else:
tip="{:,d} - {:,d} KHz".format(int(f1),int(f2))
else:
if f>=fthresh:
tip="{:,} MHz".format(.001*f)
else:
tip="{:,d} KHz".format(int(f))
b.setToolTip(tip)
if len(station_list[s])>4:
vidbw = station_list[s][4] # Video bw
afbw = station_list[s][5] # Audio bw
else:
vidbw = preset_prefs[m][0] # Default video bw for this mode
afbw = preset_prefs[m][1] # Default audio bw for this mode
#print 'CREATE_PRESETS:',f,m,vidbw,afbw
#print s,station_list[s]
#print m,preset_prefs[m]
b.clicked.connect(functools.partial(self.PresetSelect,f,m,vidbw,afbw))
i=i+1
if i>ncols:
i=1
j=j+1
# print s,f,m,j,i
grid.addWidget(b,j,i)
#sys.exit(0)
# Function to create preset a push button
def create_presets2(self,grp,station,ncols):
#print 'CREATE_PRESETS2:',tag,station
# Add a tab
if grp!=self.prev_group:
tab1 = QWidget()
self.tabs.addTab(tab1,grp)
self.preset_grid = QGridLayout()
tab1.setLayout(self.preset_grid)
self.prev_group=grp
self.ipreset=0
self.jpreset=0
# Add a button
#print 'CREATE PRESETS:',s,'\n',station_list[s]
b = QPushButton(station['Tag'])
f1=station['Freq1 (KHz)'] # Freq 1
m=station['Mode'] # Mode
if m=='AM-N':
m='AM'
f2=station['Freq2 (KHz)'] # Freq 2
if f2==0:
f2=f1
f=(f1+f2)/2 # Tune to center of band
# Set tool tip to show freq(s)
fthresh=30e3 # Above 30 MHz, show MHz instead of KHz
if f1!=f2:
if f>fthresh:
tip="{:,} - {:,} MHz".format(.001*f1,.001*f2)
else:
tip="{:,d} - {:,d} KHz".format(int(f1),int(f2))
else:
if f>=fthresh:
tip="{:,} MHz".format(.001*f)
else:
tip="{:,d} KHz".format(int(f))
b.setToolTip(tip)
vidbw = station['Video BW (KHz)'] # Video bw
if vidbw==0:
vidbw = preset_prefs[m][0] # Default video bw for this mode
afbw = station['Audio BW (KHz)'] # Video bw
if afbw==0:
afbw = preset_prefs[m][1] # Default video bw for this mode
#print 'CREATE_PRESETS:',f,m,vidbw,afbw
#print s,station_list[s]
#print m,preset_prefs[m]
b.clicked.connect(functools.partial(self.PresetSelect,f,m,vidbw,afbw))
self.ipreset+=1
if self.ipreset>ncols:
self.ipreset=1
self.jpreset+=1
# print s,f,m,j,i
self.preset_grid.addWidget(b,self.jpreset,self.ipreset)
#sys.exit(0)