diff --git a/pse.py b/pse.py index 8b35c58..363c612 100644 --- a/pse.py +++ b/pse.py @@ -4,43 +4,57 @@ from plugin.engine.tinksp import Tinksp from concurrent.futures import ThreadPoolExecutor, wait from PySide6.QtWidgets import QMainWindow, QApplication, QMessageBox, QTreeWidgetItem +from PySide6.QtCore import QObject, QThread, Signal, Slot # from PySide6 import QtCore import sys -import multiprocessing as m -from multiprocessing import Process as P from ui import Ui_MainWindow import pyperclip -def get_result(keyword, q): - engine = [Spigot, Tinksp, Minebbs, Klpbbs] - results = [] - with ThreadPoolExecutor(max_workers=6) as executor: - future_list = [] - for e in engine: - future = executor.submit(e().search, keyword) - print(0) - future_list.append(future) - wait(future_list) - for future in future_list: - for result in future.result(): - results.append(result) - print(1) - q.put(results) +class Worker(QObject): + _signal = Signal(list) + def __init__(self): + super().__init__() + print("000") + + def work(self, keyword): + print(111) + engine = [Spigot, Tinksp, Minebbs, Klpbbs] + results = [] + with ThreadPoolExecutor(max_workers=6) as executor: + future_list = [] + for e in engine: + future = executor.submit(e().search, keyword) + print(10) + future_list.append(future) + wait(future_list) + for future in future_list: + for result in future.result(): + results.append(result) + print(1) + self._signal.emit(results) class MainWindow(QMainWindow): + a = Signal(str) + def __init__(self): super().__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) + self.worker = Worker() + self.worker_thread = QThread() + self.worker._signal.connect(self.shower) + self.worker.moveToThread(self.worker_thread) + self.a.connect(self.worker.work) self.ui.searchButton.clicked.connect(self.search) self.ui.outputTreeWidget.itemDoubleClicked.connect(self.copyUrl) - + self.worker_thread.start() + def search(self): - self.ui.outputTreeWidget.clear() keyword = self.ui.searchLine.text() - q = m.Queue() - p = P(target=get_result, args=(keyword, q)) - p.start(); p.join(); results = q.get() + self.ui.outputTreeWidget.clear() + self.a.emit(keyword) + + def shower(self, results): for result in results: num = results.index(result) title = QTreeWidgetItem(self.ui.outputTreeWidget, [result.title, result.url, result.summary]) @@ -51,7 +65,6 @@ def copyUrl(self, item): QMessageBox.information(self, "Copied!", "已将该插件链接复制到剪贴板。") if __name__ == "__main__": - m.freeze_support() app = QApplication(sys.argv) window = MainWindow() window.show()