async-tkinter-loop 0.9.2__tar.gz → 0.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {async_tkinter_loop-0.9.2 → async_tkinter_loop-0.10.0}/PKG-INFO +15 -11
- {async_tkinter_loop-0.9.2 → async_tkinter_loop-0.10.0}/README.md +3 -2
- async_tkinter_loop-0.10.0/async_tkinter_loop/__init__.py +3 -0
- {async_tkinter_loop-0.9.2 → async_tkinter_loop-0.10.0}/async_tkinter_loop/async_tkinter_loop.py +27 -14
- {async_tkinter_loop-0.9.2 → async_tkinter_loop-0.10.0}/async_tkinter_loop/mixins.py +3 -4
- {async_tkinter_loop-0.9.2 → async_tkinter_loop-0.10.0}/pyproject.toml +39 -15
- async_tkinter_loop-0.9.2/async_tkinter_loop/__init__.py +0 -1
- {async_tkinter_loop-0.9.2 → async_tkinter_loop-0.10.0}/LICENSE +0 -0
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: async-tkinter-loop
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
4
4
|
Summary: Asynchronous mainloop implementation for tkinter
|
|
5
|
-
Home-page: https://github.com/insolor/async-tkinter-loop
|
|
6
5
|
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
7
|
Keywords: tkinter,async,async-await,asyncio,aiohttp
|
|
8
8
|
Author: insolor
|
|
9
9
|
Author-email: insolor@gmail.com
|
|
10
|
-
Requires-Python: >=3.
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
14
14
|
Classifier: Operating System :: OS Independent
|
|
15
15
|
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
21
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
22
|
Provides-Extra: examples
|
|
22
|
-
Requires-Dist: Pillow (>=
|
|
23
|
-
Requires-Dist: customtkinter (>=5.2.
|
|
24
|
-
Requires-Dist: httpx (>=0.23.1,<0.
|
|
23
|
+
Requires-Dist: Pillow (>=10.3.0,<12.0.0) ; extra == "examples"
|
|
24
|
+
Requires-Dist: customtkinter (>=5.2.1,<6.0.0) ; extra == "examples"
|
|
25
|
+
Requires-Dist: httpx (>=0.23.1,<0.29.0) ; extra == "examples"
|
|
26
|
+
Requires-Dist: typing-extensions
|
|
25
27
|
Project-URL: Documentation, https://insolor.github.io/async-tkinter-loop/
|
|
28
|
+
Project-URL: Homepage, https://github.com/insolor/async-tkinter-loop
|
|
26
29
|
Project-URL: Repository, https://github.com/insolor/async-tkinter-loop
|
|
27
30
|
Description-Content-Type: text/markdown
|
|
28
31
|
|
|
@@ -31,7 +34,7 @@ Description-Content-Type: text/markdown
|
|
|
31
34
|
[](https://github.com/insolor/async-tkinter-loop/actions/workflows/python-tests.yml)
|
|
32
35
|
[](https://insolor.github.io/async-tkinter-loop/)
|
|
33
36
|
[](https://coveralls.io/github/insolor/async-tkinter-loop?branch=main)
|
|
34
|
-
[](https://qlty.sh/gh/insolor/projects/async-tkinter-loop)
|
|
35
38
|
[](https://pypi.org/project/async-tkinter-loop/)
|
|
36
39
|

|
|
37
40
|
<!---->
|
|
@@ -155,7 +158,8 @@ async def load_image(url):
|
|
|
155
158
|
image = ImageTk.PhotoImage(pil_image)
|
|
156
159
|
label.image = image
|
|
157
160
|
label.config(image=image, text="")
|
|
158
|
-
|
|
161
|
+
|
|
162
|
+
button.config(state=tk.NORMAL)
|
|
159
163
|
|
|
160
164
|
|
|
161
165
|
url = "https://picsum.photos/800/640"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://github.com/insolor/async-tkinter-loop/actions/workflows/python-tests.yml)
|
|
4
4
|
[](https://insolor.github.io/async-tkinter-loop/)
|
|
5
5
|
[](https://coveralls.io/github/insolor/async-tkinter-loop?branch=main)
|
|
6
|
-
[](https://qlty.sh/gh/insolor/projects/async-tkinter-loop)
|
|
7
7
|
[](https://pypi.org/project/async-tkinter-loop/)
|
|
8
8
|

|
|
9
9
|
<!---->
|
|
@@ -127,7 +127,8 @@ async def load_image(url):
|
|
|
127
127
|
image = ImageTk.PhotoImage(pil_image)
|
|
128
128
|
label.image = image
|
|
129
129
|
label.config(image=image, text="")
|
|
130
|
-
|
|
130
|
+
|
|
131
|
+
button.config(state=tk.NORMAL)
|
|
131
132
|
|
|
132
133
|
|
|
133
134
|
url = "https://picsum.photos/800/640"
|
{async_tkinter_loop-0.9.2 → async_tkinter_loop-0.10.0}/async_tkinter_loop/async_tkinter_loop.py
RENAMED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import _tkinter
|
|
1
2
|
import asyncio
|
|
2
|
-
import tkinter
|
|
3
|
+
import tkinter as tk
|
|
4
|
+
from collections.abc import Callable, Coroutine
|
|
3
5
|
from functools import wraps
|
|
4
|
-
from
|
|
5
|
-
from typing import Any, Callable, Coroutine
|
|
6
|
+
from typing import Any
|
|
6
7
|
|
|
7
|
-
import
|
|
8
|
+
from typing_extensions import ParamSpec
|
|
8
9
|
|
|
9
10
|
|
|
10
|
-
async def main_loop(root:
|
|
11
|
+
async def main_loop(root: tk.Tk) -> None:
|
|
11
12
|
"""
|
|
12
|
-
An asynchronous implementation of tkinter mainloop.
|
|
13
|
-
|
|
13
|
+
An asynchronous implementation of tkinter mainloop. The function is not intended to be called directly from your
|
|
14
|
+
code.
|
|
14
15
|
|
|
15
16
|
Args:
|
|
16
17
|
root: tkinter root window object
|
|
@@ -22,7 +23,7 @@ async def main_loop(root: tkinter.Tk) -> None:
|
|
|
22
23
|
|
|
23
24
|
try:
|
|
24
25
|
root.winfo_exists() # Will throw TclError if the main window is destroyed
|
|
25
|
-
except TclError:
|
|
26
|
+
except tk.TclError:
|
|
26
27
|
break
|
|
27
28
|
|
|
28
29
|
await asyncio.sleep(0.01)
|
|
@@ -30,25 +31,35 @@ async def main_loop(root: tkinter.Tk) -> None:
|
|
|
30
31
|
|
|
31
32
|
def get_event_loop() -> asyncio.AbstractEventLoop:
|
|
32
33
|
"""
|
|
33
|
-
A helper function which returns
|
|
34
|
+
A helper function which returns a running event loop.
|
|
34
35
|
|
|
35
36
|
Returns:
|
|
36
37
|
event loop
|
|
37
38
|
"""
|
|
38
|
-
return asyncio.
|
|
39
|
+
return asyncio.get_running_loop()
|
|
39
40
|
|
|
40
41
|
|
|
41
|
-
def async_mainloop(root:
|
|
42
|
+
def async_mainloop(root: tk.Tk, event_loop: asyncio.AbstractEventLoop | None = None) -> None:
|
|
42
43
|
"""
|
|
43
44
|
A function, which is a substitute to the standard `root.mainloop()`.
|
|
44
45
|
|
|
45
46
|
Args:
|
|
46
47
|
root: tkinter root object
|
|
48
|
+
event_loop: asyncio event loop (optional)
|
|
47
49
|
"""
|
|
48
|
-
|
|
50
|
+
event_loop = event_loop or asyncio.new_event_loop()
|
|
51
|
+
event_loop.run_until_complete(main_loop(root))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
P = ParamSpec("P")
|
|
49
55
|
|
|
50
56
|
|
|
51
|
-
def async_handler(
|
|
57
|
+
def async_handler(
|
|
58
|
+
async_function: Callable[P, Coroutine[Any, Any, None]],
|
|
59
|
+
*args: Any, # noqa: ANN401
|
|
60
|
+
event_loop: asyncio.AbstractEventLoop | None = None,
|
|
61
|
+
**kwargs: Any, # noqa: ANN401
|
|
62
|
+
) -> Callable[P, None]:
|
|
52
63
|
"""
|
|
53
64
|
A helper function which allows to use async functions as command handlers (e.g. button click handlers) or event
|
|
54
65
|
handlers.
|
|
@@ -56,6 +67,7 @@ def async_handler(async_function: Callable[..., Coroutine[Any, Any, None]], *arg
|
|
|
56
67
|
Args:
|
|
57
68
|
async_function: async function
|
|
58
69
|
args: positional parameters which will be passed to the async function
|
|
70
|
+
event_loop: asyncio event loop (optional, for testing purposes)
|
|
59
71
|
kwargs: keyword parameters which will be passed to the async function
|
|
60
72
|
|
|
61
73
|
Returns:
|
|
@@ -94,9 +106,10 @@ def async_handler(async_function: Callable[..., Coroutine[Any, Any, None]], *arg
|
|
|
94
106
|
button = tk.Button("Press me", command=some_async_function)
|
|
95
107
|
```
|
|
96
108
|
"""
|
|
109
|
+
event_loop = event_loop or get_event_loop()
|
|
97
110
|
|
|
98
111
|
@wraps(async_function)
|
|
99
112
|
def wrapper(*handler_args) -> None:
|
|
100
|
-
|
|
113
|
+
event_loop.create_task(async_function(*handler_args, *args, **kwargs))
|
|
101
114
|
|
|
102
115
|
return wrapper
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import sys
|
|
2
|
-
import tkinter
|
|
2
|
+
import tkinter as tk
|
|
3
3
|
|
|
4
4
|
from async_tkinter_loop import async_mainloop
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class AsyncTk:
|
|
8
|
-
def async_mainloop(self:
|
|
8
|
+
def async_mainloop(self: tk.Tk) -> None:
|
|
9
9
|
async_mainloop(self)
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class AsyncCTk(AsyncTk):
|
|
13
|
-
def async_mainloop(self):
|
|
13
|
+
def async_mainloop(self) -> None:
|
|
14
14
|
# Based on the code from CustomTkinter by Tom Schimansky
|
|
15
15
|
# Source https://github.com/TomSchimansky/CustomTkinter/blob/d719950f80eb2768db96bd4cc627523e99603b1b/customtkinter/windows/ctk_tk.py#L155
|
|
16
16
|
if not self._window_exists:
|
|
@@ -18,7 +18,6 @@ class AsyncCTk(AsyncTk):
|
|
|
18
18
|
self._windows_set_titlebar_color(self._get_appearance_mode())
|
|
19
19
|
|
|
20
20
|
if not self._withdraw_called_before_window_exists and not self._iconify_called_before_window_exists:
|
|
21
|
-
# print("window dont exists -> deiconify in mainloop")
|
|
22
21
|
self.deiconify()
|
|
23
22
|
|
|
24
23
|
self._window_exists = True
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "async-tkinter-loop"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.10.0"
|
|
4
4
|
description = "Asynchronous mainloop implementation for tkinter"
|
|
5
5
|
authors = ["insolor <insolor@gmail.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -18,23 +18,22 @@ classifiers = [
|
|
|
18
18
|
]
|
|
19
19
|
|
|
20
20
|
[tool.poetry.dependencies]
|
|
21
|
-
python = "^3.
|
|
22
|
-
Pillow = {version = ">=
|
|
23
|
-
httpx = {version = ">=0.23.1,<0.
|
|
24
|
-
customtkinter = {version = "^5.2.
|
|
21
|
+
python = "^3.10"
|
|
22
|
+
Pillow = {version = ">=10.3.0,<12.0.0", optional = true}
|
|
23
|
+
httpx = {version = ">=0.23.1,<0.29.0", optional = true}
|
|
24
|
+
customtkinter = {version = "^5.2.1", optional = true}
|
|
25
|
+
typing-extensions = "*"
|
|
25
26
|
|
|
26
27
|
[tool.poetry.group.dev.dependencies]
|
|
27
|
-
pytest = "
|
|
28
|
-
pytest-cov = "
|
|
28
|
+
pytest = ">=7.4,<9.0"
|
|
29
|
+
pytest-cov = ">=4.1,<8.0"
|
|
29
30
|
pytest-timeout = "^2.0.1"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
isort = "^5.11.5"
|
|
33
|
-
customtkinter = "^5.2.0"
|
|
31
|
+
ruff = ">=0.4.7,<0.14.0"
|
|
32
|
+
customtkinter = "^5.2.1"
|
|
34
33
|
|
|
35
34
|
[tool.poetry.group.docs.dependencies]
|
|
36
35
|
mkdocs = "^1.5.2"
|
|
37
|
-
mkdocstrings = {extras = ["python"], version = ">=0.22,<0.
|
|
36
|
+
mkdocstrings = {extras = ["python"], version = ">=0.22,<0.31"}
|
|
38
37
|
mkdocs-material = "^9.2.5"
|
|
39
38
|
|
|
40
39
|
[tool.poetry.extras]
|
|
@@ -44,8 +43,33 @@ examples = ["httpx", "Pillow", "customtkinter"]
|
|
|
44
43
|
requires = ["poetry-core>=1.0.0"]
|
|
45
44
|
build-backend = "poetry.core.masonry.api"
|
|
46
45
|
|
|
47
|
-
[tool.
|
|
46
|
+
[tool.ruff]
|
|
47
|
+
target-version = "py310"
|
|
48
48
|
line-length = 120
|
|
49
49
|
|
|
50
|
-
[tool.
|
|
51
|
-
|
|
50
|
+
[tool.ruff.lint]
|
|
51
|
+
select = ["ALL"]
|
|
52
|
+
ignore = [
|
|
53
|
+
"D", # Warning about docstrings are suppressed for now
|
|
54
|
+
"ANN002",
|
|
55
|
+
"ANN003",
|
|
56
|
+
]
|
|
57
|
+
fixable = ["ALL"]
|
|
58
|
+
|
|
59
|
+
[tool.ruff.lint.per-file-ignores]
|
|
60
|
+
"tests/*" = [
|
|
61
|
+
"S101", # Don't warn about using of asserts in tests
|
|
62
|
+
"ANN001",
|
|
63
|
+
"ANN201",
|
|
64
|
+
"ANN202",
|
|
65
|
+
"D", # Don't warn about missing documentation in tests
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
"examples/*" = [
|
|
69
|
+
"ANN",
|
|
70
|
+
"D",
|
|
71
|
+
"S311",
|
|
72
|
+
"PL",
|
|
73
|
+
"INP001",
|
|
74
|
+
"RUF006",
|
|
75
|
+
]
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .async_tkinter_loop import async_handler, async_mainloop, get_event_loop
|
|
File without changes
|