-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallSignParser.py
More file actions
167 lines (127 loc) · 5.16 KB
/
CallSignParser.py
File metadata and controls
167 lines (127 loc) · 5.16 KB
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
import tkinter as tk
from tkinter import messagebox
from parser import CallSignParser, CallSignParserError, CtyDownloadError
"""
Python Call Sign Parser with Interface
Copyright (c) 2026 by Scott Anthony Hibbs KD4SIR
Released under a GPLv3 License.
If you do use or modify this software,
I'd really love to hear about it at scott hibbs at gmail dot com.
Type a call sign in the input box and get the result
from the cty.dat file. This can be updated at
https://www.country-files.com/category/big-cty/
maintained with my thanks by Jim Reisert AD1C
- Scott KD4SIR
"""
# Top level window
frame = tk.Tk()
frame.title("Call Sign Parser by Scott Hibbs KD4SIR")
frame.geometry('500x250')
def printinput1():
"""Handle the search button click or Enter key press."""
# Get input
inp = inputent.get().strip()
if len(inp) == 0:
return
# Clear previous error styling
lblreturn.config(fg="black")
try:
# Parse the call sign using the parser module
prefix, separator, suffix, country, is_valid = CallSignParser.parse(inp)
# Display results
lblrepeat.config(text=f"\n The original input is: {list(inp)}")
lblprefix.config(text=f"The prefix is: {prefix}")
lblseparator.config(text=f"The separator is: {separator}")
lblsuffix.config(text=f"The suffix is: {suffix}")
if is_valid:
lblreturn.config(text=f"This is from: {country}", fg="black")
else:
lblreturn.config(text=f"This is from: {country}", fg="orange")
except CallSignParserError as e:
# Display error to user
lblrepeat.config(text="")
lblprefix.config(text="The prefix:")
lblseparator.config(text="The separator:")
lblsuffix.config(text="The suffix:")
lblreturn.config(text=f"Error: {e}", fg="red")
def show_startup_error(error_msg):
"""Show an error dialog on startup for critical errors."""
messagebox.showerror("Startup Error", error_msg)
def update_date_label():
"""Update the database date label."""
date_str = CallSignParser.get_cty_file_date()
lbldate.config(text=f"Database updated: {date_str}")
def update_database():
"""Download the latest cty.dat file."""
if messagebox.askyesno("Update Database",
"Download the latest cty.dat from country-files.com?"):
try:
CallSignParser.download_cty_file()
update_date_label()
messagebox.showinfo("Update Complete",
"Database updated successfully!")
except CtyDownloadError as e:
messagebox.showerror("Update Failed", str(e))
def check_database_age():
"""Check if cty.dat is old and prompt to update."""
age_days = CallSignParser.get_cty_file_age_days()
if age_days == -1:
# File doesn't exist, offer to download
if messagebox.askyesno("Database Missing",
"cty.dat not found. Download now?"):
try:
CallSignParser.download_cty_file()
messagebox.showinfo("Download Complete",
"Database downloaded successfully!")
except CtyDownloadError as e:
messagebox.showerror("Download Failed", str(e))
elif age_days > 30:
# File is older than 30 days
if messagebox.askyesno("Database Outdated",
f"cty.dat is {age_days} days old.\n"
"Download the latest version?"):
try:
CallSignParser.download_cty_file()
messagebox.showinfo("Update Complete",
"Database updated successfully!")
except CtyDownloadError as e:
messagebox.showerror("Update Failed", str(e))
# Check database age on startup
check_database_age()
# Verify cty.dat is accessible on startup
try:
# This will cache the file for future use
CallSignParser._load_cty_file()
except CallSignParserError as e:
show_startup_error(str(e))
# Main Program
lbltitle = tk.Label(frame, text="\nCall Sign Look Up")
lbltitle.pack()
# Database date label
lbldate = tk.Label(frame, text="", fg="gray")
lbldate.pack()
update_date_label()
# Entry Widget creation
inputent = tk.Entry(frame, width=30, justify="center")
inputent.pack()
# Button Creation
buttonFrame = tk.Frame(frame)
buttonFrame.pack()
printButton = tk.Button(buttonFrame, text="Search", command=printinput1)
printButton.pack(side=tk.LEFT, padx=5)
updateButton = tk.Button(buttonFrame, text="Update Database", command=update_database)
updateButton.pack(side=tk.LEFT, padx=5)
# Label Creation
lblrepeat = tk.Label(frame, text="")
lblrepeat.pack()
lblprefix = tk.Label(frame, text="The prefix:")
lblprefix.pack()
lblseparator = tk.Label(frame, text="The separator:")
lblseparator.pack()
lblsuffix = tk.Label(frame, text="The suffix:")
lblsuffix.pack()
lblreturn = tk.Label(frame, text="Results:")
lblreturn.pack()
# Bindings
frame.bind('<Return>', (lambda event: printinput1()))
frame.mainloop()