I have developed an application using pyQt6, and when I run it, I would like to first open a QDialog, which should contains a "start" button and do some required pre processing, and then launch the whole application. To launch the "whole application", I use the following code :
class Launcher:
def __init__(self):
super().__init__()
# OPEN A DIALOG HERE
# ON CLICK OF BUTTON
# CLOSE DIALOG, CALL CONTROLLER
self.controller = Controller()
class Controller:
def __init__(self):
self.view= View()
class View(QMainWindow):
def __init__(self, controller):
super().__init__()
self.ui = ui()
self.ui.setupUi(self)
self.show()
What I want is the Launcher class to open a dialog before doing a self.controller = Controller(), and only then open the main window by doing the call (as described in the commented part of my code).
I am not able to find a way to do it nicely, and more importantly in a way that makes sense for the code. If I need to do that, it's because depending on the user's click, the main window that will be open is not the same.
So far I've tried to use this launcher class :
class Launcher(QDialog):
def __init__(self):
super().__init__()
self.filters = " All Files (*.*);;"
self.ui = Ui_Form()
self.ui.setupUi(self)
self.show()
self.ui.pushButton.clicked.connect(self.open_document)
self.controller = None
def open_document(self):
filename, _ = QFileDialog.getOpenFileName(self, filter=self.filters)
file = Path(filename)
self.launch(file)
def launch(self, file):
if condition1:
self.controller = Controller1(file)
elif condition2:
self.controller = Controller2(file)
# self.close()
if __name__ == '__main__':
# app = QApplication(sys.argv)
launcher = Launcher()
# sys.exit(app.exec())
Thanks in advance,
Regards.
PS. I've added the pyqt5 tag as it is more popular and very similar to pyqt6, so solution could be the same and would be more than welcome anyway.