Dec-15-2023, 03:21 PM
(Dec-15-2023, 02:02 PM)deanhystad Wrote: Or you botched the decorator. I assume I screwed up until I prove otherwise. Post your decorator and example of it's use. I'm curious.
Well, the one I came out with is something like this:
import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QLabel, QPushButton, QVBoxLayout import BSLogin class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Hello, World!") layout = QVBoxLayout() widget = QWidget() self.label = QLabel('Welcome back,') self.label.setStyleSheet('font-size: 20px;') self.name_lbl = QLabel() self.name_lbl.setStyleSheet('font-size: 20px;') self.dismissBtn = QPushButton('&OK') layout.addWidget(self.label) layout.addWidget(self.name_lbl) layout.addWidget(self.dismissBtn) self.dismissBtn.clicked.connect(lambda _: self.close()) widget.setLayout(layout) self.setCentralWidget(widget) class LoginDecorator: def __init__(self): pass def __call__(self, func): def wrapper(): login_dialog = BSLogin.BSLoginDialog() login_cookie = login_dialog.on_login_clicked() if login_cookie.state: func() else: sys.exit() return wrapper @LoginDecorator() def show_main_window(): app = QApplication(sys.argv) main_window = MainWindow() main_window.show() sys.exit(app.exec_()) if __name__ == "__main__": show_main_window()I won't copypaste the console output because it's just a memory address, no further information, not even with the default debugger in PyCharm.
I suspect the issue might be one or a combo of the following:
1) Decorators don't work well with the PyQt5 event queue
2) The way LoginCookie is passed from the QDialog to QMainWindow is not correct
3) QApplication is not initialized in the right place*
* I tried to initialize QApplication from within the
if __name__=='__main__'
clause, but this only leads to an unexpected result - a failed login warning message is shown (see the login_failed_warning()
method in my first post code).No clue why. Perhaps I should opt for the signal-slot approach...