From e2bdff0706f6b53ea69e76488ef09ee8c93acf24 Mon Sep 17 00:00:00 2001 From: mbridak Date: Fri, 1 Nov 2024 17:29:03 -0700 Subject: [PATCH] @mbridak Add function to load a call history file. --- not1mm/__main__.py | 49 +++++++++++++++++++++++++++++++++++++++++++++ not1mm/data/main.ui | 21 +++++++++++++++---- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/not1mm/__main__.py b/not1mm/__main__.py index a80eae8..3ae7f1e 100644 --- a/not1mm/__main__.py +++ b/not1mm/__main__.py @@ -199,6 +199,7 @@ def __init__(self, splash): self.setCorner(Qt.Corner.TopLeftCorner, Qt.DockWidgetArea.LeftDockWidgetArea) self.setCorner(Qt.Corner.BottomLeftCorner, Qt.DockWidgetArea.LeftDockWidgetArea) uic.loadUi(fsutils.APP_DATA_PATH / "main.ui", self) + self.history_info.hide() QApplication.instance().focusObjectChanged.connect(self.on_focus_changed) self.inputs_dict = { self.callsign: "callsign", @@ -230,6 +231,7 @@ def __init__(self, splash): self.actionCheck_Window.triggered.connect(self.launch_check_window) self.actionVFO.triggered.connect(self.launch_vfo) self.actionRecalculate_Mults.triggered.connect(self.recalculate_mults) + self.actionLoad_Call_History_File.triggered.connect(self.load_call_history) self.actionGenerate_Cabrillo_ASCII.triggered.connect( lambda x: self.generate_cabrillo("ascii") @@ -703,6 +705,45 @@ def __init__(self, splash): "You can udate to the current version by using:\npip install -U not1mm" ) + def load_call_history(self) -> None: + """""" + filename = self.filepicker("other") + if filename: + self.database.create_callhistory_table() + self.database.delete_callhistory() + + try: + with open(filename, "rt", encoding="utf-8") as file_descriptor: + lines = file_descriptor.readlines() + if "!!Order!!" in lines[0]: + item_names = lines[0].strip().split(",") + # ['!!Order!!', 'Call', 'Sect', 'State', 'CK', 'UserText', ''] + item_names = item_names[1:-1] + # ['Call', 'Sect', 'State', 'CK', 'UserText'] + lines = lines[1:] + group_list = [] + for line in lines: + if line.startswith("#"): + continue + group = {} + fields = line.strip().split(",") + # ['4U1WB','MDC','DC','89',''] + count = 0 + try: + for item in item_names: + if item == "": + continue + group[item] = fields[count] + count += 1 + group_list.append(group) + # database.add_callhistory_item(group) + # print(f"{group=}") + except IndexError: + ... + self.database.add_callhistory_items(group_list) + except FileNotFoundError as err: + self.show_message_box(f"{err}") + def on_focus_changed(self, new): """""" if self.use_esm: @@ -1728,6 +1769,14 @@ def filepicker(self, action: str) -> str: "Database (*.db)", options=options, ) + if action == "other": + file, _ = QFileDialog.getOpenFileName( + self, + "Choose a File", + "~/", + "Any (*.*)", + options=options, + ) return file def recalculate_mults(self) -> None: diff --git a/not1mm/data/main.ui b/not1mm/data/main.ui index 7baf05b..def2b27 100644 --- a/not1mm/data/main.ui +++ b/not1mm/data/main.ui @@ -9,8 +9,8 @@ 0 0 - 785 - 268 + 855 + 621 @@ -59,7 +59,7 @@ 0 - + @@ -1367,6 +1367,13 @@ + + + + + + + @@ -1443,7 +1450,7 @@ 0 0 - 878 + 855 25 @@ -1476,6 +1483,7 @@ + @@ -1978,6 +1986,11 @@ + + + Load Call History File + +