Better looking player audio + global layout

This commit is contained in:
alessandro90
2018-09-28 15:33:53 +02:00
parent 3bec594db9
commit ec00d6d67b
4 changed files with 282 additions and 230 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ Data
.ipynb_checkpoints .ipynb_checkpoints
*.ipynb *.ipynb
wav_converter.py wav_converter.py
*.txt

View File

@@ -11,8 +11,8 @@ class AudioPlayer(object):
method and set_audio_player, which loads the current file. Everything else method and set_audio_player, which loads the current file. Everything else
is managed internally. is managed internally.
""" """
__time_step = 1000 # Milliseconds. __time_step = 500 # Milliseconds.
__delay_load_audio = 250 # Milliseconds __delay_load_audio = 250 # Milliseconds
def __init__(self, play, pause, stop, volume, audio_progress): def __init__(self, play, pause, stop, volume, audio_progress):
@@ -34,7 +34,8 @@ class AudioPlayer(object):
def __set_volume(self): 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): def __reset_audio_widget(self):
if mixer.get_init(): if mixer.get_init():
@@ -60,7 +61,7 @@ class AudioPlayer(object):
mixer.Sound(self.__audio_file).get_length() * 1000 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(): if self.__load_timer.isActive():
self.__load_timer.stop() self.__load_timer.stop()
self.fname = fname self.fname = fname
@@ -71,7 +72,7 @@ class AudioPlayer(object):
self.__reset_audio_widget() self.__reset_audio_widget()
full_name = os.path.join('Data', 'Audio_wav', self.fname + '.wav') full_name = os.path.join('Data', 'Audio_wav', self.fname + '.wav')
if os.path.exists(full_name): 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.__play.setEnabled(True)
self.__audio_file = full_name self.__audio_file = full_name
self.__set_max_progress_bar() self.__set_max_progress_bar()

36
main.py
View File

@@ -3,7 +3,8 @@ import os
from pandas import read_csv from pandas import read_csv
from PyQt5.QtWidgets import (QMainWindow, from PyQt5.QtWidgets import (QMainWindow,
QApplication, QApplication,
QMessageBox,) QMessageBox,
qApp,)
from PyQt5.QtGui import QPixmap from PyQt5.QtGui import QPixmap
from PyQt5 import uic from PyQt5 import uic
from PyQt5.QtCore import QFileInfo, QSize from PyQt5.QtCore import QFileInfo, QSize
@@ -20,22 +21,24 @@ class MyApp(QMainWindow, Ui_MainWindow):
super().__init__() super().__init__()
self.setupUi(self) self.setupUi(self)
self.show() self.show()
self.actionExit.triggered.connect(qApp.quit)
self.db_version = None self.db_version = None
self.load_db() self.load_db()
self.display_signals() self.display_signals()
self.search_bar.textChanged.connect(self.display_signals) self.search_bar.textChanged.connect(self.display_signals)
self.result_list.itemSelectionChanged.connect(self.display_specs) self.result_list.itemSelectionChanged.connect(self.display_specs)
self.result_list.currentItemChanged.connect(self.display_specs)
self.play.setIcon(qta.icon('fa5.play-circle', self.play.setIcon(qta.icon('fa5.play-circle',
color = "#999999", color = "#4facf1",
color_disabled = '#000000')) color_disabled = '#7a7a7a'))
self.play.setIconSize(self.play.size()) self.play.setIconSize(self.play.size())
self.pause.setIcon(qta.icon('fa5.pause-circle', self.pause.setIcon(qta.icon('fa5.pause-circle',
color = "#999999", color = "#4facf1",
color_disabled = '#000000')) color_disabled = '#7a7a7a'))
self.pause.setIconSize(self.pause.size()) self.pause.setIconSize(self.pause.size())
self.stop.setIcon(qta.icon('fa5.stop-circle', self.stop.setIcon(qta.icon('fa5.stop-circle',
color = "#999999", color = "#4facf1",
color_disabled = '#000000')) color_disabled = '#7a7a7a'))
self.stop.setIconSize(self.stop.size()) self.stop.setIconSize(self.stop.size())
self.audio_widget = AudioPlayer(self.play, self.audio_widget = AudioPlayer(self.play,
self.pause, self.pause,
@@ -89,13 +92,22 @@ class MyApp(QMainWindow, Ui_MainWindow):
def display_specs(self): def display_specs(self):
self.display_spectrogram() 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): def display_spectrogram(self):
spectrogram_name = self.result_list.currentItem().text() default_pic = os.path.join("icons_imgs", "image_not_found.png")
path_spectr = os.path.join("Data", "Spectra", spectrogram_name + ".jpg") item = self.result_list.currentItem()
if not QFileInfo(path_spectr).exists(): if item:
path_spectr = os.path.join("icons_imgs", "image_not_found.png") 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)) self.spectrogram.setPixmap(QPixmap(path_spectr))

