修复一些问题
This commit is contained in:
@@ -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