Added gui-update-rate-setting.

This commit is contained in:
The Wobbler 2025-03-01 20:39:09 +01:00
parent df54239d67
commit cdabced202
3 changed files with 43 additions and 8 deletions

View file

@ -5,10 +5,6 @@ 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
@ -46,7 +42,7 @@ class GUI:
self.gui_update_timer = QTimer()
self.gui_update_timer.timeout.connect(self.update_gui)
self.gui_update_timer.start(GUI_UPDATE_INTERVAL)
self.gui_update_timer.start(1000 // self.app.settings.gui_update_rate)
self.window.closeEvent = self.on_exit
@ -66,6 +62,9 @@ class GUI:
def on_settings_change(self, key, value):
self.settings.update_settings(key, value)
if key == "gui_update_rate":
self.gui_update_timer.setInterval(1000 // value)
def on_track_change(self, previous_track, track):
self.track_control.on_track_change(previous_track, track)

View file

@ -11,4 +11,5 @@ class Settings:
clear_track_cache: bool=True
latest_playlist: str=None
load_on_start: bool=False
gui_update_rate: int=20

View file

@ -1,10 +1,18 @@
#!/usr/bin/python3
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QWidget, QDockWidget, QTabWidget, QLineEdit, QCheckBox, QPushButton, QVBoxLayout
from PyQt6.QtWidgets import (
QWidget,
QDockWidget,
QTabWidget,
QLineEdit,
QCheckBox,
QPushButton,
QSpinBox,
QVBoxLayout,
QSizePolicy
)
from .file import FileSettings
from .behavior import BehaviourSettings
from .category import Category
from .sub_category import SubCategory
@ -60,6 +68,28 @@ class Settings(QDockWidget):
self.tabs.addTab(self.behavior_settings, "Behavior")
self.performance_settings = Category()
# self.performance_settings.memory = SubCategory("Memory", "Memory related settings")
# self.performance_settings.add_sub_category(self.performance_settings.memory)
self.performance_settings.cpu = SubCategory("CPU", "CPU related settings")
self.performance_settings.add_sub_category(self.performance_settings.cpu)
self.performance_settings.cpu.gui_update_rate = QSpinBox()
self.performance_settings.cpu.gui_update_rate.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
self.performance_settings.cpu.gui_update_rate.setRange(1, 60)
self.performance_settings.cpu.gui_update_rate.setSuffix(" FPS")
self.performance_settings.cpu.gui_update_rate.setSingleStep(5)
self.performance_settings.cpu.add_setting(
"GUI update rate:",
self.performance_settings.cpu.gui_update_rate,
"The rate at which gui-elements like the track-progress-slider get updated. Values above 20 "
"don't really make sense on most monitors. Decreasing this value will reduce the CPU usage."
)
self.tabs.addTab(self.performance_settings, "Performance")
self.save_button = QPushButton("&Save", self.content)
self.content_layout.addWidget(self.save_button)
@ -72,6 +102,7 @@ class Settings(QDockWidget):
self.file_settings.paths.library_path_input.setText(self.app.settings.library_path)
self.behavior_settings.track.clear_cache.setChecked(self.app.settings.clear_track_cache)
self.behavior_settings.playlist.load_on_start.setChecked(self.app.settings.load_on_start)
self.performance_settings.cpu.gui_update_rate.setValue(self.app.settings.gui_update_rate)
def update_settings(self, key, value):
match key:
@ -84,8 +115,12 @@ class Settings(QDockWidget):
case "load_on_start":
self.behavior_settings.playlist.load_on_start.setChecked(value)
case "gui_update_rate":
self.performance_settings.cpu.gui_update_rate.setValue(value)
def write_settings(self):
self.app.settings.library_path = self.file_settings.paths.library_path_input.text()
self.app.settings.clear_track_cache = self.behavior_settings.track.clear_cache.isChecked()
self.app.settings.load_on_start = self.behavior_settings.playlist.load_on_start.isChecked()
self.app.settings.gui_update_rate = self.performance_settings.cpu.gui_update_rate.value()