采集卡bug修复
This commit is contained in:
58
preview.py
58
preview.py
@@ -161,6 +161,10 @@ class PreviewWindow:
|
|||||||
|
|
||||||
def create_grid_window(self):
|
def create_grid_window(self):
|
||||||
"""创建网格窗口"""
|
"""创建网格窗口"""
|
||||||
|
# 重新加载配置,确保获取最新值
|
||||||
|
config_manager.load_config()
|
||||||
|
self.config = config_manager.config
|
||||||
|
|
||||||
# 获取显示配置
|
# 获取显示配置
|
||||||
display = self.config.get('display', {})
|
display = self.config.get('display', {})
|
||||||
preview_width = display.get('preview_width', 1000)
|
preview_width = display.get('preview_width', 1000)
|
||||||
@@ -168,6 +172,20 @@ class PreviewWindow:
|
|||||||
columns = display.get('preview_columns', 2)
|
columns = display.get('preview_columns', 2)
|
||||||
rows = display.get('preview_rows', 2)
|
rows = display.get('preview_rows', 2)
|
||||||
|
|
||||||
|
# 验证配置值是否有效(防止读取到无效的小值)
|
||||||
|
if preview_width < 100 or preview_height < 100:
|
||||||
|
print(f"⚠️ 警告: 配置中的预览尺寸无效 ({preview_width}x{preview_height}),使用默认值")
|
||||||
|
preview_width = 1000
|
||||||
|
preview_height = 700
|
||||||
|
|
||||||
|
if columns < 1 or columns > 10:
|
||||||
|
columns = 2
|
||||||
|
if rows < 1 or rows > 10:
|
||||||
|
rows = 2
|
||||||
|
|
||||||
|
# 调试输出配置值
|
||||||
|
print(f"📐 预览窗口配置: {preview_width}x{preview_height}, 网格: {columns}x{rows}")
|
||||||
|
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
root.title("采集卡预览 - 点击放大")
|
root.title("采集卡预览 - 点击放大")
|
||||||
root.geometry(f"{preview_width}x{preview_height}")
|
root.geometry(f"{preview_width}x{preview_height}")
|
||||||
@@ -227,6 +245,10 @@ class PreviewWindow:
|
|||||||
texts_to_draw = []
|
texts_to_draw = []
|
||||||
frame_idx = 0
|
frame_idx = 0
|
||||||
|
|
||||||
|
# 确保至少有一些采集卡数据
|
||||||
|
if not self.caps:
|
||||||
|
texts_to_draw.append((canvas_width // 2, canvas_height // 2, "未找到采集卡", 'red'))
|
||||||
|
|
||||||
for idx in self.caps.keys():
|
for idx in self.caps.keys():
|
||||||
row = frame_idx // columns
|
row = frame_idx // columns
|
||||||
col = frame_idx % columns
|
col = frame_idx % columns
|
||||||
@@ -306,19 +328,42 @@ class PreviewWindow:
|
|||||||
canvas.delete("all")
|
canvas.delete("all")
|
||||||
|
|
||||||
# 先绘制所有图像(底层)
|
# 先绘制所有图像(底层)
|
||||||
if images_to_draw and self.debug_count <= 3:
|
if self.debug_count <= 3:
|
||||||
print(f"✅ 准备绘制 {len(images_to_draw)} 个图像到画布 ({canvas_width}x{canvas_height})")
|
print(f"📊 绘制状态: {len(images_to_draw)} 个图像, {len(texts_to_draw)} 个文本, 画布={canvas_width}x{canvas_height}")
|
||||||
|
|
||||||
for photo, x, y in images_to_draw:
|
if images_to_draw:
|
||||||
|
for i, (photo, x, y) in enumerate(images_to_draw):
|
||||||
try:
|
try:
|
||||||
|
# 确保坐标在画布范围内
|
||||||
|
if 0 <= x <= canvas_width and 0 <= y <= canvas_height:
|
||||||
canvas.create_image(x, y, image=photo, anchor='center')
|
canvas.create_image(x, y, image=photo, anchor='center')
|
||||||
|
if self.debug_count <= 3 and i == 0:
|
||||||
|
print(f" 绘制图像 #{i} 到位置 ({x}, {y})")
|
||||||
|
else:
|
||||||
|
if self.debug_count <= 3:
|
||||||
|
print(f" ⚠️ 图像 #{i} 位置 ({x}, {y}) 超出画布范围")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if "pyimage" not in str(e).lower():
|
print(f" 绘制图像 #{i} 错误: {e}")
|
||||||
print(f"绘制图像错误: {e}")
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
else:
|
||||||
|
# 如果没有图像,至少显示一些提示
|
||||||
|
if self.debug_count <= 3:
|
||||||
|
print(" ⚠️ 没有图像可绘制")
|
||||||
|
# 在画布中心显示提示
|
||||||
|
canvas.create_text(
|
||||||
|
canvas_width // 2,
|
||||||
|
canvas_height // 2,
|
||||||
|
text="等待画面...\n\n如果长时间无画面,请检查:\n1. 采集卡是否正常工作\n2. 配置是否正确",
|
||||||
|
fill='yellow',
|
||||||
|
font=('Arial', 14),
|
||||||
|
justify=tk.CENTER
|
||||||
|
)
|
||||||
|
|
||||||
# 再绘制所有文本(上层)
|
# 再绘制所有文本(上层)
|
||||||
for x, y, text, color in texts_to_draw:
|
for x, y, text, color in texts_to_draw:
|
||||||
try:
|
try:
|
||||||
|
if 0 <= x <= canvas_width and 0 <= y <= canvas_height:
|
||||||
if color == 'white':
|
if color == 'white':
|
||||||
canvas.create_text(x, y, text=text, fill=color, font=('Arial', 10, 'bold'))
|
canvas.create_text(x, y, text=text, fill=color, font=('Arial', 10, 'bold'))
|
||||||
else:
|
else:
|
||||||
@@ -326,6 +371,9 @@ class PreviewWindow:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"绘制文本错误: {e}")
|
print(f"绘制文本错误: {e}")
|
||||||
|
|
||||||
|
# 强制更新画布显示
|
||||||
|
canvas.update_idletasks()
|
||||||
|
|
||||||
# 绘制分割线,区分不同的采集卡窗口
|
# 绘制分割线,区分不同的采集卡窗口
|
||||||
try:
|
try:
|
||||||
# 绘制垂直分割线(列之间的分割线)
|
# 绘制垂直分割线(列之间的分割线)
|
||||||
|
|||||||
Reference in New Issue
Block a user