✨ Preferences dialog added. Show settings.

This commit is contained in:
Robert Honz
2024-02-04 12:19:40 +01:00
parent c8e4cc6fd7
commit c71a2bdb0b
6 changed files with 1299 additions and 8 deletions
+148 -5
View File
@@ -1,13 +1,24 @@
from PySide6.QtWidgets import QDialog
import os.path
from enum import Enum
from pathlib import Path
from PySide6 import QtCore, QtGui, QtWidgets
from tidalapi import Quality as QualityAudio
from tidal_dl_ng import __version__
from tidal_dl_ng.constants import CoverDimensions, QualityVideo, SkipExisting
from tidal_dl_ng.model.cfg import HelpSettings
from tidal_dl_ng.model.cfg import Settings as ModelSettings
from tidal_dl_ng.ui.dialog_login import Ui_DialogLogin
from tidal_dl_ng.ui.dialog_settings import Ui_DialogSettings
from tidal_dl_ng.ui.dialog_version import Ui_DialogVersion
class DialogVersion(QDialog):
class DialogVersion(QtWidgets.QDialog):
"""Version dialog."""
ui: Ui_DialogVersion
def __init__(self, parent=None):
super().__init__(parent)
@@ -22,9 +33,10 @@ class DialogVersion(QDialog):
self.exec()
class DialogLogin(QDialog):
class DialogLogin(QtWidgets.QDialog):
"""Version dialog."""
ui: Ui_DialogLogin
url_redirect: str
return_code: int
@@ -44,5 +56,136 @@ class DialogLogin(QDialog):
self.url_redirect = self.ui.te_url_redirect.toPlainText()
def accept1(self):
pass
class DialogPreferences(QtWidgets.QDialog):
"""Preferences dialog."""
ui: Ui_DialogSettings
settings: ModelSettings
settings_save: QtCore.Signal
icon: QtGui.QIcon
help_settings: HelpSettings
def __init__(self, settings: ModelSettings, settings_save: QtCore.Signal, parent=None):
super().__init__(parent)
self.settings = settings
self.settings_save = settings_save
self.help_settings = HelpSettings()
pixmapi: QtWidgets.QStyle.StandardPixmap = QtWidgets.QStyle.SP_MessageBoxQuestion
self.icon = self.style().standardIcon(pixmapi)
# Create an instance of the GUI
self.ui = Ui_DialogSettings()
# Run the .setupUi() method to show the GUI
self.ui.setupUi(self)
# Set data.
self.gui_populate()
self.exec()
def gui_populate(self):
self.populate_checkboxes()
self.populate_combo()
self.populate_line_edit()
def dialog_dir_open(self, obj_line_edit):
# If a path is set, use it otherwise the users home directory.
settings_path: str = os.path.expanduser(obj_line_edit.text()) if obj_line_edit.text() else ""
dir_current = settings_path if settings_path and os.path.exists(settings_path) else str(Path.home())
dialog = QtWidgets.QFileDialog()
# Set to directory mode only but show files.
dialog.setFileMode(QtWidgets.QFileDialog.Directory)
dialog.setViewMode(QtWidgets.QFileDialog.Detail)
dialog.setOption(QtWidgets.QFileDialog.ShowDirsOnly, False)
# There is a bug in the PyQt implementation, which hides files in Directory mode.
# Thus, we need to use the PyQt dialog instead of the native dialog.
if os.name == "nt":
dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog, True)
dialog.setDirectory(dir_current)
# Execute dialog and set path is something is choosen.
if dialog.exec():
dir_name = dialog.selectedFiles()[0]
path = Path(dir_name)
obj_line_edit.setText(str(path))
def populate_line_edit(self):
prefix_label: str = "l_"
prefix_icon: str = "icon_"
prefix_line_edit: str = "le_"
parameter_names: [str] = [
"download_base_path",
"format_album",
"format_playlist",
"format_mix",
"format_track",
"format_video",
]
for pn in parameter_names:
label_icon: QtWidgets.QLabel = getattr(self.ui, prefix_label + prefix_icon + pn)
label: QtWidgets.QLabel = getattr(self.ui, prefix_label + pn)
line_edit: QtWidgets.QLineEdit = getattr(self.ui, prefix_line_edit + pn)
label_icon.setPixmap(QtGui.QPixmap(self.icon.pixmap(QtCore.QSize(16, 16))))
label_icon.setToolTip(getattr(self.help_settings, pn))
label.setText(pn)
line_edit.setText(getattr(self.settings, pn))
# Base Path File Dialog
self.ui.b_download_base_path.clicked.connect(lambda x: self.dialog_dir_open(self.ui.le_download_base_path))
def populate_combo(self):
prefix_label: str = "l_"
prefix_icon: str = "icon_"
prefix_combo: str = "c_"
parameters: [(str, Enum)] = [
("skip_existing", SkipExisting),
("quality_audio", QualityAudio),
("quality_video", QualityVideo),
("metadata_cover_dimension", CoverDimensions),
]
for p in parameters:
pn: str = p[0]
values: Enum = p[1]
label_icon: QtWidgets.QLabel = getattr(self.ui, prefix_label + prefix_icon + pn)
label: QtWidgets.QLabel = getattr(self.ui, prefix_label + pn)
combo: QtWidgets.QComboBox = getattr(self.ui, prefix_combo + pn)
setting_current = getattr(self.settings, pn)
label_icon.setPixmap(QtGui.QPixmap(self.icon.pixmap(QtCore.QSize(16, 16))))
label_icon.setToolTip(getattr(self.help_settings, pn))
label.setText(pn)
for index, v in enumerate(values):
combo.addItem(v.name, v)
if v == setting_current:
combo.setCurrentIndex(index)
def populate_checkboxes(self):
prefix_checkbox: str = "cb_"
parameter_names: [str] = [
"lyrics_embed",
"lyrics_file",
"video_download",
"download_delay",
"video_convert_mp4",
]
for pn in parameter_names:
checkbox: QtWidgets.QCheckBox = getattr(self.ui, prefix_checkbox + pn)
checkbox.setText(pn)
checkbox.setToolTip(getattr(self.help_settings, pn))
checkbox.setIcon(self.icon)
checkbox.setChecked(getattr(self.settings, pn))
def accept(self):
# Get settings. TODO
# self.settings_save()
self.accept()