Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	gui/main.py
  • Loading branch information
lilingfengdev committed Aug 11, 2024
2 parents aca5524 + 5864e7f commit e43af9b
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 58 deletions.
2 changes: 1 addition & 1 deletion core/engine/bing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion core/engine/klpbbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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个
2 changes: 1 addition & 1 deletion core/engine/minebbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] # 一般来将,前五个才有价值 # 四个吧
10 changes: 5 additions & 5 deletions core/engine/spigotmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand All @@ -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
2 changes: 1 addition & 1 deletion core/engine/tinksp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
4 changes: 2 additions & 2 deletions core/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 14 additions & 12 deletions gui/main.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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__()
Expand All @@ -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.
Expand Down
60 changes: 37 additions & 23 deletions gui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@
################################################################################
## 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):
if not MainWindow.objectName():
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"
Expand All @@ -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")
Expand Down Expand Up @@ -70,30 +78,35 @@ 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())
self.searchLine.setSizePolicy(sizePolicy)

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)

Expand All @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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));
Expand Down
31 changes: 19 additions & 12 deletions gui/ui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
<bool>false</bool>
</property>
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
<enum>Qt::ContextMenuPolicy::DefaultContextMenu</enum>
</property>
<property name="accessibleName">
<string/>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
<enum>Qt::LayoutDirection::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
Expand All @@ -76,21 +76,14 @@
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
</property>
<property name="flat">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QPushButton" name="searchButton">
<property name="text">
<string>搜索</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="searchLine">
<property name="sizePolicy">
Expand All @@ -104,6 +97,20 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="searchButton">
<property name="text">
<string>搜索</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>关闭 Bing 翻译</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand All @@ -127,7 +134,7 @@
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand All @@ -143,7 +150,7 @@
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
<enum>QAbstractScrollArea::SizeAdjustPolicy::AdjustIgnored</enum>
</property>
<property name="showDropIndicator" stdset="0">
<bool>true</bool>
Expand Down

0 comments on commit e43af9b

Please sign in to comment.