Files
douyin_guaji-main/gui/components/device_selector.py
T
Your Name a0aad21835 feat: Optimize ADB exec-out and OCR performance
- Introduced performance enhancements for ADB exec-out, reducing execution time by 10-20% through the use of Popen with streaming reads, increased buffer sizes, and removal of unnecessary fsync calls.
- Implemented optimizations in OCR processing, cutting recognition time by 50% by refining button recognition logic and improving image loading and preprocessing methods.
- Added detailed performance diagnostics and configuration options to facilitate further optimizations.
- Created new documentation files outlining the performance improvements and recommendations for future enhancements.
2026-01-02 02:06:01 +08:00

105 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""设备选择组件
包含设备选择、刷新设备等功能的GUI组件。
"""
from __future__ import annotations
from typing import Any, Callable
import tkinter as tk
from tkinter import ttk
from gui.gui_core import find_adb_executable, list_adb_devices
def create_device_selector(
parent: Any,
on_line: Callable[[str], None],
device_var: tk.StringVar,
) -> tuple[ttk.Combobox, Callable[[], None]]:
"""创建设备选择组件。
参数:
parent: 父容器
on_line: 日志输出回调
device_var: 设备ID变量
返回:
(device_combo, refresh_devices_func) 设备下拉框和刷新函数
"""
adb_exe = find_adb_executable()
devices = list_adb_devices(adb_exe)
device_var.set(devices[0] if devices else "")
ttk.Label(parent, text="设备:").pack(side="left")
device_combo = ttk.Combobox(parent, textvariable=device_var, values=devices, width=28)
device_combo.pack(side="left", padx=(0, 10))
def refresh_devices():
nonlocal adb_exe
adb_exe = find_adb_executable()
devs = list_adb_devices(adb_exe)
device_combo["values"] = devs
if devs and not device_var.get():
device_var.set(devs[0])
if not adb_exe:
on_line("[设备] 未找到 adb.exe(请确认已安装 platform-tools)")
elif not devs:
on_line("[设备] adb 可用,但未发现 device 状态设备(可能未授权/未连接)")
ttk.Button(parent, text="刷新设备", command=refresh_devices).pack(
side="left", padx=(0, 20)
)
return device_combo, refresh_devices