Files
general-system-framework/common/generalFunc.py

50 lines
1.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 该模块定义了一些通用的功能接口
# 声明全局功能类
class CCommon:
# 获取屏幕的分辨率
@staticmethod
def fnGetScreenRate() -> tuple[int, int]:
import pyautogui
nScreenWidth, nScreenHeight = pyautogui.size()
return nScreenWidth, nScreenHeight
# 获取当前时间,'xxxx/xx/xx xx:xx:xx'
@staticmethod
def fnGetCurrentTime() -> str:
from datetime import datetime
# 获取当前本地时间datetime对象
local_time = datetime.now()
# 格式化输出为字符串
return local_time.strftime("%Y-%m-%d %H:%M:%S")
# 判断内容是否符合限制要求
@staticmethod
def fnCheckInputValid(key, modifier, key_char) -> bool:
# 允许的控制键退格、删除、方向键、Ctrl+A/C/V/X全选/粘贴/剪切)
allowed_control_keys = (
0x01000003, # 退格
0x01000007, # 删除
0x01000012, # 左方向键
0x01000014, # 右方向键
0x01000013, # 上方向键
0x01000015, # 下方向键
0x01000010, # 首页键
0x01000011, # 尾页键
)
# 允许的功能快捷键Ctrl+A/C/V/X
if modifier == 0x04000000: # Qt.ControlModifier
if key in (0x41, 0x43, 0x56, 0x58): # [Qt.Key_A, Qt.Key_C, Qt.Key_V, Qt.Key_X]:
return True
# 放行控制键
if key in allowed_control_keys:
return True
# 允许的可打印字符:大小写字母、数字、下划线
# 获取按键对应的字符
if key_char:
# 判断字符是否符合规则:字母(大小写)、数字、下划线
if key_char.isalnum() or key_char == "_":
return True
# 其他按键一律拦截返回True表示不处理该事件
return False