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. |