Skip to content

Commit b666e25

Browse files
authored
Merge pull request #209 from mbridak/121-call-history
121 call history
2 parents ca85ccf + c701425 commit b666e25

File tree

7 files changed

+877
-623
lines changed

7 files changed

+877
-623
lines changed

not1mm/__main__.py

+110-2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ class MainWindow(QtWidgets.QMainWindow):
164164
text_color = QColorConstants.Black
165165
current_palette = None
166166
use_esm = False
167+
use_call_history = False
167168
esm_dict = {}
168169

169170
radio_thread = QThread()
@@ -199,6 +200,7 @@ def __init__(self, splash):
199200
self.setCorner(Qt.Corner.TopLeftCorner, Qt.DockWidgetArea.LeftDockWidgetArea)
200201
self.setCorner(Qt.Corner.BottomLeftCorner, Qt.DockWidgetArea.LeftDockWidgetArea)
201202
uic.loadUi(fsutils.APP_DATA_PATH / "main.ui", self)
203+
self.history_info.hide()
202204
QApplication.instance().focusObjectChanged.connect(self.on_focus_changed)
203205
self.inputs_dict = {
204206
self.callsign: "callsign",
@@ -224,12 +226,15 @@ def __init__(self, splash):
224226

225227
self.actionCW_Macros.triggered.connect(self.cw_macros_state_changed)
226228
self.actionDark_Mode_2.triggered.connect(self.dark_mode_state_changed)
227-
self.actionCommand_Buttons.triggered.connect(self.command_buttons_state_change)
229+
self.actionCommand_Buttons_2.triggered.connect(
230+
self.command_buttons_state_change
231+
)
228232
self.actionLog_Window.triggered.connect(self.launch_log_window)
229233
self.actionBandmap.triggered.connect(self.launch_bandmap_window)
230234
self.actionCheck_Window.triggered.connect(self.launch_check_window)
231235
self.actionVFO.triggered.connect(self.launch_vfo)
232236
self.actionRecalculate_Mults.triggered.connect(self.recalculate_mults)
237+
self.actionLoad_Call_History_File.triggered.connect(self.load_call_history)
233238

234239
self.actionGenerate_Cabrillo_ASCII.triggered.connect(
235240
lambda x: self.generate_cabrillo("ascii")
@@ -290,6 +295,12 @@ def __init__(self, splash):
290295
self.radio_green = QtGui.QPixmap(str(icon_path / "radio_green.png"))
291296
self.radio_icon.setPixmap(self.radio_grey)
292297

298+
self.log_it.clicked.connect(self.save_contact)
299+
self.wipe.clicked.connect(self.clearinputs)
300+
self.esc_stop.clicked.connect(self.stop_cw)
301+
self.mark.clicked.connect(self.mark_spot)
302+
self.spot_it.clicked.connect(self.spot_dx)
303+
293304
self.F1.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu)
294305
self.F1.customContextMenuRequested.connect(lambda x: self.edit_macro(self.F1))
295306
self.F1.clicked.connect(lambda x: self.process_function_key(self.F1))
@@ -703,6 +714,45 @@ def __init__(self, splash):
703714
"You can udate to the current version by using:\npip install -U not1mm"
704715
)
705716

717+
def load_call_history(self) -> None:
718+
""""""
719+
filename = self.filepicker("other")
720+
if filename:
721+
self.database.create_callhistory_table()
722+
self.database.delete_callhistory()
723+
724+
try:
725+
with open(filename, "rt", encoding="utf-8") as file_descriptor:
726+
lines = file_descriptor.readlines()
727+
if "!!Order!!" in lines[0]:
728+
item_names = lines[0].strip().split(",")
729+
# ['!!Order!!', 'Call', 'Sect', 'State', 'CK', 'UserText', '']
730+
item_names = item_names[1:-1]
731+
# ['Call', 'Sect', 'State', 'CK', 'UserText']
732+
lines = lines[1:]
733+
group_list = []
734+
for line in lines:
735+
if line.startswith("#"):
736+
continue
737+
group = {}
738+
fields = line.strip().split(",")
739+
# ['4U1WB','MDC','DC','89','']
740+
count = 0
741+
try:
742+
for item in item_names:
743+
if item == "":
744+
continue
745+
group[item] = fields[count]
746+
count += 1
747+
group_list.append(group)
748+
# database.add_callhistory_item(group)
749+
# print(f"{group=}")
750+
except IndexError:
751+
...
752+
self.database.add_callhistory_items(group_list)
753+
except FileNotFoundError as err:
754+
self.show_message_box(f"{err}")
755+
706756
def on_focus_changed(self, new):
707757
""""""
708758
if self.use_esm:
@@ -1728,6 +1778,14 @@ def filepicker(self, action: str) -> str:
17281778
"Database (*.db)",
17291779
options=options,
17301780
)
1781+
if action == "other":
1782+
file, _ = QFileDialog.getOpenFileName(
1783+
self,
1784+
"Choose a File",
1785+
"~/",
1786+
"Any (*.*)",
1787+
options=options,
1788+
)
17311789
return file
17321790

