I am trying to Build a GUI DB Comparator which is divided in two layout window.
- Get the DB Detail from user and Test the connection
- Get a Excel file which contains the SQL Statement that will be performed on DB and using Datacompy Comparison will be displayed to the user.
Problem I am facing right now is
- DB Details should be on top and the Output box should be below them but it's vice versa
- While after taking the input ( DB Details ) when i click on DB Test1 button application close's itself without displaying what went wrong ( No Code error, just went off )
I am new to PySimpleGUI, might have made slilly mistakes, Please guide me through the error and statement which i need to re enter.
Here's the code of First layout window :
import PySimpleGUI as sg
import re
import datacompy
import cx_Oracle
import pandas as pd
def read_query(connection, query):
cursor = connection.cursor()
try:
cursor.execute( query )
header = [ x[0] for x in cursor.description]
rows = cursor.fetchall()
return header, rows
finally:
if cursor is not None:
cursor.close()
def createCon(uname,passw,hname,portnum,sname):
dsn_str = cx_Oracle.makedsn(host=hname,
port=portnum,
service_name = sname)
con = cx_Oracle.connect(user = uname,
password = passw,
dsn = dsn_str)
if con == True:
return con
else:
return 0
DB_creds_one = [
[
sg.Text("UserName"),
sg.In(size=(30, 2), enable_events=True, key="-uname_db1-")
],
[
sg.Text("Password"),
sg.In(size=(30, 1), enable_events=True, key="-pword_db1-")
],
[
sg.Text("Hostname"),
sg.In(size=(30, 1), enable_events=True, key="-hname_db1-")
],
[
sg.Text("Service Name"),
sg.In(size=(30, 1), enable_events=True, key="-sname_db1-")
],
[
sg.Text("Port"),
sg.In(size=(30, 1), enable_events=True, key="-port_db1-")
],
[
sg.Button('Test Con1', key='B1')
],
]
DB_creds_two = [
[
sg.Text("UserName"),
sg.In(size=(25, 1), enable_events=True, key="-uname_db2-")
],
[
sg.Text("Password"),
sg.In(size=(25, 1), enable_events=True, key="-pword_db2-")
],
[
sg.Text("Hostname"),
sg.In(size=(25, 1), enable_events=True, key="-hname_db2-")
],
[
sg.Text("Service Name"),
sg.In(size=(25, 1), enable_events=True, key="-sname_db2-")
],
[
sg.Text("Port"),
sg.In(size=(25, 1), enable_events=True, key="-port_db2-")
],
[
sg.Button('Test Con2',key='B2')
],
]
layoutprefile = [
[
sg.Column(DB_creds_one),
sg.VSeperator(),
sg.Column(DB_creds_two),
[sg.Output(size=(61, 5), key='-output-')],
[sg.Submit('Proceed'), sg.Cancel('Exit')]
]
]
window = sg.Window("DB Comparator", layoutprefile)
while True: # The Event Loop
event, values = window.read()
# print(event, values) # debug
if event in (None, 'Exit', 'Cancel'):
secondwindow = 0
break
elif event == 'B1':
# Test DB Connection 1 return Test_DB1
uname_d1 = window.FindElement('-uname_db1-')
pword_d1 = window.FindElement('-pword_db1-')
hname_d1 = window.FindElement('-hname_db1-')
sname_d1 = window.FindElement('-sname_db1-')
port_d1 = window.FindElement('-port_db1-')
if uname_d1 and pword_d1 and hname_d1 and sname_d1 and port_d1 == "":
print("ENter values")
else:
Test_DB1 = createCon(uname_d1,pword_d1,hname_d1,sname_d1,port_d1)
elif event == 'B2':
# Test DB Connection 2 return Test_DB2
uname_d2 = window.FindElement('-uname_db2-')
pword_d2 = window.FindElement('-pword_db2-')
hname_d2 = window.FindElement('-hname_db2-')
sname_d2 = window.FindElement('-sname_db2-')
port_d2 = window.FindElement('-port_db2-')
if uname_d2 and pword_d2 and hname_d2 and sname_d2 and port_d2 == "":
print("ENter values")
else:
Test_DB2 = createCon(uname_d2,pword_d2,hname_d2,sname_d2,port_d2)
if event == 'Proceed':
if (Test_DB1 and Test_DB2 != 'True'):
secondwindow = 0
sg.Popup("Incorrect Database Details Please Verify the Connection Again")
else:
window.close()
secondwindow = 1
break
if secondwindow != 1:
exit()