Skip to content

Commit 71c9e76

Browse files
import名を at から atk に変更
1 parent ac6670c commit 71c9e76

File tree

11 files changed

+70
-70
lines changed

11 files changed

+70
-70
lines changed

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ It's not easy to understand.
3737
If you use `asynctkinter`, the code above will become:
3838

3939
```python
40-
import asynctkinter as at
40+
import asynctkinter as atk
4141

4242
async def what_you_want_to_do(clock, label):
4343
print('A')
4444
await clock.sleep(1)
4545
print('B')
46-
await at.event(label, '<Button>')
46+
await atk.event(label, '<Button>')
4747
print('C')
4848

4949
nursery.start(what_you_want_to_do(...))
@@ -62,25 +62,25 @@ pip install "asynctkinter>=0.4,<0.5"
6262

6363
```python
6464
import tkinter as tk
65-
import asynctkinter as at
65+
import asynctkinter as atk
6666

6767

68-
async def main(*, clock: at.Clock, root: tk.Tk):
68+
async def main(*, clock: atk.Clock, root: tk.Tk):
6969
label = tk.Label(root, text='Hello', font=('', 80))
7070
label.pack()
7171

7272
# waits for 2 seconds to elapse
7373
await clock.sleep(2)
7474

7575
# waits for a label to be pressed
76-
event = await at.event(label, '<Button>')
76+
event = await atk.event(label, '<Button>')
7777
print(f"pos: {event.x}, {event.y}")
7878