17331791
def recalculate_mults(self) -> None:
@@ -1907,6 +1965,43 @@ def cwspeed_spinbox_changed(self) -> None:
19071965
if self.rig_control.interface == "flrig":
19081966
self.rig_control.cat.set_flrig_cw_speed(self.cw_speed.value())
19091967

1968+
def stop_cw(self):
1969+
""""""
1970+
if self.cw is not None:
1971+
if self.cw.servertype == 1:
1972+
self.cw.sendcw("\x1b4")
1973+
return
1974+
if self.rig_control:
1975+
if self.rig_control.online:
1976+
if self.pref.get("cwtype") == 3 and self.rig_control is not None:
1977+
if self.rig_control.interface == "flrig":
1978+
self.rig_control.cat.set_flrig_cw_send(False)
1979+
self.rig_control.cat.set_flrig_cw_send(True)
1980+
1981+
def mark_spot(self):
1982+
""""""
1983+
freq = self.radio_state.get("vfoa")
1984+
dx = self.callsign.text()
1985+
if freq and dx:
1986+
cmd = {}
1987+
cmd["cmd"] = "MARKDX"
1988+
cmd["dx"] = dx
1989+
cmd["freq"] = float(int(freq) / 1000)
1990+
if self.bandmap_window:
1991+
self.bandmap_window.msg_from_main(cmd)
1992+
1993+
def spot_dx(self):
1994+
""""""
1995+
freq = self.radio_state.get("vfoa")
1996+
dx = self.callsign.text()
1997+
if freq and dx:
1998+
cmd = {}
1999+
cmd["cmd"] = "SPOTDX"
2000+
cmd["dx"] = dx
2001+
cmd["freq"] = float(int(freq) / 1000)
2002+
if self.bandmap_window:
2003+
self.bandmap_window.msg_from_main(cmd)
2004+
19102005
def keyPressEvent(self, event) -> None: # pylint: disable=invalid-name
19112006
"""
19122007
This overrides Qt key event.
@@ -1921,6 +2016,12 @@ def keyPressEvent(self, event) -> None: # pylint: disable=invalid-name
19212016
None
19222017
"""
19232018
modifier = event.modifiers()
2019+
if (
2020+
event.key() == Qt.Key.Key_Equal
2021+
and modifier == Qt.KeyboardModifier.ControlModifier
2022+
):
2023+
self.save_contact()
2024+
return
19242025
if event.key() == Qt.Key.Key_K:
19252026
self.toggle_cw_entry()
19262027
return
@@ -2901,6 +3002,9 @@ def readpreferences(self) -> None:
29013002
"DISABLED": None,
29023003
}
29033004

3005+
self.use_call_history = self.pref.get("use_call_history", False)
3006+
if self.use_call_history:
3007+
self.history_info.show()
29043008
self.use_esm = self.pref.get("use_esm", False)
29053009
self.esm_dict["CQ"] = fkey_dict.get(self.pref.get("esm_cq", "DISABLED"))
29063010
self.esm_dict["EXCH"] = fkey_dict.get(self.pref.get("esm_exch", "DISABLED"))
@@ -2968,7 +3072,7 @@ def command_buttons_state_change(self) -> None:
29683072
None
29693073
"""
29703074

2971-
self.pref["command_buttons"] = self.actionCommand_Buttons.isChecked()
3075+
self.pref["command_buttons"] = self.actionCommand_Buttons_2.isChecked()
29723076
self.write_preference()
29733077
self.show_command_buttons()
29743078

@@ -3125,6 +3229,10 @@ def callsign_changed(self) -> None:
31253229
self.lookup_service.msg_from_main(cmd)
31263230
self.next_field.setFocus()
31273231
if self.contest:
3232+
if self.use_call_history and hasattr(
3233+
self.contest, "check_call_history"
3234+
):
3235+
self.contest.check_call_history(self)
31283236
if "CQ WW" in self.contest.name or "IARU HF" in self.contest.name:
31293237
self.contest.prefill(self)
31303238
return

0 commit comments

Comments
 (0)