aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-04-09 15:09:18 +0200
committerlonkaars <loek@pipeframe.xyz>2023-04-09 15:09:18 +0200
commit8ce3898e775cdd4ac91960d415a36ffdc61d0fc7 (patch)
treedfaf702b377b7e0b80b21c987d14e4acdd903cf6
parent9a6b346598d19e13a4bf0d3af6a34573253e16b7 (diff)
main window boilerplate + login dialog done
-rw-r--r--gui/.gitignore3
-rw-r--r--gui/login_dialog.py45
-rwxr-xr-xgui/main.py33
3 files changed, 81 insertions, 0 deletions
diff --git a/gui/.gitignore b/gui/.gitignore
new file mode 100644
index 0000000..4f2de9b
--- /dev/null
+++ b/gui/.gitignore
@@ -0,0 +1,3 @@
+# python files
+venv/
+__pycache__/
diff --git a/gui/login_dialog.py b/gui/login_dialog.py
new file mode 100644
index 0000000..5d24c13
--- /dev/null
+++ b/gui/login_dialog.py
@@ -0,0 +1,45 @@
+import os
+from PyQt6.QtGui import *
+from PyQt6.QtWidgets import *
+
+class LoginDialog(QDialog):
+ hostname = "localhost"
+ username = os.getlogin()
+ database = "formula1"
+ password = ""
+ field_database = None
+ field_hostname = None
+ field_username = None
+ field_password = None
+
+ def submit(self):
+ self.database = self.field_database.text()
+ self.hostname = self.field_hostname.text()
+ self.username = self.field_username.text()
+ self.password = self.field_password.text()
+ if len(self.password) == 0: self.password = None
+ self.close()
+ return
+
+ def __init__(self, parent=None):
+ super(LoginDialog, self).__init__(parent)
+
+ self.field_database = QLineEdit(self.database)
+ self.field_database.setPlaceholderText("username")
+ self.field_hostname = QLineEdit(self.hostname)
+ self.field_hostname.setPlaceholderText("hostname")
+ self.field_username = QLineEdit(self.username)
+ self.field_username.setPlaceholderText("username")
+ self.field_password = QLineEdit(self.password)
+ self.field_password.setPlaceholderText("password")
+ self.field_password.setEchoMode(QLineEdit.EchoMode.Password)
+ self.login_button = QPushButton("login")
+ self.login_button.clicked.connect(self.submit)
+ layout = QFormLayout()
+ layout.addRow(QLabel("Database:"), self.field_database)
+ layout.addRow(QLabel("Hostname:"), self.field_hostname)
+ layout.addRow(QLabel("Username:"), self.field_username)
+ layout.addRow(QLabel("Password:"), self.field_password)
+ layout.addRow(self.login_button)
+
+ self.setLayout(layout)
diff --git a/gui/main.py b/gui/main.py
new file mode 100755
index 0000000..a190eab
--- /dev/null
+++ b/gui/main.py
@@ -0,0 +1,33 @@
+#!/bin/python3
+
+import sys
+import mariadb
+from PyQt6.QtGui import *
+from PyQt6.QtWidgets import *
+from PyQt6 import *
+
+from login_dialog import *
+
+global db
+global cursor
+
+class MainWindow(QMainWindow):
+ def __init__(self, parent=None):
+ super(MainWindow, self).__init__(parent)
+ self.setWindowTitle("[floating] dab2 eindopdracht main window")
+
+if __name__ == '__main__':
+ app = QApplication(sys.argv)
+ win = MainWindow()
+ login_dialog = LoginDialog()
+ db = None
+ while True:
+ login_dialog.exec()
+ try:
+ db = mariadb.connect(host=login_dialog.hostname, user=login_dialog.username, password=login_dialog.password, database=login_dialog.database)
+ break
+ except:
+ print("Login failed, please try again")
+ cursor = db.cursor(buffered=True)
+ win.show()
+ app.exec()