7979
# waits for either 5 seconds to elapse or a label to be pressed.
8080
# i.e. waits at most 5 seconds for a label to be pressed
81-
tasks = await at.wait_any(
81+
tasks = await atk.wait_any(
8282
clock.sleep(5),
83-
at.event(label, '<Button>'),
83+
atk.event(label, '<Button>'),
8484
)
8585
if tasks[0].finished:
8686
print("Timeout")
@@ -90,21 +90,21 @@ async def main(*, clock: at.Clock, root: tk.Tk):
9090

9191
# same as the above
9292
async with clock.move_on_after(5) as timeout_tracker:
93-
event = await at.event(label, '<Button>')
93+
event = await atk.event(label, '<Button>')
9494
print(f"The label got pressed. (pos: {event.x}, {event.y})")
9595
if timeout_tracker.finished:
9696
print("Timeout")
9797

9898
# waits for both 5 seconds to elapse and a label to be pressed.
99-
tasks = await at.wait_all(
99+
tasks = await atk.wait_all(
100100
clock.sleep(5),
101-
at.event(label, '<Button>'),
101+
atk.event(label, '<Button>'),
102102
)
103103

104104
# nests as you want.
105105
tasks = await ak.wait_all(
106-
at.event(label, '<Button>'),
107-
at.wait_any(
106+
atk.event(label, '<Button>'),
107+
atk.wait_any(
108108
clock.sleep(5),
109109
...,
110110
),
@@ -113,7 +113,7 @@ async def main(*, clock: at.Clock, root: tk.Tk):
113113

114114

115115
if __name__ == "__main__":
116-
at.run(main)
116+
atk.run(main)
117117
```
118118

119119
### threading
@@ -123,11 +123,11 @@ thus threads may be the best way to perform them without blocking the main threa
123123

124124
```python
125125
from concurrent.futures import ThreadPoolExecuter
126-
import asynctkinter as at
126+
import asynctkinter as atk
127127

128128
executer = ThreadPoolExecuter()
129129

130-
async def async_fn(clock: at.Clock):
130+
async def async_fn(clock: atk.Clock):
131131
# create a new thread, run a function inside it, then
132132
# wait for the completion of that thread
133133
r = await clock.run_in_thread(thread_blocking_operation, polling_interval=1.0)
@@ -144,9 +144,9 @@ so you can catch them like you do in synchronous code:
144144

145145
```python
146146
import requests
147-
import asynctkinter as at
147+
import asynctkinter as atk
148148

149-
async def async_fn(clock: at.Clock):
149+
async def async_fn(clock: atk.Clock):
150150
try:
151151
r = await clock.run_in_thread(lambda: requests.get('htt...', timeout=10), ...)
152152
except requests.Timeout:

examples/animation_using_sleep.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import tkinter as tk
2-
import asynctkinter as at
2+
import asynctkinter as atk
33

44

5-
async def main(*, clock: at.Clock, root: tk.Tk):
5+
async def main(*, clock: atk.Clock, root: tk.Tk):
66
root.title("Looping Animation")
77
root.geometry('800x200')
88
label = tk.Label(root, text='Hello', font=('', 80))
@@ -22,4 +22,4 @@ async def main(*, clock: at.Clock, root: tk.Tk):
2222

2323

2424
if __name__ == "__main__":
25-
at.run(main)
25+
atk.run(main)

examples/bmi_calculator.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from tkinter import ttk
55
from tkinter import messagebox
66

7-
import asynctkinter as at
7+
import asynctkinter as atk
88

99

1010
class App:
@@ -15,10 +15,10 @@ async def main(self, *, clock, root):
1515
while True:
1616
await self.run_bmi_calculator(clock, root)
1717

18-
async def run_bmi_calculator(self, clock: at.Clock, root: tk.Tk):
18+
async def run_bmi_calculator(self, clock: atk.Clock, root: tk.Tk):
1919
scene = self.title_scene
2020
scene.pack(in_=root, expand=True, fill='both')
21-
await at.event(scene.children['start_button'], '<Button>')
21+
await atk.event(scene.children['start_button'], '<Button>')
2222
scene.pack_forget()
2323

2424
scene = self.input_scene
@@ -39,10 +39,10 @@ async def run_bmi_calculator(self, clock: at.Clock, root: tk.Tk):
3939
scene.pack(in_=root, expand=True, fill='both')
4040
scene.children['top_label']['text'] = f'Your BMI is {bmi:.2f}\nYou are'
4141
scene.children['bottom_label']['text'] = result
42-
await at.wait_any(clock.sleep(3), at.event(root, '<Button>'))
42+
await atk.wait_any(clock.sleep(3), atk.event(root, '<Button>'))
4343
scene.children['top_label']['text'] = ''
4444
scene.children['bottom_label']['text'] = 'bye'
45-
await at.wait_any(clock.sleep(3), at.event(root, '<Button>'))
45+
await atk.wait_any(clock.sleep(3), atk.event(root, '<Button>'))
4646
scene.pack_forget()
4747

4848
def init_style(self):
@@ -76,7 +76,7 @@ async def ask_input(msg):
7676
entry.delete(0, tk.END)
7777
entry.focus()
7878
while True:
79-
await at.event(entry, '<Return>')
79+
await atk.event(entry, '<Return>')
8080
text = entry.get()
8181
try:
8282
value = float(text)
@@ -102,4 +102,4 @@ def result_scene(self) -> ttk.Frame:
102102

103103

104104
if __name__ == '__main__':
105-
at.run(App().main)
105+
atk.run(App().main)

examples/event.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import tkinter as tk
2-
import asynctkinter as at
2+
import asynctkinter as atk
33

44

5-
async def main(*, clock: at.Clock, root: tk.Tk):
5+
async def main(*, clock: atk.Clock, root: tk.Tk):
66
root.title("Event")
77
root.geometry('800x400')
88
label = tk.Label(root, font=('', 40))
99
label.pack(expand=True, fill='both')
1010
while True:
1111
label['text'] = 'Click anywhere!'
12-
e = await at.event(label, '<Button>')
12+
e = await atk.event(label, '<Button>')
1313
label['text'] = f'You clicked at pos ({e.x}, {e.y})'
1414
await clock.sleep(1.5)
1515

1616

1717
if __name__ == "__main__":
18-
at.run(main)
18+
atk.run(main)

examples/event_with_filter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import tkinter as tk
2-
import asynctkinter as at
2+
import asynctkinter as atk
33

44

5-
async def main(*, clock: at.Clock, root: tk.Tk):
5+
async def main(*, clock: atk.Clock, root: tk.Tk):
66
root.title("Filtering Event")
77
root.geometry('900x400')
88
label = tk.Label(root, font=('', 40))
99
label.pack(expand=True, fill='both')
1010
while True:
1111
label['text'] = 'Press the left mouse button!!'
12-
await at.event(label, '<Button-1>')
12+
await atk.event(label, '<Button-1>')
1313
label['text'] = 'One more time'
14-
await at.event(label, '<Button>', filter=lambda e: e.num == 1)
14+
await atk.event(label, '<Button>', filter=lambda e: e.num == 1)
1515
label['text'] = 'Nice!!'
1616

1717
await clock.sleep(1.5)
1818

1919
label['text'] = 'Press the right mouse button!!'
20-
await at.event(label, '<Button-3>')
20+
await atk.event(label, '<Button-3>')
2121
label['text'] = 'One more time'
22-
await at.event(label, '<Button>', filter=lambda e: e.num == 3)
22+
await atk.event(label, '<Button>', filter=lambda e: e.num == 3)
2323
label['text'] = 'Great!!'
2424

2525
await clock.sleep(1.5)
2626

2727

2828
if __name__ == "__main__":
29-
at.run(main)
29+
atk.run(main)

examples/move_on_after.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import tkinter as tk
2-
import asynctkinter as at
2+
import asynctkinter as atk
33

44

5-
async def main(*, clock: at.Clock, root: tk.Tk):
5+
async def main(*, clock: atk.Clock, root: tk.Tk):
66
root.title("Appying a time limit to a code block")
77
root.geometry('400x400')
88
label = tk.Label(root, font=('', 80))
@@ -20,4 +20,4 @@ async def main(*, clock: at.Clock, root: tk.Tk):
2020

2121

2222
if __name__ == "__main__":
23-
at.run(main)
23+
atk.run(main)

examples/network_io.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import tkinter as tk
22
import requests
33

4-
import asynctkinter as at
4+
import asynctkinter as atk
55

66

7-
async def main(*, clock: at.Clock, root: tk.Tk):
7+
async def main(*, clock: atk.Clock, root: tk.Tk):
88
root.title("HTTP Request")
99
root.geometry('1000x400')
1010
label = tk.Label(root, text='Press to start a HTTP request', font=('', 40))
1111
label.pack(expand=True)
12-
await at.event(label, '<Button>')
12+
await atk.event(label, '<Button>')
1313
label['text'] = 'waiting for the server to respond...'
1414
res = await clock.run_in_thread(
1515
lambda: requests.get("https://httpbin.org/delay/2"),
@@ -20,4 +20,4 @@ async def main(*, clock: at.Clock, root: tk.Tk):
2020

2121

2222
if __name__ == '__main__':
23-
at.run(main)
23+
atk.run(main)

examples/network_io_with_animation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from tkinter import ttk
33
import requests
44

5-
import asynctkinter as at
5+
import asynctkinter as atk
66
from progress_spinner import run_progress_spinner
77

88

9-
async def main(*, clock: at.Clock, root: tk.Tk):
9+
async def main(*, clock: atk.Clock, root: tk.Tk):
1010
root.title("HTTP request + loading animation")
1111
root.geometry('720x480')
1212
bg = root.cget("bg")
@@ -22,18 +22,18 @@ async def main(*, clock: at.Clock, root: tk.Tk):
2222
canvas = tk.Canvas(root, bg=bg, height=200, width=200)
2323
canvas.pack(expand=True)
2424

25-
await at.event(button, "<Button>")
25+
await atk.event(button, "<Button>")
2626

27-
lw = 20
28-
async with at.run_as_daemon(
27+
lw = 20 # line width
28+
async with atk.run_as_daemon(
2929
run_progress_spinner(
3030
lw, lw, canvas.winfo_width() - lw, canvas.winfo_height() - lw,
3131
clock=clock, draw_target=canvas, line_width=lw,
3232
),
3333
):
3434
session = requests.Session()
3535
button['text'] = 'cancel'
36-
async with at.move_on_when(at.event(button, "<Button>")) as cancel_tracker:
36+
async with atk.move_on_when(atk.event(button, "<Button>")) as cancel_tracker:
3737
label['text'] = 'first request...'
3838
await clock.run_in_thread(
3939
lambda: session.get("https://httpbin.org/delay/2"),
@@ -49,10 +49,10 @@ async def main(*, clock: at.Clock, root: tk.Tk):
4949

5050
label['text'] = 'cancelled' if cancel_tracker.finished else 'all requests done'
5151
button['text'] = 'close'
52-
await at.event(button, "<Button>")
52+
await atk.event(button, "<Button>")
5353
await clock.sleep(0)
5454
root.destroy()
5555

5656

5757
if __name__ == '__main__':
58-
at.run(main)
58+
atk.run(main)

examples/painter1.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
'''
55

66
import tkinter as tk
7-
import asynctkinter as at
7+
import asynctkinter as atk
88

99

10-
async def main(*, clock: at.Clock, root: tk.Tk):
10+
async def main(*, clock: atk.Clock, root: tk.Tk):
1111
root.title("Painter")
1212
root.geometry('800x800')
1313
canvas = tk.Canvas(root, bg='white')
@@ -18,7 +18,7 @@ async def main(*, clock: at.Clock, root: tk.Tk):
1818
3: draw_oval,
1919
}
2020
while True:
21-
e_press = await at.event(canvas, '<Button>')
21+
e_press = await atk.event(canvas, '<Button>')
2222
command = button2command.get(e_press.num)
2323
if command is not None:
2424
await command(canvas, e_press)
@@ -28,8 +28,8 @@ async def draw_rect(canvas: tk.Canvas, e_press: tk.Event):
2828
ox, oy = e_press.x, e_press.y
2929
rect = canvas.create_rectangle(ox, oy, ox, oy, outline='orange', width=3)
3030
async with (
31-
at.move_on_when(at.event(canvas, '<ButtonRelease>', filter=lambda e: e.num == e_press.num)),
32-
at.event_freq(canvas, '<Motion>') as mouse_motion,
31+
atk.move_on_when(atk.event(canvas, '<ButtonRelease>', filter=lambda e: e.num == e_press.num)),
32+
atk.event_freq(canvas, '<Motion>') as mouse_motion,
3333
):
3434
while True:
3535
e = await mouse_motion()
@@ -41,8 +41,8 @@ async def draw_oval(canvas: tk.Canvas, e_press: tk.Event):
4141
oval = canvas.create_oval(ox, oy, ox, oy, outline='blue', width=3)
4242
bbox = canvas.create_rectangle(ox, oy, ox, oy, outline='black', dash=(3, 3))
4343
async with (
44-
at.move_on_when(at.event(canvas, '<ButtonRelease>', filter=lambda e: e.num == e_press.num)),
45-
at.event_freq(canvas, '<Motion>') as mouse_motion,
44+
atk.move_on_when(atk.event(canvas, '<ButtonRelease>', filter=lambda e: e.num == e_press.num)),
45+
atk.event_freq(canvas, '<Motion>') as mouse_motion,
4646
):
4747
while True:
4848
e = await mouse_motion()
@@ -52,4 +52,4 @@ async def draw_oval(canvas: tk.Canvas, e_press: tk.Event):
5252

5353

5454
if __name__ == '__main__':
55-
at.run(main)
55+
atk.run(main)

0 commit comments

Comments
 (0)