textual.css.query
This module contains the DOMQuery
class and related objects.
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
¶
ExpectType = TypeVar('ExpectType')
Type variable used to further restrict queries.
QueryType
module-attribute
¶
QueryType = TypeVar('QueryType', bound='Widget')
Type variable used to type generic queries.
DOMQuery
¶
Warning
You won't need to construct this manually, as DOMQuery
objects are returned by query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
DOMNode
|
A DOM node. |
required |
|
str | None
|
Query to filter children in the node. |
None
|
|
str | None
|
Query to exclude children in the node. |
None
|
|
bool
|
Query should be deep, i.e. recursive. |
True
|
|
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. |
blur
¶
first
¶
first() -> QueryType
first(expect_type: type[ExpectType]) -> ExpectType
first(expect_type=None)
Get the first matching node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
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. |
focus
¶
last
¶
last() -> QueryType
last(expect_type: type[ExpectType]) -> ExpectType
last(expect_type=None)
Get the last matching node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
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
¶
only_one() -> QueryType
only_one(expect_type: type[ExpectType]) -> ExpectType
only_one(expect_type=None)
Get the only matching node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
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 |
---|---|
QueryType | ExpectType
|
The matching Widget. |
refresh
¶
remove
¶
Remove matched nodes from the DOM.
Returns:
Type | Description |
---|---|
AwaitRemove
|
An awaitable object that waits for the widgets to be removed. |
results
¶
results(
filter_type: type[ExpectType],
) -> Iterator[ExpectType]
results(filter_type=None)
Get query results, optionally filtered by a given type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
type[ExpectType] | None
|
A Widget class to filter results, or None for no filter. |
None
|
Yields:
Type | Description |
---|---|
QueryType | ExpectType
|
Iterator[Widget | ExpectType]: An iterator of Widget instances. |
set
¶
Sets common attributes on matched nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
bool | None
|
Set |
None
|
|
bool | None
|
Set |
None
|
|
bool | None
|
Set |
None
|
|
bool | None
|
Set |
None
|
Returns:
Type | Description |
---|---|
DOMQuery[QueryType]
|
Query for chaining. |
InvalidQueryFormat
¶
Bases: QueryError
Query did not parse correctly.
NoMatches
¶
Bases: QueryError
No nodes matched the query.
TooManyMatches
¶
Bases: QueryError
Too many nodes matched the query.
WrongType
¶
Bases: QueryError
Query result was not of the correct type.