View File

@@ -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); background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #1d5eff, stop:0.5 #4177ff, stop:1 #1d5eff);
border-radius: 3px; border-radius: 3px;
} }
/*
QAbstractScrollArea::corner { QAbstractScrollArea::corner {
background: none; background: none;
border: none; border: none;
} }
*/
QScrollBar:vertical, QScrollBar:horizontal{ QScrollBar:vertical, QScrollBar:horizontal{
background-color:#343434; background-color:#343434;
border-radius: 5px; border-radius: 5px;
@@ -111,15 +111,9 @@ QScrollBar::sub-page:horizontal{
}</string> }</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item row="0" column="0"> <item>
<widget class="QSplitter" name="splitter"> <widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@@ -314,169 +308,215 @@ QTabBar::tab:!selected {
<attribute name="title"> <attribute name="title">
<string>Main</string> <string>Main</string>
</attribute> </attribute>
<widget class="QWidget" name="layoutWidget"> </widget>
<property name="geometry"> <widget class="QWidget" name="tab_2">
<rect> <attribute name="title">
<x>270</x> <string>Filters</string>
<y>110</y> </attribute>
<width>161</width> </widget>
<height>491</height> </widget>
</rect> </widget>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>170</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>153</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">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;
}</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="audio_widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <property name="styleSheet">
<item> <string notr="true">
<widget class="QWidget" name="audio_widget" native="true"> QWidget {
<property name="sizePolicy"> border: 0px;
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> }
<horstretch>0</horstretch> QPushButton {
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">QPushButton {
/*background-color: #1d5eff;*/ /*background-color: #1d5eff;*/
border: 1px solid gray; border: 0px solid gray;
border-color: #1d5eff; border-color: #1d5eff;
border-radius: 20px; border-radius: 20px;
} }
/* /*
QPushButton:disabled { QPushButton:disabled {
background-color: #7a7a7a; background-color: #7a7a7a;
} }
*/</string> */</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="3" column="0" colspan="3">
<widget class="QProgressBar" name="audio_progress">
<property name="enabled">
<bool>false</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <property name="sizePolicy">
<item row="3" column="0" colspan="3"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<widget class="QProgressBar" name="audio_progress"> <horstretch>0</horstretch>
<property name="enabled"> <verstretch>0</verstretch>
<bool>false</bool> </sizepolicy>
</property> </property>
<property name="sizePolicy"> <property name="maximumSize">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <size>
<horstretch>0</horstretch> <width>16777215</width>
<verstretch>0</verstretch> <height>10</height>
</sizepolicy> </size>
</property> </property>
<property name="maximumSize"> <property name="styleSheet">
<size> <string notr="true"/>
<width>16777215</width> </property>
<height>10</height> <property name="value">
</size> <number>0</number>
</property> </property>
<property name="styleSheet"> <property name="textVisible">
<string notr="true"/> <bool>false</bool>
</property> </property>
<property name="value"> </widget>
<number>0</number> </item>
</property> <item row="0" column="0">
<property name="textVisible"> <widget class="QPushButton" name="play">
<bool>false</bool> <property name="enabled">
</property> <bool>false</bool>
</widget> </property>
</item> <property name="sizePolicy">
<item row="0" column="0"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<widget class="QPushButton" name="play"> <horstretch>0</horstretch>
<property name="enabled"> <verstretch>0</verstretch>
<bool>false</bool> </sizepolicy>
</property> </property>
<property name="sizePolicy"> <property name="minimumSize">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <size>
<horstretch>0</horstretch> <width>41</width>
<verstretch>0</verstretch> <height>41</height>
</sizepolicy> </size>
</property> </property>
<property name="minimumSize"> <property name="text">
<size> <string/>
<width>41</width> </property>
<height>41</height> <property name="checkable">
</size> <bool>false</bool>
</property> </property>
<property name="text"> </widget>
<string/> </item>
</property> <item row="0" column="1">
<property name="checkable"> <widget class="QPushButton" name="pause">
<bool>false</bool> <property name="enabled">
</property> <bool>false</bool>
</widget> </property>
</item> <property name="sizePolicy">
<item row="0" column="1"> <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<widget class="QPushButton" name="pause"> <horstretch>0</horstretch>
<property name="enabled"> <verstretch>0</verstretch>
<bool>false</bool> </sizepolicy>
</property> </property>
<property name="sizePolicy"> <property name="minimumSize">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred"> <size>
<horstretch>0</horstretch> <width>41</width>
<verstretch>0</verstretch> <height>41</height>
</sizepolicy> </size>
</property> </property>
<property name="minimumSize"> <property name="text">
<size> <string/>
<width>41</width> </property>
<height>41</height> <property name="checkable">
</size> <bool>false</bool>
</property> </property>
<property name="text"> </widget>
<string/> </item>
</property> <item row="0" column="2">
<property name="checkable"> <widget class="QPushButton" name="stop">
<bool>false</bool> <property name="enabled">
</property> <bool>false</bool>
</widget> </property>
</item> <property name="sizePolicy">
<item row="0" column="2"> <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<widget class="QPushButton" name="stop"> <horstretch>0</horstretch>
<property name="enabled"> <verstretch>0</verstretch>
<bool>false</bool> </sizepolicy>
</property> </property>
<property name="sizePolicy"> <property name="minimumSize">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred"> <size>
<horstretch>0</horstretch> <width>41</width>
<verstretch>0</verstretch> <height>41</height>
</sizepolicy> </size>
</property> </property>
<property name="minimumSize"> <property name="text">
<size> <string/>
<width>41</width> </property>
<height>41</height> </widget>
</size> </item>
</property> <item row="2" column="0" colspan="3">
<property name="text"> <layout class="QHBoxLayout" name="horizontalLayout">
<string/> <item>
</property> <widget class="QLabel" name="label">
</widget> <property name="sizePolicy">
</item> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<item row="2" column="0" colspan="3"> <horstretch>0</horstretch>
<layout class="QHBoxLayout" name="horizontalLayout"> <verstretch>0</verstretch>
<item> </sizepolicy>
<widget class="QLabel" name="label"> </property>
<property name="sizePolicy"> <property name="maximumSize">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <size>
<horstretch>0</horstretch> <width>20</width>
<verstretch>0</verstretch> <height>20</height>
</sizepolicy> </size>
</property> </property>
<property name="maximumSize"> <property name="text">
<size> <string/>
<width>20</width> </property>
<height>20</height> <property name="pixmap">
</size> <pixmap>icons_imgs/volume.png</pixmap>
</property> </property>
<property name="text"> <property name="scaledContents">
<string/> <bool>true</bool>
</property> </property>
<property name="pixmap"> </widget>
<pixmap>icons_imgs/volume.png</pixmap> </item>
</property> <item>
<property name="scaledContents"> <widget class="QSlider" name="volume">
<bool>true</bool> <property name="styleSheet">
</property> <string notr="true">QSlider::groove:horizontal {
</widget>
</item>
<item>
<widget class="QSlider" name="volume">
<property name="styleSheet">
<string notr="true">QSlider::groove:horizontal {
/*border: 1px solid #999999;*/ /*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 */ 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; background: #7a7a7a;
@@ -492,60 +532,58 @@ QSlider::handle:horizontal {
border-radius: 8px; border-radius: 8px;
} }
</string> </string>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>0</number> <number>0</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>100</number> <number>100</number>
</property> </property>
<property name="singleStep"> <property name="singleStep">
<number>10</number> <number>10</number>
</property> </property>
<property name="value"> <property name="value">
<number>50</number> <number>50</number>
</property> </property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="spectrogram">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>153</width>
<height>100</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget> </item>
<widget class="QWidget" name="tab_2"> <item>
<attribute name="title"> <widget class="QLabel" name="spectrogram">
<string>Filters</string> <property name="sizePolicy">
</attribute> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
</widget> <horstretch>0</horstretch>
</widget> <verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>153</width>
<height>350</height>
</size>
</property>
<property name="toolTip">
<string>Signal waterfall</string>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>icons_imgs/image_not_found.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
</layout> </layout>