Skip to content

Commit 770fe90

Browse files
authored
add types to tkinter.Text methods (#4460)
1 parent ff35f99 commit 770fe90

File tree

1 file changed

+151
-53
lines changed

1 file changed

+151
-53
lines changed

stdlib/3/tkinter/__init__.pyi

Lines changed: 151 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,7 @@ class Scrollbar(Widget):
24792479
def get(self): ...
24802480
def set(self, first, last): ...
24812481

2482+
_TextIndex = Union[_tkinter.Tcl_Obj, str, float]
24822483
_TextOptionName = Literal[
24832484
"autoseparators",
24842485
"background",
@@ -2638,52 +2639,106 @@ class Text(Widget, XView, YView):
26382639
def configure(self, cnf: _TextOptionName) -> Tuple[str, str, str, Any, Any]: ...
26392640
config = configure
26402641
def cget(self, key: _TextOptionName) -> Any: ...
2641-
def bbox(self, index): ...
2642-
def compare(self, index1, op, index2): ...
2643-
def count(self, index1, index2, *args): ...
2644-
def debug(self, boolean: Optional[Any] = ...): ...
2645-
def delete(self, index1, index2: Optional[Any] = ...): ...
2646-
def dlineinfo(self, index): ...
2647-
def dump(self, index1, index2: Optional[Any] = ..., command: Optional[Any] = ..., **kw): ...
2648-
def edit(self, *args): ...
2649-
def edit_modified(self, arg: Optional[Any] = ...): ...
2650-
def edit_redo(self): ...
2651-
def edit_reset(self): ...
2652-
def edit_separator(self): ...
2653-
def edit_undo(self): ...
2654-
def get(self, index1, index2: Optional[Any] = ...): ...
2642+
def bbox(self, index: _TextIndex) -> Optional[Tuple[int, int, int, int]]: ...
2643+
def compare(self, index1: _TextIndex, op: Literal["<", "<=", "==", ">=", ">", "!="], index2: _TextIndex) -> bool: ...
2644+
def count(self, index1, index2, *args): ... # TODO
2645+
@overload
2646+
def debug(self, boolean: None = ...) -> bool: ...
2647+
@overload
2648+
def debug(self, boolean: bool) -> None: ...
2649+
def delete(self, index1: _TextIndex, index2: Optional[_TextIndex] = ...) -> None: ...
2650+
def dlineinfo(self, index: _TextIndex) -> Optional[Tuple[int, int, int, int, int]]: ...
2651+
@overload
2652+
def dump(
2653+
self,
2654+
index1: _TextIndex,
2655+
index2: Optional[_TextIndex] = ...,
2656+
command: None = ...,
2657+
*,
2658+
all: bool = ...,
2659+
image: bool = ...,
2660+
mark: bool = ...,
2661+
tag: bool = ...,
2662+
text: bool = ...,
2663+
window: bool = ...,
2664+
) -> List[Tuple[str, str, str]]: ...
2665+
@overload
2666+
def dump(
2667+
self,
2668+
index1: _TextIndex,
2669+
index2: Optional[_TextIndex],
2670+
command: Union[Callable[[str, str, str], None], str],
2671+
*,
2672+
all: bool = ...,
2673+
image: bool = ...,
2674+
mark: bool = ...,
2675+
tag: bool = ...,
2676+
text: bool = ...,
2677+
window: bool = ...,
2678+
) -> None: ...
2679+
@overload
2680+
def dump(
2681+
self,
2682+
index1: _TextIndex,
2683+
index2: Optional[_TextIndex] = ...,
2684+
*,
2685+
command: Union[Callable[[str, str, str], None], str],
2686+
all: bool = ...,
2687+
image: bool = ...,
2688+
mark: bool = ...,
2689+
tag: bool = ...,
2690+
text: bool = ...,
2691+
window: bool = ...,
2692+
) -> None: ...
2693+
def edit(self, *args): ... # docstring says "Internal method"
2694+
@overload
2695+
def edit_modified(self, arg: None = ...) -> bool: ... # actually returns Literal[0, 1]
2696+
@overload
2697+
def edit_modified(self, arg: bool) -> None: ... # actually returns empty string
2698+
def edit_redo(self) -> None: ... # actually returns empty string
2699+
def edit_reset(self) -> None: ... # actually returns empty string
2700+
def edit_separator(self) -> None: ... # actually returns empty string
2701+
def edit_undo(self) -> None: ... # actually returns empty string
2702+
def get(self, index1: _TextIndex, index2: Optional[_TextIndex] = ...) -> str: ...
2703+
# TODO: image_* methods
26552704
def image_cget(self, index, option): ...
26562705
def image_configure(self, index, cnf: Optional[Any] = ..., **kw): ...
26572706
def image_create(self, index, cnf=..., **kw): ...
26582707
def image_names(self): ...
2659-
def index(self, index): ...
2660-
def insert(self, index, chars, *args): ...
2661-
def mark_gravity(self, markName, direction: Optional[Any] = ...): ...
2662-
def mark_names(self): ...
2663-
def mark_set(self, markName, index): ...
2664-
def mark_unset(self, *markNames): ...
2665-
def mark_next(self, index): ...
2666-
def mark_previous(self, index): ...
2667-
def peer_create(self, newPathName, cnf=..., **kw): ...
2668-
def peer_names(self): ...
2669-
def replace(self, index1, index2, chars, *args): ...
2670-
def scan_mark(self, x, y): ...
2671-
def scan_dragto(self, x, y): ...
2708+
def index(self, index: _TextIndex) -> str: ...
2709+
def insert(self, index: _TextIndex, chars: str, *args: Union[_TextIndex, str, _TkinterSequence[str]]) -> None: ...
2710+
@overload
2711+
def mark_gravity(self, markName: str, direction: None = ...) -> Literal["left", "right"]: ...
2712+
@overload
2713+
def mark_gravity(self, markName: str, direction: Literal["left", "right"]) -> None: ... # actually returns empty string
2714+
def mark_names(self) -> Tuple[str, ...]: ...
2715+
def mark_set(self, markName: str, index: _TextIndex) -> None: ...
2716+
def mark_unset(self, *markNames: str) -> None: ...
2717+
def mark_next(self, index: _TextIndex) -> Optional[str]: ...
2718+
def mark_previous(self, index: _TextIndex): ...
2719+
# **kw of peer_create is same as the kwargs of Text.__init__
2720+
def peer_create(self, newPathName: Union[str, Text], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ...
2721+
def peer_names(self) -> Tuple[_tkinter.Tcl_Obj, ...]: ...
2722+
def replace(
2723+
self, index1: _TextIndex, index2: _TextIndex, chars: str, *args: Union[_TextIndex, str, _TkinterSequence[str]]
2724+
) -> None: ...
2725+
def scan_mark(self, x: int, y: int) -> None: ...
2726+
def scan_dragto(self, x: int, y: int) -> None: ...
26722727
def search(
26732728
self,
2674-
pattern,
2675-
index,
2676-
stopindex: Optional[Any] = ...,
2677-
forwards: Optional[Any] = ...,
2678-
backwards: Optional[Any] = ...,
2679-
exact: Optional[Any] = ...,
2680-
regexp: Optional[Any] = ...,
2681-
nocase: Optional[Any] = ...,
2682-
count: Optional[Any] = ...,
2683-
elide: Optional[Any] = ...,
2684-
): ...
2685-
def see(self, index): ...
2686-
def tag_add(self, tagName, index1, *args): ...
2729+
pattern: str,
2730+
index: _TextIndex,
2731+
stopindex: Optional[_TextIndex] = ...,
2732+
forwards: Optional[bool] = ...,
2733+
backwards: Optional[bool] = ...,
2734+
exact: Optional[bool] = ...,
2735+
regexp: Optional[bool] = ...,
2736+
nocase: Optional[bool] = ...,
2737+
count: Optional[Variable] = ...,
2738+
elide: Optional[bool] = ...,
2739+
) -> str: ... # returns empty string for not found
2740+
def see(self, index: _TextIndex) -> None: ...
2741+
def tag_add(self, tagName: str, index1: _TextIndex, *args: _TextIndex) -> None: ...
26872742
# tag_bind stuff is very similar to Canvas
26882743
@overload
26892744
def tag_bind(
@@ -2696,23 +2751,66 @@ class Text(Widget, XView, YView):
26962751
@overload
26972752
def tag_bind(self, tagName: str, sequence: Optional[str], func: str, add: Optional[bool] = ...) -> None: ...
26982753
def tag_unbind(self, tagName: str, sequence: str, funcid: Optional[str] = ...) -> None: ...
2699-
def tag_cget(self, tagName, option): ...
2700-
def tag_configure(self, tagName, cnf: Optional[Any] = ..., **kw): ...
2701-
tag_config: Any
2702-
def tag_delete(self, *tagNames): ...
2703-
def tag_lower(self, tagName, belowThis: Optional[Any] = ...): ...
2704-
def tag_names(self, index: Optional[Any] = ...): ...
2705-
def tag_nextrange(self, tagName, index1, index2: Optional[Any] = ...): ...
2706-
def tag_prevrange(self, tagName, index1, index2: Optional[Any] = ...): ...
2707-
def tag_raise(self, tagName, aboveThis: Optional[Any] = ...): ...
2708-
def tag_ranges(self, tagName): ...
2709-
def tag_remove(self, tagName, index1, index2: Optional[Any] = ...): ...
2754+
# allowing any string for cget instead of just Literals because there's no other way to look up tag options
2755+
def tag_cget(self, tagName: str, option: str) -> Any: ...
2756+
@overload
2757+
def tag_configure(
2758+
self,
2759+
tagName: str,
2760+
cnf: Optional[Dict[str, Any]] = ...,
2761+
*,
2762+
background: _Color = ...,
2763+
bgstipple: _Bitmap = ...,
2764+
borderwidth: _ScreenUnits = ...,
2765+
border: _ScreenUnits = ..., # alias for borderwidth
2766+
elide: bool = ...,
2767+
fgstipple: _Bitmap = ...,
2768+
font: _FontDescription = ...,
2769+
foreground: _Color = ...,
2770+
justify: Literal["left", "right", "center"] = ...,
2771+
lmargin1: _ScreenUnits = ...,
2772+
lmargin2: _ScreenUnits = ...,
2773+
lmargincolor: _Color = ...,
2774+
offset: _ScreenUnits = ...,
2775+
overstrike: bool = ...,
2776+
overstrikefg: _Color = ...,
2777+
relief: _Relief = ...,
2778+
rmargin: _ScreenUnits = ...,
2779+
rmargincolor: _Color = ...,
2780+
selectbackground: _Color = ...,
2781+
selectforeground: _Color = ...,
2782+
spacing1: _ScreenUnits = ...,
2783+
spacing2: _ScreenUnits = ...,
2784+
spacing3: _ScreenUnits = ...,
2785+
tabs: Any = ..., # the exact type is kind of complicated, see manual page
2786+
tabstyle: Literal["tabular", "wordprocessor"] = ...,
2787+
underline: bool = ...,
2788+
underlinefg: _Color = ...,
2789+
wrap: Literal["none", "char", "word"] = ..., # be careful with "none" vs None
2790+
) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ...
2791+
@overload
2792+
def tag_configure(self, tagName: str, cnf: str) -> Tuple[str, str, str, Any, Any]: ...
2793+
tag_config = tag_configure
2794+
def tag_delete(self, __first_tag_name: str, *tagNames: str) -> None: ... # error if no tag names given
2795+
def tag_lower(self, tagName: str, belowThis: Optional[str] = ...) -> None: ...
2796+
def tag_names(self, index: Optional[_TextIndex] = ...) -> Tuple[str, ...]: ...
2797+
def tag_nextrange(
2798+
self, tagName: str, index1: _TextIndex, index2: Optional[_TextIndex] = ...
2799+
) -> Union[Tuple[str, str], Tuple[()]]: ...
2800+
def tag_prevrange(
2801+
self, tagName: str, index1: _TextIndex, index2: Optional[_TextIndex] = ...
2802+
) -> Union[Tuple[str, str], Tuple[()]]: ...
2803+
def tag_raise(self, tagName: str, aboveThis: Optional[str] = ...) -> None: ...
2804+
def tag_ranges(self, tagName: str) -> Tuple[_tkinter.Tcl_Obj, ...]: ...
2805+
# tag_remove and tag_delete are different
2806+
def tag_remove(self, tagName: str, index1: _TextIndex, index2: Optional[_TextIndex] = ...) -> None: ...
2807+
# TODO: window_* methods
27102808
def window_cget(self, index, option): ...
27112809
def window_configure(self, index, cnf: Optional[Any] = ..., **kw): ...
2712-
window_config: Any
2810+
window_config = window_configure
27132811
def window_create(self, index, cnf=..., **kw): ...
27142812
def window_names(self): ...
2715-
def yview_pickplace(self, *what): ...
2813+
def yview_pickplace(self, *what): ... # deprecated
27162814

27172815
class _setit:
27182816
def __init__(self, var, value, callback: Optional[Any] = ...): ...

0 commit comments

Comments
 (0)