class SetProfilePasswordScreen(CenteredWidget): def __init__(self, encrypt): super(SetProfilePasswordScreen, self).__init__() self._encrypt = encrypt self.initUI() self.retranslateUi() self.center() def initUI(self): self.setMinimumSize(QtCore.QSize(700, 200)) self.setMaximumSize(QtCore.QSize(700, 200)) self.password = LineEdit(self) self.password.setGeometry(QtCore.QRect(40, 10, 300, 30)) self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) self.confirm_password = LineEdit(self) self.confirm_password.setGeometry(QtCore.QRect(40, 50, 300, 30)) self.confirm_password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) self.set_password = QtGui.QPushButton(self) self.set_password.setGeometry(QtCore.QRect(40, 100, 300, 30)) self.set_password.clicked.connect(self.new_password) self.not_match = QtGui.QLabel(self) self.not_match.setGeometry(QtCore.QRect(350, 50, 300, 30)) self.not_match.setVisible(False) self.not_match.setStyleSheet('QLabel { color: #BC1C1C; }') self.warning = QtGui.QLabel(self) self.warning.setGeometry(QtCore.QRect(40, 160, 500, 30)) self.warning.setStyleSheet('QLabel { color: #BC1C1C; }') def retranslateUi(self): self.setWindowTitle(QtGui.QApplication.translate("PasswordScreen", "Profile password", None, QtGui.QApplication.UnicodeUTF8)) self.password.setPlaceholderText( QtGui.QApplication.translate("PasswordScreen", "Password (at least 8 symbols)", None, QtGui.QApplication.UnicodeUTF8)) self.confirm_password.setPlaceholderText( QtGui.QApplication.translate("PasswordScreen", "Confirm password", None, QtGui.QApplication.UnicodeUTF8)) self.set_password.setText( QtGui.QApplication.translate("PasswordScreen", "Set password", None, QtGui.QApplication.UnicodeUTF8)) self.not_match.setText(QtGui.QApplication.translate("PasswordScreen", "Passwords do not match", None, QtGui.QApplication.UnicodeUTF8)) self.warning.setText( QtGui.QApplication.translate("PasswordScreen", "There is no way to recover lost passwords", None, QtGui.QApplication.UnicodeUTF8)) def new_password(self): if self.password.text() == self.confirm_password.text(): if len(self.password.text()) >= 8: self._encrypt.set_password(self.password.text()) self.close() else: self.not_match.setText( QtGui.QApplication.translate("PasswordScreen", "Password must be at least 8 symbols", None, QtGui.QApplication.UnicodeUTF8)) self.not_match.setVisible(True) else: self.not_match.setText(QtGui.QApplication.translate("PasswordScreen", "Passwords do not match", None, QtGui.QApplication.UnicodeUTF8)) self.not_match.setVisible(True)
class SetProfilePasswordScreen(CenteredWidget): def __init__(self, encrypt): super(SetProfilePasswordScreen, self).__init__() self._encrypt = encrypt self.initUI() self.retranslateUi() self.center() def initUI(self): self.setMinimumSize(QtCore.QSize(700, 200)) self.setMaximumSize(QtCore.QSize(700, 200)) self.password = LineEdit(self) self.password.setGeometry(QtCore.QRect(40, 10, 300, 30)) self.password.setEchoMode(QtWidgets.QLineEdit.Password) self.confirm_password = LineEdit(self) self.confirm_password.setGeometry(QtCore.QRect(40, 50, 300, 30)) self.confirm_password.setEchoMode(QtWidgets.QLineEdit.Password) self.set_password = QtWidgets.QPushButton(self) self.set_password.setGeometry(QtCore.QRect(40, 100, 300, 30)) self.set_password.clicked.connect(self.new_password) self.not_match = QtWidgets.QLabel(self) self.not_match.setGeometry(QtCore.QRect(350, 50, 300, 30)) self.not_match.setVisible(False) self.not_match.setStyleSheet('QLabel { color: #BC1C1C; }') self.warning = QtWidgets.QLabel(self) self.warning.setGeometry(QtCore.QRect(40, 160, 500, 30)) self.warning.setStyleSheet('QLabel { color: #BC1C1C; }') def retranslateUi(self): self.setWindowTitle(QtWidgets.QApplication.translate("PasswordScreen", "Profile password")) self.password.setPlaceholderText( QtWidgets.QApplication.translate("PasswordScreen", "Password (at least 8 symbols)")) self.confirm_password.setPlaceholderText( QtWidgets.QApplication.translate("PasswordScreen", "Confirm password")) self.set_password.setText( QtWidgets.QApplication.translate("PasswordScreen", "Set password")) self.not_match.setText(QtWidgets.QApplication.translate("PasswordScreen", "Passwords do not match")) self.warning.setText( QtWidgets.QApplication.translate("PasswordScreen", "There is no way to recover lost passwords")) def new_password(self): if self.password.text() == self.confirm_password.text(): if len(self.password.text()) >= 8: self._encrypt.set_password(self.password.text()) self.close() else: self.not_match.setText( QtWidgets.QApplication.translate("PasswordScreen", "Password must be at least 8 symbols")) self.not_match.setVisible(True) else: self.not_match.setText(QtWidgets.QApplication.translate("PasswordScreen", "Passwords do not match")) self.not_match.setVisible(True)
class ProfileSettings(CenteredWidget): """Form with profile settings such as name, status, TOX ID""" def __init__(self): super(ProfileSettings, self).__init__() self.initUI() self.center() def initUI(self): self.setObjectName("ProfileSettingsForm") self.setMinimumSize(QtCore.QSize(700, 600)) self.setMaximumSize(QtCore.QSize(700, 600)) self.nick = LineEdit(self) self.nick.setGeometry(QtCore.QRect(30, 60, 350, 27)) profile = Profile.get_instance() self.nick.setText(profile.name) self.status = QtGui.QComboBox(self) self.status.setGeometry(QtCore.QRect(400, 60, 200, 27)) self.status_message = LineEdit(self) self.status_message.setGeometry(QtCore.QRect(30, 130, 350, 27)) self.status_message.setText(profile.status_message) self.label = QtGui.QLabel(self) self.label.setGeometry(QtCore.QRect(40, 30, 91, 25)) font = QtGui.QFont() font.setPointSize(18) font.setWeight(75) font.setBold(True) self.label.setFont(font) self.label_2 = QtGui.QLabel(self) self.label_2.setGeometry(QtCore.QRect(40, 100, 100, 25)) self.label_2.setFont(font) self.label_3 = QtGui.QLabel(self) self.label_3.setGeometry(QtCore.QRect(40, 180, 100, 25)) self.label_3.setFont(font) self.tox_id = QtGui.QLabel(self) self.tox_id.setGeometry(QtCore.QRect(15, 210, 685, 21)) font.setPointSize(10) self.tox_id.setFont(font) s = profile.tox_id self.tox_id.setText(s) self.copyId = QtGui.QPushButton(self) self.copyId.setGeometry(QtCore.QRect(40, 250, 180, 30)) self.copyId.clicked.connect(self.copy) self.export = QtGui.QPushButton(self) self.export.setGeometry(QtCore.QRect(230, 250, 180, 30)) self.export.clicked.connect(self.export_profile) self.new_nospam = QtGui.QPushButton(self) self.new_nospam.setGeometry(QtCore.QRect(420, 250, 180, 30)) self.new_nospam.clicked.connect(self.new_no_spam) self.new_avatar = QtGui.QPushButton(self) self.new_avatar.setGeometry(QtCore.QRect(40, 300, 180, 30)) self.delete_avatar = QtGui.QPushButton(self) self.delete_avatar.setGeometry(QtCore.QRect(230, 300, 180, 30)) self.delete_avatar.clicked.connect(self.reset_avatar) self.new_avatar.clicked.connect(self.set_avatar) self.profile_pass = QtGui.QLabel(self) self.profile_pass.setGeometry(QtCore.QRect(40, 340, 300, 30)) font.setPointSize(18) self.profile_pass.setFont(font) self.password = LineEdit(self) self.password.setGeometry(QtCore.QRect(40, 380, 300, 30)) self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) self.leave_blank = QtGui.QLabel(self) self.leave_blank.setGeometry(QtCore.QRect(350, 380, 300, 30)) self.confirm_password = LineEdit(self) self.confirm_password.setGeometry(QtCore.QRect(40, 420, 300, 30)) self.confirm_password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) self.set_password = QtGui.QPushButton(self) self.set_password.setGeometry(QtCore.QRect(40, 470, 300, 30)) self.set_password.clicked.connect(self.new_password) self.not_match = QtGui.QLabel(self) self.not_match.setGeometry(QtCore.QRect(350, 420, 300, 30)) self.not_match.setVisible(False) self.not_match.setStyleSheet('QLabel { color: #BC1C1C; }') self.warning = QtGui.QLabel(self) self.warning.setGeometry(QtCore.QRect(40, 510, 500, 30)) self.warning.setStyleSheet('QLabel { color: #BC1C1C; }') self.default = QtGui.QPushButton(self) self.default.setGeometry(QtCore.QRect(40, 550, 620, 30)) path, name = Settings.get_auto_profile() self.auto = path + name == ProfileHelper.get_path( ) + Settings.get_instance().name self.default.clicked.connect(self.auto_profile) self.retranslateUi() if profile.status is not None: self.status.setCurrentIndex(profile.status) else: self.status.setVisible(False) QtCore.QMetaObject.connectSlotsByName(self) def retranslateUi(self): self.export.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Export profile", None, QtGui.QApplication.UnicodeUTF8)) self.setWindowTitle( QtGui.QApplication.translate("ProfileSettingsForm", "Profile settings", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Name:", None, QtGui.QApplication.UnicodeUTF8)) self.label_2.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Status:", None, QtGui.QApplication.UnicodeUTF8)) self.label_3.setText( QtGui.QApplication.translate("ProfileSettingsForm", "TOX ID:", None, QtGui.QApplication.UnicodeUTF8)) self.copyId.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Copy TOX ID", None, QtGui.QApplication.UnicodeUTF8)) self.new_avatar.setText( QtGui.QApplication.translate("ProfileSettingsForm", "New avatar", None, QtGui.QApplication.UnicodeUTF8)) self.delete_avatar.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Reset avatar", None, QtGui.QApplication.UnicodeUTF8)) self.new_nospam.setText( QtGui.QApplication.translate("ProfileSettingsForm", "New NoSpam", None, QtGui.QApplication.UnicodeUTF8)) self.profile_pass.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Profile password", None, QtGui.QApplication.UnicodeUTF8)) self.password.setPlaceholderText( QtGui.QApplication.translate("ProfileSettingsForm", "Password (at least 8 symbols)", None, QtGui.QApplication.UnicodeUTF8)) self.confirm_password.setPlaceholderText( QtGui.QApplication.translate("ProfileSettingsForm", "Confirm password", None, QtGui.QApplication.UnicodeUTF8)) self.set_password.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Set password", None, QtGui.QApplication.UnicodeUTF8)) self.not_match.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Passwords do not match", None, QtGui.QApplication.UnicodeUTF8)) self.leave_blank.setText( QtGui.QApplication.translate( "ProfileSettingsForm", "Leaving blank will reset current password", None, QtGui.QApplication.UnicodeUTF8)) self.warning.setText( QtGui.QApplication.translate( "ProfileSettingsForm", "There is no way to recover lost passwords", None, QtGui.QApplication.UnicodeUTF8)) self.status.addItem( QtGui.QApplication.translate("ProfileSettingsForm", "Online", None, QtGui.QApplication.UnicodeUTF8)) self.status.addItem( QtGui.QApplication.translate("ProfileSettingsForm", "Away", None, QtGui.QApplication.UnicodeUTF8)) self.status.addItem( QtGui.QApplication.translate("ProfileSettingsForm", "Busy", None, QtGui.QApplication.UnicodeUTF8)) if self.auto: self.default.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Mark as not default profile", None, QtGui.QApplication.UnicodeUTF8)) else: self.default.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Mark as default profile", None, QtGui.QApplication.UnicodeUTF8)) def auto_profile(self): if self.auto: Settings.reset_auto_profile() else: Settings.set_auto_profile(ProfileHelper.get_path(), Settings.get_instance().name) self.auto = not self.auto if self.auto: self.default.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Mark as not default profile", None, QtGui.QApplication.UnicodeUTF8)) else: self.default.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Mark as default profile", None, QtGui.QApplication.UnicodeUTF8)) def new_password(self): if self.password.text() == self.confirm_password.text(): if not len(self.password.text()) or len(self.password.text()) >= 8: e = toxencryptsave.LibToxEncryptSave.get_instance() e.set_password(self.password.text()) self.close() else: self.not_match.setText( QtGui.QApplication.translate( "ProfileSettingsForm", "Password must be at least 8 symbols", None, QtGui.QApplication.UnicodeUTF8)) self.not_match.setVisible(True) else: self.not_match.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Passwords do not match", None, QtGui.QApplication.UnicodeUTF8)) self.not_match.setVisible(True) def copy(self): clipboard = QtGui.QApplication.clipboard() profile = Profile.get_instance() clipboard.setText(profile.tox_id) pixmap = QtGui.QPixmap(curr_directory() + '/images/accept.png') icon = QtGui.QIcon(pixmap) self.copyId.setIcon(icon) self.copyId.setIconSize(QtCore.QSize(10, 10)) def new_no_spam(self): self.tox_id.setText(Profile.get_instance().new_nospam()) def reset_avatar(self): Profile.get_instance().reset_avatar() def set_avatar(self): choose = QtGui.QApplication.translate("ProfileSettingsForm", "Choose avatar", None, QtGui.QApplication.UnicodeUTF8) name = QtGui.QFileDialog.getOpenFileName(self, choose, None, 'Images (*.png)') if name[0]: bitmap = QtGui.QPixmap(name[0]) bitmap.scaled(QtCore.QSize(128, 128), aspectMode=QtCore.Qt.KeepAspectRatio, mode=QtCore.Qt.SmoothTransformation) byte_array = QtCore.QByteArray() buffer = QtCore.QBuffer(byte_array) buffer.open(QtCore.QIODevice.WriteOnly) bitmap.save(buffer, 'PNG') Profile.get_instance().set_avatar(str(byte_array.data())) def export_profile(self): directory = QtGui.QFileDialog.getExistingDirectory() + '/' if directory != '/': ProfileHelper.get_instance().export_profile(directory) settings = Settings.get_instance() settings.export(directory) profile = Profile.get_instance() profile.export_history(directory) def closeEvent(self, event): profile = Profile.get_instance() profile.set_name(self.nick.text()) profile.set_status_message(self.status_message.text().encode('utf-8')) profile.set_status(self.status.currentIndex())
class ProfileSettings(CenteredWidget): """Form with profile settings such as name, status, TOX ID""" def __init__(self): super(ProfileSettings, self).__init__() self.initUI() self.center() def initUI(self): self.setObjectName("ProfileSettingsForm") self.setMinimumSize(QtCore.QSize(700, 600)) self.setMaximumSize(QtCore.QSize(700, 600)) self.nick = LineEdit(self) self.nick.setGeometry(QtCore.QRect(30, 60, 350, 27)) profile = Profile.get_instance() self.nick.setText(profile.name) self.status = QtGui.QComboBox(self) self.status.setGeometry(QtCore.QRect(400, 60, 200, 27)) self.status_message = LineEdit(self) self.status_message.setGeometry(QtCore.QRect(30, 130, 350, 27)) self.status_message.setText(profile.status_message) self.label = QtGui.QLabel(self) self.label.setGeometry(QtCore.QRect(40, 30, 91, 25)) font = QtGui.QFont() font.setPointSize(18) font.setWeight(75) font.setBold(True) self.label.setFont(font) self.label_2 = QtGui.QLabel(self) self.label_2.setGeometry(QtCore.QRect(40, 100, 100, 25)) self.label_2.setFont(font) self.label_3 = QtGui.QLabel(self) self.label_3.setGeometry(QtCore.QRect(40, 180, 100, 25)) self.label_3.setFont(font) self.tox_id = QtGui.QLabel(self) self.tox_id.setGeometry(QtCore.QRect(15, 210, 685, 21)) font.setPointSize(10) self.tox_id.setFont(font) s = profile.tox_id self.tox_id.setText(s) self.copyId = QtGui.QPushButton(self) self.copyId.setGeometry(QtCore.QRect(40, 250, 180, 30)) self.copyId.clicked.connect(self.copy) self.export = QtGui.QPushButton(self) self.export.setGeometry(QtCore.QRect(230, 250, 180, 30)) self.export.clicked.connect(self.export_profile) self.new_nospam = QtGui.QPushButton(self) self.new_nospam.setGeometry(QtCore.QRect(420, 250, 180, 30)) self.new_nospam.clicked.connect(self.new_no_spam) self.copy_pk = QtGui.QPushButton(self) self.copy_pk.setGeometry(QtCore.QRect(40, 300, 180, 30)) self.copy_pk.clicked.connect(self.copy_public_key) self.new_avatar = QtGui.QPushButton(self) self.new_avatar.setGeometry(QtCore.QRect(230, 300, 180, 30)) self.delete_avatar = QtGui.QPushButton(self) self.delete_avatar.setGeometry(QtCore.QRect(420, 300, 180, 30)) self.delete_avatar.clicked.connect(self.reset_avatar) self.new_avatar.clicked.connect(self.set_avatar) self.profilepass = QtGui.QLabel(self) self.profilepass.setGeometry(QtCore.QRect(40, 340, 300, 30)) font.setPointSize(18) self.profilepass.setFont(font) self.password = LineEdit(self) self.password.setGeometry(QtCore.QRect(40, 380, 300, 30)) self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) self.leave_blank = QtGui.QLabel(self) self.leave_blank.setGeometry(QtCore.QRect(350, 380, 300, 30)) self.confirm_password = LineEdit(self) self.confirm_password.setGeometry(QtCore.QRect(40, 420, 300, 30)) self.confirm_password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) self.set_password = QtGui.QPushButton(self) self.set_password.setGeometry(QtCore.QRect(40, 470, 300, 30)) self.set_password.clicked.connect(self.new_password) self.not_match = QtGui.QLabel(self) self.not_match.setGeometry(QtCore.QRect(350, 420, 300, 30)) self.not_match.setVisible(False) self.not_match.setStyleSheet('QLabel { color: #BC1C1C; }') self.warning = QtGui.QLabel(self) self.warning.setGeometry(QtCore.QRect(40, 510, 500, 30)) self.warning.setStyleSheet('QLabel { color: #BC1C1C; }') self.default = QtGui.QPushButton(self) self.default.setGeometry(QtCore.QRect(40, 550, 620, 30)) path, name = Settings.get_auto_profile() self.auto = path + name == ProfileHelper.get_path() + Settings.get_instance().name self.default.clicked.connect(self.auto_profile) self.retranslateUi() if profile.status is not None: self.status.setCurrentIndex(profile.status) else: self.status.setVisible(False) QtCore.QMetaObject.connectSlotsByName(self) def retranslateUi(self): self.export.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Export profile", None, QtGui.QApplication.UnicodeUTF8)) self.setWindowTitle(QtGui.QApplication.translate("ProfileSettingsForm", "Profile settings", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Name:", None, QtGui.QApplication.UnicodeUTF8)) self.label_2.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Status:", None, QtGui.QApplication.UnicodeUTF8)) self.label_3.setText(QtGui.QApplication.translate("ProfileSettingsForm", "TOX ID:", None, QtGui.QApplication.UnicodeUTF8)) self.copyId.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Copy TOX ID", None, QtGui.QApplication.UnicodeUTF8)) self.new_avatar.setText(QtGui.QApplication.translate("ProfileSettingsForm", "New avatar", None, QtGui.QApplication.UnicodeUTF8)) self.delete_avatar.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Reset avatar", None, QtGui.QApplication.UnicodeUTF8)) self.new_nospam.setText(QtGui.QApplication.translate("ProfileSettingsForm", "New NoSpam", None, QtGui.QApplication.UnicodeUTF8)) self.profilepass.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Profile password", None, QtGui.QApplication.UnicodeUTF8)) self.password.setPlaceholderText(QtGui.QApplication.translate("ProfileSettingsForm", "Password (at least 8 symbols)", None, QtGui.QApplication.UnicodeUTF8)) self.confirm_password.setPlaceholderText(QtGui.QApplication.translate("ProfileSettingsForm", "Confirm password", None, QtGui.QApplication.UnicodeUTF8)) self.set_password.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Set password", None, QtGui.QApplication.UnicodeUTF8)) self.not_match.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Passwords do not match", None, QtGui.QApplication.UnicodeUTF8)) self.leave_blank.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Leaving blank will reset current password", None, QtGui.QApplication.UnicodeUTF8)) self.warning.setText(QtGui.QApplication.translate("ProfileSettingsForm", "There is no way to recover lost passwords", None, QtGui.QApplication.UnicodeUTF8)) self.status.addItem(QtGui.QApplication.translate("ProfileSettingsForm", "Online", None, QtGui.QApplication.UnicodeUTF8)) self.status.addItem(QtGui.QApplication.translate("ProfileSettingsForm", "Away", None, QtGui.QApplication.UnicodeUTF8)) self.status.addItem(QtGui.QApplication.translate("ProfileSettingsForm", "Busy", None, QtGui.QApplication.UnicodeUTF8)) self.copy_pk.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Copy public key", None, QtGui.QApplication.UnicodeUTF8)) if self.auto: self.default.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Mark as not default profile", None, QtGui.QApplication.UnicodeUTF8)) else: self.default.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Mark as default profile", None, QtGui.QApplication.UnicodeUTF8)) def auto_profile(self): if self.auto: Settings.reset_auto_profile() else: Settings.set_auto_profile(ProfileHelper.get_path(), Settings.get_instance().name) self.auto = not self.auto if self.auto: self.default.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Mark as not default profile", None, QtGui.QApplication.UnicodeUTF8)) else: self.default.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Mark as default profile", None, QtGui.QApplication.UnicodeUTF8)) def new_password(self): if self.password.text() == self.confirm_password.text(): if not len(self.password.text()) or len(self.password.text()) >= 8: e = toxencryptsave.ToxEncryptSave.get_instance() e.set_password(self.password.text()) self.close() else: self.not_match.setText( QtGui.QApplication.translate("ProfileSettingsForm", "Password must be at least 8 symbols", None, QtGui.QApplication.UnicodeUTF8)) self.not_match.setVisible(True) else: self.not_match.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Passwords do not match", None, QtGui.QApplication.UnicodeUTF8)) self.not_match.setVisible(True) def copy(self): clipboard = QtGui.QApplication.clipboard() profile = Profile.get_instance() clipboard.setText(profile.tox_id) pixmap = QtGui.QPixmap(curr_directory() + '/images/accept.png') icon = QtGui.QIcon(pixmap) self.copyId.setIcon(icon) self.copyId.setIconSize(QtCore.QSize(10, 10)) def copy_public_key(self): clipboard = QtGui.QApplication.clipboard() profile = Profile.get_instance() clipboard.setText(profile.tox_id[:64]) pixmap = QtGui.QPixmap(curr_directory() + '/images/accept.png') icon = QtGui.QIcon(pixmap) self.copy_pk.setIcon(icon) self.copy_pk.setIconSize(QtCore.QSize(10, 10)) def new_no_spam(self): self.tox_id.setText(Profile.get_instance().new_nospam()) def reset_avatar(self): Profile.get_instance().reset_avatar() def set_avatar(self): choose = QtGui.QApplication.translate("ProfileSettingsForm", "Choose avatar", None, QtGui.QApplication.UnicodeUTF8) name = QtGui.QFileDialog.getOpenFileName(self, choose, None, 'Images (*.png)', options=QtGui.QFileDialog.DontUseNativeDialog) if name[0]: bitmap = QtGui.QPixmap(name[0]) bitmap.scaled(QtCore.QSize(128, 128), aspectMode=QtCore.Qt.KeepAspectRatio, mode=QtCore.Qt.SmoothTransformation) byte_array = QtCore.QByteArray() buffer = QtCore.QBuffer(byte_array) buffer.open(QtCore.QIODevice.WriteOnly) bitmap.save(buffer, 'PNG') Profile.get_instance().set_avatar(bytes(byte_array.data())) def export_profile(self): directory = QtGui.QFileDialog.getExistingDirectory(options=QtGui.QFileDialog.DontUseNativeDialog) + '/' if directory != '/': ProfileHelper.get_instance().export_profile(directory) settings = Settings.get_instance() settings.export(directory) profile = Profile.get_instance() profile.export_history(directory) def closeEvent(self, event): profile = Profile.get_instance() profile.set_name(self.nick.text()) profile.set_status_message(self.status_message.text().encode('utf-8')) profile.set_status(self.status.currentIndex())
class Login_UI(QDialog): def __init__(self, parent=None): super(Login_UI, self).__init__(parent) self.initParas() self.initUI() def initParas(self): # 验证方式 self.login_title = gol.get_value('login_title', '明州体检') self.lgoin_width = gol.get_value('login_width', 500) self.login_height = gol.get_value('login_height', 400) self.login_bg = file_ico("login.png") self.login_style = "font: 75 14pt \"微软雅黑\";" \ "color: rgb(45, 135, 66);" \ "background-image: url(:/resource/image/login.png);" self.login_font = "font: 75 8pt;color: #CD0000" # 获取用户名 self.session = gol.get_value("tjxt_session_local") self.log = gol.get_value("log") def initUI(self): self.setWindowTitle(self.login_title) self.setFixedSize(self.lgoin_width, self.login_height) self.setWindowIcon(Icon("mztj")) self.setStyleSheet(self.login_style) self.setWindowFlags(Qt.FramelessWindowHint) #窗口模式,去掉标题栏 # 给窗体再加一个widget控件,对widget设置背景图片 self.widget = QWidget(self) self.widget.setFixedSize(self.lgoin_width, self.login_height) palette = QPalette() palette.setBrush(self.backgroundRole(), QBrush(QPixmap(self.login_bg))) self.widget.setPalette(palette) self.widget.setAutoFillBackground(True) lt_main = QVBoxLayout(self) lt_main.setAlignment(Qt.AlignCenter) layout = QFormLayout() layout.setLabelAlignment(Qt.AlignRight) layout.setFormAlignment(Qt.AlignHCenter | Qt.AlignVCenter) # 用户ID self.lb_user_id = LineEdit(None, "", LineEdit.SUCCESS_STYLE) regx = QRegExp("[a-zA-Z0-9]+$") validator = QRegExpValidator(regx, self.lb_user_id) self.lb_user_id.setValidator(validator) #根据正则做限制,只能输入数字 self.lb_user_id.setMaximumWidth(200) # self.lb_user_id.setFocusPolicy(Qt.ClickFocus) # 用户姓名 self.lb_user_name = LineEdit(None, "", LineEdit.SUCCESS_STYLE) self.lb_user_name.setDisabled(True) self.lb_user_name.setMaximumWidth(200) # 用户密码 self.lb_user_pd = LineEdit(None, "", LineEdit.SUCCESS_STYLE) self.lb_user_pd.setMaximumWidth(200) self.lb_user_pd.setEchoMode(QLineEdit.Password) # 是否自动填充 self.is_rem = QCheckBox("记住最近登录") self.is_rem.setStyleSheet(self.login_font) # 进入主界面还是接口界面 self.is_equip = QCheckBox("进入设备接口") self.is_equip.setStyleSheet(self.login_font) # 版本号 self.lb_version = QLabel(self) self.lb_version.setText('当前版本:%s' % str(gol.get_value('system_version', '读取失败'))) self.lb_version.setStyleSheet(self.login_font) self.lb_version.setGeometry(QRect(400, 360, 100, 30)) if not gol.get_value('login_auto_record', 0): self.is_rem.setChecked(False) else: self.is_rem.setChecked(True) # 自动填充最近登录信息 self.lb_user_id.setText(str(gol.get_value('login_user_id', 'BSSA'))) self.lb_user_name.setText(gol.get_value('login_user_name', '管理员')) if not gol.get_value('system_is_equip', 0): self.is_equip.setChecked(False) else: self.is_equip.setChecked(True) ######################添加布局########################################## layout0 = QHBoxLayout() layout0.addWidget(self.is_rem) layout0.addWidget(self.is_equip) layout0.addStretch() login_user = "******" layout.addWidget(QLabel("")) layout.addRow(QLabel("账户:"), self.lb_user_id) layout.addRow(login_user, self.lb_user_name) layout.addRow(QLabel("密码:"), self.lb_user_pd) layout.addRow(QLabel(""), layout0) layout.setHorizontalSpacing(10) layout.setVerticalSpacing(10) self.buttonBox = QDialogButtonBox() self.buttonBox.addButton("登录", QDialogButtonBox.YesRole) self.buttonBox.addButton("取消", QDialogButtonBox.NoRole) self.buttonBox.setCenterButtons(True) self.buttonBox.buttons()[0].setEnabled(False) # 失去焦点 # self.buttonBox.buttons()[0].setFocusPolicy(Qt.ClickFocus) # self.buttonBox.buttons()[1].setFocusPolicy(Qt.NoFocus) # 对登录进行限制 if self.lb_user_name.text(): self.buttonBox.buttons()[0].setEnabled(True) else: self.buttonBox.buttons()[0].setEnabled(False) self.lb_user_id.textEdited.connect(self.set_empty) self.lb_user_id.editingFinished.connect(self.user_get) self.is_equip.stateChanged.connect(self.on_equip_change) self.buttonBox.accepted.connect(self.login) self.buttonBox.rejected.connect(self.reject) lt_main.addSpacing(30) lt_main.addLayout(layout) lt_main.addSpacing(20) lt_main.addWidget(self.buttonBox) self.setLayout(lt_main) def on_equip_change(self, p_int): gol.set_value("system_is_equip", p_int) def user_get(self): user_id = self.lb_user_id.text() if not user_id: mes_about(self, "请输入账户!") return try: result = self.session.query(MT_TJ_USER).filter( MT_TJ_USER.xtsb == '101', MT_TJ_USER.yhdm == user_id).scalar() if result: self.lb_user_name.setText(str2(result.yhmc)) self.buttonBox.buttons()[0].setEnabled(True) except Exception as e: mes_about(self, "读取数据库失败!错误信息:%s" % e) def set_empty(self, p_str): self.lb_user_id.setText(p_str.upper()) self.lb_user_name.setText("") self.buttonBox.buttons()[0].setEnabled(False) # 验证密码 def login(self): _user_id = self.lb_user_id.text() _user_name = self.lb_user_name.text() _user_pwd = self.lb_user_pd.text() if not _user_id: mes_about("请输入账户!!") return try: result = self.session.query(MT_TJ_USER).filter( MT_TJ_USER.xtsb == '101', MT_TJ_USER.yhdm == _user_id).filter( or_(MT_TJ_USER.yhkl == _user_pwd, MT_TJ_USER.yhkl == None)).scalar() except Exception as e: mes_about(self, "从数据库中验收密码失败!错误信息:%s" % e) return if not result: mes_warn(self, "您输入的账户:%s,密码:%s,有误!\n请确认后重新登陆!" % (_user_id, _user_pwd)) return results = self.session.query(MT_TJ_YGQSKS).filter( MT_TJ_YGQSKS.yggh == _user_id).all() ksbms = [result.ksbm.rstrip() for result in results] gol.set_value('login_user_ksbms', ksbms) gol.set_value('login_user_id', _user_id) gol.set_value('login_user_name', _user_name) gol.set_value('login_user_pwd', _user_pwd) gol.set_value('login_time', cur_datetime()) ############### 写入配置 ######################### if self.is_rem.isChecked(): auto_record = 1 else: auto_record = 0 if self.is_equip.isChecked(): is_equip = 1 else: is_equip = 0 login = { "auto_record": auto_record, "user_id": _user_id, "user_name": _user_name } system = {"is_equip": is_equip} config_write("custom.ini", "login", login) config_write("custom.ini", "system", system) self.log.info('写入配置(custom.ini)文件成功') self.log.info("用户:%s(%s) 登陆成功!" % (_user_name, _user_id)) # 写入登录记录,获取主键ID login_obj = MT_TJ_LOGIN(login_id=_user_id, login_name=_user_name, login_area=gol.get_value('login_area', ''), login_ip=gol.get_value('host_ip', ''), login_host=gol.get_value('host_name', ''), login_in=gol.get_value('login_time', '')) try: self.session.add(login_obj) # 先写入数据库,但是不提交 ,此时可获取自增ID self.session.flush() gol.set_value('login_lid', login_obj.lid) self.session.commit() except Exception as e: self.session.rollback() mes_about(self, '执行发生错误:%s' % e) return # 跳转 self.accept()