-
-
Notifications
You must be signed in to change notification settings - Fork 602
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
Introduce ui.get to query the element tree #1931
Conversation
Thanks @rodja, this looks like a great start. Questions
Other commentsI'll also point out that callling them I know you don't want users to have to know html to use nicegui, and that's fine. But a large portion of programmers do know html. Any serious nicegui users will eventually run into html & css issues. Avoiding html terms is helpful to reduce confusion. If you don't know html then it doesn't matter what you call it, labels or tags or names work equally well. Hope this helps. Looking forward to this development! 😃 |
Thanks for the comments and questions @ed2050. You are right. The name "tags" is not optimal. We need to find something else. Ideally it should not be cryptical like ntags or so. Maybe "markers"? Questions 1-3: The idea is that it works like classes. You can define multiple and change them on the fly. But they are not interpreted by the browser and hence can be used without clashing with existing quasar/tailwind classes. Question 4-6: As you can see in the tests you have the "real" NiceGUI elements, when iterating over the nicegui/tests/test_get_elements.py Line 33 in f7235ab
|
Fantastic. I suspected as much, thanks for verifying. Possible names:
Acually I think After that my next choice would be marks. Names has possible confusion with html (both tag "names" aka h1,img,body, etc or occasionally name= attributes). Tags is a better fit, unfortunately overlaps with html. Userid suggests single unique values, and flags are usually boolean. That said, any of the above would work. My preference is for shorter names, but any will do. Thanks @rodja. |
I also like |
After some discussion about the naming with ChatGPT 4, it came up with this rating:
I'll go with |
When I started implementing from nicegui.elements.mixins.text_element import TextElement
ui.button('button A')
ui.label('label A')
ui.icon('home')
ui.button('button B')
ui.label('label B')
result = [b.text for b in ui.get(type=TextElement)] So we only need to think if we want to make the mixins better acessable or not. |
I'll close this PR in favor of PR #3121. |
Originated in #1923 (comment), this PR introduces
ui.get
to retrieve elements of the current page with a query language inspired by tortoise-orm'sfilter
or BeautifulSoup'sfind_all
. Therefore it also introduces a.tags
.keys
property on Element with wich the developer can set a list of queryable words.When complete this PR should allow these kinds of operations:
The object which is returned by
ui.get
is calledElements
(eg. group of elements) and allows setting props,classes,style on all containing elements at once:And it allows iterating over all elements:
If
type=
is used the iterator automatically casts to this type:ToDos
type=
text=
key=
and.keys
.within(type=
.within(key=
.exclude(type=
.exclude(key=
.exclude(text=
.not_within(type=
.not_within(key=
.key
with string or Listsimplify usage of Mixins.type
with class or List.text
with string or Listui.get
would make sense