diff --git a/features/main_window/base.py b/features/main_window/base.py
index ab8debae7b1f5c66c7721b72610abb5ad37e9f8d..b3555ecabc3717f56f31c84b176bb9baaafea449 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 9e534d307338fafeb8742f99d5773063c70af6e1..843dd6abdd09f4667a8a1c1dcc386d045dfc5809 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 c865d5aac48b0014e1f3e7775adaf2f6f54f5e08..290a39b5b485e97a2993a33c6ef100e07b4d21fa 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 29862827153cf659195d3164c0d699487519a117..8d469fb4a4838c23747f684cb92c94b4b328be25 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 58cbf1b33cdb50ab0b5e63f0e7c45857311857f8..45a4af71e0e0b09d7f4db3eab6ad02247804f348 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
+
+
+
-