rework logging, add more dataclasses, reworked config

This commit is contained in:
2024-12-17 10:02:56 +01:00
parent ccb4df10bb
commit eda556b5ea
41 changed files with 1624 additions and 865 deletions

View File

@@ -1,7 +1,5 @@
from PyQt6 import QtCore, QtGui, QtWidgets
from src import Icon, settings
from .dialog_sources.Ui_settings import Ui_Dialog as _settings
base = """'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
@@ -25,10 +23,11 @@ base = """'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/T
class Settings(QtWidgets.QDialog, _settings):
def __init__(self, user):
def __init__(self, user=None):
super().__init__()
self.setupUi(self)
self.password.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.password.setEchoMode(QtWidgets.QLineEdit.EchoMode.Normal)
self.zotero_api_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.Normal)
self.editSignature.setAcceptRichText(True)
self.editSignature.setFocusPolicy(QtCore.Qt.FocusPolicy.StrongFocus)
self.bold.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
@@ -36,7 +35,8 @@ class Settings(QtWidgets.QDialog, _settings):
self.underscore.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
self.font_size.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
self.fontComboBox.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
self.setWindowIcon(Icon("settings").icon)
# self.setWindowIcon(Icon("settings").icon)
Icon("settings", self)
self.setWindowTitle("Einstellungen")
self.font_size.setCurrentText("9")
# add button to toggle password visibility
@@ -46,6 +46,7 @@ class Settings(QtWidgets.QDialog, _settings):
self.debug.hide()
self.showPassword = True
self.togglePassword.clicked.connect(self.toggle_password)
self.toggle_api_visibility.clicked.connect(self.toggle_api)
self.tb_select_db.clicked.connect(self.select_db)
self.tb_set_save_path.clicked.connect(self.set_save_path)
self.bold.clicked.connect(self.setFontBold)
@@ -55,8 +56,15 @@ class Settings(QtWidgets.QDialog, _settings):
self.fontComboBox.currentFontChanged.connect(self.setCurrentFont)
self.debug.clicked.connect(self.debug_mode)
self.toggle_password()
self.toggle_api()
self.load_config()
self.buttonBox.accepted.connect(self.save)
# set text in gridlayout_4 to be not bold
self.toolBox.setItemIcon(0, Icon("database").icon)
self.toolBox.setItemIcon(1, Icon("api").icon)
self.toolBox.setItemIcon(2, Icon("mail").icon)
self.toolBox.setItemIcon(3, Icon("icons").icon)
def load_config(self):
self.db_name.setText(settings.database.name)
@@ -71,6 +79,36 @@ class Settings(QtWidgets.QDialog, _settings):
settings.mail.use_user_name if settings.mail.use_user_name else False
)
self.editSignature.setHtml(settings.mail.signature)
self.zotero_api_key.setText(settings.zotero.api_key)
self.zotero_library_id.setText(settings.zotero.library_id)
self.zotero_library_type.setText(settings.zotero.library_type)
for row, color in enumerate(settings.icons.colors):
# add a label with the color name, a lineedit with the color value and a button to change the color
label = QtWidgets.QLabel(color)
lineedit = QtWidgets.QLineEdit(settings.icons.colors[color])
button = QtWidgets.QPushButton("Farbe ändern")
button.clicked.connect(lambda: self.change_color(lineedit))
self.gridLayout_4.addWidget(label, row, 0)
self.gridLayout_4.addWidget(lineedit, row, 1)
self.gridLayout_4.addWidget(button, row, 2)
for i in range(self.gridLayout_4.count()):
self.gridLayout_4.itemAt(i).widget().setFont(QtGui.QFont("Segoe UI", 9))
# set scrollarea layout to be a form layout
# label = QtWidgets.QLabel("Icon Name")
# filename = QtWidgets.QLabel("Dateiname")
# self.formLayout.addRow(label, filename)
for row, icon in enumerate(settings.icons.icons):
label = QtWidgets.QLabel(icon)
lineedit = QtWidgets.QLineEdit(settings.icons.icons[icon])
self.formLayout.addRow(label, lineedit)
def change_color(self, lineedit):
colorDialog = QtWidgets.QColorDialog()
colorDialog.setSizePolicy()
color = colorDialog.getColor()
if color.isValid():
lineedit.setText(color.name())
def setCurrentFont(self):
font = self.fontComboBox.currentFont()
@@ -82,17 +120,23 @@ class Settings(QtWidgets.QDialog, _settings):
self.editSignature.setFontPointSize(int(size))
def toggle_password(self):
self.togglePassword.setIconSize(QtCore.QSize(16, 16))
# self.togglePassword.setIconSize(QtCore.QSize(16, 16))
if self.showPassword is False:
if self.password.echoMode() == QtWidgets.QLineEdit.EchoMode.Password:
self.password.setEchoMode(QtWidgets.QLineEdit.EchoMode.Normal)
Icon("show_password", self.togglePassword)
self.showPassword = True
else:
self.password.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
Icon("hide_password", self.togglePassword)
self.showPassword = False
def toggle_api(self):
if self.zotero_api_key.echoMode() == QtWidgets.QLineEdit.EchoMode.Normal:
self.zotero_api_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
Icon("hide_password", self.toggle_api_visibility)
else:
self.zotero_api_key.setEchoMode(QtWidgets.QLineEdit.EchoMode.Normal)
Icon("show_password", widget=self.toggle_api_visibility)
def setFontBold(self):
if self.bold.isChecked():
@@ -158,15 +202,38 @@ class Settings(QtWidgets.QDialog, _settings):
"use_user_name", self.use_username_smtp_login.isChecked()
)
settings.set_mail_attr("signature", signature)
print("Settings:")
print(settings)
settings.set_zotero_attr("api_key", self.zotero_api_key.text())
settings.set_zotero_attr("library_id", self.zotero_library_id.text())
settings.set_zotero_attr("library_type", self.zotero_library_type.text())
for color in self.get_colors():
settings.icons.colors[color] = self.get_colors()[color]
print(color)
for icon in self.get_icons():
settings.icons.icons[icon] = self.get_icons()[icon]
settings.icons.save()
return settings
def get_colors(self) -> dict:
colors = {}
for i in range(self.gridLayout_4.count()):
widget = self.gridLayout_4.itemAt(i).widget()
if isinstance(widget, QtWidgets.QLineEdit):
colors[self.gridLayout_4.itemAt(i - 1).widget().text()] = widget.text()
return colors
def get_icons(self):
icons = {}
for row in range(self.formLayout.count()):
widget = self.formLayout.itemAt(row).widget()
if isinstance(widget, QtWidgets.QLineEdit):
icons[self.formLayout.itemAt(row - 1).widget().text()] = widget.text()
return icons
def save(self):
config = self.return_data()
print(config.mail)
print("Saving config")
print(config)
# print(config)
config.save()
self.accept()
@@ -175,6 +242,6 @@ def launch_settings():
import sys
app = QtWidgets.QApplication(sys.argv)
window = Settings("admin")
window = Settings()
window.show()
sys.exit(app.exec())