修复一些问题
This commit is contained in:
		@@ -140,18 +140,16 @@ class MainWindow(QMainWindow):
 | 
			
		||||
                else:
 | 
			
		||||
                    image_url = f"""https://www.bing.com{image["url"]}"""
 | 
			
		||||
                    file = Path(f"{clibs.base_path}/assets/media/bg/{image_name}.jpg")
 | 
			
		||||
                    try:
 | 
			
		||||
                        req = requests.get(image_url, stream=True, timeout=10)
 | 
			
		||||
                        with open(file, "wb") as f:
 | 
			
		||||
                            for chunk in req.iter_content(chunk_size=8192):
 | 
			
		||||
                                f.write(chunk)
 | 
			
		||||
                    except Exception as e:
 | 
			
		||||
                        pass
 | 
			
		||||
                    req = requests.get(image_url, stream=True, timeout=10)
 | 
			
		||||
                    with open(file, "wb") as f:
 | 
			
		||||
                        for chunk in req.iter_content(chunk_size=8192):
 | 
			
		||||
                            f.write(chunk)
 | 
			
		||||
            # proverbs
 | 
			
		||||
            hitokoto = "https://v1.hitokoto.cn/"
 | 
			
		||||
            proverbs = []
 | 
			
		||||
            proverb_file = Path(f"{clibs.base_path}/assets/media/hitokoto.json")
 | 
			
		||||
            req = requests.get(hitokoto)
 | 
			
		||||
            print(f"req.text = {req.text}")
 | 
			
		||||
            if not proverb_file.exists():
 | 
			
		||||
                proverb_file.touch()
 | 
			
		||||
                proverb_file.write_text("[]")
 | 
			
		||||
@@ -160,7 +158,18 @@ class MainWindow(QMainWindow):
 | 
			
		||||
 | 
			
		||||
            with open(proverb_file, mode="rt", encoding="utf-8") as f:
 | 
			
		||||
                proverbs = json.load(f)
 | 
			
		||||
                proverbs.append(eval(req.text))
 | 
			
		||||
                proverb = json.loads(req.text)
 | 
			
		||||
                if None in proverb.values():
 | 
			
		||||
                    for k, v in proverb.items():
 | 
			
		||||
                        if v is None:
 | 
			
		||||
                            if v == "from_who":
 | 
			
		||||
                                proverb.update({k: "佚名"})
 | 
			
		||||
                            elif v == "from":
 | 
			
		||||
                                proverb.update({k: "不知道"})
 | 
			
		||||
                            else:
 | 
			
		||||
                                proverb.update({k: "-"})
 | 
			
		||||
 | 
			
		||||
                proverbs.append(proverb)
 | 
			
		||||
                proverbs = del_repeat_proverb(proverbs)
 | 
			
		||||
            with open(proverb_file, mode="wt", encoding="utf-8") as f:
 | 
			
		||||
                json.dump(proverbs, f, ensure_ascii=False)
 | 
			
		||||
 
 | 
			
		||||
