Optimized the CPU usage a little by creating one QTimer that updates all progress indicators instead of having a different QTimer for each Widget.

This commit is contained in:
The Wobbler 2025-03-01 17:27:03 +01:00
parent 105cc5ddf9
commit 8d74c1e14c
3 changed files with 17 additions and 21 deletions

View file

@ -1,10 +1,14 @@
#!/usr/bin/python3
from PyQt6.QtCore import Qt
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtWidgets import QDockWidget, QFileDialog
from .ui.main_window import MainWindow
GUI_UPDATE_RATE = 20
GUI_UPDATE_INTERVAL = 1000 // GUI_UPDATE_RATE
class GUI:
def __init__(self, app):
self.app = app
@ -40,15 +44,16 @@ class GUI:
self.playlist_file_selector.setNameFilters(["Playlists (*.wbz.m3u *.m3u)", "Any (*)"])
self.playlist_file_selector.setViewMode(QFileDialog.ViewMode.List)
self.connect()
self.gui_update_timer = QTimer()
self.gui_update_timer.timeout.connect(self.update_gui)
self.gui_update_timer.start(GUI_UPDATE_INTERVAL)
self.window.closeEvent = self.on_exit
self.window.show()
self.settings.update_all()
def connect(self):
self.window.closeEvent = self.on_exit
def on_exit(self, event):
self.app.library.on_exit(event)
@ -100,3 +105,8 @@ class GUI:
if playlist_path is not None and not playlist_path == "":
self.app.library.import_playlist(playlist_path)
def update_gui(self):
self.track_control.track_progress_slider.update_progress()
if self.process_dock.isVisible():
self.process_dock.update_processes()