From bd69ddbcde6deff4d6ddd22542a358f6488e0d88 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 21 Dec 2024 20:50:09 +0100 Subject: [PATCH] Got progress and track length indicators working. --- wobuzz/gui_communication.py | 12 +++++++++++- wobuzz/main.py | 3 +++ wobuzz/ui/track_control.py | 4 ++-- wobuzz/utils.py | 26 ++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 wobuzz/utils.py diff --git a/wobuzz/gui_communication.py b/wobuzz/gui_communication.py index 3ad616e..d8612fa 100644 --- a/wobuzz/gui_communication.py +++ b/wobuzz/gui_communication.py @@ -7,6 +7,10 @@ PROGRESS_UPDATE_INTERVAL = 1000 // PROGRESS_UPDATE_RATE class GUICommunication: + """ + Class handling events that are a bit more complex. + """ + def __init__(self, app): self.app = app @@ -34,11 +38,15 @@ class GUICommunication: self.app.player.seek(self.track_control.track_progress_slider.value()) def on_track_start(self): + duration = self.app.player.playing_track.duration + self.track_control.track_progress_slider.setRange( 0, - self.app.player.playing_track.duration + duration ) + self.track_control.track_length_indicator.setText(self.app.utils.format_time(duration)) + self.update_progress() def update_progress(self): @@ -52,5 +60,7 @@ class GUICommunication: progress = track_duration - remaining + self.track_control.progress_indicator.setText(self.app.utils.format_time(progress)) + self.track_control.track_progress_slider.setValue(progress) diff --git a/wobuzz/main.py b/wobuzz/main.py index 7a470e2..acec06a 100644 --- a/wobuzz/main.py +++ b/wobuzz/main.py @@ -2,6 +2,7 @@ import sys from PyQt6.QtWidgets import QApplication +from utils import Utils from wobuzz.player.player import Player from gui import GUI from gui_communication import GUICommunication @@ -11,6 +12,8 @@ class Wobuzz: def __init__(self): self.qt_app = QApplication([]) + self.utils = Utils(self) + self.player = Player(self, sys.argv[1:]) self.gui = GUI(self) self.gui_communication = GUICommunication(self) diff --git a/wobuzz/ui/track_control.py b/wobuzz/ui/track_control.py index 8771615..463d1b3 100644 --- a/wobuzz/ui/track_control.py +++ b/wobuzz/ui/track_control.py @@ -21,8 +21,8 @@ class TrackControl(QToolBar): icon = QIcon.fromTheme(QIcon.ThemeIcon.MediaSkipForward) self.next_button = self.addAction(icon, "Next") - self.current_position_indicator = QLabel("0:00") - self.addWidget(self.current_position_indicator) + self.progress_indicator = QLabel("0:00") + self.addWidget(self.progress_indicator) self.track_progress_slider = QSlider(Qt.Orientation.Horizontal, self) self.addWidget(self.track_progress_slider) diff --git a/wobuzz/utils.py b/wobuzz/utils.py new file mode 100644 index 0000000..2feefc0 --- /dev/null +++ b/wobuzz/utils.py @@ -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 + +