Wobuzz/wobuzz/gui_communication.py

57 lines
1.7 KiB
Python
Raw Normal View History

2024-12-21 19:00:06 +01:00
#!/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
2024-12-21 20:20:06 +01:00
2024-12-21 19:00:06 +01:00
self.window = self.app.gui.window
2024-12-21 20:20:06 +01:00
self.track_control = self.window.main_container.track_control
self.track_progress_slider_dragged = False
self.connect()
2024-12-21 19:00:06 +01:00
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()
2024-12-21 20:20:06 +01:00
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())
2024-12-21 19:00:06 +01:00
def on_track_start(self):
2024-12-21 20:20:06 +01:00
self.track_control.track_progress_slider.setRange(
2024-12-21 19:00:06 +01:00
0,
self.app.player.playing_track.duration
)
self.update_progress()
def update_progress(self):
2024-12-21 20:20:06 +01:00
if not self.track_progress_slider_dragged:
remaining = self.app.player.track_progress.timer.remainingTime()
2024-12-21 20:20:06 +01:00
if remaining == -1:
remaining = self.app.player.track_progress.remaining_time
2024-12-21 20:20:06 +01:00
track_duration = self.app.player.playing_track.duration
2024-12-21 19:00:06 +01:00
2024-12-21 20:20:06 +01:00
progress = track_duration - remaining
2024-12-21 19:00:06 +01:00
2024-12-21 20:20:06 +01:00
self.track_control.track_progress_slider.setValue(progress)
2024-12-21 19:00:06 +01:00