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