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.
DOMQuery
class
¶
Bases: Generic[QueryType]
Warning
You won't need to construct this manually, as DOMQuery
objects are returned by query.
Parameters
Name | Type | Description | Default |
---|---|---|---|
node |
DOMNode
|
A DOM node. |
required |
filter |
str | None
|
Query to filter children in the node. |
None
|
exclude |
str | None
|
Query to exclude children in the node. |
None
|
parent |
DOMQuery | None
|
The parent query, if this is the result of filtering another query. |
None
|
Raises
Type | Description |
---|---|
InvalidQueryFormat
|
If the format of the query is invalid. |
exclude
method
¶
filter
method
¶
first
method
¶
Get the first matching node.
Parameters
Name | Type | Description | Default |
---|---|---|---|
expect_type |
type[ExpectType] | None
|
Require matched node is of this type, or None for any type. |
None
|
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. |
last
method
¶
Get the last matching node.
Parameters
Name | Type | Description | Default |
---|---|---|---|
expect_type |
type[ExpectType] | None
|
Require matched node is of this type, or None for any type. |
None
|
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
Name | Type | Description | Default |
---|---|---|---|
expect_type |
type[ExpectType] | None
|
Require matched node is of this type, or None for any type. |
None
|
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 |
---|---|
Widget | 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
Name | Type | Description | Default |
---|---|---|---|
filter_type |
type[ExpectType] | None
|
A Widget class to filter results, or None for no filter. |
None
|
Yields:
Type | Description |
---|---|
Widget | ExpectType
|
Iterator[Widget | ExpectType]: An iterator of Widget instances. |
set_class
method
¶
set_classes
method
¶
set_styles
method
¶
Set styles on matched nodes.
Parameters
Name | Type | Description | Default |
---|---|---|---|
css |
str | None
|
CSS declarations to parser, or None. |
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.