✨ Download path dialog
This commit is contained in:
parent
a21d60c717
commit
cfb0337c69
3 changed files with 38 additions and 10 deletions
|
@ -1,11 +1,12 @@
|
||||||
from bottle import request, response, Bottle, static_file
|
from bottle import request, response, Bottle, static_file
|
||||||
from manager import Manager
|
from manager import Manager
|
||||||
from json import dumps
|
from json import dumps
|
||||||
from pathlib import Path
|
from queue import SimpleQueue
|
||||||
from tkinter import filedialog as fd
|
|
||||||
|
|
||||||
manager = Manager()
|
manager = Manager()
|
||||||
app = Bottle()
|
app = Bottle()
|
||||||
|
action_queue = SimpleQueue()
|
||||||
|
path_queue = SimpleQueue()
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
|
@ -37,8 +38,9 @@ def download():
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|
||||||
|
|
||||||
@app.get("/path")
|
@app.post("/path")
|
||||||
def get_path():
|
def get_path():
|
||||||
path = fd.askdirectory()
|
path = request.json["path"]
|
||||||
manager.path = path
|
action_queue.put(path)
|
||||||
return path
|
manager.path = path_queue.get()
|
||||||
|
return manager.path
|
||||||
|
|
|
@ -20,7 +20,7 @@ function sendNVList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_path() {
|
function get_path() {
|
||||||
axios.get("/path").then(({ data }) => {
|
axios.post("/path", { path: path.value }).then(({ data }) => {
|
||||||
path.value = data;
|
path.value = data;
|
||||||
input.value.focus();
|
input.value.focus();
|
||||||
});
|
});
|
||||||
|
|
32
main.py
32
main.py
|
@ -1,10 +1,36 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import webview
|
import webview
|
||||||
from backend import app
|
import platform
|
||||||
|
from os import _exit
|
||||||
|
from time import sleep
|
||||||
|
from backend import app, action_queue, path_queue
|
||||||
|
|
||||||
|
|
||||||
|
def select_download_path(window):
|
||||||
|
while True:
|
||||||
|
path = action_queue.get()
|
||||||
|
result = window.create_file_dialog(webview.FOLDER_DIALOG)
|
||||||
|
if result:
|
||||||
|
path_queue.put(result[0])
|
||||||
|
else:
|
||||||
|
path_queue.put(path)
|
||||||
|
|
||||||
|
|
||||||
|
def on_closed():
|
||||||
|
sleep(1)
|
||||||
|
_exit(0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Create a standard webview window
|
|
||||||
window = webview.create_window(
|
window = webview.create_window(
|
||||||
"badl - BiliBili Audio Downloader", app, width=500, height=700
|
"badl - BiliBili Audio Downloader", app, width=500, height=700
|
||||||
)
|
)
|
||||||
webview.start()
|
window.events.closed += on_closed
|
||||||
|
if os := platform.system() == "Linux":
|
||||||
|
gui = "gtk"
|
||||||
|
elif os == "Windows":
|
||||||
|
gui = "edgehtml"
|
||||||
|
else:
|
||||||
|
gui = ""
|
||||||
|
webview.start(gui=gui, func=select_download_path, args=(window,))
|
||||||
|
|
Loading…
Reference in a new issue