From ec00d6d67b9f590d96878aa0b045f147d691597e Mon Sep 17 00:00:00 2001 From: alessandro90 Date: Fri, 28 Sep 2018 15:33:53 +0200 Subject: [PATCH] Better looking player audio + global layout --- .gitignore | 1 + audio_player.py | 11 +- main.py | 36 ++-- main_window.ui | 464 ++++++++++++++++++++++++++---------------------- 4 files changed, 282 insertions(+), 230 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..1dd07df 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 @@ -71,7 +72,7 @@ class AudioPlayer(object): self.__reset_audio_widget() full_name = os.path.join('Data', 'Audio_wav', self.fname + '.wav') if os.path.exists(full_name): - mixer.init(frequency = AudioSegment.from_ogg(full_name).frame_rate) + mixer.init(frequency = AudioSegment.from_wav(full_name).frame_rate) self.__play.setEnabled(True) self.__audio_file = full_name self.__set_max_progress_bar() 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 + + + +