-
Notifications
You must be signed in to change notification settings - Fork 17
feat: 适配新 anchor #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: 适配新 anchor #161
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -44,6 +44,14 @@ class ItemData: | |||||||||||||||||
| name: str | ||||||||||||||||||
| reco_id: int = 0 | ||||||||||||||||||
| status: Status = Status.PENDING | ||||||||||||||||||
| # 是否通过 anchor 解析得到 | ||||||||||||||||||
| is_anchor: bool = False | ||||||||||||||||||
| # 锚点名称(如 "锚点"),仅当 is_anchor=True 时有效 | ||||||||||||||||||
| anchor_name: str = "" | ||||||||||||||||||
| # 锚点指向的目标节点名称 | ||||||||||||||||||
| anchor_target: str = "" | ||||||||||||||||||
| # 锚点设置者节点名称(即定义 anchor 的节点) | ||||||||||||||||||
| anchor_setter: str = "" | ||||||||||||||||||
| # 嵌套子项的容器引用(用于 RecognitionNode 添加子识别项) | ||||||||||||||||||
| nested_container: Optional[Any] = field(default=None, repr=False) | ||||||||||||||||||
| # 嵌套子项列表 | ||||||||||||||||||
|
|
@@ -59,6 +67,11 @@ class ListData: | |||||||||||||||||
| row_len: int | ||||||||||||||||||
| current: str | ||||||||||||||||||
| next_list: List[str] | ||||||||||||||||||
| anchor_flags: List[bool] = field(default_factory=list) | ||||||||||||||||||
| # 每个 next_list 项对应的锚点名称(空字符串表示非锚点) | ||||||||||||||||||
| anchor_names: List[str] = field(default_factory=list) | ||||||||||||||||||
| # 每个 next_list 项对应的锚点目标节点名称(空字符串表示非锚点) | ||||||||||||||||||
| anchor_targets: List[str] = field(default_factory=list) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def main(): | ||||||||||||||||||
|
|
@@ -193,8 +206,25 @@ def on_page_change(self, page: int): | |||||||||||||||||
| for row_len in row_len_list[start_index:end_index]: | ||||||||||||||||||
| self.create_list(self.other_page_row, self.list_data_map[row_len]) | ||||||||||||||||||
|
|
||||||||||||||||||
| def add_item_data(self, index, name, row_len: int): | ||||||||||||||||||
| data = ItemData(row_len, index, name) | ||||||||||||||||||
| def add_item_data( | ||||||||||||||||||
| self, | ||||||||||||||||||
| index, | ||||||||||||||||||
| name, | ||||||||||||||||||
| row_len: int, | ||||||||||||||||||
| is_anchor: bool = False, | ||||||||||||||||||
| anchor_name: str = "", | ||||||||||||||||||
| anchor_target: str = "", | ||||||||||||||||||
| anchor_setter: str = "", | ||||||||||||||||||
| ): | ||||||||||||||||||
| data = ItemData( | ||||||||||||||||||
| row_len, | ||||||||||||||||||
| index, | ||||||||||||||||||
| name, | ||||||||||||||||||
| is_anchor=is_anchor, | ||||||||||||||||||
| anchor_name=anchor_name, | ||||||||||||||||||
| anchor_target=anchor_target, | ||||||||||||||||||
| anchor_setter=anchor_setter, | ||||||||||||||||||
| ) | ||||||||||||||||||
| self.data[row_len][index] = data | ||||||||||||||||||
|
|
||||||||||||||||||
| def create_list(self, row: ui.row, data: ListData): | ||||||||||||||||||
|
|
@@ -227,7 +257,17 @@ def create_items(self, index: int, name: str, row_len: int): | |||||||||||||||||
| StatusIndicator(data, "status") | ||||||||||||||||||
|
|
||||||||||||||||||
| with ui.item_section(): | ||||||||||||||||||
| ui.item_label(name) | ||||||||||||||||||
| if data.is_anchor: | ||||||||||||||||||
| with ui.row(wrap=False).classes("items-center gap-1"): | ||||||||||||||||||
| display_name = data.anchor_target or name | ||||||||||||||||||
| anchor_label = ( | ||||||||||||||||||
| f"{display_name} (anchor:{data.anchor_name or '未知'}, " | ||||||||||||||||||
| f"from:{data.anchor_setter or '未知'})" | ||||||||||||||||||
| ) | ||||||||||||||||||
| ui.item_label(anchor_label) | ||||||||||||||||||
| ui.badge("⚓", color="blue-grey-4").props("rounded") | ||||||||||||||||||
| else: | ||||||||||||||||||
| ui.item_label(name) | ||||||||||||||||||
|
|
||||||||||||||||||
| with ui.item_section().props("side"): | ||||||||||||||||||
| ui.item_label().bind_text_from(data, "reco_id").bind_visibility_from( | ||||||||||||||||||
|
|
@@ -296,9 +336,12 @@ async def _handle_message(self, msg: Dict[str, Any]): | |||||||||||||||||
| if msg_type == "NextList.Starting": | ||||||||||||||||||
| name = msg.get("name", "") | ||||||||||||||||||
| next_names = msg.get("next_list", []) | ||||||||||||||||||
| anchor_flags = msg.get("anchor_flags", []) | ||||||||||||||||||
| if debug_mode: | ||||||||||||||||||
| print(f"[DEBUG] NextList.Starting: name={name}, next_list={next_names}") | ||||||||||||||||||
| self._on_next_list_starting(name, next_names) | ||||||||||||||||||
| print( | ||||||||||||||||||
| f"[DEBUG] NextList.Starting: name={name}, next_list={next_names}, anchor_flags={anchor_flags}" | ||||||||||||||||||
| ) | ||||||||||||||||||
| self._on_next_list_starting(name, next_names, anchor_flags) | ||||||||||||||||||
| await maafw.screenshotter.refresh(False) | ||||||||||||||||||
|
|
||||||||||||||||||
| # RecognitionNode.Starting - 标记进入嵌套识别模式 | ||||||||||||||||||
|
|
@@ -407,7 +450,11 @@ def _on_recognized(self, reco_id: int, name: str, hit: bool): | |||||||||||||||||
| # 如果通过 reco_id 没找到,检查当前 row(非嵌套项) | ||||||||||||||||||
| if not found: | ||||||||||||||||||
| for item in self.data[self.row_len].values(): | ||||||||||||||||||
| if item.status == Status.PENDING and item.name == name: | ||||||||||||||||||
| if item.status != Status.PENDING: | ||||||||||||||||||
| continue | ||||||||||||||||||
| name_matched = item.name == name | ||||||||||||||||||
| anchor_matched = item.is_anchor and item.anchor_target == name | ||||||||||||||||||
| if name_matched or anchor_matched: | ||||||||||||||||||
| item.reco_id = reco_id | ||||||||||||||||||
| item.status = Status.SUCCEEDED if hit else Status.FAILED | ||||||||||||||||||
| matched_item = item | ||||||||||||||||||
|
|
@@ -421,7 +468,11 @@ def _on_recognized(self, reco_id: int, name: str, hit: bool): | |||||||||||||||||
| if not found: | ||||||||||||||||||
| for row_data in self.data.values(): | ||||||||||||||||||
| for item in row_data.values(): | ||||||||||||||||||
| if item.status == Status.PENDING and item.name == name: | ||||||||||||||||||
| if item.status != Status.PENDING: | ||||||||||||||||||
| continue | ||||||||||||||||||
| name_matched = item.name == name | ||||||||||||||||||
| anchor_matched = item.is_anchor and item.anchor_target == name | ||||||||||||||||||
| if name_matched or anchor_matched: | ||||||||||||||||||
| item.reco_id = reco_id | ||||||||||||||||||
| item.status = Status.SUCCEEDED if hit else Status.FAILED | ||||||||||||||||||
| matched_item = item | ||||||||||||||||||
|
|
@@ -458,11 +509,59 @@ def _on_reco_node_ended(self): | |||||||||||||||||
| f"[DEBUG] RecognitionNode depth decreased to {self._reco_node_depth}, stack size: {len(self._recognition_stack)}" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| def _on_next_list_starting(self, current: str, next_list: List[str]): | ||||||||||||||||||
| def _on_next_list_starting( | ||||||||||||||||||
| self, current: str, next_list: List[str], anchor_flags: List[bool] = [] | ||||||||||||||||||
| ): | ||||||||||||||||||
| """处理 NextList 开始事件""" | ||||||||||||||||||
|
||||||||||||||||||
| self, current: str, next_list: List[str], anchor_flags: List[bool] = [] | |
| ): | |
| """处理 NextList 开始事件""" | |
| self, current: str, next_list: List[str], anchor_flags: List[bool] = None | |
| ): | |
| """处理 NextList 开始事件""" | |
| # Normalize mutable default | |
| anchor_flags = anchor_flags or [] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.