Skip to content

Commit

Permalink
feat: add an option configs.Env.enable_animation to set whether wid…
Browse files Browse the repository at this point in the history
…get animation is enabled globally
  • Loading branch information
Xiaokang2022 committed Nov 28, 2024
1 parent d26dbcd commit 1b23af4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
3 changes: 3 additions & 0 deletions tkintertools/core/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ class Env:
is_dark: bool
default_callback: collections.abc.Callable[[tkinter.Event], typing.Literal[False]]

enable_animation: bool

default_root = _DefaultRootDescriptor()

@classmethod
def reset(cls) -> None:
"""Reset all configs."""
cls.system = cls.get_default_system()
cls.is_dark = bool(darkdetect.isDark()) if globals().get("darkdetect") else False
cls.enable_animation = True
cls.default_callback = lambda _: False

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions tkintertools/core/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def __init__(
state: str = "normal",
anchor: typing.Literal["n", "s", "w", "e", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand All @@ -464,7 +464,7 @@ def __init__(
self.state = state
self.anchor = anchor
self.through = self.is_nested() if through is None else through
self.animation = animation
self.animation = configs.Env.enable_animation if animation is None else animation

self.widgets: list[Widget] = []
self.texts: list[Text] = []
Expand Down
36 changes: 20 additions & 16 deletions tkintertools/standard/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -161,7 +161,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -221,7 +221,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -275,7 +275,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -346,7 +346,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -430,7 +430,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -497,7 +497,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -566,7 +566,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -631,7 +631,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -767,7 +767,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -821,7 +821,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -876,7 +876,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -958,7 +958,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -1059,7 +1059,7 @@ def __init__(
name: str | None = None,
anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
through: bool | None = None,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `master`: parent canvas
Expand Down Expand Up @@ -1138,6 +1138,10 @@ def clear(self) -> None:
self.widgets[0].clear()


class OptionButton(virtual.Widget):
"""A button that has many options to choose"""


class Tooltip(virtual.Widget):
"""A tooltip that can display additional information"""

Expand All @@ -1158,7 +1162,7 @@ def __init__(
justify: typing.Literal["left", "center", "right"] = "left",
name: str | None = None,
through: bool = True,
animation: bool = True,
animation: bool | None = None,
) -> None:
"""
* `widget`: the associated widget
Expand Down

0 comments on commit 1b23af4

Please sign in to comment.