@@ -10,20 +10,32 @@ from codes.common.signal_bus import signal_bus
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class LunarClockLabel(QLabel):
 | 
			
		||||
    def __init__(self, parent=None):
 | 
			
		||||
    def __init__(self, parent=None, flag=0):
 | 
			
		||||
        super().__init__(parent)
 | 
			
		||||
        self.setMinimumWidth(350)
 | 
			
		||||
        timer = QTimer(self)
 | 
			
		||||
        timer.timeout.connect(self.update_time)
 | 
			
		||||
        timer.start(1000)
 | 
			
		||||
        self.update_time()
 | 
			
		||||
        if flag == 0:
 | 
			
		||||
            self.update_date()
 | 
			
		||||
            timer.timeout.connect(self.update_date)
 | 
			
		||||
        else:
 | 
			
		||||
            self.update_time()
 | 
			
		||||
            timer.timeout.connect(self.update_time)
 | 
			
		||||
 | 
			
		||||
    def update_date(self):
 | 
			
		||||
        dt = QDateTime.currentDateTime()
 | 
			
		||||
        g = dt.date()
 | 
			
		||||
        z = ZhDate.today()
 | 
			
		||||
        week = "一二三四五六日"[g.dayOfWeek() - 1]
 | 
			
		||||
        text = f"{g.year()}年{g.month()}月{g.day()}日 {z.chinese()[5:]} 星期{week}"
 | 
			
		||||
        self.setText(text)
 | 
			
		||||
 | 
			
		||||
    def update_time(self):
 | 
			
		||||
        dt = QDateTime.currentDateTime()
 | 
			
		||||
        g = dt.date()
 | 
			
		||||
        z = ZhDate.today()
 | 
			
		||||
        week = "一二三四五六日"[g.dayOfWeek() - 1]
 | 
			
		||||
        text = f"{g.year()}年{g.month()}月{g.day()}日 {z.chinese()[5:]} 星期{week} {dt.toString('hh:mm:ss')}"
 | 
			
		||||
        text = f"{dt.toString('hh:mm:ss')}"
 | 
			
		||||
        self.setText(text)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -54,6 +66,8 @@ class WidgetWithBg(QWidget):
 | 
			
		||||
        self.lb_empty_up = QLabel(self)
 | 
			
		||||
        layout_v.addWidget(self.lb_empty_up)
 | 
			
		||||
        # 头像区
 | 
			
		||||
        layout_h_1 = QHBoxLayout()
 | 
			
		||||
        layout_h_1.addStretch(1)
 | 
			
		||||
        self.lb_avatar = DoubleClickLabel(self)
 | 
			
		||||
        self.lb_avatar.setAlignment(Qt.AlignmentFlag.AlignCenter)
 | 
			
		||||
        avatar = QPixmap(clibs.avatar)
 | 
			
		||||
@@ -61,7 +75,15 @@ class WidgetWithBg(QWidget):
 | 
			
		||||
        self.lb_avatar.setPixmap(avatar)
 | 
			
		||||
        self.lb_avatar.setScaledContents(True)
 | 
			
		||||
        self.lb_avatar.setFixedSize(144, 144)
 | 
			
		||||
        layout_v.addWidget(self.lb_avatar, alignment=Qt.AlignmentFlag.AlignCenter)
 | 
			
		||||
        layout_h_1.addWidget(self.lb_avatar)
 | 
			
		||||
        self.lb_time = LunarClockLabel(self, flag=1)
 | 
			
		||||
        self.lb_time.setAlignment(Qt.AlignmentFlag.AlignCenter)
 | 
			
		||||
        self.lb_time.setStyleSheet("color: rgba(255,255,255,255);")
 | 
			
		||||
        self.lb_time.setFont(QFont("Arial Black", 56, QFont.Weight.Bold))
 | 
			
		||||
        layout_h_1.addWidget(self.lb_time)
 | 
			
		||||
        layout_h_1.addStretch(1)
 | 
			
		||||
        layout_v.addLayout(layout_h_1)
 | 
			
		||||
        # layout_v.addWidget(self.lb_avatar, alignment=Qt.AlignmentFlag.AlignCenter)
 | 
			
		||||
        # 艺术字区
 | 
			
		||||
        self.lb_name = QLabel(self)
 | 
			
		||||
        self.lb_name.setAlignment(Qt.AlignmentFlag.AlignCenter)
 | 
			
		||||
