George parsing utilities¶
Parsing functions used to handle data coming from TVPaint and also preparing arguments for them to be sent.
The two main functions are tv_parse_dict
and tv_parse_list
which handle the return values of George functions.
George can either return a list of values or a list of key/value pairs which are consecutive.
DataclassInstance
¶
Bases: typing_extensions.Protocol
Protocol that describes a Dataclass instance.
tv_handle_string(s: str) -> str
¶
String handling for George arguments. It wraps the string into quotes if it has spaces.
See an example here: https://www.tvpaint.com/doc/tvpaint-animation-11/george-commands#tv_projectnew
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
str
|
the input string |
required |
Returns:
Type | Description |
---|---|
str
|
the "escaped" string |
Source code in pytvpaint/george/client/parse.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
camel_to_pascal(s: str) -> str
¶
Convert a camel case string to pascal case.
Example
this_is_a_text -> ThisIsAText
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
str
|
the input string |
required |
Returns:
Type | Description |
---|---|
str
|
the string in pascal case |
Source code in pytvpaint/george/client/parse.py
50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
tv_cast_to_type(value: str, cast_type: type[T]) -> T
¶
Cast a value to the provided type using George's convention for values.
Note
"1" and "on"/"ON" values are considered True when parsing a boolean
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str
|
the input value |
required |
cast_type |
type[pytvpaint.george.client.parse.T]
|
the type to cast to |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if given an enum, and it can't find the value or the enum index is invalid |
Returns:
Type | Description |
---|---|
pytvpaint.george.client.parse.T
|
the value cast to the provided type |
Source code in pytvpaint/george/client/parse.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
tv_parse_dict(input_text: str, with_fields: FieldTypes | type[DataclassInstance]) -> dict[str, Any]
¶
Parse a list of values as key value pairs returned from TVPaint commands.
Cast the values to a provided dataclass type or list of key/types pairs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_text |
str
|
the George string result |
required |
with_fields |
pytvpaint.george.client.parse.FieldTypes | type[pytvpaint.george.client.parse.DataclassInstance]
|
the field types (can be a dataclass) |
required |
Returns:
Type | Description |
---|---|
dict[str, typing.Any]
|
a dict with the values cast to the given types |
Source code in pytvpaint/george/client/parse.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
tv_parse_list(output: str, with_fields: FieldTypes | type[DataclassInstance], unused_indices: list[int] | None = None) -> dict[str, Any]
¶
Parse a list of values returned from TVPaint commands.
Cast the values to a provided dataclass type or list of key/types pairs.
You can specify unused indices to exclude positional values from being parsed. This is useful because some George commands have unused return values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output |
str
|
the input string |
required |
with_fields |
pytvpaint.george.client.parse.FieldTypes | type[pytvpaint.george.client.parse.DataclassInstance]
|
the field types (can be a dataclass) |
required |
unused_indices |
list[int] | None
|
Some George functions return positional arguments that are unused. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
dict[str, typing.Any]
|
a dict with the values cast to the given types |
Source code in pytvpaint/george/client/parse.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
args_dict_to_list(args: dict[str, Any]) -> list[Any]
¶
Converts a dict of named arguments to a flat list of key/values.
It also filters pairs with None values
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
dict[str, typing.Any]
|
dict of arguments |
required |
Returns:
Type | Description |
---|---|
list[typing.Any]
|
key/values list |
Source code in pytvpaint/george/client/parse.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
|
validate_args_list(optional_args: Sequence[Value | tuple[Value, ...]]) -> list[Any]
¶
Some George functions only accept a list of values and not key:value pairs, so to set the last positional argument for instance, you need to give all the previous ones.
This function allows you to give a list of argument or key:value pairs (as tuples) and check that they are not None.
For example, for tv_camerainfo [<iWidth> <iHeight> [<field_order>]]
you can't give [500, None, "upper"]
because <iHeight>
is not defined.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optional_args |
collections.abc.Sequence[pytvpaint.george.client.parse.Value | tuple[pytvpaint.george.client.parse.Value, ...]]
|
list of values or tuple of values (args block) |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if not all the parameters were given |
Returns:
Type | Description |
---|---|
list[typing.Any]
|
the list of parameters |
Source code in pytvpaint/george/client/parse.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|