tkinter: add PhotoImage and BitmapImage type hints (#4923)

This commit is contained in:
Akuli
2021-01-09 20:24:36 +02:00
committed by GitHub
parent 4145873604
commit a5f0761161

View File

@@ -1,5 +1,6 @@
import _tkinter
import sys
from _typeshed import AnyPath
from enum import Enum
from tkinter.constants import * # comment this out to find undefined identifier names with flake8
from tkinter.font import _FontDescription
@@ -97,6 +98,7 @@ EXCEPTION = _tkinter.EXCEPTION
# _tkinter.TclError: unknown font style "deque(['bold'])"
_T = TypeVar("_T")
_TkinterSequence = Union[List[_T], Tuple[_T, ...]]
_TkinterSequence2D = Union[List[List[_T]], List[Tuple[_T, ...]], Tuple[List[_T], ...], Tuple[Tuple[_T, ...], ...]]
# Some widgets have an option named -compound that accepts different values
# than the _Compound defined here. Many other options have similar things.
@@ -456,8 +458,8 @@ class Misc:
y: _ScreenUnits = ...,
) -> None: ...
def event_info(self, virtual: Optional[str] = ...) -> Tuple[str, ...]: ...
def image_names(self): ...
def image_types(self): ...
def image_names(self) -> Tuple[str, ...]: ...
def image_types(self) -> Tuple[str, ...]: ...
# See #4363 and #4891
def __setitem__(self, key: str, value: Any) -> None: ...
def __getitem__(self, key: str) -> Any: ...
@@ -2594,32 +2596,71 @@ class Image:
def __del__(self): ...
def __setitem__(self, key, value): ...
def __getitem__(self, key): ...
def configure(self, **kw): ...
configure: Any
config: Any
def height(self): ...
def height(self) -> int: ...
def type(self): ...
def width(self): ...
def width(self) -> int: ...
class PhotoImage(Image):
def __init__(self, name: Optional[Any] = ..., cnf=..., master: Optional[Any] = ..., **kw): ...
def blank(self): ...
def cget(self, option): ...
def __getitem__(self, key): ...
def copy(self): ...
def zoom(self, x, y: str = ...): ...
def subsample(self, x, y: str = ...): ...
def get(self, x, y): ...
def put(self, data, to: Optional[Any] = ...): ...
def write(self, filename, format: Optional[Any] = ..., from_coords: Optional[Any] = ...): ...
def __init__(
self,
name: Optional[str] = ...,
cnf: Dict[str, Any] = ...,
master: Optional[Union[Misc, _tkinter.TkappType]] = ...,
*,
data: str = ..., # not same as data argument of put()
format: str = ...,
file: AnyPath = ...,
gamma: float = ...,
height: int = ...,
palette: Union[int, str] = ...,
width: int = ...,
) -> None: ...
def configure(
self,
*,
data: str = ...,
format: str = ...,
file: AnyPath = ...,
gamma: float = ...,
height: int = ...,
palette: Union[int, str] = ...,
width: int = ...,
) -> None: ...
config = configure
def blank(self) -> None: ...
def cget(self, option: str) -> str: ...
def __getitem__(self, key: str) -> str: ... # always string: image['height'] can be '0'
def copy(self) -> PhotoImage: ...
def zoom(self, x: int, y: Union[int, Literal[""]] = ...) -> PhotoImage: ...
def subsample(self, x: int, y: Union[int, Literal[""]] = ...) -> PhotoImage: ...
def get(self, x: int, y: int) -> Tuple[int, int, int]: ...
def put(
self, data: Union[str, _TkinterSequence[str], _TkinterSequence2D[_Color]], to: Optional[Tuple[int, int]] = ...
) -> None: ...
def write(self, filename: AnyPath, format: Optional[str] = ..., from_coords: Optional[Tuple[int, int]] = ...) -> None: ...
if sys.version_info >= (3, 8):
def transparency_get(self, x: int, y: int) -> bool: ...
def transparency_set(self, x: int, y: int, boolean: bool) -> None: ...
class BitmapImage(Image):
def __init__(self, name: Optional[Any] = ..., cnf=..., master: Optional[Any] = ..., **kw): ...
def __init__(
self,
name: Optional[Any] = ...,
cnf: Dict[str, Any] = ...,
master: Optional[Union[Misc, _tkinter.TkappType]] = ...,
*,
background: _Color,
data: str,
file: AnyPath,
foreground: _Color,
maskdata: str,
maskfile: AnyPath,
) -> None: ...
def image_names(): ...
def image_types(): ...
def image_names() -> Tuple[str, ...]: ...
def image_types() -> Tuple[str, ...]: ...
class Spinbox(Widget, XView):
def __init__(