This commit is contained in:
WorldTeacher
2024-06-28 10:14:07 +02:00
parent 1b14d09bf0
commit 6fa3e18f22
10 changed files with 109 additions and 66 deletions

View File

@@ -6,6 +6,24 @@ from src import Icon
from .dialog_sources.settings_ui import Ui_Dialog as _settings
config = OmegaConf.load("config.yaml")
base = """'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style
type="text/css">
p, li { white-space: pre-wrap; }
hr { height: 1px; border-width: 0; }
li.unchecked::marker { content: "\2610"; }
li.checked::marker { content: "\2612"; }
</style></head><body style=" font-family:''Segoe UI''; font-size:9pt; font-weight:400;
font-style:normal;">
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html>'"""
class Settings(QtWidgets.QDialog, _settings):
@@ -21,7 +39,7 @@ 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.font_size.setCurrentText("9")
# add button to toggle password visibility
if user == "admin":
@@ -52,7 +70,9 @@ class Settings(QtWidgets.QDialog, _settings):
self.sender_email.setText(config.mail.sender)
self.mail_username.setText(config.mail.user_name)
self.password.setText(config.mail.password)
self.use_username_smtp_login.setChecked(config.mail.use_user_name)
self.use_username_smtp_login.setChecked(
config.mail.use_user_name if config.mail.use_user_name else False
)
self.editSignature.setHtml(config.mail.signature)
def setCurrentFont(self):
@@ -66,17 +86,15 @@ class Settings(QtWidgets.QDialog, _settings):
def toggle_password(self):
self.togglePassword.setIconSize(QtCore.QSize(16, 16))
on_icon = Icon("hide_password")
off_icon = Icon("show_password")
if self.showPassword is False:
self.password.setEchoMode(QtWidgets.QLineEdit.EchoMode.Normal)
off_icon.set_icon(self.togglePassword)
Icon("show_password", self.togglePassword)
self.showPassword = True
else:
self.password.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
on_icon.set_icon(self.togglePassword)
Icon("hide_password", self.togglePassword)
self.showPassword = False
def setFontBold(self):
@@ -121,16 +139,26 @@ class Settings(QtWidgets.QDialog, _settings):
print(self.editSignature.toHtml())
def return_data(self):
port = self.smtp_port.text()
if port != "None":
port = int(port)
else:
port = 0
signature = self.editSignature.toHtml()
if signature != base:
signature = signature
else:
signature = ""
config.database.name = self.db_name.text()
config.database.path = self.db_path.text()
config.save_path = self.save_path.text()
config.mail.smtp_server = self.smtp_address.text()
config.mail.port = int(self.smtp_port.text())
config.mail.port = port
config.mail.sender = self.sender_email.text()
config.mail.user_name = self.mail_username.text()
config.mail.password = self.password.text()
config.mail.use_user_name = self.use_username_smtp_login.isChecked()
config.mail.signature = self.editSignature.toHtml()
config.mail.signature = signature
return config
@@ -144,6 +172,6 @@ def launch_settings():
import sys
app = QtWidgets.QApplication(sys.argv)
window = Settings()
window = Settings("admin")
window.show()
sys.exit(app.exec())