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

Enhance ElementFilter #3735

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

python-and-fiction
Copy link
Contributor

For ElementFilter's __init__\within\not_within\exclude method:
marker parameter supports string list and string with whitespace in string list now.
We can do it in ElementFilter like element's mark method.

from nicegui import ui,ElementFilter

with ui.card():
    ui.button('button A')
    ui.label('label A_A').mark('A')
    ui.label('label A_B').mark('A','B','AB')

with ui.card():
    ui.button('button B')
    ui.label('label B_B').mark('B')
    ui.label('label B_A').mark('B A BA')

ElementFilter(marker=['A','B BA']).classes('bg-red')
ElementFilter(marker=['B']).exclude(marker=['A AB']).classes('text-2xl')

ui.run()

image

For ElementFilter's `__init__\within\not_within\exclude` method:
`marker` parameter supports string list and string with  whitespace in string  list now.
parameters `kind` and `content` in method `__init__\within\not_within\exclude` support list now.
@python-and-fiction python-and-fiction changed the title Enhance marker parameter Enhance ElementFilter Sep 17, 2024
@python-and-fiction
Copy link
Contributor Author

Now ElementFilter's method supports constructing in one step.

from nicegui import ui,ElementFilter

with ui.row():
    with ui.card():
        ui.button('button A')
        ui.label('label A_A')
        ui.label('label A_B')

with ui.card():
    ui.button('button B')
    ui.label('label B_B')
    ui.label('label B_A')

with ui.column():
    with ui.list():
        ui.button('button A')
        ui.label('label A_A')
        ui.label('label A_B')

ElementFilter(kind=[ui.button,ui.label]).within(kind=[ui.card,ui.row]).classes('bg-red')
ElementFilter(kind=[ui.button,ui.label]).not_within(kind=[ui.card,ui.row]).classes('text-2xl')
ElementFilter(kind=[ui.button,ui.label]).exclude(kind=[ui.label]).classes('text-green')

ui.run()

image

@python-and-fiction
Copy link
Contributor Author

I make a tab for beginner to learn ElementFilter's method, but I don't know how to insert it in document correctly, can anyone help me? Thank you so much!

Match type for parameters in ElementFilter's method:
| ElementFilter's method | `__init__` | `within` | `not_within` | `exclude` |
| ---------------------- | ---------- | -------- | ------------ | --------- |
| parameter `kind`       | any/or     | all/and  | any/or       | any/or    |
| parameter `content`    | all/and    | ----     | ----         | any/or    |
| parameter `instance`   | ----       | all/and  | any/or       | ----      |
| parameter `marker`     | all/and    | all/and  | any/or       | any/or    |

@rodja
Copy link
Member

rodja commented Sep 17, 2024

Thanks @python-and-fiction. The review and commenting would be much easier if this would be two separate pull requests.

About the whitespace in list elements:
What would be use cases for this? Why would somebody want to write ElementFilter(marker=['A','B BA']) instead of ElementFilter(marker=['A','B', 'BA']) or ElementFilter(marker=['A B BA'])?

About the list of kinds (and the table):
We wanted the __init__ and within methods to be "all/and" to not need that table. If someone needs multiple kinds they could write itertools.chain(ElementFilter(kind=ui.button), ElementFilter(kind=ui.label)).

@python-and-fiction
Copy link
Contributor Author

@rodja Hi,I am writing a chinese guide of nicegui for beginner. When I learn element's mark methond, I found that mark method supports mark('A','B BA') .
In mark('A','B BA') , _markers will be ['A','B','BA']. So I think ElementFilter's method should be like this.
As for table, I also make a chinese table for beginner, it is easier for me to learn and review. Maybe beginner who use English need it. I don't know.

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

Successfully merging this pull request may close these issues.

2 participants