From 309128d334edc4e0b3c58f8909405cda0fa09d1b Mon Sep 17 00:00:00 2001 From: alessandro90 Date: Fri, 28 Sep 2018 15:33:53 +0200 Subject: [PATCH 1/3] Better looking player audio + global layout --- .gitignore | 1 + audio_player.py | 9 +- main.py | 36 ++-- main_window.ui | 464 ++++++++++++++++++++++++++---------------------- 4 files changed, 281 insertions(+), 229 deletions(-) diff --git a/.gitignore b/.gitignore index 0bd1f8a..c4f8489 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ Data .ipynb_checkpoints *.ipynb wav_converter.py +*.txt diff --git a/audio_player.py b/audio_player.py index af55073..8b815f6 100644 --- a/audio_player.py +++ b/audio_player.py @@ -11,8 +11,8 @@ class AudioPlayer(object): method and set_audio_player, which loads the current file. Everything else is managed internally. """ - - __time_step = 1000 # Milliseconds. + + __time_step = 500 # Milliseconds. __delay_load_audio = 250 # Milliseconds def __init__(self, play, pause, stop, volume, audio_progress): @@ -34,7 +34,8 @@ class AudioPlayer(object): def __set_volume(self): - mixer.music.set_volume(self.__volume.value() / self.__volume.maximum()) + if mixer.get_init(): + mixer.music.set_volume(self.__volume.value() / self.__volume.maximum()) def __reset_audio_widget(self): if mixer.get_init(): @@ -60,7 +61,7 @@ class AudioPlayer(object): mixer.Sound(self.__audio_file).get_length() * 1000 ) - def set_audio_player(self, fname): + def set_audio_player(self, fname = ""): if self.__load_timer.isActive(): self.__load_timer.stop() self.fname = fname diff --git a/main.py b/main.py index b34ae56..4f93501 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,8 @@ import os from pandas import read_csv from PyQt5.QtWidgets import (QMainWindow, QApplication, - QMessageBox,) + QMessageBox, + qApp,) from PyQt5.QtGui import QPixmap from PyQt5 import uic from PyQt5.QtCore import QFileInfo, QSize @@ -20,22 +21,24 @@ class MyApp(QMainWindow, Ui_MainWindow): super().__init__() self.setupUi(self) self.show() + self.actionExit.triggered.connect(qApp.quit) self.db_version = None self.load_db() self.display_signals() self.search_bar.textChanged.connect(self.display_signals) self.result_list.itemSelectionChanged.connect(self.display_specs) + self.result_list.currentItemChanged.connect(self.display_specs) self.play.setIcon(qta.icon('fa5.play-circle', - color = "#999999", - color_disabled = '#000000')) + color = "#4facf1", + color_disabled = '#7a7a7a')) self.play.setIconSize(self.play.size()) self.pause.setIcon(qta.icon('fa5.pause-circle', - color = "#999999", - color_disabled = '#000000')) + color = "#4facf1", + color_disabled = '#7a7a7a')) self.pause.setIconSize(self.pause.size()) self.stop.setIcon(qta.icon('fa5.stop-circle', - color = "#999999", - color_disabled = '#000000')) + color = "#4facf1", + color_disabled = '#7a7a7a')) self.stop.setIconSize(self.stop.size()) self.audio_widget = AudioPlayer(self.play, self.pause, @@ -89,13 +92,22 @@ class MyApp(QMainWindow, Ui_MainWindow): def display_specs(self): self.display_spectrogram() - self.audio_widget.set_audio_player(self.result_list.currentItem().text()) + item = self.result_list.currentItem() + if item: + self.audio_widget.set_audio_player(item.text()) + else: + self.audio_widget.set_audio_player() def display_spectrogram(self): - spectrogram_name = self.result_list.currentItem().text() - path_spectr = os.path.join("Data", "Spectra", spectrogram_name + ".jpg") - if not QFileInfo(path_spectr).exists(): - path_spectr = os.path.join("icons_imgs", "image_not_found.png") + default_pic = os.path.join("icons_imgs", "image_not_found.png") + item = self.result_list.currentItem() + if item: + spectrogram_name = item.text() + path_spectr = os.path.join("Data", "Spectra", spectrogram_name + ".jpg") + if not QFileInfo(path_spectr).exists(): + path_spectr = default_pic + else: + path_spectr = default_pic self.spectrogram.setPixmap(QPixmap(path_spectr)) diff --git a/main_window.ui b/main_window.ui index aded136..d0364f2 100644 --- a/main_window.ui +++ b/main_window.ui @@ -39,12 +39,12 @@ QProgressBar::chunk { background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #1d5eff, stop:0.5 #4177ff, stop:1 #1d5eff); border-radius: 3px; } -/* + QAbstractScrollArea::corner { background: none; border: none; } -*/ + QScrollBar:vertical, QScrollBar:horizontal{ background-color:#343434; border-radius: 5px; @@ -111,15 +111,9 @@ QScrollBar::sub-page:horizontal{ } - - + + - - - 0 - 0 - - Qt::Horizontal @@ -314,169 +308,215 @@ QTabBar::tab:!selected { Main - - - - 270 - 110 - 161 - 491 - + + + + Filters + + + + + + + + + + 0 + 0 + + + + + 170 + 0 + + + + + 153 + 16777215 + + + + QWidget { +background-color:rgb(52,52,52); +border: 1px solid gray; +border-radius: 8px; +} +QProgressBar { + border: 2px #7a7a7a; + border-radius: 3px; + background-color: #7a7a7a; +} + +QProgressBar::chunk { + /*background-color: #1d5eff;*/ + background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #1d5eff, stop:0.5 #4177ff, stop:1 #1d5eff); + border-radius: 3px; +} +QLabel, QPushButton, QSlider { + border: 0px; +} + + + + + + + 0 + 0 + - - - - - - 0 - 0 - - - - QPushButton { + + +QWidget { + border: 0px; +} +QPushButton { /*background-color: #1d5eff;*/ - border: 1px solid gray; + border: 0px solid gray; border-color: #1d5eff; border-radius: 20px; } + /* QPushButton:disabled { background-color: #7a7a7a; } */ + + + + + + false - - - - - false - - - - 0 - 0 - - - - - 16777215 - 10 - - - - - - - 0 - - - false - - - - - - - false - - - - 0 - 0 - - - - - 41 - 41 - - - - - - - false - - - - - - - false - - - - 0 - 0 - - - - - 41 - 41 - - - - - - - false - - - - - - - false - - - - 0 - 0 - - - - - 41 - 41 - - - - - - - - - - - - - - 0 - 0 - - - - - 20 - 20 - - - - - - - icons_imgs/volume.png - - - true - - - - - - - QSlider::groove:horizontal { + + + 0 + 0 + + + + + 16777215 + 10 + + + + + + + 0 + + + false + + + + + + + false + + + + 0 + 0 + + + + + 41 + 41 + + + + + + + false + + + + + + + false + + + + 0 + 0 + + + + + 41 + 41 + + + + + + + false + + + + + + + false + + + + 0 + 0 + + + + + 41 + 41 + + + + + + + + + + + + + + 0 + 0 + + + + + 20 + 20 + + + + + + + icons_imgs/volume.png + + + true + + + + + + + QSlider::groove:horizontal { /*border: 1px solid #999999;*/ height: 6px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */ background: #7a7a7a; @@ -492,60 +532,58 @@ QSlider::handle:horizontal { border-radius: 8px; } - - - 0 - - - 100 - - - 10 - - - 50 - - - Qt::Horizontal - - - - - - - - - - - - - 0 - 0 - - - - - 153 - 100 - - - - - - - true - - + + + 0 + + + 100 + + + 10 + + + 50 + + + Qt::Horizontal + + + + - - - - Filters - - - + + + + + + 0 + 0 + + + + + 153 + 350 + + + + Signal waterfall + + + + + + icons_imgs/image_not_found.png + + + true + + + + From 57817deec9f21d3b0fd1910b74a5d0525aeaf590 Mon Sep 17 00:00:00 2001 From: alessandro90 Date: Sat, 29 Sep 2018 12:51:27 +0200 Subject: [PATCH 2/3] bug --- audio_player.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/audio_player.py b/audio_player.py index 8b815f6..1a9f3b6 100644 --- a/audio_player.py +++ b/audio_player.py @@ -17,6 +17,7 @@ class AudioPlayer(object): def __init__(self, play, pause, stop, volume, audio_progress): self.__paused = False + self.__first_call = True self.__play = play self.__pause = pause self.__stop = stop @@ -25,8 +26,6 @@ class AudioPlayer(object): self.__audio_file = None self.__timer = QTimer() self.__timer.timeout.connect(self.__update_bar) - self.__load_timer = QTimer() - self.__load_timer.timeout.connect(self.__set_audio_player) self.__play.clicked.connect(self.__play_audio) self.__pause.clicked.connect(self.__pause_audio) self.__stop.clicked.connect(self.__stop_audio) @@ -62,25 +61,21 @@ class AudioPlayer(object): ) def set_audio_player(self, fname = ""): - if self.__load_timer.isActive(): - self.__load_timer.stop() - self.fname = fname - self.__load_timer.start(self.__delay_load_audio) - - def __set_audio_player(self): - self.__load_timer.stop() + self.__first_call = True self.__reset_audio_widget() - full_name = os.path.join('Data', 'Audio_wav', self.fname + '.wav') + full_name = os.path.join('Data', 'Audio_wav', fname + '.wav') if os.path.exists(full_name): - mixer.init(frequency = AudioSegment.from_ogg(full_name).frame_rate) self.__play.setEnabled(True) self.__audio_file = full_name self.__set_max_progress_bar() - mixer.music.load(full_name) - self.__volume.setValue(50) def __play_audio(self): if not self.__paused: + if self.__first_call: + self.__first_call = False + mixer.init(frequency = AudioSegment.from_wav(self.__audio_file).frame_rate) + mixer.music.load(full_name) + self.__set_volume() mixer.music.play() else: mixer.music.unpause() From 9743e6bc7218c5ff85b672d3c1a1e8fa337d4205 Mon Sep 17 00:00:00 2001 From: alessandro90 Date: Sat, 29 Sep 2018 13:04:42 +0200 Subject: [PATCH 3/3] Mixer init on play buttn clicked --- audio_player.py | 21 +++++++++++++++++---- main.py | 13 ------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/audio_player.py b/audio_player.py index 1a9f3b6..384f835 100644 --- a/audio_player.py +++ b/audio_player.py @@ -3,6 +3,7 @@ import sys from pydub import AudioSegment from pygame import mixer from PyQt5.QtCore import QTimer, QTimer +import qtawesome as qta class AudioPlayer(object): @@ -30,7 +31,18 @@ class AudioPlayer(object): self.__pause.clicked.connect(self.__pause_audio) self.__stop.clicked.connect(self.__stop_audio) self.__volume.valueChanged.connect(self.__set_volume) - + self.__play.setIcon(qta.icon('fa5.play-circle', + color = "#4facf1", + color_disabled = '#7a7a7a')) + self.__play.setIconSize(self.__play.size()) + self.__pause.setIcon(qta.icon('fa5.pause-circle', + color = "#4facf1", + color_disabled = '#7a7a7a')) + self.__pause.setIconSize(self.__pause.size()) + self.__stop.setIcon(qta.icon('fa5.stop-circle', + color = "#4facf1", + color_disabled = '#7a7a7a')) + self.__stop.setIconSize(self.__stop.size()) def __set_volume(self): if mixer.get_init(): @@ -67,15 +79,16 @@ class AudioPlayer(object): if os.path.exists(full_name): self.__play.setEnabled(True) self.__audio_file = full_name - self.__set_max_progress_bar() def __play_audio(self): if not self.__paused: if self.__first_call: self.__first_call = False - mixer.init(frequency = AudioSegment.from_wav(self.__audio_file).frame_rate) - mixer.music.load(full_name) + mixer.init(frequency = AudioSegment.from_wav(self.__audio_file).frame_rate, + buffer = 2048) + mixer.music.load(self.__audio_file) self.__set_volume() + self.__set_max_progress_bar() mixer.music.play() else: mixer.music.unpause() diff --git a/main.py b/main.py index 4f93501..7135ca7 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,6 @@ from PyQt5.QtWidgets import (QMainWindow, from PyQt5.QtGui import QPixmap from PyQt5 import uic from PyQt5.QtCore import QFileInfo, QSize -import qtawesome as qta from audio_player import AudioPlayer @@ -28,18 +27,6 @@ class MyApp(QMainWindow, Ui_MainWindow): self.search_bar.textChanged.connect(self.display_signals) self.result_list.itemSelectionChanged.connect(self.display_specs) self.result_list.currentItemChanged.connect(self.display_specs) - self.play.setIcon(qta.icon('fa5.play-circle', - color = "#4facf1", - color_disabled = '#7a7a7a')) - self.play.setIconSize(self.play.size()) - self.pause.setIcon(qta.icon('fa5.pause-circle', - color = "#4facf1", - color_disabled = '#7a7a7a')) - self.pause.setIconSize(self.pause.size()) - self.stop.setIcon(qta.icon('fa5.stop-circle', - color = "#4facf1", - color_disabled = '#7a7a7a')) - self.stop.setIconSize(self.stop.size()) self.audio_widget = AudioPlayer(self.play, self.pause, self.stop,