There is a main window with a button that opens a second window. The second window starts a thread that processes an excel file (pandas or openpyxl) so a user can still interact with GUI when the excel is processed. When this processing is reached, the second window crashes (the main window still runs). When the second window is opened directly (as only component of the app), it works fine. It also works when no pandas or openpyxl is used.
The code follows:
class MainWindow(QtWidgets.QMainWindow):
def __init__(self) -> None:
super().__init__()
self.main_window_ui = uic.loadUi("ui/MainWindow.ui", self)
self.main_window_ui.setWindowTitle("Test Results Application")
self.__load_buttons()
self.show()
def __load_buttons(self):
self.generate_test_report_button = self.main_window_ui.findChild(QPushButton, "testReportsButton")
self.generate_test_report_button.clicked.connect(lambda: create_test_report.CreateTestReport())
class CreateTestReport(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.test_report_generator_ui = uic.loadUi("ui/TestReportGenerator.ui", self)
self.test_report_generator_ui.setWindowTitle("Test report generator")
self.__load_buttons()
def __load_buttons(self):
self.generate_button = self.test_report_generator_ui.findChild(QPushButton, "generateButton")
self.generate_button.clicked.connect(self._generate_test_report)
def _generate_test_report(self):
params = [self.test_spec_location, self.test_report_destination, self.brand]
self.thread = ResultsParserThread(params)
self.thread.finished.connect(self.reportProgress)
self.thread.start()
class ResultsParserThread(QThread):
finished = pyqtSignal()
def __init__(self, params):
super().__init__()
self.params = params
def run(self):
self.data = test_report_creation_2.ResultsParser(*self.params)
self.data.requirement_tests()
self.finished.emit()
class ResultsParser:
def requirement_tests(self):
for excel_file in self.test_groups[0]:
excel = openpyxl.reader.excel.load_workbook(excel_file)
print("here it crashes")
for sheetname in excel.sheetnames:
print(sheetname)