-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_gui.py
68 lines (55 loc) · 2.12 KB
/
export_gui.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
import PySimpleGUI as sg
import ipaddress
from pyxl import csvread,validip
from export_to_sql import exportsql
def export_to_sql_gui():
sg.theme('kayak')
path = 'Teacher_data.xlsx'
host = 'localhost'
user = 'root'
password = ''
db_pref = csvread()
if db_pref != None:
if db_pref[0][1] == 'sql':
sql = True
host = db_pref[1][1]
user = db_pref[2][1]
password = db_pref[3][1]
if db_pref[0][1] == 'exel':
sql = False
path = db_pref[1][1]
layout_sql = [
[sg.Text('Host : ') ,sg.InputText( key='Host' ,default_text=host,expand_x=True), ],
[sg.Text('User : ') ,sg.InputText( key='User',default_text=user,expand_x=True), ],
[sg.Text('Password : ') ,sg.InputText( key='Password',default_text=password,expand_x=True),],
]
layout_exel = [
[],
[sg.Text('Select File :'),sg.InputText( key='-FILENAME-',default_text=path), sg.FileBrowse(enable_events=True)],
]
layout = [
[sg.Frame('SQL',layout_sql,expand_x=True)],
[sg.Frame('Excel',layout_exel,expand_x=True)],
[sg.Button('Export',disabled=True),sg.Push(),sg.Button('Exit')]
]
window = sg.Window('Title', layout)
while True:
event, values = window.read(timeout=100)
if event in (sg.WIN_CLOSED,'Exit'):
break
if validip(values['Host']) or values['Host'] == 'localhost' and values['User'] and values['-FILENAME-'] :
window['Export'].update(disabled=False)
else:
window['Export'].update(disabled=True)
if event == 'Export':
db_config = {
'host': values['Host'],
'user': values['User'],
'password': values['Password'],
}
x = exportsql(db_config,values['-FILENAME-'])
if x[0] == 'Error':
sg.popup(x[1])
else:
sg.popup(f'{x[0]} teacher records uploaded to sql database')
window.close()