Tablacus Explorer菜单运行的任务会阻塞UI。为了改掉这个问题,我写了一个Python脚本——long_run.py:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import subprocess
import threading
import os.path
import tkinter as tk
from tkinter import messagebox
class MainUI(tk.Tk):
def __init__(self, cmd):
tk.Tk.__init__(self)
self._output = tk.StringVar(value='Please wait...')
tk.Label(self, textvariable=self._output).pack(expand=True, fill=tk.BOTH, padx=5, pady=5)
self._is_stop = False
self.protocol("WM_DELETE_WINDOW", self.on_closing)
self._proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
threading.Thread(target=self.wait_result).start()
def on_closing(self):
if self._is_stop or messagebox.askokcancel('Quiz', 'Are you sure to exit?'):
self._is_sto