checkbox_handler
Checkbox handler for markdown checkboxes in QTextEdit.
CheckboxHandler
Bases: QObject
Handles checkbox parsing, rendering, and state management.
This class manages: - Parsing markdown to extract checkbox items - Registering custom text objects for checkbox rendering - Tracking checkbox state and positions - Converting back to markdown format
Signals
checklist_changed: Emitted when any checkbox state changes.
Source code in client/ayon_ui_qt/components/checkbox_handler.py
139 140 141 142 143 144 145 146 147 148 149 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 206 207 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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
checkboxes property
Get the list of checkbox items.
Returns:
| Type | Description |
|---|---|
List[CheckboxItem] | List of CheckboxItem objects. |
__init__(text_edit, parent=None)
Initialize the checkbox handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_edit | QTextEdit | The QTextEdit widget to manage checkboxes for. | required |
parent | QObject | None | Optional parent QObject. | None |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
160 161 162 163 164 165 166 167 168 169 170 171 172 | |
add_checkbox(checked=False, prefix='- ', doc_position=-1)
Append a new checkbox to the tracked list.
This is the public API for adding a checkbox programmatically (e.g. when the user presses Enter on a checkbox line or clicks the checklist toolbar button). The caller is responsible for inserting the actual \ufffc character into the document and then updating :attr:CheckboxItem.doc_position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checked | bool | Initial checked state. | False |
prefix | str | Markdown list prefix (e.g. | '- ' |
doc_position | int | Document character position of the | -1 |
Returns:
| Type | Description |
|---|---|
CheckboxItem | The newly created :class: |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
contains_checkboxes(markdown) staticmethod
Check if markdown text contains checkbox syntax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markdown | str | The markdown string to check. | required |
Returns:
| Type | Description |
|---|---|
bool | True if checkbox syntax is found, False otherwise. |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
578 579 580 581 582 583 584 585 586 587 588 | |
find_checkbox_at_click(click_pos, content_offset=None)
Find the checkbox hit by a viewport click using stored positions.
Uses the cached doc_position on each :class:CheckboxItem instead of scanning the full document text, making hit-testing O(n) in the number of checkboxes rather than O(len(document)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
click_pos | 'QPoint' | Click position in viewport coordinates. | required |
content_offset | 'QPoint | None' | Optional scroll offset (x, y) as a QPoint. Defaults to (0, 0) when not provided. | None |
Returns:
| Type | Description |
|---|---|
Optional[Tuple[bool, Optional[int]]] |
|
Optional[Tuple[bool, Optional[int]]] |
|
Source code in client/ayon_ui_qt/components/checkbox_handler.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
get_checkbox_at_position(pos)
Get the checkbox index at the given document position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos | int | Position in the document (one past the \ufffc char). | required |
Returns:
| Type | Description |
|---|---|
int | None | Checkbox index if found, None otherwise. |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
has_checkboxes()
Check if the document contains any checkboxes.
Returns:
| Type | Description |
|---|---|
bool | True if there are checkboxes, False otherwise. |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
570 571 572 573 574 575 576 | |
parse_and_render(markdown)
Parse markdown and render checkboxes in the document.
Extracts checkbox items from markdown, stores their state, and renders them as custom text objects with icons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markdown | str | The markdown string containing checkboxes. | required |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
remove_checkbox(index)
Remove a checkbox from the tracked list.
Re-indexes the Python list and patches the stale CHECKBOX_INDEX_PROP values stored in the live QTextDocument so that subsequent hit-tests via :meth:get_checkbox_at_position return correct indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index | int | The index of the checkbox to remove. | required |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
remove_last_checkbox()
Remove the last checkbox from the tracked list.
Used when the user presses Enter on an empty checkbox line to terminate the list.
Returns:
| Type | Description |
|---|---|
bool | True if a checkbox was removed, False if the list was empty. |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
515 516 517 518 519 520 521 522 523 524 525 526 527 | |
to_markdown()
Reconstruct markdown with current checkbox states.
Returns:
| Type | Description |
|---|---|
str | GitHub-flavored markdown string with checkbox syntax. |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |
toggle_checkbox(index)
Toggle a checkbox by its index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index | int | The index of the checkbox to toggle. | required |
Returns:
| Type | Description |
|---|---|
bool | True if the checkbox was toggled, False otherwise. |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
CheckboxItem dataclass
Represents a checkbox item in the document.
Attributes:
| Name | Type | Description |
|---|---|---|
index | int | Unique index of the checkbox. |
checked | bool | Whether the checkbox is checked. |
text | str | Text following the checkbox. |
line_number | int | Line number in the original markdown. |
prefix | str | Characters before the checkbox (e.g., "- ", "* "). |
doc_position | int | Character position of the \ufffc object in the document, or -1 if not yet placed. |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
CheckboxTextObject
Bases: QPyTextObject
Custom text object for rendering checkbox icons in QTextDocument.
Uses Material icons to render checkboxes: - Unchecked: white radio_button_unchecked - Checked: green check_circle
Source code in client/ayon_ui_qt/components/checkbox_handler.py
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 126 127 128 129 130 131 132 133 134 135 136 | |
drawObject(painter, rect, doc, posInDocument, format)
Draw the checkbox icon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
painter | QPainter | The painter to draw with. | required |
rect | Union[QRectF, QRect] | The rectangle to draw in. | required |
doc | QTextDocument | The document containing the object. | required |
posInDocument | int | Position in the document. | required |
format | QTextFormat | The text format containing checkbox state. | required |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
intrinsicSize(doc, posInDocument, format)
Return the size of the checkbox icon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc | QTextDocument | The document containing the object. | required |
posInDocument | int | Position in the document. | required |
format | QTextFormat | The text format of the object. | required |
Returns:
| Type | Description |
|---|---|
QSizeF | Size of the checkbox icon based on font size. |
Source code in client/ayon_ui_qt/components/checkbox_handler.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |