Skip to content
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

select() may generate an identifier that is unusable #23

Open
ryan-summers opened this issue Feb 17, 2022 · 2 comments
Open

select() may generate an identifier that is unusable #23

ryan-summers opened this issue Feb 17, 2022 · 2 comments

Comments

@ryan-summers
Copy link

When using the select() function, the provided path cannot necessarily be used for a subsequent select() (or getattr(), etc) and will not properly select any items.

This appears to arise because the XPATH index syntax is slightly different than the path_to syntax use different semantics.

Specifically, the current to_path syntax uses the index of the element in the child widgets list.

def path_to(widget):
from kivy.core.window import Window
root = Window
if widget.parent is root or widget.parent == widget or not widget.parent:
return "/{}".format(widget.__class__.__name__)
return "{}/{}[{}]".format(
path_to(widget.parent), widget.__class__.__name__,
widget.parent.children.index(widget))

However, the XPATH syntax uses the index into the list of previously filtered items. This means that if any items are filtered out, the index used by XPATH and the index into the Kivy child list are no longer equivalent.

@ryan-summers
Copy link
Author

This becomes problematic whenever the children of a widget have different types. The fix here is to filter the path_to children list to include only children that have the same class as the current widget.

@Hubix9
Copy link

Hubix9 commented Jul 21, 2023

Hi, thanks for posting the idea for a fix! I've noticed that there was no implementation for it and since I needed this feature I went ahead and implemented the fix with addition of a small correction.

Related PR: #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants