Skip to content

Commit

Permalink
@mbridak Add function to load a call history file.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbridak committed Nov 2, 2024
1 parent bb8dc1a commit e2bdff0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
49 changes: 49 additions & 0 deletions not1mm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
21 changes: 17 additions & 4 deletions not1mm/data/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>785</width>
<height>268</height>
<width>855</width>
<height>621</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -59,7 +59,7 @@
<number>0</number>
</property>
<item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0,0">
<item>
<layout class="QHBoxLayout" name="mainsection">
<item>
Expand Down Expand Up @@ -1367,6 +1367,13 @@
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="history_info">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="StatusLine">
<property name="sizeConstraint">
Expand Down Expand Up @@ -1443,7 +1450,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>878</width>
<width>855</width>
<height>25</height>
</rect>
</property>
Expand Down Expand Up @@ -1476,6 +1483,7 @@
<addaction name="separator"/>
<addaction name="actionEdit_Macros"/>
<addaction name="separator"/>
<addaction name="actionLoad_Call_History_File"/>
<addaction name="actionUpdate_CTY"/>
<addaction name="actionUpdate_MASTER_SCP"/>
<addaction name="separator"/>
Expand Down Expand Up @@ -1978,6 +1986,11 @@
</font>
</property>
</action>
<action name="actionLoad_Call_History_File">
<property name="text">
<string>Load Call History File</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down

0 comments on commit e2bdff0

Please sign in to comment.