Constants in uppercase

This commit is contained in:
alessandro90
2018-11-11 16:16:00 +01:00
parent 9f6a2a638e
commit 91a9305644
4 changed files with 40 additions and 40 deletions

View File

@@ -79,7 +79,7 @@ class AudioPlayer(QObject):
def set_audio_player(self, fname = ""): def set_audio_player(self, fname = ""):
self.__first_call = True self.__first_call = True
self.__reset_audio_widget() self.__reset_audio_widget()
full_name = os.path.join(Constants.data_folder, Constants.audio_folder, fname + '.ogg') full_name = os.path.join(Constants.DATA_FOLDER, Constants.AUDIO_FOLDER, fname + '.ogg')
if os.path.exists(full_name): if os.path.exists(full_name):
self.__play.setEnabled(True) self.__play.setEnabled(True)
self.__audio_file = full_name self.__audio_file = full_name

44
main.py
View File

@@ -308,7 +308,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
] ]
def set_mode_tree_widget(self): def set_mode_tree_widget(self):
for parent, children in Constants.modes.items(): for parent, children in Constants.MODES.items():
iparent = QTreeWidgetItem([parent]) iparent = QTreeWidgetItem([parent])
self.mode_tree_widget.addTopLevelItem(iparent) self.mode_tree_widget.addTopLevelItem(iparent)
for child in children: for child in children:
@@ -318,11 +318,11 @@ class MyApp(QMainWindow, Ui_MainWindow):
def manage_mode_selections(self): def manage_mode_selections(self):
selected_items = self.mode_tree_widget.selectedItems() selected_items = self.mode_tree_widget.selectedItems()
parents = Constants.modes.keys() parents = Constants.MODES.keys()
for parent in parents: for parent in parents:
for item in selected_items: for item in selected_items:
if parent == item.text(0): if parent == item.text(0):
for i in range(len(Constants.modes[parent])): for i in range(len(Constants.MODES[parent])):
item.child(i).setSelected(True) item.child(i).setSelected(True)
def set_initial_size(self): def set_initial_size(self):
@@ -398,7 +398,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
"category_code", "category_code",
"acf",] "acf",]
try: try:
self.db = read_csv(os.path.join(Constants.data_folder, 'db.csv'), self.db = read_csv(os.path.join(Constants.DATA_FOLDER, 'db.csv'),
sep = '*', sep = '*',
header = None, header = None,
index_col = 0, index_col = 0,
@@ -442,8 +442,8 @@ class MyApp(QMainWindow, Ui_MainWindow):
upper_units = upper_combo_box.currentText() upper_units = upper_combo_box.currentText()
lower_value = lower_spin_box.value() lower_value = lower_spin_box.value()
upper_value = upper_spin_box.value() upper_value = upper_spin_box.value()
inf_limit = (lower_value * Constants.conversion_factors[lower_units]) \ inf_limit = (lower_value * Constants.CONVERSION_FACTORS[lower_units]) \
// Constants.conversion_factors[upper_units] // Constants.CONVERSION_FACTORS[upper_units]
counter = 0 counter = 0
while inf_limit > upper_spin_box.maximum(): while inf_limit > upper_spin_box.maximum():
counter += 1 counter += 1
@@ -475,13 +475,13 @@ class MyApp(QMainWindow, Ui_MainWindow):
range_lbl): range_lbl):
activate_low = False activate_low = False
activate_high = False activate_high = False
color = Constants.inactive_color color = Constants.INACTIVE_COLOR
title = '' title = ''
to_display = '' to_display = ''
if activate_low_btn.isChecked(): if activate_low_btn.isChecked():
to_display += str(lower_spinbox.value()) + ' ' + lower_unit.currentText() to_display += str(lower_spinbox.value()) + ' ' + lower_unit.currentText()
activate_low = True activate_low = True
color = Constants.active_color color = Constants.ACTIVE_COLOR
if lower_confidence.value() != 0: if lower_confidence.value() != 0:
to_display += ' - ' + str(lower_confidence.value()) + ' %' to_display += ' - ' + str(lower_confidence.value()) + ' %'
else: else:
@@ -490,7 +490,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
if activate_up_btn.isChecked(): if activate_up_btn.isChecked():
to_display += str(upper_spinbox.value()) + ' ' + upper_unit.currentText() to_display += str(upper_spinbox.value()) + ' ' + upper_unit.currentText()
activate_high = True activate_high = True
color = Constants.active_color color = Constants.ACTIVE_COLOR
if upper_confidence.value() != 0: if upper_confidence.value() != 0:
to_display += ' + ' + str(upper_confidence.value()) + ' %' to_display += ' + ' + str(upper_confidence.value()) + ' %'
else: else:
@@ -531,7 +531,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
def update_status_tip(self, available_signals): def update_status_tip(self, available_signals):
if available_signals < self.total_signals: if available_signals < self.total_signals:
self.statusbar.setStyleSheet(f'color: {Constants.active_color}') self.statusbar.setStyleSheet(f'color: {Constants.ACTIVE_COLOR}')
else: else:
self.statusbar.setStyleSheet('color: #ffffff') self.statusbar.setStyleSheet('color: #ffffff')
self.statusbar.showMessage(f"{available_signals} out of {self.total_signals} signals displayed.") self.statusbar.showMessage(f"{available_signals} out of {self.total_signals} signals displayed.")
@@ -598,7 +598,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
band_filter_ok = False band_filter_ok = False
any_checked = False any_checked = False
for btn, band_limits in zip(self.frequency_filters_btns, Constants.bands): for btn, band_limits in zip(self.frequency_filters_btns, Constants.BANDS):
if btn.isChecked(): if btn.isChecked():
any_checked = True any_checked = True
if signal_freqs[0] < band_limits.upper and signal_freqs[1] >= band_limits.lower: if signal_freqs[0] < band_limits.upper and signal_freqs[1] >= band_limits.lower:
@@ -667,14 +667,14 @@ class MyApp(QMainWindow, Ui_MainWindow):
if not self.apply_remove_mode_filter_btn.isChecked(): if not self.apply_remove_mode_filter_btn.isChecked():
return True return True
signal_mode = self.db.at[signal_name, "mode"] signal_mode = self.db.at[signal_name, "mode"]
if signal_mode == Constants.unknown: if signal_mode == Constants.UNKNOWN:
if self.include_unknown_modes_btn.isChecked(): if self.include_unknown_modes_btn.isChecked():
return True return True
else: else:
return False return False
selected_items = [item for item in self.mode_tree_widget.selectedItems()] selected_items = [item for item in self.mode_tree_widget.selectedItems()]
selected_items_text = [i.text(0) for i in selected_items] selected_items_text = [i.text(0) for i in selected_items]
parents = [item for item in selected_items_text if item in Constants.modes.keys()] parents = [item for item in selected_items_text if item in Constants.MODES.keys()]
children = [item for item in selected_items_text if item not in parents] children = [item for item in selected_items_text if item not in parents]
ok = [] ok = []
for item in selected_items: for item in selected_items:
@@ -686,7 +686,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
@staticmethod @staticmethod
def filters_ok(spinbox, filter_unit, confidence, sign = 1): def filters_ok(spinbox, filter_unit, confidence, sign = 1):
band_filter = spinbox.value() * Constants.conversion_factors[filter_unit.currentText()] band_filter = spinbox.value() * Constants.CONVERSION_FACTORS[filter_unit.currentText()]
return band_filter + sign * (confidence.value() * band_filter) // 100 return band_filter + sign * (confidence.value() * band_filter) // 100
@pyqtSlot(QListWidgetItem, QListWidgetItem) @pyqtSlot(QListWidgetItem, QListWidgetItem)
@@ -727,9 +727,9 @@ class MyApp(QMainWindow, Ui_MainWindow):
self.description_text.setText(current_signal.at["description"]) self.description_text.setText(current_signal.at["description"])
for cat, cat_lab in zip(category_code, self.category_labels): for cat, cat_lab in zip(category_code, self.category_labels):
if cat == '0': if cat == '0':
cat_lab.setStyleSheet(f"color: {Constants.inactive_color};") cat_lab.setStyleSheet(f"color: {Constants.INACTIVE_COLOR};")
elif cat == '1': elif cat == '1':
cat_lab.setStyleSheet(f"color: {Constants.active_color};") cat_lab.setStyleSheet(f"color: {Constants.ACTIVE_COLOR};")
self.set_band_range(current_signal) self.set_band_range(current_signal)
self.audio_widget.set_audio_player(self.current_signal_name) self.audio_widget.set_audio_player(self.current_signal_name)
else: else:
@@ -741,7 +741,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
for lab in self.property_labels: for lab in self.property_labels:
lab.setText("N/A") lab.setText("N/A")
for lab in self.category_labels: for lab in self.category_labels:
lab.setStyleSheet(f"color: {Constants.inactive_color};") lab.setStyleSheet(f"color: {Constants.INACTIVE_COLOR};")
self.set_band_range() self.set_band_range()
self.audio_widget.set_audio_player() self.audio_widget.set_audio_player()
@@ -788,20 +788,20 @@ class MyApp(QMainWindow, Ui_MainWindow):
return 10**9 return 10**9
def display_spectrogram(self): def display_spectrogram(self):
default_pic = os.path.join(Constants.icons_folder, "nosignalselected.png") default_pic = os.path.join(Constants.ICONS_FOLDER, "nosignalselected.png")
item = self.result_list.currentItem() item = self.result_list.currentItem()
if item: if item:
spectrogram_name = item.text() spectrogram_name = item.text()
path_spectr = os.path.join(Constants.data_folder, Constants.spectra_folder, spectrogram_name + ".png") path_spectr = os.path.join(Constants.DATA_FOLDER, Constants.SPECTRA_FOLDER, spectrogram_name + ".png")
if not QFileInfo(path_spectr).exists(): if not QFileInfo(path_spectr).exists():
path_spectr = os.path.join(Constants.icons_folder, "spectrumnotavailable.png") path_spectr = os.path.join(Constants.ICONS_FOLDER, "spectrumnotavailable.png")
else: else:
path_spectr = default_pic path_spectr = default_pic
self.spectrogram.setPixmap(QPixmap(path_spectr)) self.spectrogram.setPixmap(QPixmap(path_spectr))
@staticmethod @staticmethod
def activate_band_category(band_label, activate = True): def activate_band_category(band_label, activate = True):
color = Constants.active_color if activate else Constants.inactive_color color = Constants.ACTIVE_COLOR if activate else Constants.INACTIVE_COLOR
for label in band_label: for label in band_label:
label.setStyleSheet(f"color: {color};") label.setStyleSheet(f"color: {color};")
@@ -809,7 +809,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
if current_signal is not None and not self.is_undef_freq(current_signal): if current_signal is not None and not self.is_undef_freq(current_signal):
lower_freq = int(current_signal.at["inf_freq"]) lower_freq = int(current_signal.at["inf_freq"])
upper_freq = int(current_signal.at["sup_freq"]) upper_freq = int(current_signal.at["sup_freq"])
zipped = list(zip(Constants.bands, self.band_labels)) zipped = list(zip(Constants.BANDS, self.band_labels))
for i, w in enumerate(zipped): for i, w in enumerate(zipped):
band, band_label = w band, band_label = w
if lower_freq >= band.lower and lower_freq < band.upper: if lower_freq >= band.lower and lower_freq < band.upper:

