Skip to content

Commit ba19d8c

Browse files
committed
opt(tools): 优化 graphviz_render.py, 当收到的数据与上次一样时,不刷重新绘制界面
1 parent 98bbca2 commit ba19d8c

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

tools/check_and_archive_log_files.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
#!/bin/bash
22

3+
#
4+
# .============.
5+
# // M A K E / \
6+
# // C++ DEV / \
7+
# // E A S Y / \/ \
8+
# ++ ----------. \/\ .
9+
# \\ \ \ /\ /
10+
# \\ \ \ /
11+
# \\ \ \ /
12+
# -============'
13+
#
14+
# Copyright (c) 2025 Hevake and contributors, all rights reserved.
15+
#
16+
# This file is part of cpp-tbox (https://github.com/cpp-main/cpp-tbox)
17+
# Use of this source code is governed by MIT license that can be found
18+
# in the LICENSE file in the root of the source tree. All contributing
19+
# project authors may be found in the CONTRIBUTORS.md file in the root
20+
# of the source tree.
21+
#
22+
323
# 打包日志文件脚本
424

525
if [ $# -lt 2 ]; then

tools/graphviz_render.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def __init__(self, pipe_name):
234234
self.pipe_name = pipe_name
235235
self.original_image = None
236236
self.current_pixmap = None
237+
self.last_dot_data = ''
237238
self.setup_ui()
238239

239240
def setup_ui(self):
@@ -282,27 +283,30 @@ def on_resize(self, event):
282283
self.resize_timer.start(100)
283284

284285
def update_graph(self, dot_data):
285-
try:
286-
# Render DOT data using Graphviz
287-
proc = subprocess.Popen(
288-
['dot', '-Tpng'],
289-
stdin=subprocess.PIPE,
290-
stdout=subprocess.PIPE
291-
)
292-
output, _ = proc.communicate(dot_data.encode())
286+
if dot_data != self.last_dot_data:
287+
self.last_dot_data = dot_data
288+
289+
try:
290+
# Render DOT data using Graphviz
291+
proc = subprocess.Popen(
292+
['dot', '-Tpng'],
293+
stdin=subprocess.PIPE,
294+
stdout=subprocess.PIPE
295+
)
296+
output, _ = proc.communicate(dot_data.encode())
293297

294-
# Convert to PIL Image
295-
self.original_image = Image.open(BytesIO(output))
298+
# Convert to PIL Image
299+
self.original_image = Image.open(BytesIO(output))
296300

297-
# Update timestamp
298-
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
299-
self.timestamp_label.setText(current_time)
301+
# Update image display
302+
self.update_image()
300303

301-
# Update image display
302-
self.update_image()
304+
except Exception as e:
305+
print(f"Error rendering graph: {e}")
303306

304-
except Exception as e:
305-
print(f"Error rendering graph: {e}")
307+
# Update timestamp
308+
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
309+
self.timestamp_label.setText(current_time)
306310

307311
def update_image(self):
308312
if self.original_image is None:

0 commit comments

Comments
 (0)