Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
13 kB
6
Indexable
Never
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtWidgets import QMessageBox
import re

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(600, 691)
        font = QtGui.QFont()
        font.setFamily("MS Shell Dlg 2")
        font.setBold(False)
        font.setWeight(50)
        MainWindow.setFont(font)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setStyleSheet("background-color: rgb(56, 56, 83);")
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
        self.scrollArea.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.scrollArea.setWidgetResizable(True)
        self.scrollArea.setObjectName("scrollArea")
        self.scrollAreaWidgetContents_2 = QtWidgets.QWidget()
        self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, -560, 1218, 1218))
        self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents_2)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.frame = QtWidgets.QFrame(self.scrollAreaWidgetContents_2)
        self.frame.setMinimumSize(QtCore.QSize(1200, 1200))
        self.frame.setStyleSheet("")
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.l_name = QtWidgets.QLabel(self.frame)
        self.l_name.setGeometry(QtCore.QRect(20, -10, 191, 71))
        font = QtGui.QFont()
        font.setPointSize(25)
        self.l_name.setFont(font)
        self.l_name.setStyleSheet("color: rgb(255, 255, 255)")
        self.l_name.setObjectName("l_name")
        self.textEdit = QtWidgets.QTextEdit(self.frame)
        self.textEdit.setGeometry(QtCore.QRect(20, 60, 531, 51))
        font = QtGui.QFont()
        font.setPointSize(18)
        self.textEdit.setFont(font)
        self.textEdit.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.textEdit.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.textEdit.setObjectName("textEdit")
        self.rbtn_btnmale = QtWidgets.QRadioButton(self.frame)
        self.rbtn_btnmale.setGeometry(QtCore.QRect(20, 260, 121, 51))
        font = QtGui.QFont()
        font.setPointSize(18)
        self.rbtn_btnmale.setFont(font)
        self.rbtn_btnmale.setStyleSheet("color: rgb(255, 255, 255);")
        self.rbtn_btnmale.setAutoExclusive(True)
        self.rbtn_btnmale.setObjectName("rbtn_btnmale")
        self.rbtn_female = QtWidgets.QRadioButton(self.frame)
        self.rbtn_female.setGeometry(QtCore.QRect(170, 270, 121, 31))
        font = QtGui.QFont()
        font.setPointSize(18)
        self.rbtn_female.setFont(font)
        self.rbtn_female.setStyleSheet("color: rgb(255, 255, 255);")
        self.rbtn_female.setAutoExclusive(True)
        self.rbtn_female.setObjectName("rbtn_female")
        self.l_sex = QtWidgets.QLabel(self.frame)
        self.l_sex.setGeometry(QtCore.QRect(20, 210, 141, 41))
        font = QtGui.QFont()
        font.setPointSize(25)
        self.l_sex.setFont(font)
        self.l_sex.setStyleSheet("color: rgb(255, 255, 255);")
        self.l_sex.setObjectName("l_sex")
        self.l_bday = QtWidgets.QLabel(self.frame)
        self.l_bday.setGeometry(QtCore.QRect(20, 400, 271, 51))
        font = QtGui.QFont()
        font.setPointSize(25)
        self.l_bday.setFont(font)
        self.l_bday.setStyleSheet("color: rgb(255, 255, 255);")
        self.l_bday.setObjectName("l_bday")
        self.dateEdit = QtWidgets.QDateEdit(self.frame)
        self.dateEdit.setGeometry(QtCore.QRect(20, 480, 231, 51))
        font = QtGui.QFont()
        font.setPointSize(22)
        font.setBold(False)
        font.setWeight(50)
        self.dateEdit.setFont(font)
        self.dateEdit.setStyleSheet("color: rgb(255, 255, 255);")
        self.dateEdit.setMaximumDate(QtCore.QDate(2020, 12, 31))
        self.dateEdit.setMinimumDate(QtCore.QDate(1930, 1, 1))
        self.dateEdit.setObjectName("dateEdit")
        self.l_phone = QtWidgets.QLabel(self.frame)
        self.l_phone.setGeometry(QtCore.QRect(20, 610, 281, 41))
        font = QtGui.QFont()
        font.setPointSize(25)
        self.l_phone.setFont(font)
        self.l_phone.setStyleSheet("color: rgb(255, 255, 255);")
        self.l_phone.setObjectName("l_phone")
        self.textEdit_2 = QtWidgets.QTextEdit(self.frame)
        self.textEdit_2.setGeometry(QtCore.QRect(20, 670, 491, 71))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.textEdit_2.setFont(font)
        self.textEdit_2.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.textEdit_2.setInputMethodHints(QtCore.Qt.ImhMultiLine)
        self.textEdit_2.setObjectName("textEdit_2")
        self.l_login = QtWidgets.QLabel(self.frame)
        self.l_login.setGeometry(QtCore.QRect(20, 800, 171, 51))
        font = QtGui.QFont()
        font.setPointSize(25)
        self.l_login.setFont(font)
        self.l_login.setStyleSheet("color: rgb(255, 255, 255);")
        self.l_login.setObjectName("l_login")
        self.textEdit_3 = QtWidgets.QTextEdit(self.frame)
        self.textEdit_3.setGeometry(QtCore.QRect(20, 860, 451, 71))
        font = QtGui.QFont()
        font.setPointSize(18)
        self.textEdit_3.setFont(font)
        self.textEdit_3.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.textEdit_3.setObjectName("textEdit_3")
        self.l_password = QtWidgets.QLabel(self.frame)
        self.l_password.setGeometry(QtCore.QRect(20, 950, 191, 71))
        font = QtGui.QFont()
        font.setPointSize(25)
        self.l_password.setFont(font)
        self.l_password.setStyleSheet("color: rgb(255, 255, 255);")
        self.l_password.setObjectName("l_password")
        self.textEdit_4 = QtWidgets.QTextEdit(self.frame)
        self.textEdit_4.setGeometry(QtCore.QRect(20, 1020, 451, 71))
        font = QtGui.QFont()
        font.setPointSize(18)
        self.textEdit_4.setFont(font)
        self.textEdit_4.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.textEdit_4.setObjectName("textEdit_4")
        self.btn = QtWidgets.QPushButton(self.frame)
        self.btn.setGeometry(QtCore.QRect(170, 1150, 231, 41))
        font = QtGui.QFont()
        font.setPointSize(17)
        font.setBold(True)
        font.setWeight(75)
        self.btn.setFont(font)
        self.btn.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.btn.setObjectName("btn")
        self.verticalLayout_2.addWidget(self.frame)
        self.scrollArea.setWidget(self.scrollAreaWidgetContents_2)
        self.verticalLayout.addWidget(self.scrollArea)
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Анкета"))
        self.l_name.setText(_translate("MainWindow", "ФИО:"))
        self.rbtn_btnmale.setText(_translate("MainWindow", "Мужской"))
        self.rbtn_female.setText(_translate("MainWindow", "Женский"))
        self.l_sex.setText(_translate("MainWindow", "Пол:"))
        self.l_bday.setText(_translate("MainWindow", "Дата рождения:"))
        self.l_phone.setText(_translate("MainWindow", "Номер телефона:"))
        self.l_login.setText(_translate("MainWindow", "Логин:"))
        self.l_password.setText(_translate("MainWindow", "Пароль:"))
        self.btn.setText(_translate("MainWindow", "Сохранить"))


        self.btn.clicked.connect(self.sohranenie)

        self.textEdit_2.setText("+7")



    def sohranenie(self):
        if self.rbtn_female.isChecked():
            polchel = self.rbtn_female.text()
        elif self.rbtn_btnmale.isChecked():
            polchel = self.rbtn_btnmale.text()

        text1 = 0
        text2 = 0
        text3 = 0
        text4 = 0


        e1 = self.textEdit_2.toPlainText()
        if e1[0] == "+" and e1[1] == "7":
            if len(e1) == 12:
                for i in range(1,len(e1)):
                    if e1[i].isdigit():
                        nomertelephona=e1[i]



        if nomertelephona == e1[len(e1)-1]:
            text2 = self.textEdit_2.toPlainText()
        else:
            error = QMessageBox()
            error.setWindowTitle("Ошибка")
            error.setText("правильно введите номер телефона")
            error.setInformativeText("формат +7хххххххххх")
            error.setIcon(QMessageBox.Warning)
            error.setStandardButtons(QMessageBox.Ok)
            error.exec_()



        e0=self.textEdit.toPlainText()
        pattern = re.compile(r"^[АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзиёклмнопрстуфхцчшщъыьэюя ]{1,50}\Z")
        m = pattern.match(e0)
        if m:
            text1 = self.textEdit.toPlainText()
        else:
            error = QMessageBox()
            error.setWindowTitle("Ошибка")
            error.setText("правильно введите фио")
            error.setInformativeText("доступны только буквы кириллицы")
            error.setIcon(QMessageBox.Warning)
            error.setStandardButtons(QMessageBox.Ok)
            error.exec_()



        e2=self.textEdit_3.toPlainText()
        pattern = re.compile(r"^[АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзиёклмнопрстуфхцчшщъыьэюяABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 ]{1,50}\Z")
        m = pattern.match(e2)
        if m:
            text3 = self.textEdit_3.toPlainText()
        else:
            error = QMessageBox()
            error.setWindowTitle("Ошибка")
            error.setText("правильно введите логин")
            error.setInformativeText("доступны буквы кириллицы, латинцы и цифры от 0 до 10")
            error.setIcon(QMessageBox.Warning)
            error.setStandardButtons(QMessageBox.Ok)
            error.exec_()



        e3=self.textEdit_4.toPlainText()
        pattern = re.compile(r"^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 ]{1,50}\Z")
        m = pattern.match(e3)
        if m:
            text4 = self.textEdit_4.toPlainText()
        else:
            error = QMessageBox()
            error.setWindowTitle("Ошибка")
            error.setText("правильно введите пароль")
            error.setInformativeText("доступны буквы латинцы и цифры от 0 до 10")
            error.setIcon(QMessageBox.Warning)
            error.setStandardButtons(QMessageBox.Ok)
            error.exec_()


        if self.rbtn_female.isChecked() or self.rbtn_btnmale.isChecked() and text1 != 0 and text2 != 0 and text3 != 0 and text4 != 0:
            datarozh = self.dateEdit.text()


            fname = QFileDialog.getSaveFileName(self)[0]
            f = open(fname, 'w')
            f.write(text1 + '\n')
            f.write(text2 + '\n')
            f.write(text3 + '\n')
            f.write(text4 + '\n')
            f.write(datarozh + '\n')
            f.write(polchel + '\n')
            f.close()


            #with open("anketa.txt", 'w') as f:
                #f.write("ФИО: " + text1 + '\n')
                #f.write("Номер телефона: " + text2 + '\n')
                #f.write("Логин: " + text3 + '\n')
                #f.write("Пароль: " + text4 + '\n')
                #f.write("Дата рождения: " + datarozh + '\n')
                #f.write("Пол: " + polchel + '\n')


        else:
            error = QMessageBox()
            error.setWindowTitle("Ошибка")
            error.setText("Заполните пустые поля и/или выберите пол и/или исправьте неправильные поля")
            error.setIcon(QMessageBox.Warning)
            error.setStandardButtons(QMessageBox.Ok)

            error.exec_()


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())