From 402cc0e4e8a4e6dabba188546fb4edcc1b9a3616 Mon Sep 17 00:00:00 2001 From: alessandro90 Date: Sun, 18 Nov 2018 18:08:03 +0100 Subject: [PATCH] Add location filter screen --- main.py | 61 +++++++++++++++++++++++++++++++++++++++++++------- main_window.ui | 61 +++++++++++++++++++++++++++++--------------------- utilities.py | 38 ++++++++++++++++++++++++++++--- 3 files changed, 123 insertions(+), 37 deletions(-) diff --git a/main.py b/main.py index 83f4084..1c584ff 100644 --- a/main.py +++ b/main.py @@ -288,7 +288,18 @@ class MyApp(QMainWindow, Ui_MainWindow): self.modulation_list]) self.apply_remove_modulation_filter_btn.clicked.connect(self.display_signals) self.reset_modulation_filters_btn.clicked.connect(self.reset_modulation_filters) - self.modulation_list.itemClicked.connect(self.remove_if_unselected) + self.modulation_list.itemClicked.connect(self.remove_if_unselected_modulation) + + # Set location filter screen. + + self.locations_list.addItems(Constants.LOCATIONS) + self.search_bar_location.textEdited.connect(self.show_matching_locations) + self.apply_remove_location_filter_btn.set_texts(Constants.APPLY, Constants.REMOVE) + self.apply_remove_location_filter_btn.set_slave_filters([self.search_bar_location, + self.locations_list]) + self.apply_remove_location_filter_btn.clicked.connect(self.display_signals) + self.reset_location_filters_btn.clicked.connect(self.reset_location_filters) + self.locations_list.itemClicked.connect(self.remove_if_unselected_location) # ########################################################################################## @@ -326,15 +337,27 @@ class MyApp(QMainWindow, Ui_MainWindow): self.show() @pyqtSlot(QListWidgetItem) - def remove_if_unselected(self, item): + def remove_if_unselected_modulation(self, item): if not item.isSelected(): self.show_matching_modulations(self.search_bar_modulation.text()) + @pyqtSlot(QListWidgetItem) + def remove_if_unselected_location(self, item): + if not item.isSelected(): + self.show_matching_locations(self.search_bar_location.text()) + @pyqtSlot(str) def show_matching_modulations(self, text): - for index in range(self.modulation_list.count()): - item = self.modulation_list.item(index) - if self.search_bar_modulation.text().upper() in item.text() or item.isSelected(): + self.show_matching_strings(self.modulation_list, text) + + @pyqtSlot(str) + def show_matching_locations(self, text): + self.show_matching_strings(self.locations_list, text) + + def show_matching_strings(self, list_elements, text): + for index in range(list_elements.count()): + item = list_elements.item(index) + if text.upper() in item.text() or item.isSelected(): item.setHidden(False) else: item.setHidden(True) @@ -558,7 +581,8 @@ class MyApp(QMainWindow, Ui_MainWindow): self.band_filters_ok(signal) , self.category_filters_ok(signal) , self.mode_filters_ok(signal) , - self.modulation_filters_ok(signal)]): + self.modulation_filters_ok(signal) , + self.location_filters_ok(signal)]) : self.result_list.item(index).setHidden(False) available_signals += 1 else: @@ -627,6 +651,14 @@ class MyApp(QMainWindow, Ui_MainWindow): if self.modulation_list.item(i).isSelected(): self.modulation_list.item(i).setSelected(False) + @pyqtSlot() + def reset_location_filters(self): + reset_apply_remove_btn(self.apply_remove_location_filter_btn) + self.search_bar_location.setText('') + for i in range(self.locations_list.count()): + if self.locations_list.item(i).isSelected(): + self.locations_list.item(i).setSelected(False) + def frequency_filters_ok(self, signal_name): if not self.apply_remove_freq_filter_btn.isChecked(): return True @@ -737,6 +769,15 @@ class MyApp(QMainWindow, Ui_MainWindow): return True return False + def location_filters_ok(self, signal_name): + if not self.apply_remove_location_filter_btn.isChecked(): + return True + signal_location = self.db.at[signal_name, "location"] + for item in self.locations_list.selectedItems(): + if item.text() == signal_location: + return True + return False + @staticmethod def filters_ok(spinbox, filter_unit, confidence, sign = 1): band_filter = spinbox.value() * Constants.CONVERSION_FACTORS[filter_unit.currentText()] @@ -845,9 +886,12 @@ class MyApp(QMainWindow, Ui_MainWindow): item = self.result_list.currentItem() if item: 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(): - path_spectr = os.path.join(Constants.ICONS_FOLDER, "spectrumnotavailable.png") + path_spectr = os.path.join(Constants.ICONS_FOLDER, + "spectrumnotavailable.png") else: path_spectr = default_pic self.spectrogram.setPixmap(QPixmap(path_spectr)) @@ -886,6 +930,7 @@ class MyApp(QMainWindow, Ui_MainWindow): self.reset_cat_filters_btn.clicked.emit() self.reset_mode_filters_btn.clicked.emit() self.reset_modulation_filters_btn.clicked.emit() + self.reset_location_filters_btn.clicked.emit() @pyqtSlot() def go_to_web_page_signal(self): diff --git a/main_window.ui b/main_window.ui index 982bffa..59ef163 100644 --- a/main_window.ui +++ b/main_window.ui @@ -2716,7 +2716,24 @@ Inactive - + + + + + 12 + 75 + true + + + + Include undefined frequencies + + + true + + + + true @@ -2736,7 +2753,7 @@ Inactive - + @@ -2750,23 +2767,6 @@ Inactive - - - - - 12 - 75 - true - - - - Include undefined frequencies - - - true - - - @@ -3876,8 +3876,8 @@ Inactive 12 - 75 - true + 50 + false @@ -3962,7 +3962,7 @@ Inactive - + @@ -3990,7 +3990,16 @@ Inactive - + + + + 12 + + + + QAbstractItemView::MultiSelection + + @@ -4009,7 +4018,7 @@ Inactive - + 12 @@ -4026,7 +4035,7 @@ Inactive - + 12 @@ -4038,7 +4047,7 @@ Inactive Reset - true + false diff --git a/utilities.py b/utilities.py index 7c38df4..5e292d8 100644 --- a/utilities.py +++ b/utilities.py @@ -44,7 +44,7 @@ class __Constants(object): BANDS = (__ELF, __SLF, __ULF, __VLF, __LF, __MF, __HF, __VHF, __UHF, __SHF, __EHF) ACTIVE_COLOR = "#39eaff" INACTIVE_COLOR = "#9f9f9f" - CONVERSION_FACTORS = {"Hz":1, "kHz":1000, "MHz":1000000, "GHz":1000000000} + CONVERSION_FACTORS = {"Hz": 1, "kHz": 1000, "MHz": 1000000, "GHz": 1000000000} MODES = {"FM": ["NFM", "WFM"], "AM": [], "CW": [], @@ -57,7 +57,7 @@ class __Constants(object): APPLY = "Apply" REMOVE = "Remove" UNKNOWN = "N/A" - MODULATIONS = ["8VSB", + MODULATIONS = ("8VSB", "AFSK", "AM", "BFSK", @@ -81,7 +81,39 @@ class __Constants(object): "PPM", "PSK", "QAM", - "TDMA",] + "TDMA",) + + LOCATIONS = (UNKNOWN, + "Australia", + "Canada", + "Central Europe", + "China", + "Cyprus", + "Eastern Europe", + "Europe", + "Europe, japan and Asia", + "Exmouth, Australia", + "Finland", + "France", + "Germany", + "Home Base Mobile , AL", + "Hungary", + "Iran", + "Israel", + "Japan", + "LaMour, North Dakota", + "Lualualei, Hawaii", + "North America", + "North Korea", + "Poland", + "Romania", + "Ruda, Sweden", + "UK", + "United Kingdom", + "United States", + "Varberg, Sweden", + "World Wide", + "Worldwide",) Constants = __Constants()