Query
A DOMQuery is a set of DOM nodes returned by query.
The set of nodes may be further refined with filter and exclude. Additional methods apply actions to all nodes in the query.
Info
If this sounds like JQuery, a (once) popular JS library, it is no coincidence.
ExpectType
module-attribute
¶
Type variable used to further restrict queries.
QueryType
module-attribute
¶
Type variable used to type generic queries.
DOMQuery
class
¶
Warning
You won't need to construct this manually, as DOMQuery
objects are returned by query.
Parameters
Parameter | Default | Description |
---|---|---|
node
DOMNode
|
required | A DOM node. |
filter
str | None
|
None
|
Query to filter children in the node. |
exclude
str | None
|
None
|
Query to exclude children in the node. |
parent
DOMQuery | None
|
None
|
The parent query, if this is the result of filtering another query. |
Raises
Type | Description |
---|---|
InvalidQueryFormat
|
If the format of the query is invalid. |
blur
method
¶
exclude
method
¶
filter
method
¶
first
method
¶
Get the first matching node.
Parameters
Parameter | Default | Description |
---|---|---|
expect_type
type[ExpectType] | None
|
None
|
Require matched node is of this type, or None for any type. |
Raises
Type | Description |
---|---|
WrongType
|
If the wrong type was found. |
NoMatches
|
If there are no matching nodes in the query. |
Returns
Type | Description |
---|---|
QueryType | ExpectType
|
The matching Widget. |
focus
method
¶
last
method
¶
Get the last matching node.
Parameters
Parameter | Default | Description |
---|---|---|
expect_type
type[ExpectType] | None
|
None
|
Require matched node is of this type, or None for any type. |
Raises
Type | Description |
---|---|
WrongType
|
If the wrong type was found. |
NoMatches
|
If there are no matching nodes in the query. |
Returns
Type | Description |
---|---|
QueryType | ExpectType
|
The matching Widget. |
only_one
method
¶
Get the only matching node.
Parameters
Parameter | Default | Description |
---|---|---|
expect_type
type[ExpectType] | None
|
None
|
Require matched node is of this type, or None for any type. |
Raises
Type | Description |
---|---|
WrongType
|
If the wrong type was found. |
NoMatches
|
If no node matches the query. |
TooManyMatches
|
If there is more than one matching node in the query. |
Returns
Type | Description |
---|---|
QueryType | ExpectType
|
The matching Widget. |
refresh
method
¶
remove
method
¶
Remove matched nodes from the DOM.
Returns
Type | Description |
---|---|
AwaitRemove
|
An awaitable object that waits for the widgets to be removed. |
remove_class
method
¶
Remove the given class names from the nodes.
results
method
¶
Get query results, optionally filtered by a given type.
Parameters
Parameter | Default | Description |
---|---|---|
filter_type
type[ExpectType] | None
|
None
|
A Widget class to filter results, or None for no filter. |
Yields:
Type | Description |
---|---|
QueryType | ExpectType
|
Iterator[Widget | ExpectType]: An iterator of Widget instances. |
set
method
¶
Sets common attributes on matched nodes.
Parameters
Parameter | Default | Description |
---|---|---|
display
bool | None
|
None
|
Set |
visible
bool | None
|
None
|
Set |
disabled
bool | None
|
None
|
Set |
loading
bool | None
|
None
|
Set |
Returns
Type | Description |
---|---|
DOMQuery[QueryType]
|
Query for chaining. |
set_class
method
¶
set_classes
method
¶
set_styles
method
¶
Set styles on matched nodes.
Parameters
Parameter | Default | Description |
---|---|---|
css
str | None
|
None
|
CSS declarations to parser, or None. |
toggle_class
method
¶
Toggle the given class names from matched nodes.
InvalidQueryFormat
class
¶
Bases: QueryError
Query did not parse correctly.
NoMatches
class
¶
Bases: QueryError
No nodes matched the query.
TooManyMatches
class
¶
Bases: QueryError
Too many nodes matched the query.
WrongType
class
¶
Bases: QueryError
Query result was not of the correct type.