Commit f07f490f authored by Zheng Yile's avatar Zheng Yile
Browse files

增加配置文件; 增加菜单栏'关于'; 增加自定义窗口函数; 其他代码结构上的小修改

parent 808fdd69
VERSION = "1.0.4-gui"
import sys import sys
from PyQt5.QtCore import Qt, QPropertyAnimation, pyqtSignal, pyqtProperty, QEasingCurve from .config import VERSION
from PyQt5.QtGui import QFont, QPalette, QBrush, QColor, QPainterPath, QPainter, QPen
from PyQt5.QtWidgets import QMessageBox, QPushButton, QLabel, QProgressBar, QListWidget, QDesktopWidget from PyQt5.QtCore import Qt, QPropertyAnimation, pyqtSignal, pyqtProperty, QEasingCurve, QRect, QMetaObject, QCoreApplication
from PyQt5.QtGui import QFont, QPalette, QBrush, QColor, QPainterPath, QPainter, QPen, QIcon, QPixmap
from PyQt5.QtWidgets import QMessageBox, QPushButton, QLabel, QProgressBar, QListWidget, QDesktopWidget, QMainWindow, QWidget
Font = { Font = {
'main': QFont(), 'main': QFont(),
...@@ -46,8 +48,19 @@ if sys.platform == 'win32': ...@@ -46,8 +48,19 @@ if sys.platform == 'win32':
Font['main'].setPointSize(10) Font['main'].setPointSize(10)
Font['status'].setFamily("KaiTi") Font['status'].setFamily("KaiTi")
Font['status'].setPointSize(10) Font['status'].setPointSize(10)
Style[ Style['progressBar'] = """
'progressBar'] = "QProgressBar { max-height: 12px; border: none; border-radius: 6px; text-align: center; background-color: #FFFFFF } QProgressBar::chunk { border: none; border-radius: 6px; background: qlineargradient(spread: pad, x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #05A01E, stop: 1 #75C090) }" QProgressBar {
max-height: 12px;
border: none;
border-radius: 6px;
text-align: center;
background-color: #FFFFFF
}
QProgressBar::chunk {
border: none;
border-radius: 6px;
background: qlineargradient(spread: pad, x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #05A01E, stop: 1 #75C090)
}"""
elif sys.platform == 'darwin': elif sys.platform == 'darwin':
Font['main'].setFamily("PingFang SC") Font['main'].setFamily("PingFang SC")
Font['main'].setPointSize(13) Font['main'].setPointSize(13)
...@@ -402,3 +415,77 @@ def AdjustWindowSize(window) -> None: ...@@ -402,3 +415,77 @@ def AdjustWindowSize(window) -> None:
size = window.geometry() size = window.geometry()
window.move((screen.width() - size.width()) / 2, window.move((screen.width() - size.width()) / 2,
(screen.height() - size.height()) / 2) (screen.height() - size.height()) / 2)
class Ui_window(object):
title = ""
content = ""
def __init__(self, title, content):
self.title = title
self.content = content
def setupUi(self, window):
window.setObjectName("window")
window.resize(320, 180)
icon = QIcon()
icon.addPixmap(QPixmap("favicon.ico"), QIcon.Normal, QIcon.Off)
window.setWindowIcon(icon)
window.setWindowOpacity(1.0)
self.centralwidget = QWidget(window)
self.centralwidget.setObjectName("centralwidget")
self.labelContent = QLabel(self.centralwidget)
self.labelContent.setGeometry(QRect(10, 10, 300, 160))
self.labelContent.setAlignment(Qt.AlignCenter)
self.labelContent.setObjectName("labelContent")
window.setCentralWidget(self.centralwidget)
self.retranslateUi(window)
QMetaObject.connectSlotsByName(window)
def retranslateUi(self, window):
_translate = QCoreApplication.translate
window.setWindowTitle(_translate("window", self.title))
self.labelContent.setText(_translate("window", self.content))
def CreateWindow(parent=None, title="", content="", addition=None):
global window
window = QMainWindow(parent)
window.setFont(Font["main"])
ui = Ui_window(title, content)
ui.setupUi(window)
addition and addition(ui)
AdjustWindowSize(window)
window.setWindowModality(Qt.ApplicationModal)
window.show()
def About(parent=None):
def addition(ui):
ui.labelContent.setGeometry(QRect(10, 100, 300, 70))
ui.labelTitle = QLabel(ui.centralwidget)
ui.labelTitle.setGeometry(QRect(10, 10, 300, 60))
ui.labelTitle.setAlignment(Qt.AlignBottom | Qt.AlignHCenter)
ui.labelTitle.setObjectName("labelTitle")
ui.labelVersion = QLabel(ui.centralwidget)
ui.labelVersion.setGeometry(QRect(10, 70, 300, 30))
ui.labelVersion.setAlignment(Qt.AlignTop | Qt.AlignHCenter)
ui.labelVersion.setAlignment(Qt.AlignCenter)
ui.labelVersion.setObjectName("labelVersion")
font = QFont()
font.setFamily(Font['main'].family())
font.setPointSize(Font['main'].pointSize() + 2)
ui.labelTitle.setFont(font)
font.setPointSize(Font['main'].pointSize() - 1)
ui.labelVersion.setFont(font)
ui.labelContent.setFont(font)
_translate = QCoreApplication.translate
ui.labelTitle.setText(_translate("window", "CODIA Client"))
ui.labelVersion.setText(_translate("window", f"version: {VERSION}"))
CreateWindow(parent=parent, title="关于", content="""作者:20少 郑以勒\n   20少 曹高翔""", addition=addition)
...@@ -10,7 +10,7 @@ from codiaclient.network import * ...@@ -10,7 +10,7 @@ from codiaclient.network import *
from codiaclient.network import _acquire_verification as _AcquireVerification from codiaclient.network import _acquire_verification as _AcquireVerification
from codiaclient.report import Error as codiaError, error_translate from codiaclient.report import Error as codiaError, error_translate
from codiaclient.utils import cookie_decrypt as Decrypt, cookie_encrypt as Encrypt from codiaclient.utils import cookie_decrypt as Decrypt, cookie_encrypt as Encrypt
from codiaclientgui.utils import Font, Style, ErrorDisplay, AdjustWindowSize from codiaclientgui.utils import Font, Style, ErrorDisplay, AdjustWindowSize, About
from loginWindow import Ui_windowLogin from loginWindow import Ui_windowLogin
sessionPath = path.join(cache_var['appDataPath'], ".gui.cache") sessionPath = path.join(cache_var['appDataPath'], ".gui.cache")
...@@ -34,30 +34,31 @@ def BeginLogin(callback=None): ...@@ -34,30 +34,31 @@ def BeginLogin(callback=None):
QApplication.processEvents() QApplication.processEvents()
report_var["allow_error_deg"] = 1 report_var["allow_error_deg"] = 1
uiLogin.progressBarLogin.setStyleSheet(Style["progressBar"])
uiLogin.lineEditLoginPassword.returnPressed.connect(lambda: Login(callback))
uiLogin.pushButtonLogin.clicked.connect(lambda: Login(callback)) uiLogin.pushButtonLogin.clicked.connect(lambda: Login(callback))
# uiLogin.pushButtonLogin.setFocus()
# uiLogin.pushButtonLogin.setDefault(True)
uiLogin.pushButtonLoginGoReset.clicked.connect(ShowReset) uiLogin.pushButtonLoginGoReset.clicked.connect(ShowReset)
uiLogin.pushButtonLoginGoRegister.clicked.connect(ShowRegister) uiLogin.pushButtonLoginGoRegister.clicked.connect(ShowRegister)
uiLogin.lineEditLoginPassword.setEchoMode(QLineEdit.Password)
uiLogin.lineEditLoginPassword.returnPressed.connect(lambda: Login(callback))
uiLogin.progressBarLogin.hide()
uiLogin.progressBarLogin.setStyleSheet(Style["progressBar"])
uiLogin.pushButtonRegister.clicked.connect(Register) uiLogin.pushButtonRegister.clicked.connect(Register)
uiLogin.pushButtonRegisterReturn.clicked.connect(RegisterReturn) uiLogin.pushButtonRegisterReturn.clicked.connect(RegisterReturn)
uiLogin.lineEditRegisterPassword.setEchoMode(QLineEdit.Password)
uiLogin.lineEditRegisterCheckPassword.setEchoMode(QLineEdit.Password)
uiLogin.pushButtonReset.clicked.connect(Reset) uiLogin.pushButtonReset.clicked.connect(Reset)
uiLogin.pushButtonResetAcquire.clicked.connect(AcquireVerification) uiLogin.pushButtonResetAcquire.clicked.connect(AcquireVerification)
uiLogin.pushButtonResetReturn.clicked.connect(ResetReturn) uiLogin.pushButtonResetReturn.clicked.connect(ResetReturn)
uiLogin.actionAbout.triggered.connect(lambda: About(windowLogin))
# uiLogin.pushButtonLogin.setFocus()
# uiLogin.pushButtonLogin.setDefault(True)
uiLogin.lineEditLoginPassword.setEchoMode(QLineEdit.Password)
uiLogin.lineEditResetNewPassword.setEchoMode(QLineEdit.Password) uiLogin.lineEditResetNewPassword.setEchoMode(QLineEdit.Password)
uiLogin.lineEditResetCheckNewPassword.setEchoMode(QLineEdit.Password) uiLogin.lineEditResetCheckNewPassword.setEchoMode(QLineEdit.Password)
uiLogin.lineEditRegisterPassword.setEchoMode(QLineEdit.Password)
uiLogin.lineEditRegisterCheckPassword.setEchoMode(QLineEdit.Password)
uiLogin.frameLogin.show() uiLogin.progressBarLogin.hide()
uiLogin.frameRegister.hide() uiLogin.frameRegister.hide()
uiLogin.frameReset.hide() uiLogin.frameReset.hide()
uiLogin.frameLogin.show()
# 登录客户端的网络通信 # 登录客户端的网络通信
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'loginWindow.ui' # Form implementation generated from reading ui file 'loginWindow.ui'
# #
# Created by: PyQt5 UI code generator 5.15.4 # Created by: PyQt5 UI code generator 5.15.2
# #
# WARNING: Any manual changes made to this file will be lost when pyuic5 is # WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing. # run again. Do not edit this file unless you know what you are doing.
...@@ -194,8 +194,10 @@ class Ui_windowLogin(object): ...@@ -194,8 +194,10 @@ class Ui_windowLogin(object):
self.frameLogin.raise_() self.frameLogin.raise_()
windowLogin.setCentralWidget(self.centralwidget) windowLogin.setCentralWidget(self.centralwidget)
self.menuBar = QtWidgets.QMenuBar(windowLogin) self.menuBar = QtWidgets.QMenuBar(windowLogin)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 540, 24)) self.menuBar.setGeometry(QtCore.QRect(0, 0, 540, 26))
self.menuBar.setObjectName("menuBar") self.menuBar.setObjectName("menuBar")
self.menu = QtWidgets.QMenu(self.menuBar)
self.menu.setObjectName("menu")
windowLogin.setMenuBar(self.menuBar) windowLogin.setMenuBar(self.menuBar)
self.actions = QtWidgets.QAction(windowLogin) self.actions = QtWidgets.QAction(windowLogin)
self.actions.setObjectName("actions") self.actions.setObjectName("actions")
...@@ -205,6 +207,10 @@ class Ui_windowLogin(object): ...@@ -205,6 +207,10 @@ class Ui_windowLogin(object):
self.actionsd.setObjectName("actionsd") self.actionsd.setObjectName("actionsd")
self.action_2 = QtWidgets.QAction(windowLogin) self.action_2 = QtWidgets.QAction(windowLogin)
self.action_2.setObjectName("action_2") self.action_2.setObjectName("action_2")
self.actionAbout = QtWidgets.QAction(windowLogin)
self.actionAbout.setObjectName("actionAbout")
self.menu.addAction(self.actionAbout)
self.menuBar.addAction(self.menu.menuAction())
self.retranslateUi(windowLogin) self.retranslateUi(windowLogin)
QtCore.QMetaObject.connectSlotsByName(windowLogin) QtCore.QMetaObject.connectSlotsByName(windowLogin)
...@@ -231,8 +237,10 @@ class Ui_windowLogin(object): ...@@ -231,8 +237,10 @@ class Ui_windowLogin(object):
self.label_10.setText(_translate("windowLogin", "新密码")) self.label_10.setText(_translate("windowLogin", "新密码"))
self.pushButtonResetAcquire.setText(_translate("windowLogin", "发送验证码")) self.pushButtonResetAcquire.setText(_translate("windowLogin", "发送验证码"))
self.pushButtonResetReturn.setText(_translate("windowLogin", "返回")) self.pushButtonResetReturn.setText(_translate("windowLogin", "返回"))
self.menu.setTitle(_translate("windowLogin", "帮助"))
self.actions.setText(_translate("windowLogin", "s")) self.actions.setText(_translate("windowLogin", "s"))
self.action.setText(_translate("windowLogin", "关于")) self.action.setText(_translate("windowLogin", "关于"))
self.actionsd.setText(_translate("windowLogin", "登陆")) self.actionsd.setText(_translate("windowLogin", "登陆"))
self.action_2.setText(_translate("windowLogin", "关于")) self.action_2.setText(_translate("windowLogin", "关于"))
self.actionAbout.setText(_translate("windowLogin", "关于"))
from codiaclientgui.utils import NewProgressBar, NewPushButton from codiaclientgui.utils import NewProgressBar, NewPushButton
...@@ -570,9 +570,16 @@ ...@@ -570,9 +570,16 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>540</width> <width>540</width>
<height>24</height> <height>26</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menu">
<property name="title">
<string>帮助</string>
</property>
<addaction name="actionAbout"/>
</widget>
<addaction name="menu"/>
</widget> </widget>
<action name="actions"> <action name="actions">
<property name="text"> <property name="text">
...@@ -594,6 +601,11 @@ ...@@ -594,6 +601,11 @@
<string>关于</string> <string>关于</string>
</property> </property>
</action> </action>
<action name="actionAbout">
<property name="text">
<string>关于</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
......
...@@ -18,7 +18,7 @@ from codiaclient.network import get_pack, show_pack, start_pack, logined, get_ex ...@@ -18,7 +18,7 @@ from codiaclient.network import get_pack, show_pack, start_pack, logined, get_ex
from codiaclient.network import submit, get_data from codiaclient.network import submit, get_data
from codiaclient.report import Error as codiaError, error_translate from codiaclient.report import Error as codiaError, error_translate
from codiaclient.requests import variables as requests_var from codiaclient.requests import variables as requests_var
from codiaclientgui.utils import QPalette, Font, Palette, Style, ErrorDisplay, NewListWidget, AdjustWindowSize from codiaclientgui.utils import QPalette, Font, Palette, Style, ErrorDisplay, NewListWidget, AdjustWindowSize, About
from mainWindow import Ui_windowMain from mainWindow import Ui_windowMain
...@@ -428,6 +428,7 @@ def BeginMain(callback=None): ...@@ -428,6 +428,7 @@ def BeginMain(callback=None):
lambda: GetLexer(lang=uiMain.comboBoxLanguageSubmit.currentText(), lambda: GetLexer(lang=uiMain.comboBoxLanguageSubmit.currentText(),
callback=lambda: HighlightTextEdit(textEdit=uiMain.textEditSubmit)) callback=lambda: HighlightTextEdit(textEdit=uiMain.textEditSubmit))
) )
uiMain.actionAbout.triggered.connect(lambda: About(windowMain))
uiMain.listWidgetPackHistory.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel) uiMain.listWidgetPackHistory.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
uiMain.listWidgetExercise.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel) uiMain.listWidgetExercise.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
......
...@@ -68,7 +68,7 @@ class Ui_windowMain(object): ...@@ -68,7 +68,7 @@ class Ui_windowMain(object):
self.pushButtonExerciseBegin.setObjectName("pushButtonExerciseBegin") self.pushButtonExerciseBegin.setObjectName("pushButtonExerciseBegin")
self.labelDeadline = QtWidgets.QLabel(self.frameExercise) self.labelDeadline = QtWidgets.QLabel(self.frameExercise)
self.labelDeadline.setGeometry(QtCore.QRect(780, 580, 280, 32)) self.labelDeadline.setGeometry(QtCore.QRect(780, 580, 280, 32))
self.labelDeadline.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) self.labelDeadline.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.labelDeadline.setIndent(10) self.labelDeadline.setIndent(10)
self.labelDeadline.setObjectName("labelDeadline") self.labelDeadline.setObjectName("labelDeadline")
self.progressBarExercise = NewProgressBar(self.frameExercise) self.progressBarExercise = NewProgressBar(self.frameExercise)
...@@ -212,10 +212,16 @@ class Ui_windowMain(object): ...@@ -212,10 +212,16 @@ class Ui_windowMain(object):
self.menubar = QtWidgets.QMenuBar(windowMain) self.menubar = QtWidgets.QMenuBar(windowMain)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1080, 26)) self.menubar.setGeometry(QtCore.QRect(0, 0, 1080, 26))
self.menubar.setObjectName("menubar") self.menubar.setObjectName("menubar")
self.menu = QtWidgets.QMenu(self.menubar)
self.menu.setObjectName("menu")
windowMain.setMenuBar(self.menubar) windowMain.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(windowMain) self.statusbar = QtWidgets.QStatusBar(windowMain)
self.statusbar.setObjectName("statusbar") self.statusbar.setObjectName("statusbar")
windowMain.setStatusBar(self.statusbar) windowMain.setStatusBar(self.statusbar)
self.actionAbout = QtWidgets.QAction(windowMain)
self.actionAbout.setObjectName("actionAbout")
self.menu.addAction(self.actionAbout)
self.menubar.addAction(self.menu.menuAction())
self.retranslateUi(windowMain) self.retranslateUi(windowMain)
QtCore.QMetaObject.connectSlotsByName(windowMain) QtCore.QMetaObject.connectSlotsByName(windowMain)
...@@ -248,6 +254,6 @@ class Ui_windowMain(object): ...@@ -248,6 +254,6 @@ class Ui_windowMain(object):
self.pushButtonCodeBack.setText(_translate("windowMain", "返回")) self.pushButtonCodeBack.setText(_translate("windowMain", "返回"))
self.pushButtonShowCode.setText(_translate("windowMain", "代码")) self.pushButtonShowCode.setText(_translate("windowMain", "代码"))
self.pushButtonTestDataBack.setText(_translate("windowMain", "返回")) self.pushButtonTestDataBack.setText(_translate("windowMain", "返回"))
self.menu.setTitle(_translate("windowMain", "帮助"))
self.actionAbout.setText(_translate("windowMain", "关于"))
from codiaclientgui.utils import NewListWidget, NewProgressBar, NewPushButton from codiaclientgui.utils import NewListWidget, NewProgressBar, NewPushButton
...@@ -679,8 +679,20 @@ ...@@ -679,8 +679,20 @@
<height>26</height> <height>26</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menu">
<property name="title">
<string>帮助</string>
</property>
<addaction name="actionAbout"/>
</widget>
<addaction name="menu"/>
</widget> </widget>
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>
<action name="actionAbout">
<property name="text">
<string>关于</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment