diff --git a/audio_player.py b/audio_player.py
new file mode 100644
index 0000000..118f603
--- /dev/null
+++ b/audio_player.py
@@ -0,0 +1,68 @@
+import os
+import sys
+
+from PyQt5.QtCore import QUrl, QFileInfo
+from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
+
+
+class AudioPlayer(object):
+ def __init__(self, play, pause, stop, volume, audio_progress):
+ self.play = play
+ self.pause = pause
+ self.stop = stop
+ self.volume = volume
+ self.audio_progress = audio_progress
+ self.audio_file = None
+ self.player = QMediaPlayer()
+ self.player.setVolume(51)
+ self.player.durationChanged.connect(self.set_max_progress_bar)
+ self.player.positionChanged.connect(self.set_progress_bar)
+ self.play.clicked.connect(self.audio)
+ self.pause.clicked.connect(self.pause_audio)
+ self.stop.clicked.connect(self.stop_audio)
+ self.player.stateChanged.connect(self.reset_audio_widget)
+ self.volume.valueChanged.connect(self.set_volume)
+
+ def set_volume(self):
+ self.player.setVolume(self.volume.value())
+
+ def reset_audio_widget(self):
+ if self.player.state() == QMediaPlayer.StoppedState:
+ self.audio_progress.setValue(0)
+ self.volume.setValue(51)
+ self.pause.setEnabled(False)
+ self.stop.setEnabled(False)
+
+ def set_max_progress_bar(self):
+ print(self.player.duration())
+ self.audio_progress.setMaximum(self.player.duration())
+
+ def set_progress_bar(self):
+ print(self.player.position())
+ self.audio_progress.setValue(self.player.position())
+
+ def set_media_player(self):
+ self.player.setMedia(QMediaContent(self.audio_file))
+
+ def set_audio_player(self, fname):
+ self.reset_audio_widget()
+ self.play.setEnabled(False)
+ full_name = os.path.join('Data', 'Audio', fname + '.mp3')
+ if QFileInfo(full_name).exists():
+ print('exists')
+ self.play.setEnabled(True)
+ self.audio_file = QUrl.fromLocalFile(full_name)
+ self.set_media_player()
+ else:
+ print('not exists')
+
+ def audio(self):
+ self.player.play()
+ self.stop.setEnabled(True)
+ self.pause.setEnabled(True)
+
+ def stop_audio(self):
+ self.player.stop()
+
+ def pause_audio(self):
+ self.player.pause()
diff --git a/icons_imgs/volume.png b/icons_imgs/volume.png
new file mode 100644
index 0000000..5cc5645
Binary files /dev/null and b/icons_imgs/volume.png differ
diff --git a/main.py b/main.py
index cac0f1c..21bec38 100644
--- a/main.py
+++ b/main.py
@@ -6,7 +6,10 @@ from PyQt5.QtWidgets import (QMainWindow,
QMessageBox,)
from PyQt5.QtGui import QPixmap
from PyQt5 import uic
-from PyQt5.QtCore import QFileInfo
+from PyQt5.QtCore import QFileInfo, QSize
+import qtawesome as qta
+
+from audio_player import AudioPlayer
qt_creator_file = "main_window.ui"
@@ -20,7 +23,24 @@ class MyApp(QMainWindow, Ui_MainWindow):
self.load_db()
self.display_signals()
self.search_bar.textChanged.connect(self.display_signals)
- self.result_list.itemSelectionChanged.connect(self.display_spectrogram)
+ self.result_list.itemSelectionChanged.connect(self.display_specs)
+ self.play.setIcon(qta.icon('fa5.play-circle',
+ color = "#7a7a7a",
+ color_active = '#1d5eff'))
+ self.play.setIconSize(self.play.size())
+ self.pause.setIcon(qta.icon('fa5.pause-circle',
+ color = "#7a7a7a",
+ color_active = '#1d5eff'))
+ self.pause.setIconSize(self.pause.size())
+ self.stop.setIcon(qta.icon('fa5.stop-circle',
+ color = "#7a7a7a",
+ color_active = '#1d5eff'))
+ self.stop.setIconSize(self.stop.size())
+ self.audio_widget = AudioPlayer(self.play,
+ self.pause,
+ self.stop,
+ self.volume,
+ self.audio_progress)
def load_db(self):
try:
@@ -48,6 +68,10 @@ class MyApp(QMainWindow, Ui_MainWindow):
if self.search_bar.text().lower() in signal.lower():
self.result_list.addItem(signal)
+ def display_specs(self):
+ self.display_spectrogram()
+ self.audio_widget.set_audio_player(self.result_list.currentItem().text())
+
def display_spectrogram(self):
spectrogram_name = self.result_list.currentItem().text()
path_spectr = os.path.join("Data", "Spectra", spectrogram_name + ".jpg")
diff --git a/main_window.ui b/main_window.ui
index 5f2a926..acf16ac 100644
--- a/main_window.ui
+++ b/main_window.ui
@@ -10,6 +10,12 @@
800
+
+
+ 0
+ 0
+
+
MainWindow
@@ -23,18 +29,16 @@ QPushButton {
}
QProgressBar {
- /*border: 2px solid grey;*/
- border-radius: 8px;
- background-color: #7a7a7a
+ border: 2px #7a7a7a;
+ border-radius: 3px;
+ background-color: #7a7a7a;
}
QProgressBar::chunk {
- background-color: #1d5eff;
- width: 20px;
- border-radius: 7px
-}
-
-
+ /*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;
+}
@@ -186,11 +190,7 @@ QTabWidget::tab-bar {
/* Style the tab using the tab sub-control. Note that
it reads QTabBar _not_ QTabWidget */
QTabBar::tab {
- background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
- stop: 0 #7a7a7a, stop: 1.0 #7a7a7a);
- /*background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
- stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
- stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);*/
+ background: #7a7a7a;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
min-width: 16ex;
@@ -199,11 +199,7 @@ QTabBar::tab {
}
QTabBar::tab:selected {
- background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
- stop: 0 #999999, stop: 1.0 #999999);
- /* background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
- stop: 0 #fafafa, stop: 0.4 #f4f4f4,
- stop: 0.5 #e7e7e7, stop: 1.0 #fafafa);*/
+ background: #999999;
color: #1d5eff
}
@@ -240,89 +236,227 @@ QTabBar::tab:!selected {
Main
-
+
- 480
- 280
- 221
- 421
+ 270
+ 110
+ 161
+ 491
-
-
-
-
- true
-
-
-
-
-
- 50
- 120
- 371
- 381
-
-
-
-
-
- 40
- 40
- 75
- 23
-
-
-
- PushButton
-
-
-
-
-
- 140
- 40
- 75
- 23
-
-
-
- PushButton
-
-
-
-
-
- 240
- 40
- 75
- 23
-
-
-
- PushButton
-
-
-
-
-
- 110
- 90
- 118
- 23
-
-
-
-
-
-
- 15
-
-
- false
-
-
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ QPushButton {
+ /*background-color: #1d5eff;*/
+ border: 1px solid gray;
+ border-color: #1d5eff;
+ border-radius: 20px;
+}
+/*
+QPushButton:disabled {
+ background-color: #7a7a7a;
+}
+*/
+
+
+
-
+
+
+ false
+
+
+
+ 0
+ 0
+
+
+
+
+ 16777215
+ 10
+
+
+
+
+
+
+ 75
+
+
+ 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;
+ margin: 0 5px;
+ border-radius: 3px
+}
+
+QSlider::handle:horizontal {
+ background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 gray, stop:0.5 white, stop:1.0 gray);
+ border: 1px solid #5c5c5c;
+ width: 15px;
+ margin: -5px -5px; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */
+ border-radius: 8px;
+}
+
+
+
+ 1
+
+
+ 100
+
+
+ 51
+
+
+ Qt::Horizontal
+
+
+
+
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 153
+ 100
+
+
+
+
+
+
+ true
+
+
+
+