From 19b6f4dcaa4afd6e8e7c425b37817ee60a29beeb Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sun, 22 Dec 2024 19:09:37 +0100 Subject: [PATCH] Made the Track Progress Slider clickable. --- .../gui_communication.py | 0 wobuzz/main.py | 2 +- wobuzz/ui/track_control.py | 3 ++- wobuzz/ui/track_progress_slider.py | 19 +++++++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) rename wobuzz/{ => gui_communication}/gui_communication.py (100%) create mode 100644 wobuzz/ui/track_progress_slider.py diff --git a/wobuzz/gui_communication.py b/wobuzz/gui_communication/gui_communication.py similarity index 100% rename from wobuzz/gui_communication.py rename to wobuzz/gui_communication/gui_communication.py diff --git a/wobuzz/main.py b/wobuzz/main.py index 4fde09b..42db9ed 100644 --- a/wobuzz/main.py +++ b/wobuzz/main.py @@ -5,7 +5,7 @@ from PyQt6.QtWidgets import QApplication from utils import Utils from player.player import Player from gui import GUI -from gui_communication import GUICommunication +from gui_communication.gui_communication import GUICommunication class Wobuzz: diff --git a/wobuzz/ui/track_control.py b/wobuzz/ui/track_control.py index 463d1b3..ccbded4 100644 --- a/wobuzz/ui/track_control.py +++ b/wobuzz/ui/track_control.py @@ -3,6 +3,7 @@ from PyQt6.QtCore import Qt from PyQt6.QtGui import QIcon from PyQt6.QtWidgets import QToolBar, QLabel, QSlider +from .track_progress_slider import TrackProgressSlider class TrackControl(QToolBar): @@ -24,7 +25,7 @@ class TrackControl(QToolBar): self.progress_indicator = QLabel("0:00") self.addWidget(self.progress_indicator) - self.track_progress_slider = QSlider(Qt.Orientation.Horizontal, self) + self.track_progress_slider = TrackProgressSlider(Qt.Orientation.Horizontal, self) self.addWidget(self.track_progress_slider) self.track_length_indicator = QLabel("0:00") diff --git a/wobuzz/ui/track_progress_slider.py b/wobuzz/ui/track_progress_slider.py new file mode 100644 index 0000000..cf28a66 --- /dev/null +++ b/wobuzz/ui/track_progress_slider.py @@ -0,0 +1,19 @@ +#!/usr/bin/python3 + +from PyQt6.QtCore import Qt +from PyQt6.QtGui import QMouseEvent +from PyQt6.QtWidgets import QSlider + + +class TrackProgressSlider(QSlider): + def mousePressEvent(self, event: QMouseEvent): + if event.button() == Qt.MouseButton.LeftButton: + event.accept() + + x = event.pos().x() + + value = self.maximum() * x // self.width() + self.setValue(value) + + return super().mousePressEvent(event) +