reorganize file structure
This commit is contained in:
46
common/utils.py
Normal file
46
common/utils.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from PySide6.QtWidgets import QWidget
|
||||
from qfluentwidgets import (
|
||||
InfoBarIcon, MessageBox,
|
||||
)
|
||||
|
||||
# --- API 客户端配置 ---
|
||||
BASE_URL = "https://safe-marks.oranj.work/api/v1/ext"
|
||||
|
||||
SAFE = [1, 0, -1, -2]
|
||||
SAFE_MAP = {
|
||||
1: "安全",
|
||||
0: "未知",
|
||||
-1: "不安全",
|
||||
-2: "未记录"
|
||||
}
|
||||
# 反向映射,用于 QComboBox
|
||||
SAFE_MAP_INV = {v: k for k, v in SAFE_MAP.items()}
|
||||
SAFE_MAP_ICON = {
|
||||
1: InfoBarIcon.SUCCESS.icon(),
|
||||
0: InfoBarIcon.WARNING.icon(),
|
||||
-1: InfoBarIcon.ERROR.icon(),
|
||||
-2: InfoBarIcon.INFORMATION.icon(),
|
||||
}
|
||||
|
||||
|
||||
class APIException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def show_quick_tip(widget: QWidget, caption: str, text: str):
|
||||
mb = MessageBox(caption, text, widget)
|
||||
mb.cancelButton.setHidden(True)
|
||||
mb.buttonLayout.insertStretch(0, 1)
|
||||
mb.buttonLayout.setStretch(1, 0)
|
||||
mb.yesButton.setMinimumWidth(100)
|
||||
mb.setClosableOnMaskClicked(True)
|
||||
mb.exec()
|
||||
|
||||
|
||||
def accept_warning(widget: QWidget, condition: bool,
|
||||
caption: str = "警告", text: str = "你确定要继续吗?") -> bool:
|
||||
if condition:
|
||||
mb = MessageBox(caption, text, widget)
|
||||
if not mb.exec():
|
||||
return True
|
||||
return False
|
||||
Reference in New Issue
Block a user