|
9 | 9 | """ |
10 | 10 |
|
11 | 11 | from tkinter import Event, Canvas as TkCanvas |
12 | | -from typing import Any, Callable, Dict, FrozenSet, List, Optional, Tuple |
| 12 | +from typing import Any, Callable, Dict, FrozenSet, List, Optional, Tuple, cast |
13 | 13 |
|
14 | 14 | import customtkinter as ctk |
15 | 15 |
|
@@ -506,17 +506,20 @@ def create_draggable_rectangle( |
506 | 506 | Returns: |
507 | 507 | The created DraggableRectangle instance |
508 | 508 | """ |
509 | | - return self._dispatch( |
510 | | - "create_draggable_rectangle", |
511 | | - self._builtin_create_draggable_rectangle, |
512 | | - x1, |
513 | | - y1, |
514 | | - x2, |
515 | | - y2, |
516 | | - offset=offset, |
517 | | - max_repetitions=max_repetitions, |
518 | | - center_on_canvas=center_on_canvas, |
519 | | - **kwargs, |
| 509 | + return cast( |
| 510 | + DraggableRectangle, |
| 511 | + self._dispatch( |
| 512 | + "create_draggable_rectangle", |
| 513 | + self._builtin_create_draggable_rectangle, |
| 514 | + x1, |
| 515 | + y1, |
| 516 | + x2, |
| 517 | + y2, |
| 518 | + offset=offset, |
| 519 | + max_repetitions=max_repetitions, |
| 520 | + center_on_canvas=center_on_canvas, |
| 521 | + **kwargs, |
| 522 | + ), |
520 | 523 | ) |
521 | 524 |
|
522 | 525 | def _builtin_create_draggable_rectangle( |
@@ -604,13 +607,16 @@ def copy_draggable_rectangle( |
604 | 607 | Returns: |
605 | 608 | The copied DraggableRectangle instance |
606 | 609 | """ |
607 | | - return self._dispatch( |
608 | | - "copy_draggable_rectangle", |
609 | | - self._builtin_copy_draggable_rectangle, |
610 | | - draggable_rect, |
611 | | - offset=offset, |
612 | | - max_repetitions=max_repetitions, |
613 | | - **kwargs, |
| 610 | + return cast( |
| 611 | + DraggableRectangle, |
| 612 | + self._dispatch( |
| 613 | + "copy_draggable_rectangle", |
| 614 | + self._builtin_copy_draggable_rectangle, |
| 615 | + draggable_rect, |
| 616 | + offset=offset, |
| 617 | + max_repetitions=max_repetitions, |
| 618 | + **kwargs, |
| 619 | + ), |
614 | 620 | ) |
615 | 621 |
|
616 | 622 | def _builtin_copy_draggable_rectangle( |
@@ -1553,35 +1559,47 @@ def _recreate_attached_item(self, snapshot: Dict[str, Any]) -> Optional[int]: |
1553 | 1559 | tags = tuple(snapshot.get("tags", ())) |
1554 | 1560 |
|
1555 | 1561 | if item_type == "text": |
1556 | | - return self.create_text( |
1557 | | - *item_coords, |
1558 | | - text=snapshot.get("text", ""), |
1559 | | - font=snapshot.get("font", ""), |
1560 | | - fill=snapshot.get("fill", "black"), |
1561 | | - anchor=snapshot.get("anchor", "center"), |
1562 | | - tags=tags, |
| 1562 | + return cast( |
| 1563 | + int, |
| 1564 | + self.create_text( |
| 1565 | + *item_coords, |
| 1566 | + text=snapshot.get("text", ""), |
| 1567 | + font=snapshot.get("font", ""), |
| 1568 | + fill=snapshot.get("fill", "black"), |
| 1569 | + anchor=snapshot.get("anchor", "center"), |
| 1570 | + tags=tags, |
| 1571 | + ), |
1563 | 1572 | ) |
1564 | 1573 | elif item_type == "rectangle": |
1565 | | - return self.create_rectangle( |
1566 | | - *item_coords, |
1567 | | - fill=snapshot.get("fill", ""), |
1568 | | - outline=snapshot.get("outline", "black"), |
1569 | | - width=float(snapshot.get("width", 1)), |
1570 | | - tags=tags, |
| 1574 | + return cast( |
| 1575 | + int, |
| 1576 | + self.create_rectangle( |
| 1577 | + *item_coords, |
| 1578 | + fill=snapshot.get("fill", ""), |
| 1579 | + outline=snapshot.get("outline", "black"), |
| 1580 | + width=float(snapshot.get("width", 1)), |
| 1581 | + tags=tags, |
| 1582 | + ), |
1571 | 1583 | ) |
1572 | 1584 | elif item_type == "line": |
1573 | | - return self.create_line( |
1574 | | - *item_coords, |
1575 | | - fill=snapshot.get("fill", "black"), |
1576 | | - width=float(snapshot.get("width", 1)), |
1577 | | - tags=tags, |
| 1585 | + return cast( |
| 1586 | + int, |
| 1587 | + self.create_line( |
| 1588 | + *item_coords, |
| 1589 | + fill=snapshot.get("fill", "black"), |
| 1590 | + width=float(snapshot.get("width", 1)), |
| 1591 | + tags=tags, |
| 1592 | + ), |
1578 | 1593 | ) |
1579 | 1594 | elif item_type == "oval": |
1580 | | - return self.create_oval( |
1581 | | - *item_coords, |
1582 | | - fill=snapshot.get("fill", ""), |
1583 | | - outline=snapshot.get("outline", "black"), |
1584 | | - width=float(snapshot.get("width", 1)), |
1585 | | - tags=tags, |
| 1595 | + return cast( |
| 1596 | + int, |
| 1597 | + self.create_oval( |
| 1598 | + *item_coords, |
| 1599 | + fill=snapshot.get("fill", ""), |
| 1600 | + outline=snapshot.get("outline", "black"), |
| 1601 | + width=float(snapshot.get("width", 1)), |
| 1602 | + tags=tags, |
| 1603 | + ), |
1586 | 1604 | ) |
1587 | 1605 | return None |
0 commit comments