async-tkinter-loop 0.9.3__tar.gz → 0.10.1__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.
@@ -1,30 +1,31 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: async-tkinter-loop
3
- Version: 0.9.3
3
+ Version: 0.10.1
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.8,<4.0
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
20
18
  Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
21
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
22
  Provides-Extra: examples
23
- Requires-Dist: Pillow (>=9.1.1,<11.0.0) ; extra == "examples"
23
+ Requires-Dist: Pillow (>=10.3.0,<12.0.0) ; extra == "examples"
24
24
  Requires-Dist: customtkinter (>=5.2.1,<6.0.0) ; extra == "examples"
25
- Requires-Dist: httpx (>=0.23.1,<0.26.0) ; extra == "examples"
26
- Requires-Dist: typing-extensions (>=4.7.0,<=5.0)
25
+ Requires-Dist: httpx (>=0.23.1,<0.29.0) ; extra == "examples"
26
+ Requires-Dist: typing-extensions
27
27
  Project-URL: Documentation, https://insolor.github.io/async-tkinter-loop/
28
+ Project-URL: Homepage, https://github.com/insolor/async-tkinter-loop
28
29
  Project-URL: Repository, https://github.com/insolor/async-tkinter-loop
29
30
  Description-Content-Type: text/markdown
30
31
 
