I have tried some suggestions on the net but couldn't succeed yet. Not sure if it is possible but will explain what I am trying to achieve.
I have a MainWindow which has the following method. And a button initializes three instances of browser widgets beforehand.
def handleSearches(self):
# do the search
browseThreads = []
for idx, browser in enumerate(self.browsers):
browseThreads.append(BrowseThread(browser, self.data["options"][idx]))
for browseThread in browseThreads:
browseThread.start()
Where the browser as defined QWidget like following;
class Browser(QtWidgets.QWidget):
def __init__(self, title):
super().__init__()
self.gridLayout = QtWidgets.QGridLayout(self)
self.gridLayout.setObjectName("gridLayout")
self.webView = QWebEngineView()
self.webView.setUrl(QtCore.QUrl("https://www.google.com.tr"))
# some codes
def search(self, question, candidate, mode):
self.candidate = candidate
url = "https://www.google.com.tr/search?q={}".format(urllib.parse.quote_plus(candidate))
self.webView.setUrl(QtCore.QUrl(url))
def find_text(self, text):
soup = BS(self.src,'lxml')
# some source code alteration here
self.webView.page().setHtml(str(soup), self.webView.page().requestedUrl())
def on_page_load(self):
self.webView.page().toHtml(self.on_source_fetched)
def on_source_fetched(self, data):
self.src = data
self.find_text(self.candidate)
My Thread class is defined like following,
class BrowseThread (QThread):
def __init__(self, browser, searchString):
QThread.__init__(self)
self.searchString = searchString
self.browser = browser
def run(self):
self.search_text(self.searchString)
def search_text(self, text):
self.browser.search(text, '', 1)
What I am trying to achieve is to search different strings in parallel in 3 instances without blocking anything. Thread didn't work I guess because the browser widget GUI needs an update. How to do this?
Thanks.