88from not1mm .lib .database import DataBase
99import os
1010from json import loads
11+ from json .decoder import JSONDecodeError
1112
1213import logging
1314
1617
1718class DXCCWindow (QDockWidget ):
1819 message = pyqtSignal (dict )
20+ ctyfile = {}
1921 dbname = None
2022 db = None
2123 model = None
@@ -54,10 +56,37 @@ def __init__(self, action):
5456 self .get_log ()
5557 self .dxcc_table .resizeColumnsToContents ()
5658 self .dxcc_table .resizeRowsToContents ()
59+ self .load_cty_data ()
5760
5861 def setActive (self , mode : bool ):
5962 self .active = bool (mode )
6063
64+ def load_cty_data (self ):
65+ try :
66+ with open (
67+ fsutils .APP_DATA_PATH / "cty.json" , "rt" , encoding = "utf-8"
68+ ) as c_file :
69+ self .ctyfile = loads (c_file .read ())
70+ except (IOError , JSONDecodeError , TypeError ):
71+ logging .critical ("There was an error parsing the BigCity file." )
72+
73+ def dxcc_lookup (self , dxcc : str ) -> str :
74+ """Lookup callsign in cty.dat file.
75+
76+ Parameters
77+ ----------
78+ callsign : str
79+ callsign to lookup
80+
81+ Returns
82+ -------
83+ return : dict
84+ {'entity': 'European Russia', 'cq': 16, 'itu': 29, 'continent': 'EU', 'lat': 53.65, 'long': -41.37, 'tz': 4.0, 'len': 2, 'primary_pfx': 'UA', 'exact_match': False}
85+ """
86+
87+ result = self .ctyfile .get (dxcc , {})
88+ return result .get ("entity" , "" )
89+
6190 def get_log (self ):
6291 """dxcc_table"""
6392
@@ -74,6 +103,8 @@ def get_log(self):
74103 self .dxcc_table .insertRow (row_number )
75104 for column , data in enumerate (row_data .values ()):
76105 item = QtWidgets .QTableWidgetItem (str (data ))
106+ if column == 0 :
107+ item .setToolTip (self .dxcc_lookup (data ))
77108 if column > 0 and column < 7 :
78109 if data == 0 :
79110 item .setBackground (QBrush (QColor (44 , 138 , 44 )))
0 commit comments