|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import sys |
| 4 | +import re |
| 5 | +import math |
| 6 | +from my_queries import pull_project_rows |
| 7 | +from PyQt5.QtWidgets import QMainWindow, QTableWidget, QTableWidgetItem, QFileDialog, QMessageBox, QMenu, QTextEdit |
| 8 | +from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QComboBox, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QMessageBox |
| 9 | +from PyQt5 import QtCore |
| 10 | +from PyQt5.QtCore import Qt, pyqtSignal |
| 11 | +from PyQt5.QtGui import QFont, QFontMetrics |
| 12 | +import mysql.connector |
| 13 | +from functools import partial |
| 14 | + |
| 15 | +class ThingyWindow(QMainWindow): |
| 16 | + def __init__(self, conn): |
| 17 | + super().__init__() |
| 18 | + self.conn = conn |
| 19 | + self.setGeometry(400, 100, 300, 150) |
| 20 | + |
| 21 | + # now perform layout of this window |
| 22 | + self.initUI() |
| 23 | + |
| 24 | + def initUI(self): |
| 25 | + central_widget = QWidget() # Create a central widget |
| 26 | + layout = QVBoxLayout(central_widget) |
| 27 | + layout.setContentsMargins(10, 10, 0, 0) |
| 28 | + layout.setSpacing(0) |
| 29 | + |
| 30 | + label = QLabel('THINGIES!', self) |
| 31 | + layout.addWidget(label) |
| 32 | + |
| 33 | + self.list = ["List Projects", "u01_devhu"] |
| 34 | + for form in self.list: |
| 35 | + row_widget = QWidget() # Create a new widget for each row |
| 36 | + row_layout = QHBoxLayout(row_widget) |
| 37 | + row_layout.setSpacing(0) |
| 38 | + row_layout.setContentsMargins(10, 5, 0, 0) |
| 39 | + |
| 40 | + row_layout.addWidget(QLabel(form, row_widget)) |
| 41 | + |
| 42 | + b = QPushButton('Edit', row_widget) |
| 43 | + b.setFixedWidth(80) |
| 44 | + b.clicked.connect(lambda checked, name=form: self.button_clicked(name)) |
| 45 | + row_layout.addWidget(b) |
| 46 | + layout.addWidget(row_widget) |
| 47 | + |
| 48 | + self.setWindowTitle('Do things') |
| 49 | + self.setCentralWidget(central_widget) |
| 50 | + |
| 51 | + # if we're here we want to launch the instance filter window |
| 52 | + def button_clicked(self, name): |
| 53 | + if self.list.index(name) == 0: |
| 54 | + ## user wants a query that goes to the base class and gets all the rows similar to this spreadsheet: |
| 55 | + # https://docs.google.com/spreadsheets/d/1B1w7Rw_jkkneBYINoVJj-XBC1FlRZXuI3Y400rPBHKk/edit#gid=0 |
| 56 | + print(self.list.index(name), name) |
| 57 | + |
| 58 | + if self.list.index(name) == 1: |
| 59 | + ## user wants a query that goes to the assets modules and gets all the contributors associated with |
| 60 | + # project.short_name = "u01_devhu" |
| 61 | + print(self.list.index(name), name) |
| 62 | + |
| 63 | +class LoginWindow(QWidget): |
| 64 | + def __init__(self): |
| 65 | + super().__init__() |
| 66 | + self.setWindowTitle('MySQL Login') |
| 67 | + self.setGeometry(100, 100, 300, 150) |
| 68 | + |
| 69 | + self.label_username = QLabel('Username:', self) |
| 70 | + self.input_username = QLineEdit(self) |
| 71 | + self.input_username.setText('owhite') |
| 72 | + |
| 73 | + self.label_password = QLabel('Password:', self) |
| 74 | + self.input_password = QLineEdit(self) |
| 75 | + self.input_password.setEchoMode(QLineEdit.Password) |
| 76 | + self.input_password.setText('TaritRagi83') |
| 77 | + |
| 78 | + self.button_login = QPushButton('Login', self) |
| 79 | + self.button_login.clicked.connect(self.login) |
| 80 | + |
| 81 | + layout = QVBoxLayout() |
| 82 | + layout.addWidget(self.label_username) |
| 83 | + layout.addWidget(self.input_username) |
| 84 | + layout.addWidget(self.label_password) |
| 85 | + layout.addWidget(self.input_password) |
| 86 | + layout.addWidget(self.button_login) |
| 87 | + |
| 88 | + self.setLayout(layout) |
| 89 | + |
| 90 | + def login(self): |
| 91 | + username = self.input_username.text() |
| 92 | + password = self.input_password.text() |
| 93 | + |
| 94 | + try: |
| 95 | + # Connect to the MySQL database |
| 96 | + conn = mysql.connector.connect( |
| 97 | + host='mysql-devel.igs.umaryland.edu', |
| 98 | + user=username, |
| 99 | + password=password, |
| 100 | + database='nemo_assets_devel' |
| 101 | + ) |
| 102 | + |
| 103 | + if conn.is_connected(): |
| 104 | + print("Connected to MySQL database") |
| 105 | + # Here you can do something with the connection, like execute queries |
| 106 | + self.open_instances_window(conn) |
| 107 | + else: |
| 108 | + self.show_error_message("Error", "Invalid username or password") |
| 109 | + |
| 110 | + except mysql.connector.Error as e: |
| 111 | + print(f"Error connecting to MySQL database: {e}") |
| 112 | + |
| 113 | + def open_instances_window(self, conn): |
| 114 | + self.instances_window = ThingyWindow(conn) |
| 115 | + self.instances_window.show() |
| 116 | + self.close() |
| 117 | + |
| 118 | + def show_error_message(self, title, message): |
| 119 | + msg_box = QMessageBox() |
| 120 | + msg_box.setIcon(QMessageBox.Warning) |
| 121 | + msg_box.setWindowTitle(title) |
| 122 | + msg_box.setText(message) |
| 123 | + msg_box.exec_() |
| 124 | + |
| 125 | + |
| 126 | +def manual_login(): |
| 127 | + print ("skipping window-based login") |
| 128 | + try: |
| 129 | + # Connect to the MySQL database |
| 130 | + conn = mysql.connector.connect( |
| 131 | + host='mysql-devel.igs.umaryland.edu', |
| 132 | + user='owhite', |
| 133 | + password='TaritRagi83', |
| 134 | + database='nemo_assets_devel' |
| 135 | + ) |
| 136 | + |
| 137 | + except mysql.connector.Error as e: |
| 138 | + print(f"Error connecting to MySQL database: {e}") |
| 139 | + |
| 140 | + return(conn) |
| 141 | + |
| 142 | + |
| 143 | +if __name__ == '__main__': |
| 144 | + app = QApplication(sys.argv) |
| 145 | + |
| 146 | + if True: |
| 147 | + login_window = LoginWindow() |
| 148 | + login_window.show() |
| 149 | + |
| 150 | + else: |
| 151 | + conn = manual_login() |
| 152 | + window = InstancesWindow(conn) |
| 153 | + # window.show() |
| 154 | + |
| 155 | + (i, t) = hack() |
| 156 | + w2 = InstanceEditor(conn, "HACK", i, t) |
| 157 | + w2.show() |
| 158 | + |
| 159 | + sys.exit(app.exec_()) |
0 commit comments