-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
545 lines (479 loc) · 18.5 KB
/
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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
# Application GUI
# Updated 12/06/2021 by Kieran Lane
# Change Log (v1.0)
# 1.0 Initial script creation
# Imports
import PySimpleGUI as sg
import config as cfg
import setup
# Usage 'import gui'
# Examples
# gui.start_interface()
# Interface Keys
# -BTN_PROFILE-
# -BTN_SETTINGS-
# -BTN_THEME-
#
# -IN_USERNAME-
# -IN_PASSWORD-
# -IN_TOKEN-
# -BTN_SFDETAILS-
#
# -IN_OPP-
# -IN_QUOTE-
# -CHK_SEAPPROVE-
# -BTN_QUOTEDETAILS-
#
# -IN_FILTER-
# -BTN_FILTER-
# -BTN_CLEARFILTER-
# -TBL_ADDRESSES-
# -BTN_ADDRESSES-
#
# -IN_BAN-
# -BTN_BANSEARCH-
# -TBL_AIPS-
# -BTN_AIPS-
#
# -BTN_LOADQUOTE-
# -TBL_QUOTELINES-
# -IN_DSR-
# -BTN_SPCR-
#
# -OUT_CONSOLE-
# SCRIPT START
# def start_interface():
settings_confirm = False
double_filter = False
sg.ChangeLookAndFeel('DarkGrey13')
# menu_def = [
# ['File', ['Open', 'Save', 'Exit', 'Properties']],
# ['Help', 'About']
# ]
layout = [
# UI Menu
# [
# sg.Menu(
# menu_def,
# tearoff=False
# )
# ],
# UI Elements
[
# Centered UI
sg.Frame(
'',
layout=[
# Title and Theme Selector
[
# Settings
sg.Button(
image_filename=cfg.get_files('settings'),
image_size=(30, 30),
image_subsample=40,
button_color=None,
key='-BTN_SETTINGS-'
),
# Title
sg.Text(
'Scenario Manager SE Tools',
size=(50, 1),
justification='center',
font=("Helvetica", 25)
),
# Theme Selector
sg.Button(
image_filename=cfg.get_files('theme'),
image_size=(30, 30),
image_subsample=40,
button_color=None,
key='BTN_THEME'
)
],
# Section Divider
[
sg.Text(
'',
size=(16, 2),
justification='center'
)
],
# Salesforce Details and Quote Details Sections
[
# Salesforce Details
sg.Frame(
layout=[
# Username
[
sg.Text(
'Username',
size=(8, 1),
),
sg.InputText(
'*@centurylink.com',
size=(18, 1),
key='-IN_USERNAME-'
)
],
# Password
[
sg.Text(
'Password',
size=(8, 1)
),
sg.InputText(
'P@ssW0rd!',
size=(18, 1),
key='-IN_PASSWORD-'
)
],
# API Token
[
sg.Text(
'APIToken',
size=(8, 1)
),
sg.InputText(
'ThnksFrThMmrs1',
size=(18, 1),
key='-IN_TOKEN-'
)
],
# Save Button
[
sg.Button(
button_text='Save Details',
size=(25, 1),
key='-BTN_SFDETAILS-'
)
]
],
title='Salesforce Details',
element_justification='center',
title_location=sg.TITLE_LOCATION_TOP,
font=('', 15)
),
# Section Divider
sg.Text(
' ',
size=(16, 2),
justification='center',
font=('', 10)
),
# Quote Details
sg.Frame(
layout=[
# Opportunity
[
sg.Text(
'Opportunity',
size=(16, 1)
),
sg.InputText(
'1234567',
size=(16, 1),
key='-IN_OPP-'
)
],
# Quote Details
[
sg.Text(
'Scenario Manager #',
size=(16, 1)
),
sg.InputText(
'SM123456',
size=(16, 1),
key='-IN_QUOTE-'
)
],
# SE Approval
[
sg.Text(
'Above information is needed for all sections',
size=(31, 1)
)
],
# Load Button
[
sg.Button(
button_text='SE Approve',
size=(30, 1),
key='-BTN_SEAPPROVE-'
)
]
],
title='Quote Details',
element_justification='center',
title_location=sg.TITLE_LOCATION_TOP,
font=('', 15)
)
],
# Section Divider
[
sg.Text(
'',
size=(16, 2),
justification='center'
)
],
# Add Addresses, Bulk Import of AIPs, Bulk Add SPCR ID
[
# Add Address
sg.Frame(
'Add Addresses',
layout=[
# Address Filtering
[
sg.Text('Filter', size=(6, 1), auto_size_text=True, justification='left'),
sg.InputText('LO', size=(20, 1), key='-IN_FILTER-'),
sg.Button(button_text='Filter', key='-BTN_FILTER-'),
sg.Button(button_text='Reset', key='-BTN_CLEARFILTER-')
],
# Address Table
[
sg.Table(
values=cfg.get_addresses('value'),
headings=cfg.get_addresses('header'),
display_row_numbers=False,
auto_size_columns=False,
justification='center',
# select_mode=sg.TABLE_SELECT_MODE_EXTENDED,
col_widths=cfg.get_addresses('column'),
num_rows=cfg.get_addresses('length'),
key='-TBL_ADDRESSES-',
# vertical_scroll_only=False
# min(25, len(cfg.get_addresses('value')))
)
],
# Address Submit
[
sg.Button(
button_text='Add',
size=(25, 1),
key='-BTN_ADDRESSES-'
)
]
],
element_justification='center',
title_location=sg.TITLE_LOCATION_TOP,
font=('', 15)
),
# Bulk Import AIPs
sg.Frame(
'Bulk Import AIPs',
layout=[
# BAN Search
[
sg.Text(
'BAN #',
size=(6, 1),
auto_size_text=True,
justification='left'
),
sg.InputText(
'123456',
size=(20, 1),
key='-IN_BAN-'
),
sg.Button(
button_text='Search',
key='-BTN_BANSEARCH-'
)
],
# AIP Table
[
sg.Table(
values=cfg.get_aip('value'),
headings=cfg.get_aip('header'),
display_row_numbers=False,
auto_size_columns=False,
justification='center',
col_widths=cfg.get_aip('column'),
num_rows=cfg.get_aip('length'),
key='-TBL_AIPS-',
# vertical_scroll_only=False
# min(25, len(cfg.get_aip('value')))
)
],
# Import Button
[
sg.Button(
button_text='Import',
size=(25, 1),
key='-BTN_AIPS-'
)
]
],
element_justification='center',
title_location=sg.TITLE_LOCATION_TOP,
font=('', 15)
),
# Bulk Add SPCR ID
sg.Frame(
'Bulk Add SPCR ID',
layout=[
# Load Quote Lines
[
sg.Button(
button_text='Load Quote',
size=(25, 1),
key='-BTN_LOADQUOTE-'
)
],
# SPCR Table
[
sg.Table(
values=cfg.get_spcr('value'),
headings=cfg.get_spcr('header'),
display_row_numbers=False,
auto_size_columns=False,
justification='center',
col_widths=cfg.get_spcr('column'),
num_rows=cfg.get_spcr('length'),
key='-TBL_QUOTELINES-',
# vertical_scroll_only=False
# min(25, len(cfg.get_aip('value')))
)
],
# Add SPCR Button
[
sg.Text('SPCR #', size=(6, 1), auto_size_text=True, justification='left'),
sg.InputText('DSR123456', size=(20, 1), key='-IN_DSR-'),
sg.Button(button_text='Add SPCR', key='-BTN_SPCR-')
]
],
element_justification='center',
title_location=sg.TITLE_LOCATION_TOP,
font=('', 15)
)
],
# Section Divider
[
sg.Text(
'',
size=(16, 2),
justification='center'
)
],
# Console
# [
# sg.Frame(
# 'Console',
# layout=[
#
# # Console Element
# [
# sg.Output(
# size=(155, 5),
# key='-OUT_CONSOLE-'
# )
# ]
# ],
# element_justification='center',
# title_location=sg.TITLE_LOCATION_TOP,
# font=('', 15)
# )
# ]
],
element_justification='center',
border_width=0
)
]
]
window = sg.Window('Scenario Manager Tools', layout, default_element_size=(40, 1), grab_anywhere=False, finalize=True)
# Updating default values from saved configuration
window['-IN_USERNAME-'].update(cfg.config_file('username', 'read', ''))
window['-IN_PASSWORD-'].update(cfg.config_file('password', 'read', ''))
window['-IN_TOKEN-'].update(cfg.config_file('token', 'read', ''))
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
# print(event, values)
# sg.Print(window['-TBL_ADDRESSES-'].get())
# Setup Details
if event == '-BTN_SFDETAILS-':
cfg.config_file('username', 'write', values['-IN_USERNAME-'])
cfg.config_file('password', 'write', values['-IN_PASSWORD-'])
cfg.config_file('token', 'write', values['-IN_TOKEN-'])
print("Details have been successfully saved to " + cfg.config_file('path', 'read', ''))
print("These values will be loaded at next launch!")
print("Please note, manually editing this file may cause issues, delete if you encounter issues.")
print("")
if event == '-BTN_SEAPPROVE-':
test = cfg.se_approve(values['-IN_OPP-'], values['-IN_QUOTE-'])
print(test)
if event == '-BTN_SETTINGS-':
if not setup.driver_setup() or settings_confirm:
if not setup.driver_setup():
print("Chrome Web Driver appears to be missing, please wait...")
print("Starting download of latest chrome driver")
print("OS identified as " + setup.what_am_i())
setup.latest_download()
settings_confirm = False
print("Setup complete")
print("")
elif setup.driver_setup():
print("Chrome Web Driver appears to be present, you can update by clicking the 'Settings' button again")
print("")
settings_confirm = True
# Add Addresses
if event == '-BTN_FILTER-':
if not double_filter:
window['-TBL_ADDRESSES-'].update(
values=cfg.get_addresses('value', 'filter', values['-IN_FILTER-'], '')
)
double_filter = True
elif double_filter:
window['-TBL_ADDRESSES-'].update(
values=cfg.get_addresses('value', 'filter', values['-IN_FILTER-'], window['-TBL_ADDRESSES-'].get())
)
if event == '-BTN_CLEARFILTER-':
window['-TBL_ADDRESSES-'].update(
values=cfg.get_addresses('value')
)
double_filter = False
if event == '-BTN_ADDRESSES-':
selected_values = []
full_table = window['-TBL_ADDRESSES-'].get()
selected = values['-TBL_ADDRESSES-']
for i in selected:
selected_values.append(full_table[i][1])
print(selected_values)
print("INSERT FUNCTION TO USE THESE VALUES TO ADD ADDRESSES")
print("")
# Import AIPs
if event == '-BTN_BANSEARCH-':
aips = cfg.get_aip(mode='prod', ban=values['-IN_BAN-'])
if aips == 'Invalid BAN':
print("Invalid BAN - Please correct")
else:
window['-TBL_AIPS-'].update(values=aips['value'])
print("Successfully got AIPs")
print("")
if event == '-BTN_AIPS-':
selected_values = []
full_table = window['-TBL_AIPS-'].get()
selected = values['-TBL_AIPS-']
for i in selected:
selected_values.append(full_table[i][0])
print(selected_values)
print("INSERT FUNCTION TO USE THESE VALUES TO IMPORT AIPS")
print("")
# Add SPCR
if event == '-BTN_LOADQUOTE-':
quote = values['-IN_QUOTE-']
print("INSERT FUNCTION TO GET LINE ITEMS IN QUOTE " + quote + " AND ADD TO TABLE")
print("")
if event == '-BTN_SPCR-':
selected_values = []
spcr = values['-IN_DSR-']
full_table = window['-TBL_QUOTELINES-'].get()
selected = values['-TBL_QUOTELINES-']
for i in selected:
selected_values.append(full_table[i][0])
print(selected_values)
print("INSERT FUNCTION TO ADD " + spcr + " SPCR ID TO THESE SELECTED LINES")
print("")
window.close()