Improved settings layout.
This commit is contained in:
parent
83744eb3f4
commit
53c6bccfe6
4 changed files with 102 additions and 13 deletions
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from .settings import Settings
|
||||
from .settings import Settings
|
||||
|
|
31
wobuzz/ui/settings/category.py
Normal file
31
wobuzz/ui/settings/category.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtWidgets import QWidget, QScrollArea, QVBoxLayout
|
||||
|
||||
|
||||
class Category(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.layout = QVBoxLayout(self)
|
||||
self.setLayout(self.layout)
|
||||
|
||||
self.scroll_area = QScrollArea(self)
|
||||
self.scroll_area.setWidgetResizable(True)
|
||||
|
||||
self.settings_container = QWidget(self.scroll_area)
|
||||
self.settings_layout = QVBoxLayout(self.settings_container)
|
||||
|
||||
# spacer widget to create a sort of list where the subcategory-spacing doesn't depend on the window height
|
||||
spacer_widget = QWidget(self)
|
||||
|
||||
self.settings_layout.addWidget(spacer_widget)
|
||||
|
||||
self.settings_container.setLayout(self.settings_layout)
|
||||
|
||||
self.scroll_area.setWidget(self.settings_container)
|
||||
|
||||
self.layout.addWidget(self.scroll_area)
|
||||
|
||||
def add_sub_category(self, sub_category):
|
||||
self.settings_layout.insertWidget(self.settings_layout.count() - 1, sub_category)
|
|
@ -1,9 +1,12 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtWidgets import QWidget, QDockWidget, QTabWidget, QPushButton, QVBoxLayout
|
||||
from PyQt6.QtWidgets import QWidget, QDockWidget, QTabWidget, QLineEdit, QCheckBox, QPushButton, QVBoxLayout
|
||||
|
||||
from .file import FileSettings
|
||||
from .behavior import BehaviourSettings
|
||||
from .category import Category
|
||||
from .sub_category import SubCategory
|
||||
|
||||
|
||||
class Settings(QDockWidget):
|
||||
|
@ -27,10 +30,34 @@ class Settings(QDockWidget):
|
|||
self.tabs = QTabWidget(self.content)
|
||||
self.content_layout.addWidget(self.tabs)
|
||||
|
||||
self.file_settings = FileSettings()
|
||||
self.file_settings = Category()
|
||||
|
||||
self.file_settings.paths = SubCategory("Paths", "Path related settings")
|
||||
self.file_settings.add_sub_category(self.file_settings.paths)
|
||||
|
||||
self.file_settings.paths.library_path_input = QLineEdit()
|
||||
self.file_settings.paths.add_setting("Library Path:", self.file_settings.paths.library_path_input)
|
||||
|
||||
self.tabs.addTab(self.file_settings, "Files")
|
||||
|
||||
self.behavior_settings = BehaviourSettings()
|
||||
self.behavior_settings = Category()
|
||||
|
||||
self.behavior_settings.playlist = SubCategory("Playlist", "Playlist behavior")
|
||||
self.behavior_settings.add_sub_category(self.behavior_settings.playlist)
|
||||
|
||||
self.behavior_settings.playlist.load_on_start = QCheckBox()
|
||||
self.behavior_settings.playlist.add_setting("Load on start:", self.behavior_settings.playlist.load_on_start)
|
||||
|
||||
self.behavior_settings.track = SubCategory("Track", "Track behavior")
|
||||
self.behavior_settings.add_sub_category(self.behavior_settings.track)
|
||||
|
||||
self.behavior_settings.track.clear_cache = QCheckBox()
|
||||
self.behavior_settings.track.add_setting(
|
||||
"Clear cache:",
|
||||
self.behavior_settings.track.clear_cache,
|
||||
"Automatically clear the track's cache after it finished. This greatly reduces RAM usage."
|
||||
)
|
||||
|
||||
self.tabs.addTab(self.behavior_settings, "Behavior")
|
||||
|
||||
self.save_button = QPushButton("&Save", self.content)
|
||||
|
@ -42,23 +69,23 @@ class Settings(QDockWidget):
|
|||
self.save_button.pressed.connect(self.write_settings)
|
||||
|
||||
def update_all(self, _=True): # ignore visible parameter passed by visibilityChanged event
|
||||
self.file_settings.library_path_input.setText(self.app.settings.library_path)
|
||||
self.behavior_settings.clear_track_cache.setChecked(self.app.settings.clear_track_cache)
|
||||
self.behavior_settings.load_on_start.setChecked(self.app.settings.load_on_start)
|
||||
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)
|
||||
|
||||
def update_settings(self, key, value):
|
||||
match key:
|
||||
case "library_path":
|
||||
self.file_settings.library_path_input.setText(value)
|
||||
self.file_settings.paths.library_path_input.setText(value)
|
||||
|
||||
case "clear_track_cache":
|
||||
self.behavior_settings.clear_track_cache.setDown(value)
|
||||
self.behavior_settings.track.clear_cache.setDown(value)
|
||||
|
||||
case "load_on_start":
|
||||
self.behavior_settings.load_on_start.setChecked(value)
|
||||
self.behavior_settings.playlist.load_on_start.setChecked(value)
|
||||
|
||||
def write_settings(self):
|
||||
self.app.settings.library_path = self.file_settings.library_path_input.text()
|
||||
self.app.settings.clear_track_cache = self.behavior_settings.clear_track_cache.isChecked()
|
||||
self.app.settings.load_on_start = self.behavior_settings.load_on_start.isChecked()
|
||||
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()
|
||||
|
||||
|
|
31
wobuzz/ui/settings/sub_category.py
Normal file
31
wobuzz/ui/settings/sub_category.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtGui import QFont
|
||||
from PyQt6.QtWidgets import QGroupBox, QLabel, QSizePolicy, QFormLayout
|
||||
|
||||
|
||||
class SubCategory(QGroupBox):
|
||||
description_font = QFont()
|
||||
description_font.setPointSize(8)
|
||||
|
||||
def __init__(self, title: str, description: str, parent=None):
|
||||
super().__init__(title, parent)
|
||||
|
||||
self.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed)
|
||||
self.setAlignment(Qt.AlignmentFlag.AlignLeading | Qt.AlignmentFlag.AlignVCenter)
|
||||
|
||||
self.layout = QFormLayout()
|
||||
self.setLayout(self.layout)
|
||||
|
||||
self.description = QLabel(description + "\n", self)
|
||||
self.layout.addRow(self.description)
|
||||
|
||||
def add_setting(self, text: str, setting, description: str=None):
|
||||
self.layout.addRow(text, setting)
|
||||
|
||||
if description is not None:
|
||||
description_label = QLabel(" " + description)
|
||||
description_label.setFont(self.description_font)
|
||||
self.layout.addRow(description_label)
|
||||
|
Loading…
Add table
Reference in a new issue