Skip to content
This repository was archived by the owner on Mar 31, 2020. It is now read-only.

Commit 63b21b9

Browse files
committed
Happy, suhail?
Suhail last said: - Replaced requirements.txt with Pipfile so that it works with pipenv - Moved and renamed the main python file to fit the original project layout
2 parents b095e9f + 20b3572 commit 63b21b9

File tree

2 files changed

+70
-78
lines changed

2 files changed

+70
-78
lines changed

main.py

Lines changed: 0 additions & 76 deletions
This file was deleted.

project/__main__.py

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,76 @@
11
import asynctk as tk
22
import asyncio
3+
import os
4+
import pathlib
35

46
root = tk.AsyncTk()
7+
8+
9+
async def file_select():
10+
"""File select dialogue"""
11+
manager = tk.AsyncToplevel(root)
12+
dir = pathlib.Path()
13+
dirbox = tk.AsyncEntry(manager)
14+
dirbox.grid(row=0, column=0)
15+
foldermap = tk.AsyncFrame(manager)
16+
foldermap.grid(row=1, column=0)
17+
18+
def populate_folder(folder):
19+
nonlocal dir
20+
dir = manager.dir
21+
for i in os.listdir(folder):
22+
if (dir / i).is_file():
23+
24+
async def cb():
25+
manager.file = dir / i
26+
await manager.destroy()
27+
28+
tk.AsyncButton(foldermap, text=f"{i} [FILE]", callback=cb).pack()
29+
elif (dir / i).is_dir():
30+
31+
async def cb():
32+
manager.dir = dir / i
33+
populate_folder(manager.dir)
34+
35+
tk.AsyncButton(foldermap, text=f"{i} [FOLDER]", callback=cb).pack()
36+
37+
def boxcallback(*i):
38+
change_dir(dirbox.get())
39+
40+
def change_dir(path):
41+
nonlocal dir, foldermap
42+
dir = pathlib.Path(path)
43+
manager.dir = dir
44+
asyncio.ensure_future(foldermap.destroy())
45+
foldermap = tk.AsyncFrame(manager)
46+
foldermap.grid(row=1, column=0)
47+
populate_folder(dir)
48+
49+
dirbox.bind("<Return>", boxcallback)
50+
change_dir(".")
51+
await root.wait_window(manager)
52+
return manager.dir
53+
54+
555
async def save():
6-
print('test')
56+
print(await file_select())
57+
58+
759
root.protocol("WM_DELETE_WINDOW", lambda: asyncio.ensure_future(save()))
8-
root.mainloop()
60+
61+
62+
root.menu = tk.AsyncMenu(root)
63+
root.config(menu=root.menu)
64+
65+
66+
root.dropdown = tk.AsyncMenu(root.menu)
67+
68+
root.dropdown.add_command(label="Do nothing", command=lambda: None)
69+
root.dropdown.add_command(
70+
label="Save processor time", command=lambda: asyncio.ensure_future(root.destroy())
71+
)
72+
73+
root.menu.add_cascade(label="Unhelpful menu", menu=root.dropdown)
74+
75+
76+
root.mainloop()

0 commit comments

Comments
 (0)