-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui8b.py
More file actions
821 lines (731 loc) · 29.5 KB
/
gui8b.py
File metadata and controls
821 lines (731 loc) · 29.5 KB
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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
import PySimpleGUI as sg
from tkinter import ttk
from ahk import AHK, Hotkey
import keyboard
import webbrowser
import time
import pandas as pd
import csv
import re
from tempfile import NamedTemporaryFile
import shutil
import csv
import codecs
import datetime
import subprocess
import pyperclip
import win32ui
import os
import sys
# maybe devise ahk script that starts the python program?
ahk = AHK()
#sg.theme('DarkAmber')
sg.theme('DarkTeal6')
for window in ahk.windows():
if b'Mailware' in window.title:
mailware = ahk.find_window(title=window.title)
if b'ibProject' in window.title:
ib = ahk.find_window(title=window.title)
if b'Search for Customer' == window.title:
custfind = ahk.find_window(title=window.title)
custfind.close()
# --- 07/1/21: now writes properly to file ----> need to transpose this into current csv settings
def updating(arg1, **kwargs): # maybe insert a facID column to help id places? going by names always is..not cool
today = datetime.date.today().strftime("%B %d, %Y")
filename = 'AllDetails.csv' #put name of csv file here
tempfile = NamedTemporaryFile(mode='a', delete=False)
newfile = today + '-' + filename
fields = ['Sno', 'Registration Number', 'Name', 'RollNo', 'Status']
with codecs.open(filename, 'r', encoding='utf8') as csvfile, tempfile:
reader = csv.DictReader(csvfile, fieldnames=fields)
writer = csv.DictWriter(tempfile, delimiter=',', lineterminator='\n', fieldnames=fields)
for row in reader:
reg = row['Registration Number']
name = row['Name']
rollno = row['RollNo']
status = row['Status']
for key, value in kwargs.items():
if row['Sno'] == str(arg1) and key == 'regNum':
reg = value
if row['Sno'] == str(arg1) and key == 'name':
name = value
if row['Sno'] == str(arg1) and key == 'rollno':
rollno = value
if row['Sno'] == str(arg1) and key == 'status':
status = value
print('updating row', row['Sno'])
row = ({'Sno': row['Sno'], 'Registration Number': reg, 'Name': name, 'RollNo': rollno, 'Status': status})
writer.writerow(row)
print('Done! Alh')
shutil.move(tempfile.name, filename)
# this function for updating csv entries
# def updatingentry(arg1, **kwargs):
# today = datetime.date.today().strftime("%B %d, %Y")
# filename = 'customers10-Copy.csv'
# tempfile = NamedTemporaryFile(mode='a', delete=False)
# newfile = today + '-' + filename
# fields = ['name', 'street', 'address', 'zip', 'website']
# with codecs.open(filename, 'r', encoding='utf8') as csvfile, tempfile:
# reader = csv.DictReader(csvfile, fieldnames=fields)
# writer = csv.DictWriter(tempfile, delimiter=',', lineterminator='\n', fieldnames=fields)
# for row in reader:
# name = row['name']
# street = row['street']
# address = row['address']
# zip = row['zip']
# website = row['website']
# for key, value in kwargs.items():
# if row['name'] == str(arg1) and key == 'street':
# street = value
# if row['name'] == str(arg1) and key == 'address':
# address = value
# if row['name'] == str(arg1) and key == 'zip':
# zip = value
# if row['name'] == str(arg1) and key == 'website':
# website = value
# if row['name'] == str(arg1) and key == 'name':
# name = value
# print('updating row', row['name'])
# row = ({'name': name, 'street': street, 'address': address, 'zip': zip, 'website': website})
# writer.writerow(row)
# print('Done! Alh')
# shutil.move(tempfile.name, filename)
#updating2('Bibb Correctional Facility', street='565 Bibb Lane, Apt. #625')
#updating2('Bibb Correctional Facility', street='565 Bibb Lane')
# this function for making new entries to csv
# def newentry(arg1, **kwargs):
# filename = 'customers10-Copy.csv'
# #filename = 'customers10.csv'
# fields = ['name', 'street', 'address', 'zip', 'website']
# with codecs.open(filename, 'a', encoding='utf8') as csvfile:
# writer = csv.DictWriter(csvfile, delimiter=',', lineterminator='\n', fieldnames=fields)
# name = str(arg1)
# street = ''
# address = ''
# zip = ''
# website = ''
# for key, value in kwargs.items():
# if key == 'street':
# street = value
# if key == 'address':
# address = value
# if key == 'zip':
# zip = value
# if key == 'website':
# website = value
# row = ({'name': name, 'street': street, 'address': address, 'zip': zip, 'website': website})
# writer.writerow(row)
# print('Done! Alh')
# def finding(input):
# f = open('customers10.csv', 'rt') #also #filename = 'customers10-Copy.csv'
# csv_reader = csv.DictReader(f, escapechar='\\')
# # check = 'bibb'
# for row in csv_reader:
# if input.title() in row['name']:
# print(row['name'])
# print(row['address'])
# print(row['street'])
# print(row['zip'])
# return row['name']
# else:
# return "Not found! Please contact admin."
# f.close
# def WindowExists(classname):
# try:
# win32ui.FindWindow(classname, None)
# except win32ui.error:
# return False
# else:
# return True
def finding(fn, ln):
for window in ahk.windows():
if b'Search for Customer' == window.title:
custfind = ahk.find_window(title=window.title)
custfind.close()
if b'Mailware' in window.title:
mailware = ahk.find_window(title=window.title)
mailware.activate()
# try:
# custfind.activate()
# except NameError:
# mailware.activate()
# mailware.activate()
# keyboard.send('esc')
keyboard.send('f4')
time.sleep(1)
keyboard.send('alt+f')
keyboard.write(fn.strip())
keyboard.send('tab')
keyboard.write(ln.strip())
time.sleep(1)
keyboard.send('enter')
# don't bother with find inmate aspect, just keep program to creating account with info given
# when running find_inmate, add continue after its called in while loop
# def find_inmate(fn, ln, inm):
# try:
# mailware.activate()
# except NameError:
# sg.popup('Mailware not active, now starting program - please wait.')
# subprocess.call([r"C:\Program Files (x86)\Mailware 2014\Mailware.exe"])
# try:
# custfind.activate()
# except NameError:
# keyboard.send('f4')
# keyboard.send('esc')
# keyboard.send('f4')
# keyboard.send('alt+f') # this puts cursor at first name in mailware
# keyboard.write(fn.title())
# keyboard.send('tab')
# keyboard.write(ln.title())
# keyboard.send('enter')
# return fn, ln, inm
"""
def my_popup():
for window in ahk.windows():
if b'Mailware' in window.title:
mailware = ahk.find_window(title=window.title)
if b'ibProject' in window.title:
ib = ahk.find_window(title=window.title)
if b'Search for Customer' in window.title:
custfind = ahk.find_window(title=window.title)
if b'Inmate Account' in window.title:
prog = ahk.find_window(title=window.title)
layout1 = [
[sg.Text("Does inmate customer account exist?")],
[sg.Button("Yes, done for now."), sg.Button("No, proceed to click on 'Create Account'.")]
]
win = sg.Window("My Popup", layout1, modal=True,
grab_anywhere=True, enable_close_attempted_event=True)
ev, val = win.read()
if ev in (sg.WINDOW_CLOSED, 'Yes, done for now.', sg.WINDOW_CLOSE_ATTEMPTED_EVENT, 'CANCEL'):
custfind.activate()
win.close()
if ev == "No, proceed to click on 'Create Account'.":
#prog.activate() >>>> need to fix here (how to revert focus back to main program)
win.close()
win.close()
#window.write_event_value(event, None)
"""
# below functions take inputs and puts them into mailware, after some stuff checked
# this function finds data from CSV based on facility, so facility's address info
# def fieldentry(facility):
# #f = open('customers10.csv', 'rt')
# f = open('customers10-Copy.csv', 'rt')
# csv_reader = csv.DictReader(f, escapechar='\\')
# for row in csv_reader:
# if facility in row['name']: # >>>>>>>>>>>>>>>>> need to update this logic, add 2nd check
# n = row['name'] # like matching state as well as facility !! <<<<--- 09/10/21
# str = row['street']
# str2 = row['street2']
# zpp = row['zip']
# break
# f.close
# print(row)
# results = [n, str, str2, zpp]
# return results
#this function finds data from CSV based on facility, so facility's address info
def fieldentry2(facility, state):
#f = open('customers10.csv', 'rt')
f = open('customers10-Copy.csv', 'rt')
csv_reader = csv.DictReader(f, escapechar='\\')
for row in csv_reader:
if facility in row['name'] and state in row['address']: # >>>>>>>>>>>>>>>>> need to update this logic, add 2nd check
n = row['name'] # like matching state as well as facility !! <<<<--- 09/10/21
strt = row['street']
if row['street2'] is not None:
strt2 = row['street2'], #need to add this also, 12/01/21, done on 12/09/21
zpp = row['zip']
break
f.close
print(row)
if row['street2'] is not None and len(row['street2']) > 1:
# 01/28/22: fix the below, the str casting of str2, looks like a tuple inside mailware
results = [n.strip(), strt.strip(), str(strt2).strip(), zpp.strip()] #add str2 to this array <<< 12/01/21, then continue tracing where else code needs to be updated
else:
results = [n.strip(), strt.strip(), zpp.strip()]
return results
# finish here!!!
def lencheck(fac, fn, ln, inm):
#print(len(fn))
for ele in fac:
assert (len(ele) <= 40), "Facility name is too long; 40 char limit."
assert (len(fn) <= 15), "Check inmate's first name: will be truncated if longer than 15 characters."
assert (len(ln+' #'+str(inm)) <= 20), "Check inmate's last name + number: will be truncated if longer than 20 characters."
return fac, fn, ln, inm
"""
>>> this is how to handle lencheck results, let user know if length too long
try:
lencheck('joe', 'ok', '123')
except AssertionError:
print("Careful with inmate information - some part may be too long and thus shorted by Mailware.")
"""
# this function updates the address in mailware
def mailwareupdate(fac):
for window in ahk.windows():
if b'Search for Customer' == window.title:
custfind = ahk.find_window(title=window.title)
custfind.close()
if b'Mailware' in window.title:
mailware = ahk.find_window(title=window.title)
mailware.activate()
keyboard.send('f4')
keyboard.send('esc')
keyboard.send('alt+n') #this entry puts cursor at first name of new customer form
keyboard.send('alt+c') #this entry takes program to current customer
keyboard.send('esc') #this ensures that no popup gets in the way
#keyboard.send('alt+p') #this entry puts cursor at first name of ship-to address
#keyboard.write(fn)
keyboard.send('tab')
keyboard.send('tab')
#keyboard.write(ln+' '+'#'+inm)
keyboard.send('tab')
keyboard.send('tab')
keyboard.write(fac[0]) # prison name
keyboard.send('tab')
keyboard.write(fac[1]) # street address
keyboard.send('tab')
#if isinstance(fac[2], str):
if len(fac) == 4:
keyboard.write(fac[2]) # street address 2
keyboard.send('tab')
keyboard.send('tab')
str_zip = str(fac[3])
zip_zero = str_zip.zfill(5)
keyboard.write(zip_zero) # zip code
# time.sleep(1)
keyboard.send('tab')
keyboard.send('tab')
else:
keyboard.send('tab')
keyboard.send('tab')
str_zip = str(fac[2])
zip_zero = str_zip.zfill(5)
keyboard.write(zip_zero) # zip code
# time.sleep(1)
keyboard.send('tab')
keyboard.send('tab')
# if fac[3] == 85132:
# keyboard.write(fac[3]) # zip code
# keyboard.send('tab')
# #time.sleep(2)
# #keyboard.write('Florence') # because this ZIP is bugged in mailware, adding "Florence" and AZ manually
# keyboard.write('Florence', 1) # 09/30/21: still doesn't work, mailware wont let auto add in this case..stupid zip
# keyboard.send('tab')
# keyboard.write('AZ')
#else:
#ib.activate() # this if want to refocus back to pycharm
# str_zip = str(fac[2])
# zip_zero = str_zip.zfill(5)
# keyboard.write(zip_zero) # zip code
# # time.sleep(1)
# keyboard.send('tab')
# keyboard.send('tab')
# # 10/08/21: updated above, now also picks up on 0's in updating addr zip
# # keyboard.write(fac[2]) # zip code
# # #time.sleep(1)
# # keyboard.send('tab')
# # keyboard.send('tab')
# # #ib.activate() # this if want to refocus back to pycharm
# 10/26/21: solution for PA state facilities>> keep two entries for all PA facs, one for bill-to
# and other for ship-to, when input request comes for any PA state fac, then take all info
# from those two entries (need to correlate positioning of cursor with respect to ship-to too
def mailwarefocus(fac, fn, ln, inm):
for window in ahk.windows():
if b'Search for Customer' == window.title:
custfind = ahk.find_window(title=window.title)
custfind.close()
if b'Mailware' in window.title:
mailware = ahk.find_window(title=window.title)
mailware.activate()
keyboard.send('f4')
keyboard.send('esc')
keyboard.send('alt+n') #this entry puts cursor at first name of new customer form
#keyboard.send('alt+c') #this entry takes program to current customer
keyboard.write(fn.capitalize())
keyboard.send('tab')
keyboard.send('tab')
keyboard.write(ln.capitalize()+' '+'#'+inm)
keyboard.send('tab')
keyboard.send('tab')
keyboard.write(fac[0]) # prison name
keyboard.send('tab')
keyboard.write(fac[1]) # street address
keyboard.send('tab')
#if isinstance(fac[2], str):
if len(fac) == 4:
keyboard.write(fac[2]) # street address 2
keyboard.send('tab')
keyboard.send('tab')
str_zip = str(fac[3])
zip_zero = str_zip.zfill(5)
keyboard.write(zip_zero) # zip code
# time.sleep(1)
keyboard.send('tab')
keyboard.send('tab')
else:
keyboard.send('tab')
keyboard.send('tab')
str_zip = str(fac[2])
zip_zero = str_zip.zfill(5)
keyboard.write(zip_zero) # zip code
# time.sleep(1)
keyboard.send('tab')
keyboard.send('tab')
# if len(fac[2]) > 0:
# keyboard.write(fac[2]) # street address, line 2, needs to be added everywhere required, 12/01/21, done 12/09/21
# keyboard.send('tab')
# keyboard.send('tab')
# if fac[3] == 85132:
# keyboard.write(fac[3]) # zip code
# keyboard.send('tab')
# time.sleep(2)
# #keyboard.write('Florence') # because this ZIP is bugged in mailware, adding "Florence" and AZ manually
# keyboard.write('Florence', 2) # 09/30/21: still doesn't work, mailware wont let auto add in this case..stupid zip
# keyboard.send('tab')
# keyboard.write('AZ')
# else:
# str_zip = str(fac[3]) #12/09/21: edited to fac[3], should now reference zip code
# zip_zero = str_zip.zfill(5)
# keyboard.write(zip_zero) # zip code
# #time.sleep(1)
# keyboard.send('tab')
# keyboard.send('tab')
# #ib.activate() # this if want to refocus back to pycharm
# now zipcodes will always have 5 digits minimum (problem when dealing with states beginning with 0
# str_inm_num = str(values['inm'])
# tx_zerofilled = str_inm_num.zfill(8)
# pyperclip.copy(tx_zerofilled)
states0 = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DC", "DE", "FL", "GA",
"HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD",
"MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ",
"NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC",
"SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]
us_state_abbrev = {
'Alabama': 'AL',
'Alaska': 'AK',
'American Samoa': 'AS',
'Arizona': 'AZ',
'Arkansas': 'AR',
'California': 'CA',
'Colorado': 'CO',
'Connecticut': 'CT',
'Delaware': 'DE',
'District of Columbia': 'DC',
'Florida': 'FL',
'Georgia': 'GA',
'Guam': 'GU',
'Hawaii': 'HI',
'Idaho': 'ID',
'Illinois': 'IL',
'Indiana': 'IN',
'Iowa': 'IA',
'Kansas': 'KS',
'Kentucky': 'KY',
'Louisiana': 'LA',
'Maine': 'ME',
'Maryland': 'MD',
'Massachusetts': 'MA',
'Michigan': 'MI',
'Minnesota': 'MN',
'Mississippi': 'MS',
'Missouri': 'MO',
'Montana': 'MT',
'Nebraska': 'NE',
'Nevada': 'NV',
'New Hampshire': 'NH',
'New Jersey': 'NJ',
'New Mexico': 'NM',
'New York': 'NY',
'North Carolina': 'NC',
'North Dakota': 'ND',
'Northern Mariana Islands':'MP',
'Ohio': 'OH',
'Oklahoma': 'OK',
'Oregon': 'OR',
'Pennsylvania': 'PA',
'Puerto Rico': 'PR',
'Rhode Island': 'RI',
'South Carolina': 'SC',
'South Dakota': 'SD',
'Tennessee': 'TN',
'Texas': 'TX',
'Utah': 'UT',
'Vermont': 'VT',
'Virgin Islands': 'VI',
'Virginia': 'VA',
'Washington': 'WA',
'West Virginia': 'WV',
'Wisconsin': 'WI',
'Wyoming': 'WY'
}
# thank you to @kinghelix and @trevormarburger for this idea
abbrev_us_state = dict(map(reversed, us_state_abbrev.items()))
myDict = {}
def statesfac():
# below will create dictionary that to populate two combo boxes
for s in states0:
#f = open('customers10.csv', 'rt')
f = open('customers10-Copy.csv', 'rt')
csv_reader = csv.DictReader(f, escapechar='\\')
addr = []
for row in csv_reader:
saved = row['address']
#addr.append(saved)
if s in abbrev_us_state:
j = abbrev_us_state[s]
# print(abbrev_us_state[i])
st = re.search('[^0-9]+(\,\s){1}(?P<state>[A-Z]{2}|[A-Za-z]+){1}\s([0-9]{5})', saved).groupdict()['state']
if s == st:
addr.append(row['name']) #change this to append also street2 or physicalstreet if h3[i-2] !=h0[1]
if j == st:
addr.append(row['name'])
myDict[s] = addr
print("done: "+s)
print(myDict['AZ'])
# now run first instance of this func to populate combo boxes, can run again later if it csv updated within program
statesfac()
"""
q1 = input("do you need to update anything?")
if q1 == 'yes':
q_name = input("name?")
q_street = input("street?")
q_address = input("address?")
q_zip = input("zip?")
q_website = input("website?")
newentry(q_name, street=q_street, address=q_address, zip=q_zip, website=q_website)
"""
def testeree():
print("ok here is good")
options = {
"font": ('Helvetica', 16),
"size": (25, 5),
"readonly": True,
"enable_events": True,
#"element_justification": 'center'
}
options2 = {
"font": ('Helvetica', 16),
"size": (45, 5),
"readonly": True,
"enable_events": True,
}
# below is labels
firstname = sg.Text("Inmate First Name:", justification='center')
lastname = sg.Text("Inmate Last Name:", justification='left')
inmnumber = sg.Text("Inmate Number: ", justification='left')
stateselectlabel = sg.Text("First, select state: ", justification='left')
facilityselected = sg.Text("Then, choose facility: ", justification='left')
# below is input areas
fn = sg.Input(key='fn', tooltip='Enter inmate first name here = ', size=(30,1), justification='center')
ln = sg.Input(key='ln', tooltip='Enter inmate last name here = ', size=(30,1), justification='center')
inm = sg.Input(key='inm', tooltip='Enter inmate number here =: ', size=(30,1), justification='center')
# , justification='left'
# arrangement of buttons:
# check info online
# check inmate name in mailware
# update account in mailware
# create inmate account
# quit
# clear all data
"""
search
find
updateinfo
x
y
z
"""
# these are buttons
x = sg.Button('Create Inmate Account')
y = sg.Button('Quit')
z = sg.Button('Clear All Data')
xyz = sg.Button('Need to create or update facility info?')
search = sg.Button('Check Info Online')
updateinfo = sg.Button('Update Address in Mailware')
newfac = sg.Button('Add New Facility to CSV - Admin Only')
find = sg.Button('Find Inmate in JPay')
restart = sg.Button('Restart Program')
#fin = sg.Button('Find Inmate')
layout = [
[firstname],
[fn],
[lastname],
[ln],
[inmnumber],
[inm],
[stateselectlabel],
[sg.Combo(sorted(list(myDict.keys())), **options, key="mainproject", tooltip='Select state first, then facility below.')],
[facilityselected],
[sg.Combo((), **options2, key="subproject", tooltip='Select state above first, then facility.')],
#[fin],
[search],
[find],
[updateinfo],
[x],
[y],
[z],
#[restart]
]
window = sg.Window('Inmate Account Creation', layout, use_ttk_buttons=True, finalize=True, resizable=True)
#window2 = sg.Window('Updating/Creating New Facility', layout2, use_ttk_buttons=True, finalize=True)
while True:
event, values = window.read()
ready = False
if event in (sg.WINDOW_CLOSED, 'Quit'):
break
# elif event == 'Restart Program': #---10/20/21: doesnt work yet, trying to restart itself
# os.execl(sys.executable, 'python', __file__, *sys.argv[1:])
elif event == "mainproject":
testeree()
lst = sorted(myDict[values[event]])
window['subproject'].Update(value=lst[0], values=lst)
ready = True
#elif event == 'Find Inmate': # here, just have inmate info pulled from custfind, which should already be open
# 08/03/21: no, don't pull custfind or any cust searching info, just do acc creation with this program
#find_inmate(values['fn'], values['ln'], values['inm'])
#time.sleep(2)
#sg.popup("Was inmate found?")
# from here, take values entered into name first and last, then close cust find window (via escape)
#my_popup() # <<< change here
#continue
elif event == 'Find Inmate in JPay':
#url_jpay = 'https://www.google.com/search?q=' + values['mainproject'] + ' inmate locator'
url_jpay = 'https://www.jpay.com/SearchResult.aspx?searchText='+values['inm']+'&searchState='+values['mainproject']+'&returnUrl=InmateInfo.aspx'
webbrowser.open(url_jpay, new=0, autoraise=True)
elif event == 'Check Inmate Name in Mailware':
if values['fn'] == '' or values['ln'] == '':
sg.popup("Please input first and last name.", title="Error")
continue
try:
finding(values['fn'], values['ln'])
except NameError:
sg.popup("Something not running, contact Admin.", title="Error")
continue
elif event == 'Create Inmate Account':
try: #below is where 2 instances of fieldentry being changed for testing fieldentry2
#lencheck(fieldentry(values['subproject']), values['fn'], values['ln'], values['inm'])
lencheck(fieldentry2(values['subproject'], values['mainproject']), values['fn'], values['ln'], values['inm'])
except AssertionError:
sg.popup("Length of one or more fields is too long, will be truncated by Mailware - verify account info!")
#mailwarefocus(fieldentry(values['subproject']), values['fn'], values['ln'], values['inm'])
mailwarefocus(fieldentry2(values['subproject'], values['mainproject']), values['fn'], values['ln'], str(values['inm']).upper())
continue
#mailwarefocus(fieldentry(values['subproject']), values['fn'], values['ln'], values['inm'])
if values['fn'] == '' or values['ln'] == '' or values['inm'] == '' or values['subproject'] == '':
sg.popup("Please select state and enter complete info for all fields.", title="Error")
#window['fn'].update('')
#window['ln'].update('')
#window['inm'].update('')
continue
try:
#mailwarefocus(fieldentry(values['subproject']), values['fn'], values['ln'], values['inm'])
mailwarefocus(fieldentry2(values['subproject'], values['mainproject']), values['fn'], values['ln'], str(values['inm']).upper())
#sg.Popup('Ok clicked', keep_on_top=True)
continue
except NameError:
sg.popup("Mailware needs to be turned on!")
continue
#if event == 'Add New Facility to CSV - Admin Only':
#newentry()
if event == 'Clear All Data':
window['fn'].update('')
window['ln'].update('')
window['inm'].update('')
window['mainproject'].update('')
window['subproject'].update('')
keyboard.send('tab')
if event == 'Check Info Online':
url = 'https://www.google.com/search?q=' + values['mainproject'] + ' inmate locator'
vinelinks = ['LA', 'MA', 'AK']
if (values['mainproject'] in vinelinks):
url = 'https://www.google.com/search?q=' + values['mainproject'] + ' vinelink inmate'
if values['inm'] == '' or values['mainproject'] == '':
sg.popup("Please enter inmate number and state to search that DOC.", title="Error")
#window['fn'].update('')
#window['ln'].update('')
#window['inm'].update('')
continue
else:
if values['mainproject'] == 'TX':
str_inm_num = str((values['inm']).strip())
tx_zerofilled = str_inm_num.zfill(8)
pyperclip.copy(tx_zerofilled)
elif values['mainproject'] == 'AR':
str_inm_num = str((values['inm']).strip())
ar_zerofilled = str_inm_num.zfill(6)
pyperclip.copy(ar_zerofilled)
else:
pyperclip.copy(str((values['inm']).upper()).strip())
# original location of url value, 02/07/22
webbrowser.open(url, new=0, autoraise=True)
if event == 'Update Address in Mailware':
#mailwareupdate(fieldentry(values['subproject']))
mailwareupdate(fieldentry2(values['subproject'], values['mainproject']))
# elif event == 'Need to create or update facility info?':
# break
# q1 = input("Create or Update?")
# if q1 == 'Create':
# facname = input("What is new facility's name?")
# facstreet = input("What is new facility's street?")
# facaddr = input("What is new facility's address?")
# faczip = input("What is new facility's zip?")
# facwebsite = input("What is new facility's street?")
# newentry(facname, street=facstreet, address=facaddr, zip=faczip, website=facwebsite)
# print("Added "+facname+" to CSV!")
# if q1 == 'Update':
# facname = input("What is facility's name?")
# # check logic here! not ready yet
# print(finding(facname))
# facstreet = input("What is new facility's street?")
# facaddr = input("What is new facility's address?")
# faczip = input("What is new facility's zip?")
# facwebsite = input("What is new facility's street?")
# updatingentry(facname, street=facstreet, address=facaddr, zip=faczip, website=facwebsite)
# print("Added "+facname+" to CSV!")
window.close()
"""
elif event == 'Create New Inmate Acc from Search Fields':
for window in ahk.windows():
if b'Search for Customer' == window.title:
custfind = ahk.find_window(title=window.title)
custfind.activate()
else:
sg.popup("No search field open in Mailware.")
continue
keyboard.send('alt+f') # this moves cursor to first name area
keyboard.send('ctrl+c')
texty = pyperclip.paste()
window['fn'].update(texty)
#keyboard.send('alt+l') # this moves cursor to last name area
layout = [
[firstname],
[fn],
[lastname],
[ln],
[inmnumber],
[inm],
[stateselectlabel],
[sg.Combo(list(myDict.keys()), **options, key="mainproject", tooltip='Select state first, then facility below.')],
[facilityselected],
[sg.Combo((), **options, key="subproject", tooltip='Select state above first, then facility.')],
[x],
[y]
]
"""
"""
[ sg.Frame('Labelled Group',[[
a, a1, b, b1, c, c1]])]
[ sg.Frame('Inmate Information',[[
[firstname, fn],
[lastname, ln],
[inmnumber, inm]]])]
# this is name of that shazam print window >>>>
b'Shazam Report Wizard: \\\\paradise\\mailware2013\\data\\Reports\\A - Inmate Standard Letter.srw'
for mailware entry fields:
99999999999999999999 = last name max length is 20 chars
999999999999999 = first name max length is 15 chars
99999999999999999999999999999999999999999999999999999999999999999999 = 69
9999999999999999999999999999999999999999
9999999999999999999999999999999999999999
9999999999999999999999999999999999999999 = max length of addr and company name fields is 40 chars
"""