OOPing it more: Removed gui_communication/track_control.py and the complete gui_communication directory.

This commit is contained in:
The Wobbler 2025-01-25 16:02:03 +01:00
parent 07e53ef2e7
commit cd6d37497f
9 changed files with 126 additions and 156 deletions

View file

@ -1,16 +1,26 @@
#!/usr/bin/python3
from PyQt6.QtCore import Qt
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtGui import QMouseEvent
from PyQt6.QtWidgets import QSlider, QStyle, QStyleOptionSlider
PROGRESS_UPDATE_RATE = 60
PROGRESS_UPDATE_INTERVAL = 1000 // PROGRESS_UPDATE_RATE
class TrackProgressSlider(QSlider):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def __init__(self, app, parent=None):
super().__init__(Qt.Orientation.Horizontal, parent)
self.app = app
self.track_control = None
self.dragged = False
self.progress_update_timer = QTimer()
self.progress_update_timer.timeout.connect(self.update_progress)
self.progress_update_timer.start(PROGRESS_UPDATE_INTERVAL)
option = QStyleOptionSlider()
style = self.style()
@ -19,6 +29,9 @@ class TrackProgressSlider(QSlider):
self.sliderPressed.connect(self.on_press)
self.sliderReleased.connect(self.on_release)
def post_init(self):
self.track_control = self.app.gui.track_control
def mousePressEvent(self, event: QMouseEvent):
# we need a custom press event bc. PyQt doesn't set the slider position when clicked
if event.button() == Qt.MouseButton.LeftButton:
@ -44,3 +57,27 @@ class TrackProgressSlider(QSlider):
def on_release(self):
self.dragged = False
if self.app.player.current_playlist.has_tracks():
self.app.player.seek(self.value())
def update_progress(self):
if not self.dragged:
if self.app.player.playing:
remaining = self.app.player.track_progress.timer.remainingTime()
if remaining == -1:
remaining = self.app.player.track_progress.remaining_time
track_duration = self.app.player.current_playlist.current_track.duration
progress = track_duration - remaining
self.track_control.progress_indicator.setText(self.app.utils.format_time(progress))
self.track_control.track_progress_slider.setValue(progress)
else:
self.track_control.progress_indicator.setText(self.app.utils.format_time(0))
self.track_control.track_progress_slider.setValue(0)