-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataStructures.py
164 lines (146 loc) · 5.13 KB
/
dataStructures.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
PHONETIC_ALPHABET = {
'A': 'ALPHA',
'B': 'BRAVO',
'C': 'CHARLIE',
'D': 'DELTA',
'E': 'ECHO',
'F': 'FOXTROT',
'G': 'GOLF',
'H': 'HOTEL',
'I': 'INDIA',
'J': 'JULIET',
'K': 'KILO',
'L': 'LIMA',
'M': 'MIKE',
'N': 'NOVEMBER',
'O': 'OSCAR',
'P': 'PAPA',
'Q': 'QUEBEC',
'R': 'ROMEO',
'S': 'SIERRA',
'T': 'TANGO',
'U': 'UNIFORM', #'UNICORN',
'V': 'VICTOR',
'W': 'WHISKEY',
'X': 'XRAY',
'Y': 'YANKEE',
'Z': 'ZULU',
'0': 'ZERO',
'1': 'ONE',
'2': 'TWO',
'3': 'THREE', #'TREE',
'4': 'FOUR', #'FOWER',
'5': 'FIVE', #'FIFE',
'6': 'SIX',
'7': 'SEVEN',
'8': 'EIGHT',
'9': 'NINER', #'NINE'
' ': ''
}
#Class for a single station
class Station:
#Constructor
def __init__(self, callsign='', name='', ack=False, note='', id = None):
self.callsign = callsign.upper()
self.name = name
self.ack = ack
self.note = note
self.id = id
if ack:
self.ackText = 'Yes'
else:
self.ackText = ''
#Test a station for a callsign match
def match(self, pattern):
match = True
for i in range(len(self.callsign)):
if pattern[i] != '/' and pattern[i] != self.callsign[i]:
match = False
return match
#Load from database, given an ID
def loadFromDatabase(self, p):
p.cur.execute('SELECT callsign, name, ack, note FROM stations WHERE rowid = ?', (self.id,))
line = p.cur.fetchone()
if len(line) > 0:
self.callsign = line[0]
self.name = line[1]
self.ack = line[2]
self.note = line[3]
else:
raise RuntimeError
#Save to database, either update or insert
def saveToDatabase(self, p):
if self.id is not None:
p.cur.execute('UPDATE stations SET callsign = ?, name = ?, ack = ?, note = ? WHERE rowid = ?;',
(self.callsign, self.name, self.ack, self.note, self.id))
p.con.commit()
else:
p.cur.execute('INSERT INTO stations (callsign, name, ack, note) VALUES (?, ?, ?, ?);',
(self.callsign, self.name, self.ack, self.note))
p.con.commit()
self.id = p.cur.lastrowid
#Change the station's acknowledge status
def toggleAck(self):
if self.ack:
self.ack = False
self.ackText = ''
else:
self.ack = True
self.ackText = 'Yes'
#Get an array of phonetic words from the callsign
def getPhoneticArray(self):
outList = []
for callChar in self.callsign:
outList.append(PHONETIC_ALPHABET[callChar])
return outList
#Class for a single net script
class Script:
#Constructor
def __init__(self, name='', contents = '', id = None):
self.name = name
self.contents = contents
self.id = id
#Load from database, given an ID
def loadFromDatabase(self, p):
p.cur.execute('SELECT name, contents FROM scripts WHERE rowid = ?', (self.id,))
line = p.cur.fetchone()
if len(line) > 0:
self.name = line[0]
self.contents = line[1]
else:
raise RuntimeError
#Save to database, either update or insert
def saveToDatabase(self, p):
if self.id is not None:
p.cur.execute('UPDATE scripts SET name = ?, contents = ? WHERE rowid = ?;', (self.name, self.contents, self.id))
p.con.commit()
else:
p.cur.execute('INSERT INTO scripts (name, contents) VALUES (?, ?);', (self.name, self.contents))
p.con.commit()
self.id = p.cur.lastrowid
#A class to handle the list of stations
class StationList:
currentStation = Station()
currentStationIndex = 0
def __init__(self, p):
self.list = []
self.updateListFromDatabase(p)
self.currentStationIndex = 0
self.currentStation = self.list[self.currentStationIndex]
def updateListFromDatabase(self, p):
for row in p.cur.execute('SELECT rowid, callsign, name, ack, note FROM stations ORDER BY callsign;'):
self.list.append(Station(row[1], row[2], row[3], row[4], row[0]))
def selectNext(self):
self.currentStationIndex = self.currentStationIndex + 1
if self.currentStationIndex >= len(self.list):
self.currentStationIndex = 0
self.currentStation = self.list[self.currentStationIndex]
def selectPrevious(self):
self.currentStationIndex = self.currentStationIndex - 1
if self.currentStationIndex < 0:
self.currentStationIndex = len(self.list) - 1
self.currentStation = self.list[self.currentStationIndex]
def selectStation(self, index):
if index >= 0 and index < len(self.list):
self.currentStationIndex = index
self.currentStation = self.list[self.currentStationIndex]