View File

@@ -30,8 +30,8 @@ class DownloadThread(QThread):
def run(self): def run(self):
try: try:
db = urllib3.PoolManager().request('GET', Constants.db_location) db = urllib3.PoolManager().request('GET', Constants.DB_LOCATION)
# db = urllib.request.urlopen(Constants.db_location) # db = urllib.request.urlopen(Constants.DB_LOCATION)
# raise urllib.error.URLError('Test') # raise urllib.error.URLError('Test')
except urllib3.exceptions.MaxRetryError: # No internet connection. except urllib3.exceptions.MaxRetryError: # No internet connection.
self.__status = ThreadStatus.NO_CONNECTION_ERR self.__status = ThreadStatus.NO_CONNECTION_ERR
@@ -43,8 +43,8 @@ class DownloadThread(QThread):
if not checksum_ok(db.data, "folder"): if not checksum_ok(db.data, "folder"):
self.__status = ThreadStatus.BAD_DOWNLOAD_ERR self.__status = ThreadStatus.BAD_DOWNLOAD_ERR
return return
if os.path.exists(Constants.data_folder): if os.path.exists(Constants.DATA_FOLDER):
rmtree(Constants.data_folder) rmtree(Constants.DATA_FOLDER)
try: try:
# data_folder = db.read() # data_folder = db.read()
with ZipFile(BytesIO(db.data)) as zipped: with ZipFile(BytesIO(db.data)) as zipped:

