Add pyqtSlot to callables
This commit is contained in:
@@ -2,11 +2,11 @@ import os
|
||||
import sys
|
||||
from pydub import AudioSegment
|
||||
from pygame import mixer
|
||||
from PyQt5.QtCore import QTimer, QTimer
|
||||
from PyQt5.QtCore import QTimer, QTimer, pyqtSlot, QObject
|
||||
import qtawesome as qta
|
||||
|
||||
|
||||
class AudioPlayer(object):
|
||||
class AudioPlayer(QObject):
|
||||
"""
|
||||
This is the audio player widget. The only public methods are the __init__
|
||||
method and set_audio_player, which loads the current file. Everything else
|
||||
@@ -16,6 +16,7 @@ class AudioPlayer(object):
|
||||
__time_step = 500 # Milliseconds.
|
||||
|
||||
def __init__(self, play, pause, stop, volume, audio_progress):
|
||||
super().__init__()
|
||||
self.__paused = False
|
||||
self.__first_call = True
|
||||
self.__play = play
|
||||
@@ -43,6 +44,7 @@ class AudioPlayer(object):
|
||||
color_disabled = '#7a7a7a'))
|
||||
self.__stop.setIconSize(self.__stop.size())
|
||||
|
||||
@pyqtSlot()
|
||||
def __set_volume(self):
|
||||
if mixer.get_init():
|
||||
mixer.music.set_volume(self.__volume.value() / self.__volume.maximum())
|
||||
@@ -57,6 +59,7 @@ class AudioPlayer(object):
|
||||
self.__enable_buttons(False, False, False)
|
||||
self.__paused = False
|
||||
|
||||
@pyqtSlot()
|
||||
def __update_bar(self):
|
||||
pos = mixer.music.get_pos()
|
||||
if pos == -1:
|
||||
@@ -79,6 +82,7 @@ class AudioPlayer(object):
|
||||
self.__play.setEnabled(True)
|
||||
self.__audio_file = full_name
|
||||
|
||||
@pyqtSlot()
|
||||
def __play_audio(self):
|
||||
if not self.__paused:
|
||||
if self.__first_call:
|
||||
@@ -95,12 +99,14 @@ class AudioPlayer(object):
|
||||
self.__timer.start(self.__time_step)
|
||||
self.__enable_buttons(False, True, True)
|
||||
|
||||
@pyqtSlot()
|
||||
def __stop_audio(self):
|
||||
mixer.music.stop()
|
||||
self.__audio_progress.reset()
|
||||
self.__timer.stop()
|
||||
self.__enable_buttons(True, False, False)
|
||||
|
||||
@pyqtSlot()
|
||||
def __pause_audio(self):
|
||||
mixer.music.pause()
|
||||
self.__timer.stop()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from PyQt5.QtWidgets import QPushButton
|
||||
from PyQt5.QtCore import pyqtSlot
|
||||
|
||||
class DoubleTextButton(QPushButton):
|
||||
def __init__(self, parent = None):
|
||||
@@ -12,6 +13,7 @@ class DoubleTextButton(QPushButton):
|
||||
def set_slave_filters(self, *filters):
|
||||
self.filters = filters
|
||||
|
||||
@pyqtSlot()
|
||||
def manage_click(self):
|
||||
if self.isChecked():
|
||||
self.setText(self.text_b)
|
||||
|
||||
37
main.py
37
main.py
@@ -8,10 +8,11 @@ from PyQt5.QtWidgets import (QMainWindow,
|
||||
QApplication,
|
||||
QMessageBox,
|
||||
qApp,
|
||||
QDesktopWidget,)
|
||||
QDesktopWidget,
|
||||
QListWidgetItem,)
|
||||
from PyQt5.QtGui import QPixmap
|
||||
from PyQt5 import uic
|
||||
from PyQt5.QtCore import QFileInfo, QSize, Qt
|
||||
from PyQt5.QtCore import QFileInfo, QSize, Qt, pyqtSlot
|
||||
|
||||
from audio_player import AudioPlayer
|
||||
|
||||
@@ -37,6 +38,8 @@ class MyApp(QMainWindow, Ui_MainWindow):
|
||||
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}
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -62,10 +65,9 @@ class MyApp(QMainWindow, Ui_MainWindow):
|
||||
self.ehf_filter_btn,
|
||||
)
|
||||
self.lower_freq_confidence.valueChanged.connect(
|
||||
lambda: self.upper_freq_confidence.setValue(
|
||||
self.lower_freq_confidence.value()
|
||||
)
|
||||
lambda value: self.upper_freq_confidence.setValue(value)
|
||||
)
|
||||
# self.lower_freq_spinbox.valueChanged.connect(self.set_min_value_upper_limit)
|
||||
self.apply_remove_freq_filter_btn.set_texts("Apply", "Remove")
|
||||
self.apply_remove_freq_filter_btn.set_slave_filters(
|
||||
*self.frequency_filters_btns,
|
||||
@@ -79,6 +81,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
|
||||
)
|
||||
self.apply_remove_freq_filter_btn.clicked.connect(self.display_signals)
|
||||
self.reset_frequency_filters_btn.clicked.connect(self.reset_frequency_filters)
|
||||
|
||||
UrlColors = namedtuple("UrlColors", ["inactive", "active", "clicked"])
|
||||
self.url_button.colors = UrlColors("#9f9f9f", "#4c75ff", "#942ccc")
|
||||
self.category_labels = [self.cat_mil,
|
||||
@@ -222,13 +225,24 @@ class MyApp(QMainWindow, Ui_MainWindow):
|
||||
else:
|
||||
self.setStatusTip(f"Database version: {self.db_version}")
|
||||
|
||||
# @pyqtSlot(int) # Da sistemare.
|
||||
# def set_min_value_upper_limit(self, lower_spinbox_value):
|
||||
# conversion_factor = self.conversion_factors[self.lower_freq_filter_unit.currentText()]
|
||||
# print("enter")
|
||||
# if self.upper_freq_spinbox.value() * self.conversion_factors[self.upper_freq_filter_unit.currentText()] < lower_spinbox_value * conversion_factor:
|
||||
# print('IF')
|
||||
# self.upper_freq_spinbox.setValue(lower_spinbox_value * conversion_factor // self.conversion_factors[self.upper_freq_filter_unit.currentText()])
|
||||
|
||||
@pyqtSlot()
|
||||
def display_signals(self):
|
||||
self.result_list.clear()
|
||||
text = self.search_bar.text()
|
||||
for signal in self.signal_names:
|
||||
if self.search_bar.text().lower() in signal.lower() and \
|
||||
if text.lower() in signal.lower() and \
|
||||
self.frequency_filters_ok(signal):
|
||||
self.result_list.addItem(signal)
|
||||
|
||||
@pyqtSlot()
|
||||
def reset_frequency_filters(self):
|
||||
if self.apply_remove_freq_filter_btn.isChecked():
|
||||
self.apply_remove_freq_filter_btn.setChecked(False)
|
||||
@@ -254,8 +268,6 @@ class MyApp(QMainWindow, Ui_MainWindow):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
conversion_factors = {"Hz":1, "kHz":1000, "MHz":1000000,
|
||||
"GHz":1000000000}
|
||||
|
||||
signal_freqs = (int(self.db.at[signal_name, "inf_freq"]),
|
||||
int(self.db.at[signal_name, "sup_freq"]))
|
||||
@@ -275,14 +287,14 @@ class MyApp(QMainWindow, Ui_MainWindow):
|
||||
lower_tol = self.lower_freq_confidence.value()
|
||||
lower_limit = lower_freq_filter - lower_tol / 100 * lower_freq_filter
|
||||
lower_units = self.lower_freq_filter_unit.currentText()
|
||||
lower_limit *= conversion_factors[lower_units]
|
||||
lower_limit *= self.conversion_factors[lower_units]
|
||||
if not signal_freqs[1] >= lower_limit:
|
||||
lower_limit_ok = False
|
||||
if upper_freq_filter > 0:
|
||||
upper_tol = self.upper_freq_confidence.value()
|
||||
upper_limit = upper_freq_filter + lower_tol / 100 * lower_freq_filter
|
||||
upper_units = self.upper_freq_filter_unit.currentText()
|
||||
upper_limit *= conversion_factors[upper_units]
|
||||
upper_limit *= self.conversion_factors[upper_units]
|
||||
if not signal_freqs[0] < upper_limit:
|
||||
upper_limit_ok = False
|
||||
if any_checked:
|
||||
@@ -290,9 +302,9 @@ class MyApp(QMainWindow, Ui_MainWindow):
|
||||
else:
|
||||
return lower_limit_ok and upper_limit_ok
|
||||
|
||||
def display_specs(self):
|
||||
@pyqtSlot(QListWidgetItem, QListWidgetItem)
|
||||
def display_specs(self, item, previous_item):
|
||||
self.display_spectrogram()
|
||||
item = self.result_list.currentItem()
|
||||
if item:
|
||||
self.current_signal_name = item.text()
|
||||
words = self.current_signal_name.split(' ')
|
||||
@@ -433,6 +445,7 @@ class MyApp(QMainWindow, Ui_MainWindow):
|
||||
for band_label in self.band_labels:
|
||||
self.activate_band_category(band_label, False)
|
||||
|
||||
@pyqtSlot()
|
||||
def go_to_web_page_signal(self):
|
||||
if self.current_signal_name:
|
||||
self.url_button.setStyleSheet(f"color: {self.url_button.colors.clicked}")
|
||||
|
||||
Reference in New Issue
Block a user