完成日志界面的制作
This commit is contained in:
@@ -15,7 +15,7 @@ bg = f"{base_path}/assets/media/bg.jpg"
|
||||
win_width, win_height = 1100, 500
|
||||
conn, cursor = None, None
|
||||
listW_items = {"实用工具": "w10_practical", "效率提升": "w20_efficiency", "财务分析": "w30_financial"}
|
||||
|
||||
icon = f"{base_path}/assets/media/icon.ico"
|
||||
|
||||
def delete_files_in_directory(directory):
|
||||
path = Path(directory)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import sqlite3
|
||||
import time
|
||||
from inspect import currentframe
|
||||
from functools import singledispatch
|
||||
|
||||
from codes.common import clibs
|
||||
|
||||
@@ -9,15 +10,15 @@ def db_init():
|
||||
if clibs.db_file.exists():
|
||||
return
|
||||
|
||||
clibs.conn = sqlite3.connect(clibs.db_file, isolation_level=None, check_same_thread=False, cached_statements=2048, timeout=10.0)
|
||||
clibs.cursor = clibs.conn.cursor()
|
||||
clibs.cursor.execute("PRAGMA journal_mode=wal")
|
||||
clibs.cursor.execute("PRAGMA wal_checkpoint=TRUNCATE")
|
||||
clibs.cursor.execute("PRAGMA synchronous=normal")
|
||||
clibs.cursor.execute("PRAGMA temp_store=memory")
|
||||
clibs.cursor.execute("PRAGMA mmap_size=30000000000")
|
||||
clibs.cursor.execute("PRAGMA cache_size=200000")
|
||||
clibs.cursor.execute(
|
||||
conn = sqlite3.connect(clibs.db_file, isolation_level=None, check_same_thread=False, cached_statements=2048, timeout=10.0)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("PRAGMA journal_mode=wal")
|
||||
cursor.execute("PRAGMA wal_checkpoint=TRUNCATE")
|
||||
cursor.execute("PRAGMA synchronous=normal")
|
||||
cursor.execute("PRAGMA temp_store=memory")
|
||||
cursor.execute("PRAGMA mmap_size=30000000000")
|
||||
cursor.execute("PRAGMA cache_size=200000")
|
||||
cursor.execute(
|
||||
"""
|
||||
create table if not exists logs(
|
||||
id integer primary key autoincrement,
|
||||
@@ -28,7 +29,7 @@ def db_init():
|
||||
)
|
||||
"""
|
||||
)
|
||||
clibs.cursor.execute(
|
||||
cursor.execute(
|
||||
"""
|
||||
create table if not exists users(
|
||||
id integer primary key autoincrement,
|
||||
@@ -39,14 +40,18 @@ def db_init():
|
||||
)
|
||||
"""
|
||||
)
|
||||
db_write_logs("数据库初始化成功!", "login_ui")
|
||||
db_close()
|
||||
cursor.execute(f"INSERT INTO logs (level, module, content) VALUES (?, ?, ?)", ("info", "login_ui", "数据库初始化成功!"))
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
def db_lock(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
clibs.lock.acquire(True)
|
||||
ret = func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
print(f"db operation error: {e}")
|
||||
ret = None
|
||||
finally:
|
||||
clibs.lock.release()
|
||||
return ret
|
||||
@@ -62,6 +67,13 @@ def db_backup():
|
||||
db.unlink()
|
||||
|
||||
def db_conn():
|
||||
# import traceback, inspect
|
||||
# print("[Conn] 被调用", traceback.format_stack()[-2])
|
||||
# print("[Conn] conn=", clibs.conn, "cursor=", clibs.cursor)
|
||||
|
||||
if clibs.conn is not None:
|
||||
return
|
||||
|
||||
clibs.conn = sqlite3.connect(clibs.db_file, isolation_level=None, check_same_thread=False, cached_statements=2048, timeout=3.0)
|
||||
clibs.cursor = clibs.conn.cursor()
|
||||
clibs.cursor.execute("PRAGMA journal_mode=wal")
|
||||
@@ -92,9 +104,30 @@ def db_write_logs(content, module="", level="info"):
|
||||
|
||||
clibs.cursor.execute(f"INSERT INTO logs (level, module, content) VALUES (?, ?, ?)", (level, module, content))
|
||||
|
||||
@singledispatch
|
||||
@db_lock
|
||||
def db_query_logs():
|
||||
...
|
||||
def db_query_logs(dummy: bool = True):
|
||||
clibs.cursor.execute(f"SELECT * FROM logs")
|
||||
records = clibs.cursor.fetchall()
|
||||
len_records = len(records)
|
||||
return records, len_records
|
||||
|
||||
@db_query_logs.register
|
||||
def _(levels: list):
|
||||
placeholders = ",".join("?" * len(levels))
|
||||
clibs.cursor.execute(f"SELECT * FROM logs WHERE level IN ({placeholders})", (*levels, ))
|
||||
records = clibs.cursor.fetchall()
|
||||
len_records = len(records)
|
||||
return records, len_records
|
||||
|
||||
@db_query_logs.register
|
||||
def _(search_text: str, records: list):
|
||||
ids = [_[0] for _ in records]
|
||||
placeholder = ",".join("?" * len(ids))
|
||||
clibs.cursor.execute(f"SELECT * FROM logs WHERE id IN ({placeholder}) and content like ?", (ids + [f"%{search_text}%", ]))
|
||||
records = clibs.cursor.fetchall()
|
||||
len_records = len(records)
|
||||
return records, len_records
|
||||
|
||||
@db_lock
|
||||
def db_write_users(username, password_encrypted, salt):
|
||||
|
||||
@@ -14,7 +14,11 @@ class SignalBus(QObject):
|
||||
|
||||
current_stacked_page = Signal(str) # 获取当前页面的page_id
|
||||
init_stacked_page = Signal(str) # 设置打开侧边栏后的初始页面
|
||||
qa_stacked_page_switch = Signal(str) # 切换stacked widget页面
|
||||
stacked_page_switch = Signal(str) # 切换stacked widget的页面
|
||||
stacked_page_switch_setting = Signal() # 切换stacked widget的设置页面后的触发信号
|
||||
stacked_page_switch_log = Signal() # 切换stacked widget的日志页面后的触发信号
|
||||
stacked_page_switch_about = Signal() # 切换stacked widget的关于页面后的触发信号
|
||||
qa_switch_change = Signal(bool) # 切换折叠侧边栏的状态
|
||||
home_overlay_trigger = Signal() # 触发软件锁屏
|
||||
home_overlay_auth = Signal() # 触发密码框的显示与隐藏
|
||||
home_overlay_close = Signal() # 退出锁屏后的收尾信号
|
||||
|
||||
Reference in New Issue
Block a user