-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyer_control_tk.py
executable file
·151 lines (127 loc) · 5.48 KB
/
keyer_control_tk.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
############################################################################################
#
# Rig Control GUI - Tk version - Rev 1.0
# Copyright (C) 2024 by Joseph B. Attili, aa2il AT arrl DOT net
#
# Portion of GUI related to keyer controls - Tk version
#
# To Do: This should be part of a library
#
############################################################################################
#
# 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
if sys.version_info[0]==3:
from tkinter import *
import tkinter.ttk as ttk
else:
from Tkinter import *
import ttk
from functools import partial
from os import system
################################################################################
class KEYER_CONTROL():
def __init__(self,P):
self.P = P
parent = P.root
self.sock = P.sock
self.winkey_mode = P.keyer_device.winkey_mode
print('KEYER CONTROL INIT:',hex(self.winkey_mode))
self.win=Toplevel(parent)
self.win.title("Keyer Control")
self.tabs = ttk.Notebook(self.win) # Create Tab Control
self.win.withdraw()
self.win.protocol("WM_DELETE_WINDOW", self.hide)
# Add a tab for keyer control
tab1 = ttk.Frame(self.tabs) # Create a tab
self.tabs.add(tab1, text='Keyer Ctrl') # Add the tab
self.tabs.pack(expand=1, fill="both") # Pack to make visible
######################################################################
# Create a frame with buttons to select Iambic mode
IambicFrame = Frame(tab1)
IambicFrame.pack(side=TOP)
self.status = StringVar(parent)
Label(IambicFrame, textvariable=self.status ).pack(side=TOP)
self.status.set( 'WinKeyer Mode='+hex(self.winkey_mode) )
self.iambic = IntVar(parent)
self.keyer_modes = {'Iambic A':1 , 'Iambic B':0 , 'Ultimatic':2,'Bug':3}
for (txt,val) in self.keyer_modes.items():
Radiobutton(IambicFrame,
text=txt,
indicatoron = 0,
variable=self.iambic,
command=lambda: self.SelectIambic(self),
value=val).pack(side=LEFT,anchor=W)
self.SelectIambic(1)
######################################################################
# Create a frame with buttons to support other misc functions
MiscFrame = Frame(tab1)
MiscFrame.pack(side=TOP)
self.Buttons=[]
self.Flags=[]
self.keyer_flags={"Paddle Watchdog":0x80 , "Paddle Echo":0x40, "Paddle Swap":0x08, \
"Serial Echo":0x04, "Autospace":0x02, "Contest Spacing":0x01}
i=0
for (txt,mask) in self.keyer_flags.items():
b = Button(MiscFrame, text=txt,
command=lambda j=i, m=mask: self.ToggleButton(0,j,m) )
b.pack(side=LEFT,anchor=W)
self.Buttons.append(b)
self.Flags.append(None)
self.ToggleButton(1,i,mask)
i+=1
# Ready to rock & roll
self.hide()
def show(self):
print('Show Keyer Control Window ...')
self.win.update()
self.win.deiconify()
def hide(self):
print('Hide Keyer Control Window ...')
self.win.withdraw()
############################################################################################
def CloseWindow(self):
print('Close window')
self.P.gui.KeyerCtrlCB()
def SelectIambic(self,iopt=None):
print('\nSELECT IAMBIC: opt=',iopt,'\twk mode=',hex(self.winkey_mode))
if iopt==1:
m = (self.winkey_mode & 0x30) >> 4
print('\tm=',hex(m))
self.iambic.set( m )
else:
m = self.iambic.get()
print('\tm=',m)
self.winkey_mode = (self.winkey_mode & ~0x30) | (m<<4)
print('\twk mode=',hex(self.winkey_mode))
self.P.keyer_device.send_command(chr(0x0E)+chr(self.winkey_mode))
self.status.set( 'WinKeyer Mode='+hex(self.winkey_mode) )
def ToggleButton(self,iopt,i,mask):
print('\nTOGGLE BUTTON: opt=',iopt,'\ti=',i,'\tmask=',mask)
if iopt==1:
m = self.winkey_mode & mask
print('\tm=',hex(m))
self.Flags[i] = m>0
else:
self.Flags[i] = not self.Flags[i]
if self.Flags[i]:
self.winkey_mode = self.winkey_mode | mask
else:
self.winkey_mode = self.winkey_mode & ~mask
print('\t',self.Flags[i],'\twk mode=',hex(self.winkey_mode))
self.P.keyer_device.send_command(chr(0x0E)+chr(self.winkey_mode))
self.status.set( 'WinKeyer Mode='+hex(self.winkey_mode) )
if not self.Flags[i]:
self.Buttons[i].configure(relief='raised')
else:
self.Buttons[i].configure(relief='sunken')