Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Commit

Permalink
Version 0.1 finally here! See changelog for details.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcontis committed Jul 31, 2016
1 parent 9e4722a commit af64157
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
53 changes: 37 additions & 16 deletions Fobber/Client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys, SQL_Handler
from PyQt5.QtWidgets import QDialog, QApplication, QTableWidgetItem
from PyQt5.QtWidgets import QDialog, QApplication, QTableWidgetItem, QMessageBox
import mainwindow, sqlwindow

class MainWindow(QDialog, mainwindow.Ui_FobberWindow):
Expand All @@ -14,35 +14,56 @@ def __init__(self, parent=None):

def connection():
conn, data = SQL_Handler.connectToDatabase('fobs', form.UsernameField.text(), form.PasswordField.text(), 'localhost')
print(conn, data)
if conn is not None:
buildTable()
form.close()
form2.show()
form2.logoutButton.clicked.connect(mainMenu)
form2.sqlTable.setColumnCount(len(data))
form2.sqlTable.setRowCount(len(list(data.values())[0]))
form2.sqlTable.setHorizontalHeaderLabels([d for d in data.keys()])
for col, key in enumerate(data.keys()):
for row, item in enumerate(data[key]):
itemWidget = QTableWidgetItem(str(item))
form2.sqlTable.setItem(row, col, itemWidget)
print(data)
form2.refreshButton.clicked.connect(lambda: buildTable())
form2.validationButton.clicked.connect(lambda: saveChanges())
else:
Q = QMessageBox()
Q = QMessageBox.information(Q, 'Error', 'Connection failed.',
QMessageBox.Ok)

def mainMenu():
form2.close()
form2.destroy()
form.open()
form.show()

def buildTable():
cconn, data = SQL_Handler.connectToDatabase('fobs', form.UsernameField.text(), form.PasswordField.text(), 'localhost')
form2.sqlTable.clear()
SQL_Handler.getAndSetData(cconn)
form2.sqlTable.setColumnCount(len(data))
form2.sqlTable.setRowCount(len(list(data.values())[0]))
form2.sqlTable.setHorizontalHeaderLabels(sorted([d for d in data.keys()]))
form2.sqlTable.resizeRowsToContents()
form2.sqlTable.resizeColumnsToContents()
for col, key in enumerate(sorted(data.keys())):
for row, item in enumerate(data[key]):
itemWidget = QTableWidgetItem(str(item))
form2.sqlTable.setItem(row, col, itemWidget)

def saveChanges():
conn, data = SQL_Handler.connectToDatabase('fobs', form.UsernameField.text(), form.PasswordField.text(), 'localhost')
cursor = conn.cursor()
for col in range(0,len(data.keys())):
for row in range(0,len(list(data.values())[0])):
text = form2.sqlTable.item(row,col).text()
keys = sorted(list(data.keys()))[col]
text2 = data.get(sorted(list(data.keys()))[col])[row]
fob_id = form2.sqlTable.item(row,3).text()
if text != text2:
print('UPDATE fobs SET {} = "{}" WHERE fob_id = "{}"'.format(str(keys), str(text), str(fob_id)))
cursor.execute('UPDATE fobs SET {} = "{}" WHERE fob_id = "{}"'.format(str(keys), str(text), str(fob_id)))
conn.commit()

if __name__ == '__main__':
app = QApplication(sys.argv)
count = 0
form = MainWindow()
form.show()
form.loginButton.clicked.connect(connection)
form2 = SQLWindow()

sys.exit(app.exec_())



sys.exit(app.exec_())
10 changes: 7 additions & 3 deletions Fobber/SQL_Handler.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import pymysql
from PyQt5.QtWidgets import QMessageBox
import Client

conn = None
data = {}
def connectToDatabase(db, user, psswrd, host):
try:
global conn
conn = pymysql.connect(
db=db,
user=user,
passwd=psswrd,
host=host
)
global data
data = getAndSetData(conn)
return conn, data
except pymysql.err.OperationalError:
Q = QMessageBox()
Q = QMessageBox.question(Q, 'Error', 'Your username and/or password was incorrect. Please try again.', QMessageBox.Ok)
return None
Q = QMessageBox.information(Q, 'Error', 'Your username and/or password was incorrect. Please try again.', QMessageBox.Ok)
return None, None

def getAndSetData(conn):
data = {}
Expand All @@ -26,4 +31,3 @@ def getAndSetData(conn):
l = [row[0] for row in cursor.fetchall()]
data[column] = l
return data

7 changes: 5 additions & 2 deletions Fobber/sqlwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def setupUi(self, SQLWindow):
self.validationButton.setGeometry(QtCore.QRect(10, 340, 93, 28))
self.validationButton.setObjectName("validationButton")
self.logoutButton = QtWidgets.QPushButton(self.centralwidget)
self.logoutButton.setGeometry(QtCore.QRect(110, 340, 93, 28))
self.logoutButton.setGeometry(QtCore.QRect(210, 340, 93, 28))
self.logoutButton.setObjectName("logoutButton")

self.refreshButton = QtWidgets.QPushButton(self.centralwidget)
self.refreshButton.setGeometry(QtCore.QRect(110, 340, 93, 28))
self.refreshButton.setObjectName("refreshButton")
self.retranslateUi(SQLWindow)
QtCore.QMetaObject.connectSlotsByName(SQLWindow)

Expand All @@ -28,4 +30,5 @@ def retranslateUi(self, FobberWindow):
FobberWindow.setWindowTitle(_translate("FobberWindow", "Fobber v0.0.1"))
self.validationButton.setText(_translate("FobberWindow", "Save Changes"))
self.logoutButton.setText(_translate("FobberWindow", "Log Out"))
self.refreshButton.setText(_translate("FobberWindow", "Refresh"))

0 comments on commit af64157

Please sign in to comment.