@@ -99,13 +121,13 @@ class WidgetWithBg(QWidget):
 | 
			
		||||
        self.line_right.setLineWidth(1)
 | 
			
		||||
        self.line_right.setFixedWidth(100)
 | 
			
		||||
        # 时间区-时间
 | 
			
		||||
        self.lb_time = LunarClockLabel(self)
 | 
			
		||||
        self.lb_time.setAlignment(Qt.AlignmentFlag.AlignCenter)
 | 
			
		||||
        self.lb_time.setStyleSheet("color: rgba(255,255,255,255);")
 | 
			
		||||
        self.lb_time.setFont(QFont("Consolas", 12, QFont.Weight.Bold))
 | 
			
		||||
        self.lb_date = LunarClockLabel(self)
 | 
			
		||||
        self.lb_date.setAlignment(Qt.AlignmentFlag.AlignCenter)
 | 
			
		||||
        self.lb_date.setStyleSheet("color: rgba(255,255,255,255);")
 | 
			
		||||
        self.lb_date.setFont(QFont("Consolas", 12, QFont.Weight.Bold))
 | 
			
		||||
        layout_h.addStretch(1)
 | 
			
		||||
        layout_h.addWidget(self.line_left)
 | 
			
		||||
        layout_h.addWidget(self.lb_time)
 | 
			
		||||
        layout_h.addWidget(self.lb_date)
 | 
			
		||||
        layout_h.addWidget(self.line_right)
 | 
			
		||||
        layout_h.addStretch(1)
 | 
			
		||||
        layout_v.addLayout(layout_h)
 | 
			
		||||
@@ -141,10 +163,6 @@ class WidgetWithBg(QWidget):
 | 
			
		||||
        self.lb_avatar.doubleClicked.connect(self.toggle_auth_show)
 | 
			
		||||
        self.le_password.returnPressed.connect(self.validate_password)
 | 
			
		||||
        signal_bus.home_overlay_auth.connect(self.toggle_auth_show)
 | 
			
		||||
        # self.sc_caL = QShortcut(QKeySequence("Esc"), self)
 | 
			
		||||
        # self.sc_caL.activated.connect(self.toggle_auth_show)
 | 
			
		||||
        # self.sc_caS = QShortcut(QKeySequence("Ctrl+Alt+M"), self)
 | 
			
		||||
        # self.sc_caS.activated.connect(signal_bus.ho_full_screen.emit)
 | 
			
		||||
 | 
			
		||||
    def toggle_auth_show(self):
 | 
			
		||||
        if self.le_is_visible:
 | 
			
		||||
@@ -178,7 +196,7 @@ class WidgetWithBg(QWidget):
 | 
			
		||||
            self.hide_le_password()
 | 
			
		||||
            return False
 | 
			
		||||
        else:
 | 
			
		||||
            QMessageBox.critical(self, "错误", "密码不正确,请确认后重新输入!")
 | 
			
		||||
            # QMessageBox.critical(self, "错误", "密码不正确,请确认后重新输入!")
 | 
			
		||||
            self.show_le_password()
 | 
			
		||||
            return False
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
from PySide6.QtWidgets import QWidget, QLabel, QMessageBox, QVBoxLayout, QTreeWidget, QHBoxLayout, QPushButton, QFrame, QLineEdit, QCheckBox, QTreeWidgetItem, QDialog
 | 
			
		||||
from PySide6.QtWidgets import QWidget, QLabel, QMessageBox, QVBoxLayout, QTreeWidget, QHeaderView, QHBoxLayout, QPushButton, QFrame, QLineEdit, QCheckBox, QTreeWidgetItem, QDialog, QPlainTextEdit, QApplication
 | 
			
		||||
from PySide6.QtCore import Qt, Signal
 | 
			
		||||
from PySide6.QtGui import QColor, QIcon, QFont, QKeySequence, QIntValidator, QShortcut
 | 
			
		||||
 | 
			
		||||
@@ -6,6 +6,30 @@ from codes.common.signal_bus import signal_bus
 | 
			
		||||
from codes.common import db_operation
 | 
			
		||||
from codes.common import clibs
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class LogDialog(QDialog):
 | 
			
		||||
    def __init__(self, content, parent=None):
 | 
			
		||||
        super().__init__(parent)
 | 
			
		||||
        self.setWindowTitle("日志详情")
 | 
			
		||||
        self.setGeometry(100, 100, 700, 300)
 | 
			
		||||
        self.center_on_screen()
 | 
			
		||||
        layout = QVBoxLayout(self)
 | 
			
		||||
        self.plain_text_edit = QPlainTextEdit()
 | 
			
		||||
        self.plain_text_edit.setReadOnly(True)
 | 
			
		||||
        self.plain_text_edit.setPlainText(content)
 | 
			
		||||
        layout.addWidget(self.plain_text_edit)
 | 
			
		||||
 | 
			
		||||
    def center_on_screen(self):
 | 
			
		||||
        screen_geometry = QApplication.primaryScreen().geometry()
 | 
			
		||||
        screen_width = screen_geometry.width()
 | 
			
		||||
        screen_height = screen_geometry.height()
 | 
			
		||||
        dialog_width = self.width()
 | 
			
		||||
        dialog_height = self.height()
 | 
			
		||||
        x = (screen_width - dialog_width) // 2
 | 
			
		||||
        y = (screen_height - dialog_height) // 2
 | 
			
		||||
        self.move(x, y)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PageNumberInput(QDialog):
 | 
			
		||||
    def __init__(self, parent=None):
 | 
			
		||||
        super().__init__(parent)
 | 
			
		||||