@@ -33,7 +34,7 @@ Description-Content-Type: text/markdown
33
34
  [![Python tests](https://github.com/insolor/async-tkinter-loop/actions/workflows/python-tests.yml/badge.svg)](https://github.com/insolor/async-tkinter-loop/actions/workflows/python-tests.yml)
34
35
  [![Documentation](https://github.com/insolor/async-tkinter-loop/actions/workflows/deploy-docs.yml/badge.svg)](https://insolor.github.io/async-tkinter-loop/)
35
36
  [![Coverage Status](https://coveralls.io/repos/github/insolor/async-tkinter-loop/badge.svg?branch=main)](https://coveralls.io/github/insolor/async-tkinter-loop?branch=main)
36
- [![Maintainability](https://api.codeclimate.com/v1/badges/2566146b14ef72177613/maintainability)](https://codeclimate.com/github/insolor/async-tkinter-loop/maintainability)
37
+ [![Maintainability](https://qlty.sh/badges/01e7abf5-a53c-42ce-a0e1-c1b0bd24d095/maintainability.svg)](https://qlty.sh/gh/insolor/projects/async-tkinter-loop)
37
38
  [![PyPI](https://img.shields.io/pypi/v/async-tkinter-loop)](https://pypi.org/project/async-tkinter-loop/)
38
39
  ![Supported Python versions](https://img.shields.io/pypi/pyversions/async-tkinter-loop)
39
40
  <!--![PyPI - Downloads](https://img.shields.io/pypi/dm/async-tkinter-loop)-->
@@ -157,7 +158,8 @@ async def load_image(url):
157
158
  image = ImageTk.PhotoImage(pil_image)
158
159
  label.image = image
159
160
  label.config(image=image, text="")
160
- button.config(state=tk.NORMAL)
161
+
162
+ button.config(state=tk.NORMAL)
161
163
 
162
164
 
163
165
  url = "https://picsum.photos/800/640"
@@ -3,7 +3,7 @@
3
3
  [![Python tests](https://github.com/insolor/async-tkinter-loop/actions/workflows/python-tests.yml/badge.svg)](https://github.com/insolor/async-tkinter-loop/actions/workflows/python-tests.yml)
4
4
  [![Documentation](https://github.com/insolor/async-tkinter-loop/actions/workflows/deploy-docs.yml/badge.svg)](https://insolor.github.io/async-tkinter-loop/)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/insolor/async-tkinter-loop/badge.svg?branch=main)](https://coveralls.io/github/insolor/async-tkinter-loop?branch=main)
6
- [![Maintainability](https://api.codeclimate.com/v1/badges/2566146b14ef72177613/maintainability)](https://codeclimate.com/github/insolor/async-tkinter-loop/maintainability)
6
+ [![Maintainability](https://qlty.sh/badges/01e7abf5-a53c-42ce-a0e1-c1b0bd24d095/maintainability.svg)](https://qlty.sh/gh/insolor/projects/async-tkinter-loop)
7
7
  [![PyPI](https://img.shields.io/pypi/v/async-tkinter-loop)](https://pypi.org/project/async-tkinter-loop/)
8
8
  ![Supported Python versions](https://img.shields.io/pypi/pyversions/async-tkinter-loop)
9
9
  <!--![PyPI - Downloads](https://img.shields.io/pypi/dm/async-tkinter-loop)-->
@@ -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
- button.config(state=tk.NORMAL)
130
+
131
+ button.config(state=tk.NORMAL)
131
132
 
132
133
 
133
134
  url = "https://picsum.photos/800/640"
@@ -1 +1,3 @@
1
1
  from .async_tkinter_loop import async_handler, async_mainloop, get_event_loop, main_loop
2
+
3
+ __all__ = ["async_handler", "async_mainloop", "get_event_loop", "main_loop"]
@@ -1,17 +1,17 @@
1
1
  import _tkinter
2
2
  import asyncio
3
- import tkinter
3
+ import tkinter as tk
4
+ from collections.abc import Callable, Coroutine
4
5
  from functools import wraps
5
- from typing import Any, Callable, Coroutine
6
+ from typing import Any
6
7
 
7
- from tkinter import TclError
8
8
  from typing_extensions import ParamSpec
9
9
 
10
10
 
11
- async def main_loop(root: tkinter.Tk) -> None:
11
+ async def main_loop(root: tk.Tk) -> None:
12
12
  """
13
- An asynchronous implementation of tkinter mainloop.
14
- The function is not intended to be called directly from your code.
13
+ An asynchronous implementation of tkinter mainloop. The function is not intended to be called directly from your
14
+ code.
15
15
 
16
16
  Args:
17
17
  root: tkinter root window object
@@ -23,7 +23,7 @@ async def main_loop(root: tkinter.Tk) -> None:
23
23
 
24
24
  try:
25
25
  root.winfo_exists() # Will throw TclError if the main window is destroyed
26
- except TclError:
26
+ except tk.TclError:
27
27
  break
28
28
 
29
29
  await asyncio.sleep(0.01)
@@ -31,28 +31,35 @@ async def main_loop(root: tkinter.Tk) -> None:
31
31
 
32
32
  def get_event_loop() -> asyncio.AbstractEventLoop:
33
33
  """
34
- A helper function which returns an event loop using current event loop policy.
34
+ A helper function which returns a running event loop.
35
35
 
36
36
  Returns:
37
37
  event loop
38
38
  """
39
- return asyncio.get_event_loop_policy().get_event_loop()
39
+ return asyncio.get_running_loop()
40
40
 
41
41
 
42
- def async_mainloop(root: tkinter.Tk) -> None:
42
+ def async_mainloop(root: tk.Tk, event_loop: asyncio.AbstractEventLoop | None = None) -> None:
43
43
  """
44
44
  A function, which is a substitute to the standard `root.mainloop()`.
45
45
 
46
46
  Args:
47
47
  root: tkinter root object
48
+ event_loop: asyncio event loop (optional)
48
49
  """
49
- get_event_loop().run_until_complete(main_loop(root))
50
+ event_loop = event_loop or asyncio.new_event_loop()
51
+ event_loop.run_until_complete(main_loop(root))
50
52
 
51
53
 
52
54
  P = ParamSpec("P")
53
55
 
54
56
 
55
- def async_handler(async_function: Callable[P, Coroutine[Any, Any, None]], *args, **kwargs) -> Callable[P, None]:
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]:
56
63
  """
57
64
  A helper function which allows to use async functions as command handlers (e.g. button click handlers) or event
58
65
  handlers.
@@ -60,6 +67,7 @@ def async_handler(async_function: Callable[P, Coroutine[Any, Any, None]], *args,
60
67
  Args:
61
68
  async_function: async function
62
69
  args: positional parameters which will be passed to the async function
70
+ event_loop: asyncio event loop (optional, for testing purposes)
63
71
  kwargs: keyword parameters which will be passed to the async function
64
72
 
65
73
  Returns:
@@ -98,9 +106,11 @@ def async_handler(async_function: Callable[P, Coroutine[Any, Any, None]], *args,
98
106
  button = tk.Button("Press me", command=some_async_function)
99
107
  ```
100
108
  """
109
+ event_loop = event_loop or get_event_loop()
101
110
 
102
111
  @wraps(async_function)
103
112
  def wrapper(*handler_args) -> None:
104
- get_event_loop().create_task(async_function(*handler_args, *args, **kwargs))
113
+ loop = event_loop or get_event_loop()
114
+ loop.create_task(async_function(*handler_args, *args, **kwargs))
105
115
 
106
116
  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: tkinter.Tk):
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.9.3"
3
+ version = "0.10.1"
4
4
  description = "Asynchronous mainloop implementation for tkinter"
5
5
  authors = ["insolor <insolor@gmail.com>"]
6
6
  license = "MIT"
@@ -18,24 +18,22 @@ classifiers = [
18
18
  ]
19
19
 
20
20
  [tool.poetry.dependencies]
21
- python = "^3.8"
22
- Pillow = {version = ">=9.1.1,<11.0.0", optional = true}
23
- httpx = {version = ">=0.23.1,<0.26.0", optional = true}
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
24
  customtkinter = {version = "^5.2.1", optional = true}
25
- typing-extensions = ">=4.7.0,<=5.0"
25
+ typing-extensions = "*"
26
26
 
27
27
  [tool.poetry.group.dev.dependencies]
28
- pytest = "^7.4.0"
29
- pytest-cov = "^4.1.0"
28
+ pytest = ">=7.4,<9.0"
29
+ pytest-cov = ">=4.1,<8.0"
30
30
  pytest-timeout = "^2.0.1"
31
- flake8 = "^5.0.4"
32
- black = "^23.3.0"
33
- isort = "^5.11.5"
31
+ ruff = ">=0.4.7,<0.14.0"
34
32
  customtkinter = "^5.2.1"
35
33
 
36
34
  [tool.poetry.group.docs.dependencies]
37
35
  mkdocs = "^1.5.2"
38
- mkdocstrings = {extras = ["python"], version = ">=0.22,<0.24"}
36
+ mkdocstrings = {extras = ["python"], version = ">=0.22,<0.31"}
39
37
  mkdocs-material = "^9.2.5"
40
38
 
41
39
  [tool.poetry.extras]
@@ -45,8 +43,33 @@ examples = ["httpx", "Pillow", "customtkinter"]
45
43
  requires = ["poetry-core>=1.0.0"]
46
44
  build-backend = "poetry.core.masonry.api"
47
45
 
48
- [tool.black]
46
+ [tool.ruff]
47
+ target-version = "py310"
49
48
  line-length = 120
50
49
 
51
- [tool.isort]
52
- profile = "black"
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
+ ]