Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

fix: 同名节点导致的时间线错乱#888

Merged
IsHPDuwu merged 2 commits into
Class-Widgets:mainfrom
IsHPDuwu:fix/period.name.buyaochongfu!!
Aug 27, 2025
Merged

fix: 同名节点导致的时间线错乱#888
IsHPDuwu merged 2 commits into
Class-Widgets:mainfrom
IsHPDuwu:fix/period.name.buyaochongfu!!

Conversation

@IsHPDuwu

Copy link
Copy Markdown
Member

No description provided.

@IsHPDuwu IsHPDuwu requested a review from baiyao105 August 27, 2025 06:10
@baiyao105 baiyao105 requested review from ChimeYao-bot and removed request for baiyao105 August 27, 2025 07:25
ChimeYao-bot

This comment was marked as duplicate.

@IsHPDuwu IsHPDuwu requested a review from ChimeYao-bot August 27, 2025 07:45

@ChimeYao-bot ChimeYao-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看了你最新提交(menu.py,新增 te_check_parts_name 并连接到 te_name_edit.textChanged)。思路没问题:避免同名节点,但还有几点需要修正,避免运行错误或误判:

核心问题

  1. 信号/槽签名textChanged 会传字符串参数,但方法没有接收,会报 TypeError。建议改成:
def te_check_parts_name(self, _=None):
  1. 名称拆分/判重不稳

    • 只按第一个 ' - ' 拿到名称(split(' - ', 1)),不要依赖长度。
    • 比较前做 .strip().lower(),避免大小写或空格差异误判。
  2. 选中项切换未更新currentItemChanged 也要触发检查,保证按钮状态实时更新。


建议实现(直接替换连接和方法)

te_name_edit.currentTextChanged.connect(self.te_check_parts_name)
part_list.currentItemChanged.connect(self.te_check_parts_name)

def te_check_parts_name(self, _=None):
    """检查当前输入的节点名是否重复"""
    te_add_part_button = self.findChild(ToolButton, 'add_part_button')
    te_edit_part_button = self.findChild(ToolButton, 'edit_part_button')
    te_name_edit = self.findChild(EditableComboBox, 'name_part_combo')
    part_list = self.findChild(ListWidget, 'part_list')

    if te_add_part_button is None and te_edit_part_button is None:
        return

    name = (te_name_edit.currentText() if te_name_edit else "").strip()
    norm_name = name.lower()
    if not norm_name:
        if te_add_part_button: te_add_part_button.setEnabled(False)
        if te_edit_part_button: te_edit_part_button.setEnabled(False)
        return

    current_item = part_list.currentItem() if part_list else None

    for i in range(part_list.count() if part_list else 0):
        item = part_list.item(i)
        if not item: continue
        part_name = item.text().split(' - ', 1)[0].strip()
        if part_name.lower() == norm_name:
            if current_item is item:
                if te_add_part_button: te_add_part_button.setEnabled(False)
                if te_edit_part_button: te_edit_part_button.setEnabled(True)
            else:
                if te_add_part_button: te_add_part_button.setEnabled(False)
                if te_edit_part_button: te_edit_part_button.setEnabled(False)
            return

    if te_add_part_button: te_add_part_button.setEnabled(True)
    if te_edit_part_button: te_edit_part_button.setEnabled(True)

测试要点

  • 输入空名 → Add/Edit 禁用
  • 输入已有节点名 → Add 禁用,Edit 仅在选中自身时可用
  • 名称大小写或空格差异 → 视为同名
  • 切换选中项 → 按钮状态自动更新
  • 多个 ' - ' 的文本仍能正确解析

总结:

  • 修正槽签名 + 拆分/比较逻辑 + currentItemChanged 触发,运行更稳健
  • 合并前手工验证上述测试用例即可

@IsHPDuwu IsHPDuwu merged commit 4be5eee into Class-Widgets:main Aug 27, 2025
9 of 10 checks passed
@baiyao105

Copy link
Copy Markdown
Member
image 高级货就是不一样。

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants