Wobuzz/wobuzz/gui_communication.py

38 lines
1.1 KiB
Python

#!/usr/bin/python3
from PyQt6.QtCore import QTimer
PROGRESS_UPDATE_RATE = 60
PROGRESS_UPDATE_INTERVAL = 1000 // PROGRESS_UPDATE_RATE
class GUICommunication:
def __init__(self, app):
self.app = app
self.window = self.app.gui.window
self.progress_update_timer = QTimer()
self.progress_update_timer.timeout.connect(self.update_progress)
self.progress_update_timer.start(PROGRESS_UPDATE_INTERVAL)
self.on_track_start()
def on_track_start(self):
self.window.main_container.track_control.track_progress_slider.setRange(
0,
self.app.player.playing_track.duration
)
self.update_progress()
def update_progress(self):
remaining = self.app.player.track_progress.timer.remainingTime()
if remaining == -1:
remaining = self.app.player.track_progress.remaining_time
track_duration = self.app.player.playing_track.duration
progress = track_duration - remaining
self.window.main_container.track_control.track_progress_slider.setValue(progress)