diff --git a/core/engine/bing.py b/core/engine/bing.py index 75964bd..0e15cb2 100644 --- a/core/engine/bing.py +++ b/core/engine/bing.py @@ -9,7 +9,7 @@ class Bing: def get_bing_url(self, keywords): keywords = keywords.strip('\n') - bing_url = re.sub(r'^', 'https://cn.bing.com/search?q=', keywords) + bing_url = re.sub(r'^', 'https://www.bing.com/search?q=', keywords) bing_url = re.sub(r'\s', '+', bing_url) return bing_url diff --git a/core/engine/klpbbs.py b/core/engine/klpbbs.py index aaaef35..48ca62d 100644 --- a/core/engine/klpbbs.py +++ b/core/engine/klpbbs.py @@ -6,5 +6,5 @@ class Klpbbs: - def search(self, keywords,engine=Bing()) -> typing.List[SearchResult]: + def search(self, keywords, translation=True, engine=Bing()) -> typing.List[SearchResult]: return engine.search(keywords, site="klpbbs.com")[:3] # 一般来将,前五个才有价值 # 更加fw,3个 \ No newline at end of file diff --git a/core/engine/minebbs.py b/core/engine/minebbs.py index a85faff..478e94b 100644 --- a/core/engine/minebbs.py +++ b/core/engine/minebbs.py @@ -6,5 +6,5 @@ class Minebbs(): - def search(self, keywords, engine=Bing()) -> typing.List[SearchResult]: + def search(self, keywords, translation=True, engine=Bing()) -> typing.List[SearchResult]: return engine.search(keywords, site="minebbs.com")[:4] # 一般来将,前五个才有价值 # 四个吧 diff --git a/core/engine/spigotmc.py b/core/engine/spigotmc.py index 74bd5a0..f395fc7 100644 --- a/core/engine/spigotmc.py +++ b/core/engine/spigotmc.py @@ -13,7 +13,7 @@ def __init__(self, url, title, summary, count): class Spigot(SearchEngine): - def search(self, keywords) -> typing.List[SearchResult]: + def search(self, keywords, translation=True) -> typing.List[SearchResult]: key = translate(keywords, EN) headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/93.0.4577.63 Safari/537.36'} @@ -25,8 +25,8 @@ def search(self, keywords) -> typing.List[SearchResult]: SpigotResult(url=plug["url"], title=plug["name"], summary=plug["tag"], count=plug["download"]["count"])) result.sort(key=lambda obj: obj.count, reverse=True) result = result[:10] - for plug in result: - plug.summary = translate(plug.summary) - plug.title = translate(plug.title) - + if translation: + for plug in result: + plug.summary = translate(plug.summary) + plug.title = translate(plug.title) return result diff --git a/core/engine/tinksp.py b/core/engine/tinksp.py index 0357e20..8f7f23f 100644 --- a/core/engine/tinksp.py +++ b/core/engine/tinksp.py @@ -6,5 +6,5 @@ class Tinksp: - def search(self, keywords, engine=Bing()) -> typing.List[SearchResult]: + def search(self, keywords, translation, engine=Bing()) -> typing.List[SearchResult]: return engine.search(keywords, site="tinksp.com")[:5] diff --git a/core/search.py b/core/search.py index a0c1173..b24e583 100644 --- a/core/search.py +++ b/core/search.py @@ -8,13 +8,13 @@ from concurrent.futures import ThreadPoolExecutor, wait -def search(keyword: str) -> List[SearchResult]: +def search(keyword: str, translation=True) -> List[SearchResult]: 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) + future = executor.submit(e().search, keyword, translation) future_list.append(future) wait(future_list) for future in future_list: diff --git a/gui/main.py b/gui/main.py index cb578be..56a6f0f 100644 --- a/gui/main.py +++ b/gui/main.py @@ -1,5 +1,3 @@ -import traceback - from core.search import search from PySide6.QtWidgets import QMainWindow, QApplication, QMessageBox, QTreeWidgetItem from PySide6.QtCore import QObject, QThread, Signal @@ -15,18 +13,17 @@ def __init__(self): super().__init__() # print("000") - def work(self, keyword): - try: - results = search(keyword) - print("searching...") - self._signal.emit(results) - print("emitted signal _") - except Exception as e: - traceback.print_exception(e) + def work(self, lyst: list): + keyword, boolean = lyst[0], lyst[1] + print("Working") + results = search(keyword, boolean) + print("searching...") + self._signal.emit(results) + print("emitted signal _") class MainWindow(QMainWindow): - a = Signal(str) + a = Signal(list) def __init__(self): super().__init__() @@ -42,13 +39,18 @@ def __init__(self): self.worker_thread.start() def searcher(self): + self.ui.progressBar.setMaximum(0) keyword = self.ui.searchLine.text() self.ui.outputTreeWidget.clear() - self.a.emit(keyword) + state = self.ui.checkBox.checkState() + print(state) + translation = True if state == self.ui.checkBox.checkState().Unchecked else False + self.a.emit([keyword, translation]) def shower(self, results): for result in results: title = QTreeWidgetItem(self.ui.outputTreeWidget, [result.title, result.url, result.summary]) + self.ui.progressBar.setMaximum(100) def copyurl(self, item): # copy a text to the clipboard. diff --git a/gui/ui.py b/gui/ui.py index ff89cd8..04bb97b 100644 --- a/gui/ui.py +++ b/gui/ui.py @@ -3,16 +3,24 @@ ################################################################################ ## Form generated from reading UI file 'ui.ui' ## -## Created by: Qt User Interface Compiler version 6.5.3 +## Created by: Qt User Interface Compiler version 6.7.2 ## ## WARNING! All changes made in this file will be lost when recompiling UI file! ################################################################################ -from PySide6.QtCore import (QCoreApplication, QMetaObject, QSize, Qt) -from PySide6.QtGui import (QAction, QFont, QIcon) -from PySide6.QtWidgets import (QAbstractScrollArea, QFrame, QGridLayout, - QGroupBox, QHBoxLayout, QLineEdit, QProgressBar, QPushButton, QSizePolicy, - QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget) +from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, + QMetaObject, QObject, QPoint, QRect, + QSize, QTime, QUrl, Qt) +from PySide6.QtGui import (QAction, QBrush, QColor, QConicalGradient, + QCursor, QFont, QFontDatabase, QGradient, + QIcon, QImage, QKeySequence, QLinearGradient, + QPainter, QPalette, QPixmap, QRadialGradient, + QTransform) +from PySide6.QtWidgets import (QAbstractScrollArea, QApplication, QCheckBox, QFrame, + QGridLayout, QGroupBox, QHBoxLayout, QHeaderView, + QLineEdit, QMainWindow, QProgressBar, QPushButton, + QSizePolicy, QTreeWidget, QTreeWidgetItem, QVBoxLayout, + QWidget) class Ui_MainWindow(object): def setupUi(self, MainWindow): @@ -20,7 +28,7 @@ def setupUi(self, MainWindow): MainWindow.setObjectName(u"MainWindow") MainWindow.resize(779, 594) icon = QIcon() - icon.addFile(u"o.ico", QSize(), QIcon.Normal, QIcon.Off) + icon.addFile(u"o.ico", QSize(), QIcon.Mode.Normal, QIcon.State.Off) MainWindow.setWindowIcon(icon) MainWindow.setStyleSheet(u"QTreeView {\n" " border:none\n" @@ -33,12 +41,12 @@ def setupUi(self, MainWindow): self.actionSearchType = QAction(MainWindow) self.actionSearchType.setObjectName(u"actionSearchType") icon1 = QIcon() - icon1.addFile(u"icons/radio-circle-marked.png", QSize(), QIcon.Normal, QIcon.Off) + icon1.addFile(u"icons/radio-circle-marked.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off) self.actionSearchType.setIcon(icon1) self.actionSearchName = QAction(MainWindow) self.actionSearchName.setObjectName(u"actionSearchName") icon2 = QIcon() - icon2.addFile(u"icons/radio-circle.png", QSize(), QIcon.Normal, QIcon.Off) + icon2.addFile(u"icons/radio-circle.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off) self.actionSearchName.setIcon(icon2) self.actionTextViewer = QAction(MainWindow) self.actionTextViewer.setObjectName(u"actionTextViewer") @@ -70,23 +78,18 @@ def setupUi(self, MainWindow): self.groupBox.setFont(font) self.groupBox.setMouseTracking(False) self.groupBox.setTabletTracking(False) - self.groupBox.setContextMenuPolicy(Qt.DefaultContextMenu) - self.groupBox.setLayoutDirection(Qt.LeftToRight) + self.groupBox.setContextMenuPolicy(Qt.ContextMenuPolicy.DefaultContextMenu) + self.groupBox.setLayoutDirection(Qt.LayoutDirection.LeftToRight) self.groupBox.setAutoFillBackground(False) - self.groupBox.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) + self.groupBox.setAlignment(Qt.AlignmentFlag.AlignLeading|Qt.AlignmentFlag.AlignLeft|Qt.AlignmentFlag.AlignTop) self.groupBox.setFlat(False) self.verticalLayout = QVBoxLayout(self.groupBox) self.verticalLayout.setObjectName(u"verticalLayout") self.gridLayout = QGridLayout() self.gridLayout.setObjectName(u"gridLayout") - self.searchButton = QPushButton(self.groupBox) - self.searchButton.setObjectName(u"searchButton") - - self.gridLayout.addWidget(self.searchButton, 0, 1, 1, 1) - self.searchLine = QLineEdit(self.groupBox) self.searchLine.setObjectName(u"searchLine") - sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) + sizePolicy = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.searchLine.sizePolicy().hasHeightForWidth()) @@ -94,6 +97,16 @@ def setupUi(self, MainWindow): self.gridLayout.addWidget(self.searchLine, 0, 0, 1, 1) + self.searchButton = QPushButton(self.groupBox) + self.searchButton.setObjectName(u"searchButton") + + self.gridLayout.addWidget(self.searchButton, 0, 1, 1, 1) + + self.checkBox = QCheckBox(self.groupBox) + self.checkBox.setObjectName(u"checkBox") + + self.gridLayout.addWidget(self.checkBox, 0, 2, 1, 1) + self.verticalLayout.addLayout(self.gridLayout) @@ -112,8 +125,8 @@ def setupUi(self, MainWindow): self.line = QFrame(self.centralwidget) self.line.setObjectName(u"line") - self.line.setFrameShape(QFrame.HLine) - self.line.setFrameShadow(QFrame.Sunken) + self.line.setFrameShape(QFrame.Shape.HLine) + self.line.setFrameShadow(QFrame.Shadow.Sunken) self.verticalLayout_2.addWidget(self.line) @@ -125,12 +138,12 @@ def setupUi(self, MainWindow): self.outputTreeWidget.setHeaderItem(__qtreewidgetitem) self.outputTreeWidget.setObjectName(u"outputTreeWidget") self.outputTreeWidget.setEnabled(True) - sizePolicy1 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + sizePolicy1 = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) sizePolicy1.setHorizontalStretch(0) sizePolicy1.setVerticalStretch(0) sizePolicy1.setHeightForWidth(self.outputTreeWidget.sizePolicy().hasHeightForWidth()) self.outputTreeWidget.setSizePolicy(sizePolicy1) - self.outputTreeWidget.setSizeAdjustPolicy(QAbstractScrollArea.AdjustIgnored) + self.outputTreeWidget.setSizeAdjustPolicy(QAbstractScrollArea.SizeAdjustPolicy.AdjustIgnored) self.outputTreeWidget.setProperty("showDropIndicator", True) self.outputTreeWidget.setIndentation(20) self.outputTreeWidget.setRootIsDecorated(False) @@ -181,8 +194,9 @@ def retranslateUi(self, MainWindow): self.groupBox.setAccessibleName("") #endif // QT_CONFIG(accessibility) self.groupBox.setTitle("") - self.searchButton.setText(QCoreApplication.translate("MainWindow", u"\u641c\u7d22", None)) self.searchLine.setPlaceholderText(QCoreApplication.translate("MainWindow", u"\u8bf7\u8f93\u5165\u4f60\u60f3\u67e5\u8be2\u7684\u63d2\u4ef6", None)) + self.searchButton.setText(QCoreApplication.translate("MainWindow", u"\u641c\u7d22", None)) + self.checkBox.setText(QCoreApplication.translate("MainWindow", u"\u5173\u95ed Bing \u7ffb\u8bd1", None)) self.progressBar.setFormat(QCoreApplication.translate("MainWindow", u" \u672a\u5f00\u59cb", None)) ___qtreewidgetitem = self.outputTreeWidget.headerItem() ___qtreewidgetitem.setText(2, QCoreApplication.translate("MainWindow", u"\u7b80\u4ecb", None)); diff --git a/gui/ui.ui b/gui/ui.ui index 8e7ed51..5737369 100644 --- a/gui/ui.ui +++ b/gui/ui.ui @@ -61,13 +61,13 @@ false - Qt::DefaultContextMenu + Qt::ContextMenuPolicy::DefaultContextMenu - Qt::LeftToRight + Qt::LayoutDirection::LeftToRight false @@ -76,7 +76,7 @@ - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop false @@ -84,13 +84,6 @@ - - - - 搜索 - - - @@ -104,6 +97,20 @@ + + + + 搜索 + + + + + + + 关闭 Bing 翻译 + + + @@ -127,7 +134,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -143,7 +150,7 @@ - QAbstractScrollArea::AdjustIgnored + QAbstractScrollArea::SizeAdjustPolicy::AdjustIgnored true