Got progress and track length indicators working.
This commit is contained in:
parent
24d589b172
commit
bd69ddbcde
4 changed files with 42 additions and 3 deletions
|
@ -7,6 +7,10 @@ PROGRESS_UPDATE_INTERVAL = 1000 // PROGRESS_UPDATE_RATE
|
||||||
|
|
||||||
|
|
||||||
class GUICommunication:
|
class GUICommunication:
|
||||||
|
"""
|
||||||
|
Class handling events that are a bit more complex.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
|
@ -34,11 +38,15 @@ class GUICommunication:
|
||||||
self.app.player.seek(self.track_control.track_progress_slider.value())
|
self.app.player.seek(self.track_control.track_progress_slider.value())
|
||||||
|
|
||||||
def on_track_start(self):
|
def on_track_start(self):
|
||||||
|
duration = self.app.player.playing_track.duration
|
||||||
|
|
||||||
self.track_control.track_progress_slider.setRange(
|
self.track_control.track_progress_slider.setRange(
|
||||||
0,
|
0,
|
||||||
self.app.player.playing_track.duration
|
duration
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.track_control.track_length_indicator.setText(self.app.utils.format_time(duration))
|
||||||
|
|
||||||
self.update_progress()
|
self.update_progress()
|
||||||
|
|
||||||
def update_progress(self):
|
def update_progress(self):
|
||||||
|
@ -52,5 +60,7 @@ class GUICommunication:
|
||||||
|
|
||||||
progress = track_duration - remaining
|
progress = track_duration - remaining
|
||||||
|
|
||||||
|
self.track_control.progress_indicator.setText(self.app.utils.format_time(progress))
|
||||||
|
|
||||||
self.track_control.track_progress_slider.setValue(progress)
|
self.track_control.track_progress_slider.setValue(progress)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from PyQt6.QtWidgets import QApplication
|
from PyQt6.QtWidgets import QApplication
|
||||||
|
from utils import Utils
|
||||||
from wobuzz.player.player import Player
|
from wobuzz.player.player import Player
|
||||||
from gui import GUI
|
from gui import GUI
|
||||||
from gui_communication import GUICommunication
|
from gui_communication import GUICommunication
|
||||||
|
@ -11,6 +12,8 @@ class Wobuzz:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.qt_app = QApplication([])
|
self.qt_app = QApplication([])
|
||||||
|
|
||||||
|
self.utils = Utils(self)
|
||||||
|
|
||||||
self.player = Player(self, sys.argv[1:])
|
self.player = Player(self, sys.argv[1:])
|
||||||
self.gui = GUI(self)
|
self.gui = GUI(self)
|
||||||
self.gui_communication = GUICommunication(self)
|
self.gui_communication = GUICommunication(self)
|
||||||
|
|
|
@ -21,8 +21,8 @@ class TrackControl(QToolBar):
|
||||||
icon = QIcon.fromTheme(QIcon.ThemeIcon.MediaSkipForward)
|
icon = QIcon.fromTheme(QIcon.ThemeIcon.MediaSkipForward)
|
||||||
self.next_button = self.addAction(icon, "Next")
|
self.next_button = self.addAction(icon, "Next")
|
||||||
|
|
||||||
self.current_position_indicator = QLabel("0:00")
|
self.progress_indicator = QLabel("0:00")
|
||||||
self.addWidget(self.current_position_indicator)
|
self.addWidget(self.progress_indicator)
|
||||||
|
|
||||||
self.track_progress_slider = QSlider(Qt.Orientation.Horizontal, self)
|
self.track_progress_slider = QSlider(Qt.Orientation.Horizontal, self)
|
||||||
self.addWidget(self.track_progress_slider)
|
self.addWidget(self.track_progress_slider)
|
||||||
|
|
26
wobuzz/utils.py
Normal file
26
wobuzz/utils.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
|
||||||
|
class Utils:
|
||||||
|
def __init__(self, app):
|
||||||
|
self.app = app
|
||||||
|
print(self.format_time(4656))
|
||||||
|
|
||||||
|
def format_time(self, ms):
|
||||||
|
seconds = int(ms / 1000) % 60
|
||||||
|
minutes = int(ms / (1000 * 60)) % 60
|
||||||
|
hours = int(ms / (1000 * 60 * 60))
|
||||||
|
|
||||||
|
seconds_str, minutes_str, hours_str = ("",) * 3 # create empty strings
|
||||||
|
|
||||||
|
if hours > 0:
|
||||||
|
hours_str = f"{hours}:"
|
||||||
|
|
||||||
|
minutes_str = f"{minutes}:".zfill(2)
|
||||||
|
seconds_str = f"{seconds}".zfill(2)
|
||||||
|
|
||||||
|
output = hours_str + minutes_str + seconds_str
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue