-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.py
executable file
·3699 lines (3163 loc) · 135 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.1
# Copyright (C) 2021-5 by Joseph B. Attili, aa2il AT arrl DOT net
#
# GUI for CW keyer.
#
############################################################################################
#
# 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 os
if sys.version_info[0]==3:
from tkinter import *
import tkinter.font
import tkinter.messagebox
from tkinter import ttk
else:
from Tkinter import *
import tkFont
import tkMessageBox
import random
import csv
import pytz
from datetime import datetime, date, tzinfo
import time
import cw_keyer
import hint
from dx import Station
from pprint import pprint
import webbrowser
from rig_io import ClarReset,SetTXSplit
from rig_io import DELAY
from rig_control_tk import *
from rotor_control_tk import *
from keyer_control_tk import *
from ToolTip import *
from fileio import *
from threading import enumerate
from cwt import *
from cwopen import *
from foc import *
from sst import *
from sprint import *
from mst import *
from skcc import *
from calls import *
from cqp import *
from wpx import *
from fd import *
from ss import *
from vhf import *
from ten import *
from naqp import *
from iaru import *
from cqww import *
from sats import *
from settings import *
from paddling import *
from ragchew import *
from dx_qso import *
from qrz import *
from utilities import cut_numbers,freq2band,Oh_Canada,error_trap,show_ascii
import pyautogui
from widgets_tk import StatusBar,SPLASH_SCREEN
#from bm_gui import *
############################################################################################
UTC = pytz.utc
WPM_STEP = 2 # Key speed step for up/dn buttons - was 4
############################################################################################
def cleanup(x): return x.strip().upper()
# Routine to list threads
def show_threads():
print('\nList of running threads:')
threads = enumerate()
for th in threads:
print(th,th.getName())
print(' ')
# The GUI
class GUI():
def __init__(self,P):
# Create root window
print("\nCreating GUI ...")
self.root = Tk()
# width_size x height_size + x_position + y_position
if P.GEO==None:
geo='1200x400+250+250'
else:
#pyKeyer.py -geo 1500x400+0+240
geo=P.GEO
self.root.geometry(geo)
# Over-ride default-font with custom settings
# Not necesary but I'm leaving this code here fore later reference
if False:
print('Default font:',tkinter.font.nametofont('TkTextFont').actual())
print('Families:',tkinter.font.families())
self.defaultFont = tkinter.font.nametofont("TkDefaultFont")
self.defaultFont.configure(family='DejaVu Sans Mono',
size=20,
weight=tkinter.font.NORMAL)
self.root.option_add("*Font", "ariel")
print('New Default font:',tkinter.font.nametofont('TkTextFont').actual())
self.root.option_add("*Label*Font", "Helvetica 20")
self.root.option_add("*Button*Font", "Arial 15 bold")
sys.exit(0)
# Init
self.last_focus=None
self.WIN_NAME='ROOT WINDOW'
self.OnTop=False
self.dx_station = None
self.CHECK_DIAL = 1
self.last_qso=None
self.rig=None
self.pounced=False
self.searching=False
self.MY_CALL = P.SETTINGS['MY_CALL']
# Create spash screen
self.splash = SPLASH_SCREEN(self.root,'keyer_splash.png')
self.status_bar = self.splash.status_bar
# More inits
self.Done=False
self.contest = False
self.P = P
self.RUNNING=False
self.P.root = self.root
self.text_buff=''
self.macro_label=''
self.last_text=None
# Special fonts for various widgets
FAMILY='monospace'
#FAMILY='DejaVu Sans Mono'
if sys.version_info[0]==3:
self.font1 = tkinter.font.Font(family=FAMILY,size=12,weight="bold")
self.font2 = tkinter.font.Font(family=FAMILY,size=28,weight="bold")
self.font3 = tkinter.font.Font(family=FAMILY,size=14) # ,weight="bold")
else:
self.font1 = tkFont.Font(family=FAMILY,size=12,weight="bold")
self.font2 = tkFont.Font(family=FAMILY,size=28,weight="bold")
self.font3 = tkFont.Font(family=FAMILY,size=14) # ,weight="bold")
if False:
print('\nfamilies=',tkinter.font.families())
print('\nnames=',tkinter.font.names())
print('\nfont1=',self.font1.actual())
print('font2=',self.font2.actual())
sys.exit(0)
# Function to actually construct the gui
def construct_gui(self):
P=self.P
self.status_bar.setText("Constructing GUI ...")
P.MEM.take_snapshot()
# More inits
self.keyer=P.keyer;
self.start_time = None
self.time_on = None
self.nqsos_start = 0
self.sock = self.P.sock
rig=''
if P.sock.rig_type2 and P.sock.rig_type2!='None':
rig=' - '+P.sock.rig_type2
if P.sock2 and P.sock2.rig_type2 and P.sock2.rig_type2!='None':
rig+=' + '+P.sock2.rig_type2
if P.sock3 and P.sock3.rig_type2 and P.sock3.rig_type2!='None':
rig+=' + '+P.sock3.rig_type2
self.root.title("pyKeyer by AA2IL"+rig)
self.tuning = False
self.root.protocol("WM_DELETE_WINDOW", self.Quit)
self.MACRO_TXT = StringVar()
self.last_call=''
self.last_shift_key=''
self.last_hint=''
self.q = P.q
self.exch_out=''
self.ndigits=3
self.prev_call=''
self.prev_qso={}
self.prefill=False
self.cntr=0
# Read adif log - why is this stuff in here???? Its not gui, move it elsewhere!!!!
self.log_book = []
if P.LOG_FILE==None:
P.LOG_FILE = P.WORK_DIR+self.MY_CALL.replace('/','_')+".adif"
print('Opening log file',P.LOG_FILE,'...')
P.MEM.take_snapshot()
self.status_bar.setText("Reading log book "+P.LOG_FILE+" ...")
print('GUI: Reading ADIF log file',P.LOG_FILE)
qsos = parse_adif(P.LOG_FILE,upper_case=True,verbosity=0)
for qso in qsos:
self.log_book.append(qso)
self.nqsos_start = len(self.log_book)
print('There are',len(self.log_book),'QSOs in the log book')
P.MEM.take_snapshot()
#sys.exit(0)
# Keep an ADIF copy of the log as well
if os.path.exists(P.LOG_FILE):
self.fp_adif = open(P.LOG_FILE,"a+")
else:
self.fp_adif = open(P.LOG_FILE,"w")
#self.fp_adif.write('Simple Log Export<eoh>\n')
self.fp_adif.write('Created by pyKeyer by AA2IL\n')
self.fp_adif.write('<USERDEF1:13>RUNNING,{1,0}\n')
self.fp_adif.write('<eoh>\n')
self.fp_adif.flush()
print("GUI: ADIF file name=",P.LOG_FILE)
P.MEM.take_snapshot()
# Also save all sent text to a file
self.fp_txt = open(P.WORK_DIR+self.MY_CALL.replace('/','_')+".TXT","a+")
# Add a check file
fname77='snippets.txt'
if os.path.exists(fname77):
self.fp_snip = open(fname77,"a+")
else:
self.fp_snip = open(fname77,"w")
self.fp_snip.write('%s\n' % ('#/bin/tcsh -f') )
self.fp_snip.write('%s\n' % (' ') )
self.fp_snip.write('%s\n' % ('set fname="capture_*.wav"') )
self.fp_snip.write('%s\n' % (' ') )
# Add a tab to manage Rig
self.rig = RIG_CONTROL(P)
# Add a tab to manage Rotor
# This is actually rather difficult since there doesn't
# appear to be a tk equivalent to QLCDnumber
self.rotor_ctrl = ROTOR_CONTROL(self.rig.tabs,P)
# Add a tab to manage keyer
if self.P.keyer_device:
self.keyer_ctrl = KEYER_CONTROL(P)
else:
self.keyer_ctrl = None
# Create pop-up window for Settings and Paddle Practice - Need these before we can create the menu
self.status_bar.setText("Constructing GUI ...")
self.SettingsWin = SETTINGS_GUI(self.root,self.P,refreshCB=self.RefreshSettings)
self.SettingsWin.hide()
self.PaddlingWin = PADDLING_GUI(self.root,self.P)
if P.SENDING_PRACTICE:
self.PaddlingWin.show()
else:
self.PaddlingWin.hide()
# Add menu bar
self.ncols=12
row=0
self.create_menu_bar()
# Set up basic logging entry boxes
row+=1
self.call_lab = Label(self.root, text="Call",font=self.font1)
self.call_lab.grid(row=row,columnspan=4,column=0,sticky=E+W)
self.call = Entry(self.root,font=self.font2,selectbackground='lightgreen')
self.call.grid(row=row+1,rowspan=2,column=0,columnspan=4,sticky=E+W)
self.call.bind("<Key>", self.key_press )
self.call.focus_set()
self.default_color = self.call.cget("background")
self.default_object=self.call # Make this the default object to take the focus
# For normal operating, these will be visible
self.name_lab = Label(self.root, text="Name",font=self.font1)
self.name_lab.grid(row=row,columnspan=4,column=4,sticky=E+W)
self.name = Entry(self.root,font=self.font2,selectbackground='lightgreen')
self.name.grid(row=row+1,rowspan=2,column=4,columnspan=4,sticky=E+W)
self.name.bind("<Key>", self.key_press )
self.rstin_lab = Label(self.root, text="RST in",font=self.font1)
self.rstin_lab.grid(row=row,columnspan=1,column=8,sticky=E+W)
self.rstin = Entry(self.root,font=self.font2)
self.rstin.grid(row=row+1,rowspan=2,column=8,columnspan=1,sticky=E+W)
self.rstin.bind("<Key>", self.key_press )
self.rstout_lab = Label(self.root, text="RST out",font=self.font1)
self.rstout_lab.grid(row=row,columnspan=1,column=9,sticky=E+W)
self.rstout = Entry(self.root,font=self.font2)
self.rstout.grid(row=row+1,rowspan=2,column=9,columnspan=1,sticky=E+W)
self.rstout.bind("<Key>", self.key_press )
if self.P.contest_name=='SATELLITES':
self.rstin.insert(0,'5')
self.rstout.insert(0,'5nn')
else:
self.rstin.insert(0,'5NN')
self.rstout.insert(0,'5NN')
# For contests, some subset of these will be visible instead
self.exch_lab = Label(self.root, text="Exchange",font=self.font1)
self.exch_lab.grid(row=row,columnspan=7,column=4,sticky=E+W)
self.exch = Entry(self.root,font=self.font2,selectbackground='lightgreen')
self.exch.grid(row=row+1,rowspan=2,column=4,columnspan=6,sticky=E+W)
self.exch.bind("<Key>", self.key_press )
self.qth_lab = Label(self.root, text="QTH",font=self.font1)
self.qth_lab.grid(row=row,columnspan=3,column=8,sticky=E+W)
self.qth = Entry(self.root,font=self.font2,selectbackground='lightgreen')
self.qth.grid(row=row+1,rowspan=2,column=8,columnspan=2,sticky=E+W)
self.qth.bind("<Key>", self.key_press )
self.serial_lab = Label(self.root, text="Serial",font=self.font1)
self.serial_lab.grid(row=row,columnspan=1,column=4,sticky=E+W)
self.serial_box = Entry(self.root,font=self.font2,selectbackground='lightgreen')
self.serial_box.grid(row=row+1,rowspan=2,column=4,columnspan=1,sticky=E+W)
self.serial_box.bind("<Key>", self.key_press )
self.prec_lab = Label(self.root, text="Prec",font=self.font1)
self.prec_lab.grid(row=row,columnspan=1,column=5,sticky=E+W)
self.prec = Entry(self.root,font=self.font2,selectbackground='lightgreen')
self.prec.grid(row=row+1,rowspan=2,column=5,columnspan=1,sticky=E+W)
self.prec.bind("<Key>", self.key_press )
self.cat_lab = Label(self.root, text="Category",font=self.font1)
self.cat_lab.grid(row=row,columnspan=1,column=5,sticky=E+W)
self.cat = Entry(self.root,font=self.font2,selectbackground='lightgreen')
self.cat.grid(row=row+1,rowspan=2,column=5,columnspan=1,sticky=E+W)
self.cat.bind("<Key>", self.key_press )
self.call2_lab = Label(self.root, text="Call",font=self.font1)
self.call2_lab.grid(row=row,columnspan=1,column=6,sticky=E+W)
self.call2 = Entry(self.root,font=self.font2)
self.call2.grid(row=row+1,rowspan=2,column=6,columnspan=1,sticky=E+W)
self.call2.bind("<Key>", self.key_press )
self.check_lab = Label(self.root, text="Check",font=self.font1)
self.check_lab.grid(row=row,columnspan=1,column=7,sticky=E+W)
self.check = Entry(self.root,font=self.font2,selectbackground='lightgreen')
self.check.grid(row=row+1,rowspan=2,column=7,columnspan=1,sticky=E+W)
self.check.bind("<Key>", self.key_press )
self.notes_lab = Label(self.root, text="Notes",font=self.font1)
self.notes_lab.grid(row=row,columnspan=1,column=8,sticky=E+W)
self.notes = Entry(self.root,font=self.font2,fg='blue')
self.notes.grid(row=row+1,rowspan=2,column=8,columnspan=1,sticky=E+W)
self.notes.bind("<Key>", self.key_press )
self.hint_lab = Label(self.root, text="Hint",font=self.font1)
self.hint_lab.grid(row=row,columnspan=1,column=8,sticky=E+W)
self.hint = Entry(self.root,font=self.font2,fg='blue')
self.hint.grid(row=row+1,rowspan=2,column=8,columnspan=1,sticky=E+W)
self.hint.bind("<Key>", self.key_press )
self.scp_lab = Label(self.root, text="Super Check Partial",font=self.font1)
self.scp_lab.grid(row=row,columnspan=1,column=9,sticky=E+W)
self.scp = Entry(self.root,font=self.font2,fg='blue',selectbackground='white')
self.scp.grid(row=row+1,rowspan=2,column=9,columnspan=1,sticky=E+W)
self.scp.bind('<Double-Button-1>',self.SCP_Selection)
self.scp.bind("<Key>", self.key_press )
# Checkbox to indicate if we've received QSL
self.qsl_rcvd=tk.IntVar()
self.qsl_rcvd.set(0)
self.qsl=tk.Checkbutton(self.root,text='QSL Rcvd', \
variable=self.qsl_rcvd)
self.qsl.grid(row=row+1,column=9,columnspan=1)
tip = ToolTip(self.qsl, ' QSL has been received ')
# Buttons to access FLDIGI logger
if False:
btn = Button(self.root, text='Get',command=self.Set_Log_Fields, \
takefocus=0 )
btn.grid(row=row+1,column=self.ncols-2)
tip = ToolTip(btn, ' Get FLDIGI Logger Fields ' )
btn = Button(self.root, text='Put',command=self.Read_Log_Fields,\
takefocus=0 )
btn.grid(row=row+1,column=self.ncols-1)
tip = ToolTip(btn, ' Set FLDIGI Logger Fields ' )
btn = Button(self.root, text='Wipe',command=self.Clear_Log_Fields,\
takefocus=0 )
btn.grid(row=row+2,column=self.ncols-2)
tip = ToolTip(btn, ' Clear FLDIGI Logger Fields ' )
# Make sure all columns are adjusted when we resize the width of the window
for i in range(12):
Grid.columnconfigure(self.root, i, weight=1,uniform='twelve')
# Set up two text entry box with a scroll bar
# The upper box is so we can type in what we receive
row+=3
self.txt2_row=row
self.txt2 = Text(self.root, height=5, width=80, bg='white')
self.txt2.grid(row=row,column=0,columnspan=self.ncols,stick=N+S+E+W)
self.S2 = Scrollbar(self.root)
self.S2.grid(row=row,column=self.ncols,sticky=N+S)
self.S2.config(command=self.txt2.yview)
self.txt2.config(yscrollcommand=self.S2.set)
self.txt2.bind("<Key>", self.key_press )
self.show_hide_txt2()
# The lower box is so we can type in what we want to send
row+=1
Grid.rowconfigure(self.root, row, weight=1) # Allows resizing
self.txt = Text(self.root, height=5, width=80, bg='white')
self.txt.grid(row=row,column=0,columnspan=self.ncols,stick=N+S+E+W)
self.S = Scrollbar(self.root)
self.S.grid(row=row,column=self.ncols,sticky=N+S)
self.S.config(command=self.txt.yview)
self.txt.config(yscrollcommand=self.S.set)
if self.P.DIGI:
c='red'
self.txt.configure(font=self.font3)
else:
c='black'
c='red'
self.txt.tag_configure('highlight', foreground=c, relief='raised')
self.txt.bind("<Key>", self.key_press )
self.txt.bind('<Button-1>', self.Text_Mouse )
self.txt.bind('<Button-2>', self.Text_Mouse )
self.txt.bind('<Button-3>', self.Text_Mouse )
# Also bind mouse entering or leaving the app
#self.root.bind("<Key>", self.key_press2 )
self.root.bind("<Enter>", self.Hoover )
self.root.bind("<Leave>", self.Leave )
self.root.bind('<Button-1>', self.Root_Mouse )
# Function buttons for pre-defined macros
row += 10
self.btns1=[]
self.btns2=[]
for i in range(12):
if i<4:
c='pale green'
elif i<8:
c='indian red'
else:
c='slateblue1'
Grid.columnconfigure(self.root, i, weight=1)
btn = Button(self.root, text=str(i) , background=c, \
command=lambda j=i: self.Send_Macro(j) )
btn.grid(row=row,column=i,sticky=E+W)
self.btns1.append(btn)
btn = Button(self.root, text=str(i) , background=c, \
command=lambda j=i+12: self.Send_Macro(j) )
btn.grid(row=row+1,column=i,sticky=E+W)
self.btns2.append(btn)
# Bottom row with various functions
row += 3
col=0
# Set up a spin box to control select contest macro set
Label(self.root, text='Macros:').grid(row=row,column=col,sticky=E+W)
if False:
SB = ttk.Combobox(self.root,
textvariable=self.MACRO_TXT,
takefocus=0 )
SB['values'] = self.P.CONTEST_LIST
SB.bind('<<ComboboxSelected>>', self.set_macros)
else:
# I prefer the way OptionMenu looks
# Also, there are differences between the tk and ttk versions
SB = ttk.OptionMenu(self.root,
self.MACRO_TXT,
self.P.CONTEST_LIST[0],
*self.P.CONTEST_LIST,
command=self.set_macros)
SB.grid(row=row,column=col+1,columnspan=2,sticky=E+W)
col += 3
# Set up a spin box to control keying speed (WPM)
self.WPM_TXT = StringVar()
Label(self.root, text='WPM:').grid(row=row,column=col,sticky=E+W)
SB = Spinbox(self.root, \
from_=cw_keyer.MIN_WPM, \
to=cw_keyer.MAX_WPM, \
textvariable=self.WPM_TXT, \
bg='white', \
justify='center', \
command=lambda j=0: self.set_wpm(0))
SB.grid(row=row,column=col+1,columnspan=1,sticky=E+W)
SB.bind("<Key>", self.key_press )
self.WPM_TXT.set(str(self.keyer.WPM))
self.set_wpm(0)
btn = Button(self.root, text='+'+str(WPM_STEP)+' WPM', command=lambda j=WPM_STEP: self.set_wpm(j) )
btn.grid(row=row+1,column=col,sticky=E+W)
tip = ToolTip(btn,' Increase Speed ')
btn = Button(self.root, text='-'+str(WPM_STEP)+' WPM', command=lambda j=-WPM_STEP: self.set_wpm(j) )
btn.grid(row=row+1,column=col+1,sticky=E+W)
tip = ToolTip(btn,' Decrease Speed ')
# Entry box to allow changing my counter
col += 2
self.counter_lab=Label(self.root, text='Serial:')
self.counter_lab.grid(row=row,column=col,sticky=E+W)
self.counter = Entry(self.root,font=self.font2)
self.counter.bind("<Key>", self.key_press )
self.counter.grid(row=row,rowspan=1,column=col+1,columnspan=1,sticky=E+W)
self.counter.delete(0, END)
self.counter.insert(0,str(self.P.MY_CNTR))
self.counter_lab.grid_remove()
self.counter.grid_remove()
self.dec_btn = Button(self.root, text='Dec', command=lambda j=-1: self.update_counter(j) )
self.dec_btn.grid(row=row+1,column=col+1,sticky=E+W)
tip = ToolTip(self.dec_btn,' Decrement Serial')
self.inc_btn = Button(self.root, text='Inc', command=lambda j=+1: self.update_counter(j) )
self.inc_btn.grid(row=row+1,column=col,sticky=E+W)
tip = ToolTip(self.inc_btn,' Increment Serial')
# Radio button group to support SO2R
col += 2
self.iRadio = IntVar(value=1)
self.Radio1 = Radiobutton(self.root, text=P.sock1.rig_type2,
variable=self.iRadio,
value=1,command=self.SelectRadio)
self.Radio1.grid(row=row,column=col,sticky=E+W)
tip = ToolTip(self.Radio1, ' Rig 1 ' )
col += 1
if P.sock2:
self.Radio2 = Radiobutton(self.root, text=P.sock2.rig_type2,
variable=self.iRadio,
value=2,command=self.SelectRadio)
self.Radio2.grid(row=row,column=col,sticky=E+W)
tip = ToolTip(self.Radio2, ' Rig 2 ' )
if P.sock3:
col += 1
self.Radio3 = Radiobutton(self.root, text=P.sock3.rig_type2,
variable=self.iRadio,
value=3,command=self.SelectRadio)
self.Radio3.grid(row=row,column=col,sticky=E+W)
tip = ToolTip(self.Radio3, ' Rig 3 ' )
# Other buttons - any buttons we need to modify, we need to grab handle to them
# before we try to pack them. Otherwise, all we get is the results of the packing
# Enable/Disable TX button - should be sufficient to just press <CR> in the txt box
# Put in a pull-down menu if we really need this
if False:
self.SendBtn = Button(self.root, text='Send',command=self.Toggle_Immediate_TX,\
takefocus=0 )
self.SendBtn.grid(row=row,column=self.ncols-2)
tip = ToolTip(self.SendBtn, ' Enable/Disable Immediate Text Sending ' )
self.Toggle_Immediate_TX(1)
# PTT button
self.PTTBtn = Button(self.root, text=' PTT ',
command=self.Toggle_PTT,\
takefocus=0 )
self.PTTBtn.grid(row=row,column=self.ncols-3)
tip = ToolTip(self.PTTBtn, ' Push-To-Talk ' )
# Force rig into a specific mode and set filters
self.MODE = StringVar()
self.ModeList=['CW','USB','LSB','FM','RTTY','BPSK31']
self.ModeBox = ttk.OptionMenu(self.root,
self.MODE,
self.ModeList[0],
*self.ModeList,
command=self.Set_Rig_Mode)
self.ModeBox.grid(row=row,column=self.ncols-2)
tip = ToolTip(self.ModeBox, ' Set Rig Mode ' )
if P.INIT_MODE!=None:
self.MODE.set(P.INIT_MODE)
self.Set_Rig_Mode(None)
# QRZ button
btn = Button(self.root, text='QRZ ?',command=self.Call_LookUp,\
takefocus=0 )
btn.grid(row=row,column=self.ncols-1)
tip = ToolTip(btn, ' Query QRZ.com ' )
# Flag it button
btn = Button(self.root, text='Flag It',command=self.Flag_It,\
takefocus=0 )
btn.grid(row=row+1,column=self.ncols-1)
tip = ToolTip(btn, ' Flag Last QSO ' )
# Set up a spin box to allow satellite logging
row += 1
col = 0
self.SAT_TXT = StringVar()
self.sat_lab = Label(self.root, text='Satellites:')
self.sat_lab.grid(row=row,column=col,sticky=E+W)
sat_list=sorted( SATELLITE_LIST )
if False:
self.sat_SB = ttk.Combobox(self.root,
textvariable=self.SAT_TXT,
takefocus=0 )
self.sat_SB['values'] = sat_list
self.sat_SB.bind('<<ComboboxSelected>>', self.set_satellite)
else:
self.sat_SB = ttk.OptionMenu(self.root,
self.SAT_TXT,
sat_list[0],
*sat_list,
command=self.set_satellite)
self.sat_SB.grid(row=row,column=col+1,columnspan=2,sticky=E+W)
self.set_satellite('None')
# Reset clarifier
ClarReset(self,self.P.RX_Clar_On)
# Some other info
col=8
P.RATE_TXT="QSO Rate:"
self.rate_lab = Label(self.root, text=P.RATE_TXT,font=self.font1)
self.rate_lab.grid(row=row,columnspan=4,column=col,sticky=W)
# Buttons to allow quick store & return to spotted freqs
self.spots=[]
for j in range(self.P.NUM_ROWS):
row += 1
for i in range(12):
if i<4:
c='pale green'
elif i<8:
c='indian red'
else:
c='slateblue1'
#Grid.columnconfigure(self.root, i, weight=1,uniform='twelve')
btn = Button(self.root, text='--' , background=c)
btn.grid(row=row,column=i,sticky=E+W)
btn.bind('<Button-1>', self.Spots_Mouse )
btn.bind('<Button-2>', self.Spots_Mouse )
btn.bind('<Button-3>', self.Spots_Mouse )
tip = ToolTip(btn, ' Quick Store/Recall ' )
spot = OrderedDict()
spot['Button'] = btn
#spot['Call'] = None
spot['FreqA'] = None
spot['FreqB'] = None
spot['Mode'] = None
spot['Split'] = None
spot['Ant'] = None
spot['Fields'] = None
self.spots.append(spot)
# Status bar along the bottom
row+=1
self.status_bar = StatusBar(self.root)
self.status_bar.setText("Howdy Ho!")
self.status_bar.grid(row=row+1,rowspan=1,column=0,columnspan=self.ncols,sticky=E+W)
# Set macros & restore the state from the last time in
self.PaddlingWin.final_inits()
self.set_macros()
self.RestoreState()
# Kick-off gui updater
self.root.after(2000,self.Updater)
# And away we go!
self.root.deiconify()
self.splash.destroy()
self.root.update_idletasks()
if P.DESKTOP!=None:
cmd='wmctrl -r "'+self.root.title()+'" -t '+str(P.DESKTOP)
os.system(cmd)
cmd='wmctrl -r "'+self.PaddlingWin.win.title()+'" -t '+str(P.DESKTOP)
os.system(cmd)
print('CONSTRUCT GUI - And away we go!!!')
P.MEM.take_snapshot()
# Callback to show or hide the upper text box
def show_hide_txt2(self):
show = self.P.SHOW_TEXT_BOX2
if show:
wght=1
self.txt2.grid()
self.S2.grid()
else:
wght=0
self.txt2.grid_remove()
self.S2.grid_remove()
Grid.rowconfigure(self.root, self.txt2_row, weight=wght) # Allows or disables resizing
# Callback to process mouse events in the root window
def Root_Mouse(self,event):
root = self.P.gui.root
widget = event.widget
obj = self.Master(widget)
window=obj.root
title=window.title()
print('ROOT MOUSE button=',event.num,'\twidget=',widget,
'\twindow=',window,'\ttitle=',title)
if event.num==1:
# Left click --> grab window selection
obj.OnTop=True
if self.P.PLATFORM=='Linux':
#os.system('wmctrl -a pyKeyer add.above')
os.system('wmctrl -a "'+title+'"')
# A bunch of failed attempts - keep this around bx we'll need
# something differnet for windoz
#window.attributes('-topmost', True)
#window.grab_set()
#window.grab_set_global()
#window.lift()
#root.focus_force()
#window.after_idle(window.attributes,'-topmost',False)
#root.update()
#stk=root.tk.eval('wm stackorder '+str(window))
#print('stk=',stk)
# Make this box the default
if event.widget in self.boxes:
self.default_object=event.widget
return
if evt.num==1:
# Left click --> select
try:
#print(SEL_FIRST,SEL_LAST)
txt = self.txt.get(SEL_FIRST,SEL_LAST)
print("Select text:",txt)
# print("SEL_FIRST:",type(SEL_FIRST)," SEL_LAST:",SEL_LAST)
except TclError:
print("No text selected")
elif evt.num==2:
# Middle click --> insert
try:
txt = self.txt.get(SEL_FIRST,SEL_LAST)
print("Select text:",txt)
except TclError:
print("No text selected")
txt = self.last_txt
print('Insert')
#self.txt.insert(END, txt+'\n')
self.txt.see(END)
self.last_txt=txt
if self.P.Immediate_TX:
self.q.put(txt)
else:
self.text_buff+=txt
self.q.put(txt+' ')
self.text_buff=''
elif evt.num==3:
# Right click --> ???
pass
# Callback to process mouse events in the big text box
def Text_Mouse(self,evt):
print('TEXT MOUSE: button=',evt.num,'\tpos=',evt.x,evt.y)
shift = ((evt.state & 0x0001) != 0)
control = (evt.state & 0x0004) != 0
mode = self.MODE.get()
#print('\tshift=',shift,'\tctrl=',control)
if evt.num==1:
# Right click --> Make the text box the default widget so we can type things in to xmit
if mode=='CW' or shift or control:
self.force_focus(evt.widget)
return('break')
# Left click --> select a word
idx3=self.txt.index("current")
idx4=self.txt.index("current wordstart")
idx5=self.txt.index("current wordend")
print('\tLeft click ... idx=',idx3,idx4,idx5)
txt = self.txt.get(idx4,idx5).replace(chr(10),'')
print("\ttxt=",txt,'\tlen=',len(txt),'\t',show_ascii(txt))
if len(txt)==0:
print('\tOoops - nothing selected')
return('break')
# Insert text into next entry box
widget=self.default_object
widget.delete(0, END)
widget.insert(0,txt)
# Take care of dupes & hints
if widget==self.call:
self.dup_check(txt)
self.get_hint()
if self.P.AUTOFILL:
self.P.KEYING.insert_hint()
# Move on to the next entry box
evt.widget=widget
self.default_object=self.P.KEYING.next_event('Tab',evt)
self.force_focus(self.default_object)
return('break')
# Keeping this around for now
# Left click --> select
try:
idx1=self.txt.index(SEL_FIRST)
idx2=self.txt.index(SEL_FIRST)
idx3=self.txt.index(CURRENT)
print('\tLeft click ... idx=',idx1,idx2,idx3)
txt = self.txt.get(SEL_FIRST,SEL_LAST)
print("Select text:",txt)
# print("SEL_FIRST:",type(SEL_FIRST)," SEL_LAST:",SEL_LAST)
except TclError:
print("No text selected")
elif evt.num==2:
# Middle click --> insert
try:
txt = self.txt.get(SEL_FIRST,SEL_LAST)
print("Select text:",txt)
except TclError:
print("No text selected")
txt = self.last_txt
print('Insert')
#self.txt.insert(END, txt+'\n')
self.txt.see(END)
self.last_txt=txt
if self.P.Immediate_TX:
self.q.put(txt)
else:
self.text_buff+=txt
self.q.put(txt+' ')
self.text_buff=''
elif evt.num==3:
# Right click --> Mske the text box the default widget so we can type things in to xmit
self.force_focus(evt.widget)
return('break')
# Callback to process mouse events on the spot buttons
def Spots_Mouse(self,evt):
#print 'HELLO!!!!!!!',evt.num
# Determine which button was clicked
for i in range(len(self.spots)):
if self.spots[i]['Button'] == evt.widget:
idx=i
break
# Take action
if evt.num==1:
# Left click --> save
self.Spots_cb(idx,1)
elif evt.num==2:
# Middle click --> clear
self.Spots_cb(idx,-1)
elif evt.num==3:
# Right click --> tune
self.Spots_cb(idx,2)
# Callback to set logs fields, optionally from fldigi
def Set_Log_Fields(self,fields=None,CALL_ONLY=False):
if self.P.WF_ONLY and False:
print('GUI - SET_LOG_FIELDS skipped - can crash fldigi if in waterfall-only mode')
return
if not self.P.WF_ONLY and fields==None:
fields = self.sock.get_log_fields(CALL_ONLY)
if CALL_ONLY and len(fields['Call'])==0:
return
#print("GUI - SET_LOG_FIELDS ...",fields)
self.call.delete(0, END)
self.call.insert(0,fields['Call'])
self.call.configure(fg='black')
if CALL_ONLY:
return fields
self.name.delete(0, END)
self.name.insert(0,fields['Name'])
self.qth.delete(0, END)
self.qth.insert(0,fields['QTH'])
self.rstin.delete(0, END)
rst=fields['RST_in']
if rst=='':
rst='5nn'
self.rstin.insert(0,rst)
self.rstout.delete(0, END)
rst=fields['RST_out']
if rst=='':
rst='5nn'
self.rstout.insert(0,rst)
self.exch.delete(0, END)
self.exch.insert(0,fields['Exchange'])
self.cat.delete(0, END)
self.cat.insert(0,fields['Category'])
self.prec.delete(0, END)
self.prec.insert(0,fields['Prec'])
self.check.delete(0, END)
self.check.insert(0,fields['Check'])
return fields
# Callback to read log fields and optionally send to fldigi
def Read_Log_Fields(self,send2fldigi=True):
print("GUI - READ_LOG_FIELDS ...",send2fldigi,'\tcontest=',self.P.contest_name)
call = self.get_call()
name = self.get_name()
qth = self.get_qth()
rst_in = self.get_rst_in()
rst_out = self.get_rst_out()
cat = self.get_cat()
prec = self.get_prec()
check = self.get_check()
if self.P.contest_name=='NAQP-CW':
exchange=qth
else:
exchange=self.get_exchange()
fields = {'Call':call,'Name':name,'RST_in':rst_in,'RST_out':rst_out, \
'QTH':qth,'Exchange':exchange, \
'Category':cat,'Prec':prec,'Check':check}
if send2fldigi and not self.P.WF_ONLY:
print('\tfields=',fields)
self.sock.set_log_fields(fields)
return fields
# Callback to wipe out log fields
def Clear_Log_Fields(self):
print('CLEAR_LOG_FILEDS: ...')
self.call.delete(0, END)
self.call.configure(bg=self.default_color,fg='black')
self.name.delete(0, END)
self.qth.delete(0, END)
self.rstin.delete(0, END)
self.rstout.delete(0, END)
if self.P.contest_name=='SATELLITES':
self.rstin.insert(0,'5')
self.rstout.insert(0,'5nn')
else:
self.rstin.insert(0,'5NN')
self.rstout.insert(0,'5NN')
self.cat.delete(0, END)
self.scp.delete(0, END)
self.prec.delete(0, END)
self.check.delete(0, END)
self.qsl_rcvd.set(0)
self.info.delete(0,END)
self.prefill=False
self.prev_call=''
# Callback to select a radio for SO2R
def SelectRadio(self):
iRadio=self.iRadio.get()
if iRadio==1:
self.P.sock=self.P.sock1
self.P.ser=self.P.ser1
elif iRadio==2:
self.P.sock=self.P.sock2
self.P.ser=self.P.ser2
else:
self.P.sock=self.P.sock3
self.P.ser=self.P.ser3
self.sock=self.P.sock
print("You selected radio " + str(iRadio),'\tP.sock=',self.P.sock)
rig=self.P.sock.rig_type2
self.root.title("pyKeyer by AA2IL"+rig)
# Callback to toggle PTT
def Toggle_PTT(self,iop=None):
if iop==None:
self.P.PTT = not self.P.PTT