View File

@@ -14,12 +14,12 @@ class _ReadOnlyProperty(object):
class Constants(object): class Constants(object):
db_location = _ReadOnlyProperty('https://aresvalley.com/Storage/Artemis/Database/data.zip') DB_LOCATION = _ReadOnlyProperty('https://aresvalley.com/Storage/Artemis/Database/data.zip')
ref_loc = _ReadOnlyProperty('https://aresvalley.com/Storage/Artemis/Database/data.zip.log') REF_LOC = _ReadOnlyProperty('https://aresvalley.com/Storage/Artemis/Database/data.zip.log')
data_folder = _ReadOnlyProperty('Data') DATA_FOLDER = _ReadOnlyProperty('Data')
spectra_folder = _ReadOnlyProperty('Spectra') SPECTRA_FOLDER = _ReadOnlyProperty('Spectra')
audio_folder = _ReadOnlyProperty('Audio') AUDIO_FOLDER = _ReadOnlyProperty('Audio')
icons_folder = _ReadOnlyProperty('icons_imgs') ICONS_FOLDER = _ReadOnlyProperty('icons_imgs')
__Band = namedtuple("Band", ["lower", "upper"]) __Band = namedtuple("Band", ["lower", "upper"])
__ELF = __Band(0, 30) # Formally it is (3, 30) Hz. __ELF = __Band(0, 30) # Formally it is (3, 30) Hz.
__SLF = __Band(30, 300) __SLF = __Band(30, 300)
@@ -32,11 +32,11 @@ class Constants(object):
__UHF = __Band(300 * 10**6, 3000 * 10**6) __UHF = __Band(300 * 10**6, 3000 * 10**6)
__SHF = __Band(3 * 10**9, 30 * 10**9) __SHF = __Band(3 * 10**9, 30 * 10**9)
__EHF = __Band(30 * 10**9, 300 * 10**9) __EHF = __Band(30 * 10**9, 300 * 10**9)
bands = _ReadOnlyProperty((__ELF, __SLF, __ULF, __VLF, __LF, __MF, __HF, __VHF, __UHF, __SHF, __EHF)) BANDS = _ReadOnlyProperty((__ELF, __SLF, __ULF, __VLF, __LF, __MF, __HF, __VHF, __UHF, __SHF, __EHF))
active_color = _ReadOnlyProperty("#39eaff") ACTIVE_COLOR = _ReadOnlyProperty("#39eaff")
inactive_color = _ReadOnlyProperty("#9f9f9f") INACTIVE_COLOR = _ReadOnlyProperty("#9f9f9f")
conversion_factors = _ReadOnlyProperty({"Hz":1, "kHz":1000, "MHz":1000000, "GHz":1000000000}) CONVERSION_FACTORS = _ReadOnlyProperty({"Hz":1, "kHz":1000, "MHz":1000000, "GHz":1000000000})
modes = _ReadOnlyProperty({"FM": ["NFM", "WFM"], MODES = _ReadOnlyProperty({"FM": ["NFM", "WFM"],
"AM": [], "AM": [],
"CW": [], "CW": [],
"SK": ["FSK", "PSK", "MSK"], "SK": ["FSK", "PSK", "MSK"],
@@ -46,7 +46,7 @@ class Constants(object):
"RAW": [], "RAW": [],
"SC-FDMA": [],} "SC-FDMA": [],}
) )
unknown = "Unknown" UNKNOWN = "Unknown"
def reset_apply_remove_btn(button): def reset_apply_remove_btn(button):
@@ -65,7 +65,7 @@ def checksum_ok(data, what):
else: else:
raise ValueError("Wrong entry name.") raise ValueError("Wrong entry name.")
try: try:
reference = read_csv(Constants.ref_loc, delimiter = '*').iat[-1, n] reference = read_csv(Constants.REF_LOC, delimiter = '*').iat[-1, n]
except HTTPError: except HTTPError:
return False return False
return code.hexdigest() == reference return code.hexdigest() == reference