Files
douyin_guaji-main/gui/components/device_selector.py
T
Your Name 223c127e11 chore: Clean up and refactor codebase for improved maintainability
- Removed obsolete command-line test parameters from `run_cli.py` to streamline functionality.
- Introduced a new `ocr_preprocess.py` module for unified OCR image preprocessing, enhancing recognition stability.
- Updated various components to utilize the new preprocessing function, improving code organization and readability.
- Adjusted configuration values in `config.json` for better performance and consistency.
- Added comprehensive technical documentation for the Douyin project, detailing code modification standards and operational guidelines.
- Cleaned up excessive blank lines across multiple files to enhance overall readability.
2025-12-30 23:11:34 +08:00

92 lines
1.6 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