Initial Commit.

This commit is contained in:
Yorusora
2025-04-28 11:33:05 +08:00
parent f0eb8083b1
commit f928fa4d9c
28 changed files with 7126 additions and 0 deletions

96
func/utils/PublicFunc.py Normal file
View File

@ -0,0 +1,96 @@
from datetime import datetime
from logging import error, info
from PySide6.QtWidgets import QMessageBox
from func.utils.Constants import Constants
from func.utils.CustomException import TipsTypeValueNotExistError, MsgBoxTypeValueNotExistError
class PublicFunc:
@staticmethod
def get_current_localtime() -> str:
"""
获取当前本地时间
Parameters:
Returns:
str格式化为"%H:%M:%S"的当前本地时间
Raises:
"""
return str(datetime.now().strftime("%H:%M:%S"))
@staticmethod
def format_status_msg(msg) -> str:
"""
格式化状态栏信息
Parameters:
msg - str需要被格式化的字符串
Returns:
str格式化为"%H:%M:%S"的当前本地时间 + 信息
Raises:
"""
return str(datetime.now().strftime("%H:%M:%S")) + " " + msg
@staticmethod
def text_output(main_window: object, content: str, tips_type: str) -> None:
"""
更新textBrowser中的内容同时输出日志
Parameters:
main_window - objectQt的含有textBrowser属性的对象这里一般指的是mainWindow里面有唯一的textBrowser属性
content - str需要输出的内容
tips_type - 日志输出的类型
Returns:
Raises:
TipsTypeValueNotExistError
"""
if tips_type is Constants.TIPS_TYPE_INFO:
info(f"{tips_type}: {content}")
main_window.textBrowser_info.append(
f"<font color='black'>{PublicFunc.get_current_localtime()} {tips_type}: {content}</font>")
elif tips_type is Constants.TIPS_TYPE_ERROR:
error(f"{tips_type}: {content}")
main_window.textBrowser_info.append(
f"<font color='red'>{PublicFunc.get_current_localtime()} {tips_type}: {content}</font>")
else:
raise TipsTypeValueNotExistError()
main_window.textBrowser_info.verticalScrollBar().setValue(
main_window.textBrowser_info.verticalScrollBar().maximum())
@staticmethod
def msgbox_output(main_window: object, content: str, msg_box_type: str) -> None:
"""
更新messageBox中的内容并弹出
Parameters:
main_window - objectQt的含有messageBox属性的对象这里一般指的是mainWindow里面有唯一的messageBox属性
content - str需要输出的内容
msg_box_type - strmessageBox弹窗的类型
Returns:
Raises:
MsgBoxTypeValueNotExistError
"""
main_window.msgBox.setText(f"{msg_box_type}: {content}")
if msg_box_type is Constants.MSGBOX_TYPE_INFO:
main_window.msgBox.setIcon(QMessageBox.Information)
elif msg_box_type is Constants.MSGBOX_TYPE_WARNING:
main_window.msgBox.setIcon(QMessageBox.Warning)
elif msg_box_type is Constants.MSGBOX_TYPE_ERROR:
main_window.msgBox.setIcon(QMessageBox.Critical)
elif msg_box_type is Constants.MSGBOX_TYPE_QUESTION:
main_window.msgBox.setIcon(QMessageBox.Question)
else:
raise MsgBoxTypeValueNotExistError()
main_window.msgBox.exec()