From 92ca64635ca3eb9c64dd2448584e6b584acf0b35 Mon Sep 17 00:00:00 2001 From: tianyaaz Date: Tue, 27 Apr 2021 21:14:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E5=90=8D?= =?UTF-8?q?=E8=BE=83=E9=95=BF=E6=97=B6=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- features/main_window/base.py | 30 +++++++++++++++++++-------- features/ui/ui_login.py | 1 + features/ui/ui_login.ui | 3 +++ features/ui/ui_logined.py | 18 +++++++++++----- features/ui/ui_logined.ui | 40 ++++++++++++++++++++++++++++-------- 5 files changed, 71 insertions(+), 21 deletions(-) diff --git a/features/main_window/base.py b/features/main_window/base.py index ab8debae..b3555eca 100644 --- a/features/main_window/base.py +++ b/features/main_window/base.py @@ -9,7 +9,7 @@ from typing import Tuple, List import qdarkstyle from PySide2.QtCore import QPoint, QRectF -from PySide2.QtGui import QMouseEvent, QPainter, QLinearGradient +from PySide2.QtGui import QMouseEvent, QPainter, QLinearGradient, QCursor from PySide2.QtGui import QCloseEvent from PySide2.QtCore import Signal, Qt, QUrl, QPropertyAnimation from PySide2.QtWidgets import QApplication, QListWidgetItem, QWizard, QHeaderView, QMessageBox @@ -642,11 +642,15 @@ class LoginForm(QDialog, login_Ui_Form): """ shared_memo = shared_memory.SharedMemory(name="sharedMemory") # 通过name找到共享内存token buff = shared_memo.buf - # buff[:199]位存放token,buff[199:201]位存放用户名长度,用户名字段最长为64字节,最多21个汉字(字符集utf8) - # buff[201:实际用户名长度(用utf8转换为bytes后的长度)]存放用户名 - buff[:token_len] = token.encode("utf-8") # 将token存放进共享内存中,工作空间重启后也能获取到 - buff[token_len:token_len + 2] = str(username_len).encode("utf-8") # 将用户名长度存放共享内存 - buff[token_len + 2:token_len + 2 + username_len] = username.encode("utf-8") + # token长度随着用户名长度的增加而增加,用户名最长为21个汉字加一个字符 + # buff[:3]存放token长度,目前最长的用户名21汉字加一字符生成的token长度为343 + # buff[3:5]存放用户名长度,用户名字段最长为64字节,最多21个汉字(字符集utf8) + # buff[5:token_len+5]位存放token + # buff[token_len+5:实际用户名长度(用utf8转换为bytes后的长度)]存放用户名 + buff[:3] = str(token_len).encode("utf-8") # 存放token长度 + buff[3:5] = str(username_len).encode("utf-8") # 将用户名长度存放共享内存 + buff[5:token_len+5] = token.encode("utf-8") # 将token存放进共享内存中,工作空间重启后也能获取到 + buff[token_len+5:token_len+5+username_len] = username.encode("utf-8") # 存放用户名 self.usernameError.setText("登录成功") time.sleep(0.5) self.close() @@ -659,6 +663,15 @@ class LoginForm(QDialog, login_Ui_Form): def usernameErrorChange(self): self.usernameError.setText("") self.passwordError.setText("") + username = self.usernameLineEdit.text() + if len(username.encode("utf-8")) > 64: + self.usernameError.setText("最多只能输入21个汉字") + self.loginButton.setEnabled(False) + self.loginButton.setCursor(QCursor(Qt.ForbiddenCursor)) + else: + self.usernameError.setText("") + self.loginButton.setEnabled(True) + self.loginButton.setCursor(QCursor(Qt.PointingHandCursor)) class LoginedForm(QDialog, logined_Ui_Form): @@ -669,8 +682,9 @@ class LoginedForm(QDialog, logined_Ui_Form): self.init() shared_memo = shared_memory.SharedMemory(name="sharedMemory") # 通过name找到共享内存token buff = shared_memo.buf - username_len = int(bytes(buff[199:201]).decode()) - username = bytes(buff[201:201 + username_len]).decode("utf-8") + token_len = int(bytes(buff[:3]).decode()) + username_len = int(bytes(buff[3:5]).decode()) + username = bytes(buff[token_len+5:token_len+5+username_len]).decode("utf-8") self.usernameLabel.setText(username) def init(self): diff --git a/features/ui/ui_login.py b/features/ui/ui_login.py index 9e534d30..843dd6ab 100644 --- a/features/ui/ui_login.py +++ b/features/ui/ui_login.py @@ -103,6 +103,7 @@ class Ui_Form(object): "selection-color: white;\n" "selection-background-color: blue;\n" "}") + self.usernameLineEdit.setMaxLength(64) self.horizontalLayout_2.addWidget(self.usernameLineEdit) diff --git a/features/ui/ui_login.ui b/features/ui/ui_login.ui index c865d5aa..290a39b5 100644 --- a/features/ui/ui_login.ui +++ b/features/ui/ui_login.ui @@ -186,6 +186,9 @@ selection-color: white; selection-background-color: blue; } + + 64 + 请输入用户名 diff --git a/features/ui/ui_logined.py b/features/ui/ui_logined.py index 29862827..8d469fb4 100644 --- a/features/ui/ui_logined.py +++ b/features/ui/ui_logined.py @@ -53,20 +53,28 @@ class Ui_Form(object): self.horizontalLayout.setObjectName(u"horizontalLayout") self.label = QLabel(self.layoutWidget) self.label.setObjectName(u"label") + self.label.setFrameShape(QFrame.NoFrame) + self.label.setFrameShadow(QFrame.Plain) + self.label.setTextFormat(Qt.AutoText) self.label.setAlignment(Qt.AlignCenter) - self.label.setMargin(50) + self.label.setMargin(0) self.horizontalLayout.addWidget(self.label) + self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) + + self.horizontalLayout.addItem(self.verticalSpacer_2) + self.usernameLabel = QLabel(self.layoutWidget) self.usernameLabel.setObjectName(u"usernameLabel") + self.usernameLabel.setCursor(QCursor(Qt.IBeamCursor)) + self.usernameLabel.setLayoutDirection(Qt.LeftToRight) + self.usernameLabel.setWordWrap(True) + self.usernameLabel.setMargin(0) + self.usernameLabel.setTextInteractionFlags(Qt.TextSelectableByMouse) self.horizontalLayout.addWidget(self.usernameLabel) - self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) - - self.horizontalLayout.addItem(self.verticalSpacer_2) - self.verticalLayout.addLayout(self.horizontalLayout) diff --git a/features/ui/ui_logined.ui b/features/ui/ui_logined.ui index 58cbf1b3..45a4af71 100644 --- a/features/ui/ui_logined.ui +++ b/features/ui/ui_logined.ui @@ -69,21 +69,23 @@ + + QFrame::NoFrame + + + QFrame::Plain + 用 户 名 + + Qt::AutoText + Qt::AlignCenter - 50 - - - - - - - + 0 @@ -100,6 +102,28 @@ + + + + IBeamCursor + + + Qt::LeftToRight + + + + + + true + + + 0 + + + Qt::TextSelectableByMouse + + + -- Gitee