Answer the question
In order to leave comments, you need to log in
How to transmit a signal from a third-party module?
Hello. There is a program that is knocked down into one file. Now I want to scatter this whole thing into modules.
How do I receive a signal in pyqt from another module?
Right now I'm signaling like this:
self.parserBazos.newTextSignalBazos.connect(self.addNewItemBazos)
config_dir = 'modules/sk_sk/bazos/config/config.ini'
open_file_number_dir = 'modules/sk_sk/bazos/database/database_number.txt'
open_file_csv_dir = 'modules/sk_sk/bazos/database/database.csv'
class ParserBazos(QtCore.QObject):
running = False
newTextSignalBazos = QtCore.pyqtSignal(str)
def run(self):
bazos.main(config_dir, open_file_number_dir, open_file_csv_dir)
class MyWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.parserButton_1.clicked.connect(self.threadBazos)
def threadBazos(self):
self.thread_1 = QtCore.QThread()
self.parserBazos = ParserBazos()
self.parserBazos.moveToThread(self.thread_1)
self.parserBazos.newTextSignalBazos.connect(self.addNewItemBazos)
self.thread_1.started.connect(self.parserBazos.run)
self.thread_1.start()
@QtCore.pyqtSlot(str)
def addNewItemBazos(self, string):
self.ui.parserList_1.addItem(string)
def print_item(data):
data_item = data['phone'], data['country_code'], data['name'], data['title'], data['location'], data['link_page'], data['login'], data['link_login']
print(data_item)
return data_item
Answer the question
In order to leave comments, you need to log in
ParserBazos to a separate file, import it, then everything is the same
#####
from <file_with_ParserBazos> import ParserBazos
#####
config_dir = 'modules/sk_sk/bazos/config/config.ini'
open_file_number_dir = 'modules/sk_sk/bazos/database/database_number.txt'
open_file_csv_dir = 'modules/sk_sk/bazos/database/database.csv'
class MyWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.parserButton_1.clicked.connect(self.threadBazos)
def threadBazos(self):
self.thread_1 = QtCore.QThread()
self.parserBazos = ParserBazos()
self.parserBazos.moveToThread(self.thread_1)
self.parserBazos.newTextSignalBazos.connect(self.addNewItemBazos)
self.thread_1.started.connect(self.parserBazos.run)
self.thread_1.start()
@QtCore.pyqtSlot(str)
def addNewItemBazos(self, string):
self.ui.parserList_1.addItem(string)
def __init__(self, parent=None):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.parserBazos = ParserBazos() # <-
self.thread_1 = QtCore.QThread() # <-
self.ui.parserButton_1.clicked.connect(self.threadBazos)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question