@@ -64,7 +88,11 @@ class W08Log(QWidget):
 | 
			
		||||
    def ui_init(self):
 | 
			
		||||
        layout_v = QVBoxLayout(self)
 | 
			
		||||
        self.treeW = QTreeWidget()
 | 
			
		||||
        self.treeW.setUniformRowHeights(True)
 | 
			
		||||
        self.treeW.setHeaderLabels(["ID", "时间戳", "告警级别", "模块信息", "告警内容"])
 | 
			
		||||
        header = self.treeW.header()
 | 
			
		||||
        for i in range(self.treeW.columnCount()):
 | 
			
		||||
            header.setSectionResizeMode(i, QHeaderView.ResizeMode.ResizeToContents)
 | 
			
		||||
        layout_v.addWidget(self.treeW, stretch=9)
 | 
			
		||||
 | 
			
		||||
        layout_h = QHBoxLayout()
 | 
			
		||||
@@ -113,6 +141,7 @@ class W08Log(QWidget):
 | 
			
		||||
        self.setLayout(layout_v)
 | 
			
		||||
 | 
			
		||||
    def setup_slot(self):
 | 
			
		||||
        self.treeW.itemDoubleClicked.connect(self.show_single_log)
 | 
			
		||||
        self.pb_previous.clicked.connect(self.previous_page)
 | 
			
		||||
        self.pb_next.clicked.connect(self.next_page)
 | 
			
		||||
        self.pb_search.clicked.connect(self.search_page)
 | 
			
		||||
@@ -153,9 +182,6 @@ class W08Log(QWidget):
 | 
			
		||||
 | 
			
		||||
        self.records, self.len_records = db_operation.db_query_logs(levels=levels)
 | 
			
		||||
        if search_text:
 | 
			
		||||
            # ids = [_[0] for _ in self.records]
 | 
			
		||||
            # placeholder = ",".join(ids)
 | 
			
		||||
            # clibs.cursor.execute(f"SELECT * FROM logs WHERE id IN ({placeholder}) and content like ?", (ids + [search_text, ]))
 | 
			
		||||
            self.records, self.len_records = db_operation.db_query_logs(search_text, self.records)
 | 
			
		||||
 | 
			
		||||
        self.is_searching = True
 | 
			
		||||
@@ -219,6 +245,16 @@ class W08Log(QWidget):
 | 
			
		||||
            color = colors[record[2]]
 | 
			
		||||
            for col in range(5):
 | 
			
		||||
                item.setBackground(col, color)
 | 
			
		||||
            item.setTextAlignment(0, Qt.AlignmentFlag.AlignRight)
 | 
			
		||||
        self.treeW.scrollToBottom()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def show_single_log(self, item, column):
 | 
			
		||||
        log_id = f"id = {item.text(0)}"
 | 
			
		||||
        log_ts = f"ts = {item.text(1)}"
 | 
			
		||||
        log_level = f"level = {item.text(2)}"
 | 
			
		||||
        log_module = f"module = {item.text(3)}\n"
 | 
			
		||||
        deco_line = "=" * 40
 | 
			
		||||
        log_msg = item.text(4)
 | 
			
		||||
        content = "\n".join([log_id, log_ts, log_level, log_module, deco_line, log_msg])
 | 
			
		||||
        dialog = LogDialog(content, self)
 | 
			
		||||
        dialog.exec()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user