set icons, validators
This commit is contained in:
@@ -1,13 +1,17 @@
|
|||||||
from .sources.Ui_dialog_createUser import Ui_Dialog
|
from .sources.Ui_dialog_createUser import Ui_Dialog
|
||||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||||
|
from PyQt6.QtGui import QRegularExpressionValidator
|
||||||
from src.logic import Database
|
from src.logic import Database
|
||||||
|
from src.utils import Icon, Log
|
||||||
from src.schemas import User
|
from src.schemas import User
|
||||||
|
import re
|
||||||
|
|
||||||
class CreateUser(QtWidgets.QDialog, Ui_Dialog):
|
class CreateUser(QtWidgets.QDialog, Ui_Dialog):
|
||||||
def __init__(self, fieldname, data):
|
def __init__(self, fieldname, data):
|
||||||
super(CreateUser, self).__init__()
|
super(CreateUser, self).__init__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
self.setWindowTitle("Benutzer erstellen")
|
||||||
|
self.setWindowIcon(Icon("user").icon)
|
||||||
# disable buttonbox save
|
# disable buttonbox save
|
||||||
self.db = Database()
|
self.db = Database()
|
||||||
self.buttonBox.button(
|
self.buttonBox.button(
|
||||||
@@ -25,12 +29,22 @@ class CreateUser(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
QtWidgets.QDialogButtonBox.StandardButton.Save
|
QtWidgets.QDialogButtonBox.StandardButton.Save
|
||||||
).clicked.connect(self.saveUser)
|
).clicked.connect(self.saveUser)
|
||||||
self.userid = None
|
self.userid = None
|
||||||
|
self.userno.setMaxLength(20)
|
||||||
|
self.user_mail.setValidator(
|
||||||
|
QRegularExpressionValidator(
|
||||||
|
QtCore.QRegularExpression(
|
||||||
|
r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.userno.textChanged.connect(
|
||||||
|
lambda: self.validateInputUserno(self.userno.text(), "int")
|
||||||
|
)
|
||||||
def checkFields(self):
|
def checkFields(self):
|
||||||
if (
|
if (
|
||||||
self.username.text() != ""
|
self.username.hasAcceptableInput()
|
||||||
and self.userno.text() != ""
|
and self.userno.hasAcceptableInput()
|
||||||
and self.user_mail.text() != ""
|
and self.user_mail.hasAcceptableInput()
|
||||||
):
|
):
|
||||||
self.buttonBox.button(
|
self.buttonBox.button(
|
||||||
QtWidgets.QDialogButtonBox.StandardButton.Save
|
QtWidgets.QDialogButtonBox.StandardButton.Save
|
||||||
@@ -46,3 +60,19 @@ class CreateUser(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
usermail = self.user_mail.text()
|
usermail = self.user_mail.text()
|
||||||
self.db.insertUser(username, userno, usermail)
|
self.db.insertUser(username, userno, usermail)
|
||||||
self.userid = userno
|
self.userid = userno
|
||||||
|
|
||||||
|
def validateInputUserno(self, value, type):
|
||||||
|
lastchar = value[-1] if value else ""
|
||||||
|
# if lastchar is not of the type, remove it
|
||||||
|
if type == "int":
|
||||||
|
if not lastchar.isdigit():
|
||||||
|
self.userno.setText(value[:-1])
|
||||||
|
|
||||||
|
def validateInputMail(self, value):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def launch():
|
||||||
|
app = QtWidgets.QApplication([])
|
||||||
|
window = CreateUser("id", "123456")
|
||||||
|
window.exec()
|
||||||
Reference in New Issue
Block a user