✨ Settings will be saved to file.
This commit is contained in:
+64
-48
@@ -6,6 +6,7 @@ from PySide6 import QtCore, QtGui, QtWidgets
|
|||||||
from tidalapi import Quality as QualityAudio
|
from tidalapi import Quality as QualityAudio
|
||||||
|
|
||||||
from tidal_dl_ng import __version__
|
from tidal_dl_ng import __version__
|
||||||
|
from tidal_dl_ng.config import Settings
|
||||||
from tidal_dl_ng.constants import CoverDimensions, QualityVideo, SkipExisting
|
from tidal_dl_ng.constants import CoverDimensions, QualityVideo, SkipExisting
|
||||||
from tidal_dl_ng.model.cfg import HelpSettings
|
from tidal_dl_ng.model.cfg import HelpSettings
|
||||||
from tidal_dl_ng.model.cfg import Settings as ModelSettings
|
from tidal_dl_ng.model.cfg import Settings as ModelSettings
|
||||||
@@ -61,20 +62,52 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
"""Preferences dialog."""
|
"""Preferences dialog."""
|
||||||
|
|
||||||
ui: Ui_DialogSettings
|
ui: Ui_DialogSettings
|
||||||
settings: ModelSettings
|
settings: Settings
|
||||||
settings_save: QtCore.Signal
|
data: ModelSettings
|
||||||
|
s_settings_save: QtCore.Signal
|
||||||
icon: QtGui.QIcon
|
icon: QtGui.QIcon
|
||||||
help_settings: HelpSettings
|
help_settings: HelpSettings
|
||||||
|
parameters_checkboxes: [str]
|
||||||
|
parameters_combo: [(str, Enum)]
|
||||||
|
parameters_line_edit: [str]
|
||||||
|
prefix_checkbox: str = "cb_"
|
||||||
|
prefix_label: str = "l_"
|
||||||
|
prefix_icon: str = "icon_"
|
||||||
|
prefix_line_edit: str = "le_"
|
||||||
|
prefix_combo: str = "c_"
|
||||||
|
|
||||||
def __init__(self, settings: ModelSettings, settings_save: QtCore.Signal, parent=None):
|
def __init__(self, settings: Settings, settings_save: QtCore.Signal, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.settings_save = settings_save
|
self.data = settings.data
|
||||||
|
self.s_settings_save = settings_save
|
||||||
self.help_settings = HelpSettings()
|
self.help_settings = HelpSettings()
|
||||||
pixmapi: QtWidgets.QStyle.StandardPixmap = QtWidgets.QStyle.SP_MessageBoxQuestion
|
pixmapi: QtWidgets.QStyle.StandardPixmap = QtWidgets.QStyle.SP_MessageBoxQuestion
|
||||||
self.icon = self.style().standardIcon(pixmapi)
|
self.icon = self.style().standardIcon(pixmapi)
|
||||||
|
|
||||||
|
self.parameters_checkboxes = [
|
||||||
|
"lyrics_embed",
|
||||||
|
"lyrics_file",
|
||||||
|
"video_download",
|
||||||
|
"download_delay",
|
||||||
|
"video_convert_mp4",
|
||||||
|
]
|
||||||
|
self.parameters_combo = [
|
||||||
|
("skip_existing", SkipExisting),
|
||||||
|
("quality_audio", QualityAudio),
|
||||||
|
("quality_video", QualityVideo),
|
||||||
|
("metadata_cover_dimension", CoverDimensions),
|
||||||
|
]
|
||||||
|
self.parameters_line_edit = [
|
||||||
|
"download_base_path",
|
||||||
|
"format_album",
|
||||||
|
"format_playlist",
|
||||||
|
"format_mix",
|
||||||
|
"format_track",
|
||||||
|
"format_video",
|
||||||
|
]
|
||||||
|
|
||||||
# Create an instance of the GUI
|
# Create an instance of the GUI
|
||||||
self.ui = Ui_DialogSettings()
|
self.ui = Ui_DialogSettings()
|
||||||
|
|
||||||
@@ -113,49 +146,29 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
obj_line_edit.setText(str(path))
|
obj_line_edit.setText(str(path))
|
||||||
|
|
||||||
def populate_line_edit(self):
|
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:
|
for pn in self.parameters_line_edit:
|
||||||
label_icon: QtWidgets.QLabel = getattr(self.ui, prefix_label + prefix_icon + pn)
|
label_icon: QtWidgets.QLabel = getattr(self.ui, self.prefix_label + self.prefix_icon + pn)
|
||||||
label: QtWidgets.QLabel = getattr(self.ui, prefix_label + pn)
|
label: QtWidgets.QLabel = getattr(self.ui, self.prefix_label + pn)
|
||||||
line_edit: QtWidgets.QLineEdit = getattr(self.ui, prefix_line_edit + pn)
|
line_edit: QtWidgets.QLineEdit = getattr(self.ui, self.prefix_line_edit + pn)
|
||||||
|
|
||||||
label_icon.setPixmap(QtGui.QPixmap(self.icon.pixmap(QtCore.QSize(16, 16))))
|
label_icon.setPixmap(QtGui.QPixmap(self.icon.pixmap(QtCore.QSize(16, 16))))
|
||||||
label_icon.setToolTip(getattr(self.help_settings, pn))
|
label_icon.setToolTip(getattr(self.help_settings, pn))
|
||||||
label.setText(pn)
|
label.setText(pn)
|
||||||
line_edit.setText(getattr(self.settings, pn))
|
line_edit.setText(getattr(self.data, pn))
|
||||||
|
|
||||||
# Base Path File Dialog
|
# Base Path File Dialog
|
||||||
self.ui.b_download_base_path.clicked.connect(lambda x: self.dialog_dir_open(self.ui.le_download_base_path))
|
self.ui.b_download_base_path.clicked.connect(lambda x: self.dialog_dir_open(self.ui.le_download_base_path))
|
||||||
|
|
||||||
def populate_combo(self):
|
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:
|
for p in self.parameters_combo:
|
||||||
pn: str = p[0]
|
pn: str = p[0]
|
||||||
values: Enum = p[1]
|
values: Enum = p[1]
|
||||||
label_icon: QtWidgets.QLabel = getattr(self.ui, prefix_label + prefix_icon + pn)
|
label_icon: QtWidgets.QLabel = getattr(self.ui, self.prefix_label + self.prefix_icon + pn)
|
||||||
label: QtWidgets.QLabel = getattr(self.ui, prefix_label + pn)
|
label: QtWidgets.QLabel = getattr(self.ui, self.prefix_label + pn)
|
||||||
combo: QtWidgets.QComboBox = getattr(self.ui, prefix_combo + pn)
|
combo: QtWidgets.QComboBox = getattr(self.ui, self.prefix_combo + pn)
|
||||||
setting_current = getattr(self.settings, pn)
|
setting_current = getattr(self.data, pn)
|
||||||
|
|
||||||
label_icon.setPixmap(QtGui.QPixmap(self.icon.pixmap(QtCore.QSize(16, 16))))
|
label_icon.setPixmap(QtGui.QPixmap(self.icon.pixmap(QtCore.QSize(16, 16))))
|
||||||
label_icon.setToolTip(getattr(self.help_settings, pn))
|
label_icon.setToolTip(getattr(self.help_settings, pn))
|
||||||
@@ -168,24 +181,27 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
combo.setCurrentIndex(index)
|
combo.setCurrentIndex(index)
|
||||||
|
|
||||||
def populate_checkboxes(self):
|
def populate_checkboxes(self):
|
||||||
prefix_checkbox: str = "cb_"
|
for pn in self.parameters_checkboxes:
|
||||||
parameter_names: [str] = [
|
checkbox: QtWidgets.QCheckBox = getattr(self.ui, self.prefix_checkbox + pn)
|
||||||
"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.setText(pn)
|
||||||
checkbox.setToolTip(getattr(self.help_settings, pn))
|
checkbox.setToolTip(getattr(self.help_settings, pn))
|
||||||
checkbox.setIcon(self.icon)
|
checkbox.setIcon(self.icon)
|
||||||
checkbox.setChecked(getattr(self.settings, pn))
|
checkbox.setChecked(getattr(self.data, pn))
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
# Get settings. TODO
|
# Get settings. TODO
|
||||||
# self.settings_save()
|
self.to_settings()
|
||||||
self.accept()
|
self.done(1)
|
||||||
|
|
||||||
|
def to_settings(self):
|
||||||
|
for item in self.parameters_checkboxes:
|
||||||
|
setattr(self.settings.data, item, getattr(self.ui, self.prefix_checkbox + item).isChecked())
|
||||||
|
|
||||||
|
for item in self.parameters_line_edit:
|
||||||
|
setattr(self.settings.data, item, getattr(self.ui, self.prefix_line_edit + item).text())
|
||||||
|
|
||||||
|
for item in self.parameters_combo:
|
||||||
|
setattr(self.settings.data, item[0], getattr(self.ui, self.prefix_combo + item[0]).currentData())
|
||||||
|
|
||||||
|
self.s_settings_save.emit()
|
||||||
|
|||||||
+5
-5
@@ -8,7 +8,6 @@ from tidal_dl_ng import __version__
|
|||||||
from tidal_dl_ng.dialog import DialogLogin, DialogPreferences, DialogVersion
|
from tidal_dl_ng.dialog import DialogLogin, DialogPreferences, DialogVersion
|
||||||
from tidal_dl_ng.helper.path import get_format_template
|
from tidal_dl_ng.helper.path import get_format_template
|
||||||
from tidal_dl_ng.helper.tidal import items_results_all, search_results_all, user_media_lists
|
from tidal_dl_ng.helper.tidal import items_results_all, search_results_all, user_media_lists
|
||||||
from tidal_dl_ng.model.cfg import Settings as ModelSettings
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import qdarktheme
|
import qdarktheme
|
||||||
@@ -53,7 +52,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
s_populate_tree_lists: QtCore.Signal = QtCore.Signal(list)
|
s_populate_tree_lists: QtCore.Signal = QtCore.Signal(list)
|
||||||
s_statusbar_message: QtCore.Signal = QtCore.Signal(object)
|
s_statusbar_message: QtCore.Signal = QtCore.Signal(object)
|
||||||
s_tr_results_add_top_level_item: QtCore.Signal = QtCore.Signal(object)
|
s_tr_results_add_top_level_item: QtCore.Signal = QtCore.Signal(object)
|
||||||
s_settings_save: QtCore.Signal = QtCore.Signal(object)
|
s_settings_save: QtCore.Signal = QtCore.Signal()
|
||||||
|
|
||||||
def __init__(self, tidal: Tidal | None = None):
|
def __init__(self, tidal: Tidal | None = None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -328,8 +327,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
def on_tr_results_add_top_level_item(self, widget_item: QtWidgets.QTreeWidgetItem):
|
def on_tr_results_add_top_level_item(self, widget_item: QtWidgets.QTreeWidgetItem):
|
||||||
self.tr_results.addTopLevelItem(widget_item)
|
self.tr_results.addTopLevelItem(widget_item)
|
||||||
|
|
||||||
def on_settings_save(self, settings: ModelSettings):
|
def on_settings_save(self):
|
||||||
pass
|
self.settings.save()
|
||||||
|
self.apply_settings(self.settings)
|
||||||
|
|
||||||
def search(self, query: str, types_media: SearchTypes) -> [ResultItem]:
|
def search(self, query: str, types_media: SearchTypes) -> [ResultItem]:
|
||||||
result_search: dict[str, [SearchTypes]] = search_results_all(
|
result_search: dict[str, [SearchTypes]] = search_results_all(
|
||||||
@@ -528,7 +528,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
DialogVersion(self)
|
DialogVersion(self)
|
||||||
|
|
||||||
def on_preferences(self) -> None:
|
def on_preferences(self) -> None:
|
||||||
DialogPreferences(settings=self.settings.data, settings_save=self.s_settings_save, parent=self)
|
DialogPreferences(settings=self.settings, settings_save=self.s_settings_save, parent=self)
|
||||||
|
|
||||||
def on_tr_results_expanded(self, child: QtWidgets.QTreeWidgetItem) -> None:
|
def on_tr_results_expanded(self, child: QtWidgets.QTreeWidgetItem) -> None:
|
||||||
child.removeChild(child.child(0))
|
child.removeChild(child.child(0))
|
||||||
|
|||||||
Reference in New Issue
Block a user