#!/usr/bin/python3 from PyQt6.QtCore import QTimer PROGRESS_UPDATE_RATE = 60 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 self.window = self.app.gui.window self.track_control = self.window.main_container.track_control self.track_progress_slider_dragged = False self.connect() 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 connect(self): self.track_control.track_progress_slider.sliderPressed.connect(self.on_progress_slider_press) self.track_control.track_progress_slider.sliderReleased.connect(self.on_progress_slider_release) def on_progress_slider_press(self): self.track_progress_slider_dragged = True def on_progress_slider_release(self): self.track_progress_slider_dragged = False 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, duration ) self.track_control.track_length_indicator.setText(self.app.utils.format_time(duration)) self.update_progress() def update_progress(self): if not self.track_progress_slider_dragged: 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.track_control.progress_indicator.setText(self.app.utils.format_time(progress)) self.track_control.track_progress_slider.setValue(progress)