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
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
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()

36
main.py
View File

@@ -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))

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);
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{
}</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@@ -314,169 +308,215 @@ QTabBar::tab:!selected {
<attribute name="title">
<string>Main</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>270</x>
<y>110</y>
<width>161</width>
<height>491</height>
</rect>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Filters</string>
</attribute>
</widget>
</widget>
</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>
<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 name="styleSheet">
<string notr="true">QPushButton {
<property name="styleSheet">
<string notr="true">
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;
}
*/</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>
<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 name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>10</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="play">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>41</width>
<height>41</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pause">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>41</width>
<height>41</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="stop">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>41</width>
<height>41</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>icons_imgs/volume.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="volume">
<property name="styleSheet">
<string notr="true">QSlider::groove:horizontal {
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>10</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="play">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>41</width>
<height>41</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pause">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>41</width>
<height>41</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="stop">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>41</width>
<height>41</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>icons_imgs/volume.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="volume">
<property name="styleSheet">
<string notr="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;
}
</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</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>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Filters</string>
</attribute>
</widget>
</widget>
</item>
<item>
<widget class="QLabel" name="spectrogram">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<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>
</item>
</layout>