Python Forum
Database connection problems [login, PyQt5, PySql]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database connection problems [login, PyQt5, PySql]
#5
(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...
Reply


Messages In This Thread
RE: Database connection problems [login, PyQt5, PySql] - by gradlon93 - Dec-15-2023, 03:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  "ModuleNotFoundError: No module named 'PyQt5.QtWidgets'; 'PyQt5' is not a package" chipx 3 7,726 Dec-09-2021, 07:05 AM
Last Post: chipx
  pysql connection to cloud server database times out Pedroski55 9 4,923 Oct-11-2021, 10:34 PM
Last Post: Pedroski55
  Serial connection connection issue Joni_Engr 15 8,406 Aug-30-2021, 04:46 PM
Last Post: deanhystad
  in a login interface when i try login with a user supposed to say test123 but nothing NullAdmin 3 2,371 Feb-20-2021, 04:43 AM
Last Post: bowlofred
  Connection DATABASE to Python MenThoLLt 3 2,503 Jan-17-2020, 10:35 PM
Last Post: DT2000
  Unable to login to remote SQL Server database sipriusPT 1 15,178 Dec-20-2019, 10:16 AM
Last Post: sipriusPT
  Problems converting pyqt4 script to pyqt5 using pyqt4topyqt5.py Vysero 1 2,837 Jul-31-2018, 08:56 PM
Last Post: Axel_Erfurt
  Error in running MS Access Database connection code pyuser1 4 7,815 Feb-01-2018, 08:28 PM
Last Post: pyuser1
  Connection to MS SQL Database not working mruprai 1 2,818 Sep-25-2017, 03:58 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020