Что я делаю:
Я пытаюсь создать словарь английского языка Engli sh, содержащий слово, его этимологическое значение и несколько предложений. Я войду в Слово, и я хочу получить Смысл и Приговоры. Значение Часть находится в моем локальном файле sqlite. Предложения извлекаются из некоторых целых rnet ссылок (круглых предложений). Чтобы показать данные из обеих частей, я использую функцию qtextbrowser.append()
. Ответ смысловой части намного быстрее, чем ответ части Sentences, и он сразу же печатается в терминале с помощью print (). но в данный момент он не отображается в QTextBrowser. QTextBrowser ожидает завершения от обеих частей. И только тогда он показывает полный результат.
Что я хочу:
Я хочу немедленно увидеть результат значения Значение в qtextbrowser. Я готов уделить время второй части на основе целых чисел rnet.
Для меня важна каждая секунда, и я хочу использовать этот интервал для чтения части значения (в то время как часть предложения вытащил из inte rnet).
Я пытался с setOpenLinks () и setExternalLinks. Они могут открывать только предоставленную ссылку в браузере, например Chrome и Firefox.
Я разделил две части в двух разных браузерах qtext. Но ничего не изменилось.
Значение:
self.displayresult.clear()
self.examplesentence.clear()
for row in wordlist: #wordlist obtained from a local sqlite file
str0 = '------------' + '\n' + row[0].upper() + '\n' + '----------------' + '\n' + row[1]
self.displayresult.append(str0)
self.displayresult.append('---------------------------------------------')
self.displayresult.append('---------------------------------------------')
Часть предложения:
link1 = 'https://sentencedict.com/' + searchedword + '.html'
source1 = requests.get(link1).text
soup = BeautifulSoup(source1, 'lxml')
for article in soup.find_all('div', id='all'):
self.examplesentence.append('<span style=\" color: green; font-weight: bold;\">%s</span>' % '----------------SENTECE DICT------------------')
for row in article.find_all('div'):
sentenceresult1 = row.text
if sentenceresult1.find('adsbygoogle') != -1:
continue
self.examplesentence.append('<span style=\" color: green;\">%s</span>' % sentenceresult1)
Это целый код (на тот случай, если вам нужно его увидеть;):
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'edu1.ui'
#
# Created by: PyQt5 UI code generator 5.13.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3
from bs4 import BeautifulSoup
import requests
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1066, 701)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(140, 140, 140))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(210, 210, 210))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush)
brush = QtGui.QBrush(QtGui.QColor(175, 175, 175))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush)
brush = QtGui.QBrush(QtGui.QColor(70, 70, 70))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush)
brush = QtGui.QBrush(QtGui.QColor(93, 93, 93))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(140, 140, 140))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Shadow, brush)
brush = QtGui.QBrush(QtGui.QColor(197, 197, 197))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.AlternateBase, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipBase, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(140, 140, 140))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(210, 210, 210))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush)
brush = QtGui.QBrush(QtGui.QColor(175, 175, 175))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Midlight, brush)
brush = QtGui.QBrush(QtGui.QColor(70, 70, 70))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush)
brush = QtGui.QBrush(QtGui.QColor(93, 93, 93))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(140, 140, 140))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Shadow, brush)
brush = QtGui.QBrush(QtGui.QColor(197, 197, 197))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipBase, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(70, 70, 70))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(140, 140, 140))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(210, 210, 210))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush)
brush = QtGui.QBrush(QtGui.QColor(175, 175, 175))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Midlight, brush)
brush = QtGui.QBrush(QtGui.QColor(70, 70, 70))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush)
brush = QtGui.QBrush(QtGui.QColor(93, 93, 93))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush)
brush = QtGui.QBrush(QtGui.QColor(70, 70, 70))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(70, 70, 70))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(140, 140, 140))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(140, 140, 140))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Shadow, brush)
brush = QtGui.QBrush(QtGui.QColor(140, 140, 140))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipBase, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.PlaceholderText, brush)
MainWindow.setPalette(palette)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("Annotation 2020-03-10 005223.png"), QtGui.QIcon.Normal, QtGui.QIcon.On)
MainWindow.setWindowIcon(icon)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout_2 = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout_2.setObjectName("gridLayout_2")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.typehere = QtWidgets.QLineEdit(self.centralwidget)
font = QtGui.QFont()
font.setFamily("Calibri")
font.setPointSize(12)
self.typehere.setFont(font)
self.typehere.setObjectName("typehere")
self.horizontalLayout.addWidget(self.typehere)
self.search = QtWidgets.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setFamily("Calibri")
font.setPointSize(12)
font.setKerning(True)
self.search.setFont(font)
self.search.setObjectName("search")
self.horizontalLayout.addWidget(self.search)
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1)
self.displayresult = QtWidgets.QTextBrowser(self.centralwidget)
font = QtGui.QFont()
font.setFamily("Calibri")
font.setPointSize(12)
self.displayresult.setFont(font)
self.displayresult.setObjectName("displayresult")
self.gridLayout.addWidget(self.displayresult, 1, 0, 1, 1)
self.verticalLayout.addLayout(self.gridLayout)
self.examplesentence = QtWidgets.QTextBrowser(self.centralwidget)
self.examplesentence.setObjectName("examplesentence")
self.verticalLayout.addWidget(self.examplesentence)
self.gridLayout_2.addLayout(self.verticalLayout, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.search.clicked.connect(self.pressed)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Ajay\'s Dictionary"))
self.search.setText(_translate("MainWindow", "Search"))
self.search.setShortcut(_translate("MainWindow", "Return"))
def pressed(self):
conn = sqlite3.connect('sq.sqlite')
cur = conn.cursor()
searchedword = self.typehere.text()
wordlist =[]
for row2 in cur.execute('''SELECT * FROM SampleV WHERE wordsV MATCH ?''',[searchedword]):
wordlist.append(row2)
relatedwordlist=[]
for row in wordlist:
temp = row[2]
rootlist = temp.split('|')
for root in rootlist:
if root == '':
continue
else:
for row in cur.execute('''SELECT * FROM SampleV WHERE for_wordsV MATCH ?''',[root]):
relatedwordlist.append(row)
print('--------------------------')
relatedwordlistRemoveRepetition = []
for row in relatedwordlist:
relatedwordlistRemoveRepetition.append(row[0])
relatedwordlistRemoveRepetition = list(dict.fromkeys(relatedwordlistRemoveRepetition))
relatedwordlistRemoveRepetition = sorted(relatedwordlistRemoveRepetition)
print(sorted(relatedwordlistRemoveRepetition))
self.displayresult.clear()
self.examplesentence.clear()
for row in wordlist:
str0 = '------------' + '\n' + row[0].upper() + '\n' + '----------------' + '\n' + row[1]
self.displayresult.append(str0)
def listToString(s):
# initialize an empty string
str1 = ""
# traverse in the string
for ele in s:
str1 = str1 + ele + '|'
# return string
return str1
self.displayresult.append('---------------------------------------------')
self.displayresult.append('---------------------------------------------')
self.displayresult.append(listToString(relatedwordlistRemoveRepetition))
cur.close()
link1 = 'https://sentencedict.com/' + searchedword + '.html'
try:
source1 = requests.get(link1).text
soup = BeautifulSoup(source1, 'lxml')
for article in soup.find_all('div', id='all'):
self.examplesentence.append('<span style=\" color: green; font-weight: bold;\">%s</span>' % '----------------SENTECE DICT------------------')
for row in article.find_all('div'):
sentenceresult1 = row.text
if sentenceresult1.find('adsbygoogle') != -1:
continue
self.examplesentence.append('<span style=\" color: green;\">%s</span>' % sentenceresult1)
except:
sentenceresult1 = 'BROKE AT '+ link1
self.examplesentence.append(sentenceresult1)
link2 = 'https://eng.ichacha.net/mzj/'+ searchedword + '.html'
try:
source2 = requests.get(link2).text
soup = BeautifulSoup(source2, 'lxml')
for article in soup.find_all('section', class_='jkbox'):
self.examplesentence.append('<span style=\" color: green; font-weight: bold;\">%s</span>' % '----------------ICHAHA------------------')
for row in article.find_all('li'):
sentenceresult2 = row.text
self.examplesentence.append('<span style=\" color: green;\">%s</span>' % sentenceresult2)
print(dir(self.examplesentence))
except:
sentenceresult2 = 'BROKE AT'+ link2
self.examplesentence.append(sentenceresult2)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())