Jul-08-2019, 10:22 PM
I'm using PySimpleGUI and PyAutoGUI to automate a very tedious Excel to Enovia data migration project, where my task is to look for a part on Enovia, type in specific attributes from excel and save it. I came up with this, it takes these initial conditions, manipulates the mouse and keyboard and edits the part for me.
The makeChanges() function has been tested extensively standalone and is doing great at editing it. However when I use the 'Edit' button, it executes the makeChanges() function except it freezes the GUI and will essentially crash if messed with, unless the entire makeChanges() function has executed, and only then is the GUI manipulatable.
The makeChanges() function has been tested extensively standalone and is doing great at editing it. However when I use the 'Edit' button, it executes the makeChanges() function except it freezes the GUI and will essentially crash if messed with, unless the entire makeChanges() function has executed, and only then is the GUI manipulatable.
import PySimpleGUI as sg import pyautogui, time, ctypes pyautogui.FAILSAFE = True pyautogui.PAUSE = 1 #Setting up lazy variables s = time.sleep moveToo = ctypes.windll.user32.SetCursorPos#(x, y) coords, py = pyautogui #Initializing Layout of Window and acquiring initial conditions layout = [[sg.Text('Please enter initial conditions(Only the first two letters)')], [sg.Text('Desired Lines', size=(14, 1)), sg.Input(size=(20,1), key='lines')], [sg.Text('Company Name ', size=(14, 1)), sg.InputText(size=(20,1), key='company')], [sg.Text('Filetype', size=(14, 1)), sg.InputText(size=(20,1), key='filetype')], [sg.Text('Dashnumbers', size=(14, 1)), sg.InputText(size=(20,1), key='dashnumbers')], [sg.Button('Edit'), sg.Button('Quit'), sg.Button('Continue')]] window = sg.Window('Automatic Intern', layout) #Button Callback Functions def Bu1(): #Button 1 makeChanges(values['company'], values['dashnumbers'], values['filetype']) def Bu2(): #Button 2 window.Close() #Callback Edit Function def makeChanges(company, dashnumbers, filetype): for i in range(len(lines)): #Convert to integars lines[i] = int(lines[i]) lines[i] -= 1 #Subtract 1 to get real row numbers print(lines[i]) #Parse through lines and make necessary edits for n, val in enumerate(lines): #Iterate through each element print(lines[n]) #Print element value py.moveTo(497,258,0.5)#Move to First Dropdown Marker, Checkpoint 1 py.moveRel(0,30*lines[n]) #Add another function that exectues the edit py.click() py.moveRel(73, 124) py.click() s(2.5) py.moveTo(249, 256)#Moving to and Clicking Hamburger Menu py.click() py.moveTo(273, 281)#Moving to and Clicking Edit Details py.click() py.moveTo(394, 786)#Moving to 'Customer' dropdown py.click() py.typewrite(company)#Typewrite given Company py.hotkey('tab') py.typewrite(dashnumbers)#Typein py.hotkey('space') py.hotkey('tab') py.typewrite(filetype)#Given Filetype py.hotkey('tab') py.hotkey('enter') py.moveTo(843, 98)#Move and Click Search Bar py.click() py.moveTo(806, 125)#Click last search result py.click() s(2) print('Done') event, values = window.Read() #Acquriing data in GUI lines = values['lines'].split(' ') print(event) if event == 'Edit': #Pass onto makeChanges() Bu1() window.Close() print('Executed') elif event == 'Quit': #Quit the program Bu2() window.Close()What I would like is to for the GUI to be running while the edit function executes instead of freezing, and also in the future, to pause/continue the editing at any given time with buttons I intend to add into the GUI. Please do excuse the ugliness of the code. I'm new and I would love some tips on how to be better, so please do grill me on everything that makes you cringe.
