def ZS_change_user(handle=0xA161A, name='量化优选'): print('------------------开始切换账户--------------', name) user_l = [ '钻石卡 0380327515 普通 湖南鸿通投资 长沙芙蓉中路证券营业部', '钻石卡 0380328755 普通 鸿通量化稳健 长沙芙蓉中路证券营业部' ] if name == '量化优选': name = user_l[0] if name == '量化稳健': name = user_l[1] cb_button = ComboBoxWrapper(handle) cb_button.select(name)
def save_setfile(self, place, band): app, wnd_main = self.run_storm() if None in (app, wnd_main): self.controller.send_msg('w', 'Error', "Can't start StormInterface", 1) return check = CheckStorm( kwargs={ 'currTest': self, 'app': app, 'place': place, 'band': band, 'controller': self.controller }) check.start() if place <= 1: port = '30000' else: port = '30001' ComboBoxWrapper(wnd_main[u'Port ConnectionComboBox']).select('UDP') wnd_main[u'Local addEdit'].set_text(self.conn_loc_ip) wnd_main[u'Local portEdit'].set_text(port) wnd_main[u'Remote addEdit'].set_text(self.conn_rem_ip) wnd_main[u'Remote portEdit'].set_text(port) wnd_main[u'Rx Address:Edit'].set_text(band) ComboBoxWrapper(wnd_main[u'Rx Address:ComboBox']).select(band) wnd_main[u'Connect'].click() wnd_main.wait('ready') time.sleep(1) if not self.is_connected(wnd_main=wnd_main): self.controller.log_signal.emit('Connection fail. Reconnect') self.save_setfile(place, band) wnd_main[u'Create SetFile'].click() self.save_file(band) try: wnd_main.wait('ready') except pywinauto.findwindows.ElementAmbiguousError: getAnswer = False while not getAnswer: window = app.Dialog msg = window[u'Static2'].window_text() if msg != u'Finished to create setfile': app.kill() else: getAnswer = True window[u'OK'].click() wnd_main[u'Disconnect'].click() self.controller.log_signal.emit( 'Save set file for band {} - OK'.format(band)) self.count_bands += 1 if self.count_bands == len(self.bands): app.kill()
def save_setfile(self, place, band): app, wnd_main = self.run_storm() if None in (app, wnd_main): raw_input("\nCan't start StormInterface\nPress enter for return... ") self.parent.menu() check = CheckStorm(kwargs={'currTest': self, 'app': app, 'place': place, 'band': band}) check.start() if place <= 1: port = '30000' else: port = '30001' ComboBoxWrapper(wnd_main[u'Port ConnectionComboBox']).select('UDP') wnd_main[u'Local addEdit'].set_text(self.conn_loc_ip) wnd_main[u'Local portEdit'].set_text(port) wnd_main[u'Remote addEdit'].set_text(self.conn_rem_ip) wnd_main[u'Remote portEdit'].set_text(port) wnd_main[u'Rx Address:Edit'].set_text(band) ComboBoxWrapper(wnd_main[u'Rx Address:ComboBox']).select(band) wnd_main[u'Connect'].click() wnd_main.wait('ready') if not self.is_connected(wnd_main=wnd_main): print('\nConnection fail. Reconnect') self.save_setfile(place, band) wnd_main[u'Create SetFile'].click() self.save_file(band) try: wnd_main.wait('ready') except pywinauto.findwindows.ElementAmbiguousError: getAnswer = False while not getAnswer: window = app.Dialog msg = window[u'Static2'].window_text() if msg != u'Finished to create setfile': app.kill() else: getAnswer = True window[u'OK'].click() wnd_main[u'Disconnect'].click() print('\nSave set file for band {} - OK'.format(band)) self.count_bands += 1 if self.count_bands == len(self.parent.utils.get_bands()): app.kill()
def data_loading(app, file_path_variable): # from pywinauto.controls.win32_controls import ComboBoxWrapper # from pywinauto.controls.uia_controls import ToolbarWrapper time.sleep(30) # click on the loading button app.window(best_match='National Roads Condition Database - Version*', top_level_only=True)\ .child_window(best_match='Loading').click() # if the file_path_variable directory contains a file 'BatchList' use the 'Select Batch File' # else use 'Create Batch file' if os.path.isfile(file_path_variable + '/BatchList.txt'): filename = file_path_variable + '/BatchList.txt' print("\nfile name exists using Select", filename) time.sleep(30) app.window(best_match='National Roads Condition Database - Version', top_level_only=True) \ .child_window(best_match='Select Batch file').click() filename = filename.replace('/', '\\') print("\nfile exists", filename) time.sleep(15) # check existence of the app2 variable if it is there destroy it as connecting to the file selection # is going to create it and it could get messy if it's still there from processing the previous LA. try: app2 except NameError: print('app2 not used') else: del app2 # Connect to the selection window and enter the batch file name. app2 = Application(backend="uia").connect( title_re='Select a batch file', visible_only=True) print("\nConnect app2 filename is ", filename) app2.window(title_re='Select a batch file') \ .File_name_Edit.set_text(filename) time.sleep(15) batch_split_button2 = app2.window(title_re='Select a batch file') \ .child_window(auto_id='1', control_type="SplitButton") from pywinauto.controls.win32_controls import ButtonWrapper ButtonWrapper(batch_split_button2).click() del app2 else: # else pick the first .hmd file and use 'Create Batch File' print("\nBatchfile file missing") time.sleep(30) # app.window(best_match='National Roads Condition Database - Version', top_level_only=True).child_window( # best_match='OK').click() app.window(best_match='National Roads Condition Database - Version', top_level_only=True) \ .child_window(best_match='Create Batch file').click() # filename = filename.replace('/', '\\') # print("\nfile exists", filename) # time.sleep(15) # app2 = Application(backend="uia").connect(title_re='Select a batch file', visible_only=True) # print("\nConnect app2 filename is ", filename) file_search_variable = (file_path_variable + '/*.hmd').replace( '/', '\\') print("\nfile_search_variable = ", file_search_variable) filename = glob.glob(file_search_variable) # filename = filename[0] print("\nFile found : ", filename) filename = filename[1].replace('/', '\\') time.sleep(20) # click on 'Create Batch File' then OK on the following window # app.window(best_match='National Roads Condition Database') \ # .child_window(best_match='Create Batch file').click() time.sleep(30) app.window(best_match='National Roads Condition Database') \ .child_window(title='NRCD').OK.click() # app.window(best_match='National Roads Condition Database Version *') \ # .child_window(best_match='OK').click() time.sleep(30) # There will be a file selection window. Connect to it (it's not part of NRCD) # So it's a new application. # # But first if app3 is already there get rid of it first. try: app3 except NameError: print('app3 not used') else: del app3 app3 = Application(backend="uia").connect( title='Create a file in the required directory') print("\nconnect app3") time.sleep(15) # edit_text_box2 = app3.window(title_re='Select a batch file') \ # .child_window(best_match="File name:") # from pywinauto.controls.win32_controls import EditWrapper # EditWrapper(edit_text_box2).set_text(filename) # app.window(best_match='National Roads Condition Database - Version *') \ # .child_window(best_match='NRCD') \ # .child_window(best_match='OK').click() # put the filename that was found into the filename box # app3.window(title_re='Create a file in the required directory').print_control_identifiers() app3.window(title_re='Create a file in the required directory') \ .File_name_Edit.set_text(filename) # Click on the open button, this is a bit more involved so that it works with a locked screen. batch_split_button1 = app3.window(title_re='Create a file in the required directory') \ .child_window(auto_id='1', control_type="SplitButton") from pywinauto.controls.win32_controls import ButtonWrapper ButtonWrapper(batch_split_button1).click() # remove references to the window where the filename was entered as it will use # the same variable next time round (next LA) del app3 # if the file_path_variable directory string contains WDM if "WDM" in file_path_variable: # then Survey Contractor = WDM survey_contractor: str = "WDM" # else if the directory string contains 'G-L' select survey contractor 'Ginger-Lehmann' elif "G-L" in file_path_variable: survey_contractor: str = "Ginger-Lehmann" # else if the directory string contains 'PTS' select survey contractor 'Ginger-Lehmann' elif "PTS" in file_path_variable: survey_contractor: str = "PTS" # it's not one of those we know about. Should another contractor start surveying then add another 'elif' else: survey_contractor = "Unknown contractor" print(survey_contractor) from pywinauto.controls.win32_controls import ComboBoxWrapper surveyor_combobox = app.window(best_match='National Roads Condition Database') \ .child_window(best_match='Survey Contractor', control_type='Group') \ .child_window(auto_id="3", control_type="ComboBox") ComboBoxWrapper(surveyor_combobox).select(survey_contractor) # click 'OK' to close the data loading window as we have all the appropriate details entered in the window. app.window(best_match='National Roads Condition Database') \ .child_window(best_match='OK').click() # back on the NRCD main screen, click the process radio button then the actual 'Process' button app.window(best_match='National Roads Condition Database - Version *', top_level_only=True).child_window(best_match='Process').click() # The log entry contains the first file to be loaded (the rest will not appear and NRCD uses the # batchfile to find them logger.info('Starting loading with ' + filename) time.sleep(60) # wait for the loading to finish. It checks the number of windows open for NECD.exe. If these are less than # two the section is complete, otherwise it loops. while nrcd_running_check('2'): logger.info('waiting for loading to complete') time.sleep(300) logger.info('loading completed') return # back to main
def scanner_qa(app, file_path_variable): from pywinauto.controls.win32_controls import ComboBoxWrapper from pywinauto.controls.win32_controls import ButtonWrapper import re # there is a regex search below ! time.sleep(150) main_screen = app.window( best_match='National Roads Condition Database - V*') # turn all the process check boxes off. main_screen_process_checkbox = main_screen.child_window( title="Process", auto_id="15", control_type="CheckBox") main_screen_process_checkbox2 = main_screen.child_window( title="Process", auto_id="16", control_type="CheckBox") main_screen_process_checkbox3 = main_screen.child_window( title="Process", auto_id="17", control_type="CheckBox") main_screen_process_checkbox4 = main_screen.child_window( title="Process", auto_id="18", control_type="CheckBox") time.sleep(60) ButtonWrapper(main_screen_process_checkbox).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox2).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox3).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox4).uncheck_by_click() filename = file_path_variable.replace('/', '\\') print(filename) # time.sleep(15) # use the location of the file_path_variable to extract the local authority, nation and year. local_authority = filename.split("\\")[-1] nation = filename.split("\\")[-2] year: str = re.search('[1-2][0-9]{3}', filename).group(0) # regex search # logger.info('starting Scanner QA output for ' + local_authority) # print(local_authority) print(nation) print(year) logger.info('starting SCANNER QA for ' + local_authority) # Load the human name to database name csv table lookup_table_filename = '//trllimited/data/INF_ScannerQA/Audit_Reports/Tools/LA_to_NRCD_Name.csv' la_lookup_table = pd.read_csv(lookup_table_filename, index_col='Audit_Report_name', dtype={'INDEX': str}) la_db_name: str = la_lookup_table.loc[local_authority, "NRCD_Name"] # enter the Scanner QA section of NRCD and wait for the Survey QA options group to exist. app.window( best_match='National Roads Condition Database', top_level_only=True).child_window(best_match='Scanner QA').click() time.sleep(30) app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="Survey QA Options", auto_id="9", control_type="Group") \ .wait("exists ready", timeout=90, retry_interval=60) group_control = app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="Survey QA Options", auto_id="9", control_type="Group") # group_control.print_control_identifiers() # exclude the previous year and the U roads (uncheck_by_click) then select the LA abd survey year. ButtonWrapper( group_control.child_window( title="Include Previous Year", control_type="CheckBox")).uncheck_by_click() ButtonWrapper( group_control.child_window( title="U Roads", control_type="CheckBox")).uncheck_by_click() ComboBoxWrapper( group_control.child_window(auto_id="24", control_type="ComboBox")).select(la_db_name) ComboBoxWrapper( group_control.child_window(auto_id="25", control_type="ComboBox")).select(" 2021/22") # Export the data group_control.child_window(auto_id="26", title="Export QA Data").click() # build output file name. # LIVE # output_file_name = os.path.normpath("//trllimited/data/INF_ScannerQA/Audit_Reports/NRCD Data/" + nation + "/" + # local_authority + "_" + year + ".csv") # test output_file_name = os.path.normpath("C:/Users/rjaques/temp/Data/" + nation + "/" + local_authority + "_" + year + ".csv") # add the year combination (year and '-' and 2 digit next year so # convert year string to numeric, add one, convert back to string and use the last 2 chars print(year) print(int(year)) print(int(year) + 1) print(str(int(year) + 1)) next_year = str(int(year) + 1)[-2:] print(next_year) survey_period = year + '-' + next_year print(survey_period) print(output_file_name) time.sleep(60) # connect to the output file name selection window and enter the name from above and save the file. app5 = Application(backend="uia").connect( title_re='Select an output file name', visible_only=True) print("\nConnect app5 filename is ", output_file_name) time.sleep(30) # app5.window(title_re='Select an output file name').print_control_identifiers() # split output_file_name into the directory path and the filename (because Mickysoft has changed the window !) # directory_path = os.path.dirname(output_file_name) # app5.window(title_re='Select an output file name') \ # .Toolbar4_Edit.set_text(directory_path) # selected_filename = os.path.basename(output_file_name) app5.window(title_re='Select an output file name') \ .File_name_Edit.set_text(output_file_name) # app5.window(title_re='Select an output file name').File_name_Edit.set_text(output_file_name) # app5.window(title_re='Select an output file name').print_control_identifiers() batch_split_button1 = app5.window(title_re='Select an output file name') \ .child_window(title='Save', auto_id='1', control_type="Button") from pywinauto.controls.win32_controls import ButtonWrapper ButtonWrapper(batch_split_button1).click() # app5.window(title_re='Select an output file name').type_keys(output_file_name, with_spaces=True) # app5.window(title_re='Select an output file name').Save.click() del app5 time.sleep(60) logger.info('waiting for ' + local_authority + ' QA output to finish') app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="NRCD") \ .wait("exists ready", timeout=10000, retry_interval=60) # app.window(best_match='National Roads Condition Database - Version *') \ # .child_window(title="NRCD") \ # .print_control_identifiers() app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="NRCD").OK.click() # Wait patiently # while nrcd_running_check("2"): # logger.info('waiting for ' + local_authority + 'QA output to finish') # time.sleep(90) logger.info(local_authority + ' QA output complete') return # back to main code block
def assign_urb_rural(app): from pywinauto.controls.win32_controls import ComboBoxWrapper from pywinauto.controls.win32_controls import ButtonWrapper time.sleep(60) main_screen = app.window( best_match='National Roads Condition Database - V*') time.sleep(60) # on the main screen turn all the check boxes off. main_screen_process_checkbox = main_screen.child_window( title="Process", auto_id="15", control_type="CheckBox") main_screen_process_checkbox2 = main_screen.child_window( title="Process", auto_id="16", control_type="CheckBox") main_screen_process_checkbox3 = main_screen.child_window( title="Process", auto_id="17", control_type="CheckBox") main_screen_process_checkbox4 = main_screen.child_window( title="Process", auto_id="18", control_type="CheckBox") time.sleep(60) ButtonWrapper(main_screen_process_checkbox).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox2).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox3).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox4).uncheck_by_click() del main_screen_process_checkbox del main_screen_process_checkbox2 del main_screen_process_checkbox3 del main_screen_process_checkbox4 logger.info('starting urban & rural attributes') time.sleep(30) # start the attributes section. app.window( best_match='National Roads Condition Database', top_level_only=True).child_window(best_match='Attributes').click() time.sleep(30) # to set the urban rural attribute the selections are all made in the 'Attributes Options' part of the window. # wait for it to exist. app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="Attributes Options", auto_id="12", control_type="Group") \ .wait("exists ready", timeout=90, retry_interval=60) # set groupcontrol to that part of the window. group_control = app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="Attributes Options", auto_id="12", control_type="Group") # groupcontrol.print_control_identifiers() # Select SCANNER and the survey year and click on OK ComboBoxWrapper(group_control.child_window(auto_id="14", control_type="ComboBox")) \ .select("SCANNER") ComboBoxWrapper(group_control.child_window(auto_id="15", control_type="ComboBox"))\ .select(" 2021/22") app.window(best_match='National Roads Condition Database').child_window( best_match='OK').click() # back to the main window where the process click box is already set by the NRCD prog and it's waiting # for the process button at the bottom to be clicked. main_screen.Process.click() time.sleep(60) # after an appropriate time start waiting for the processing to finish. # wait for the window to close. It checks the number of windows open for NECD.exe. If these are less than # two the section is complete, otherwise it loops. while nrcd_running_check('2'): logger.info('waiting for Urban/Rural Attributes to complete') time.sleep(300) logger.info('U/R attributes complete') return # to the main code block
def fitting(app): from pywinauto.controls.win32_controls import ComboBoxWrapper from pywinauto.controls.win32_controls import ButtonWrapper # from pywinauto.controls import uia_controls # from pywinauto.controls import common_controls # Turn all the process radio buttons off. main_screen_process_checkbox = main_screen.child_window( title="Process", auto_id="15", control_type="CheckBox") main_screen_process_checkbox2 = main_screen.child_window( title="Process", auto_id="16", control_type="CheckBox") main_screen_process_checkbox3 = main_screen.child_window( title="Process", auto_id="17", control_type="CheckBox") main_screen_process_checkbox4 = main_screen.child_window( title="Process", auto_id="18", control_type="CheckBox") ButtonWrapper(main_screen_process_checkbox).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox2).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox3).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox4).uncheck_by_click() del main_screen_process_checkbox del main_screen_process_checkbox2 del main_screen_process_checkbox3 del main_screen_process_checkbox4 logger.info('starting fitting') time.sleep(30) # click fitting to start the next section app.window(best_match='National Roads Condition Database', top_level_only=True).child_window(best_match='Fitting').click() time.sleep(10) # set the check boxes for fitting the data using a grid. ButtonWrapper(app.window(best_match='National Roads Condition Database') .child_window(title="Fit unfitted data", auto_id="22", control_type="RadioButton")) \ .check_by_click() ButtonWrapper(app.window(best_match='National Roads Condition Database') .child_window(title="Fit using a grid", auto_id="14", control_type="RadioButton")) \ .check_by_click() ButtonWrapper(app.window(best_match='National Roads Condition Database') .child_window(title="SCANNER", auto_id="7", control_type="RadioButton")) \ .check_by_click() # and set the survey year batch_combobox24 = app.window(best_match='National Roads Condition Database - Version*') \ .child_window(best_match='Year options:', auto_id="21", control_type="Group") \ .child_window(auto_id='24', control_type="ComboBox") ComboBoxWrapper(batch_combobox24).select(" 2021/22") time.sleep(5) # with everything set click the OK button to return to the main window. main_screen.child_window(title="OK", auto_id="11", control_type="Button").click() time.sleep(60) # the 'process' click box is already set so click on the main screen Process button at the bottom # then wait for the fitting to complete. main_screen.Process.click() time.sleep(600) # wait for the loading to finish. It checks the number of windows open for NECD.exe. If these are less than # two the section is complete, otherwise it loops. while nrcd_running_check('2'): logger.info('waiting for Fitting to complete') time.sleep(300) logger.info('fitting complete') time.sleep(60) # go back to the main code block. return
def THX_change_user(top_window, handle=0x10B72, user_name='中天国富-鸿**号'): user_l = ['中天国富-鸿**号', '国金证券-鸿**号', '中信证券-牛*华'] cb_button = ComboBoxWrapper(handle) cb_button.select(user_name)
def assign_la(app, file_path_variable): logger.info('starting local authority assignment') app.window( best_match='National Roads Condition Database', top_level_only=True).child_window(best_match='Attributes').click() time.sleep(15) group_control = app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="Local Authority Attribute", auto_id="3", control_type="Group") group_control.child_window(title="Select Batch File", auto_id="7", control_type="Button") \ .click() time.sleep(30) #app.window(best_match='National Roads Condition Database') \ # .child_window(title='NRCD').OK.click() # app.window(best_match='National Roads Condition Database - Version *') \ # .child_window(title="Local Authority Attribute", auto_id="3", control_type="Group") \ # .child_window(title="Select Batch File", auto_id="7", control_type="Button") \ # .click() filename = file_path_variable + '/BatchList.txt' print("\nfilename is ", filename) logger.info('File name is ' + filename) filename = filename.replace('/', '\\') time.sleep(15) app4 = Application(backend="uia").connect(title_re='Select a batch file', visible_only=True) print("\nConnect app4 filename is ", filename) logger.info('Connecting to the batch file selection with ' + filename) time.sleep(60) # split filename into the directory path and the filename (because Mickysoft has changed the window !) # directory_path = os.path.dirname(filename) # app4.window(title_re='Select a batch file') \ # .Toolbar4_Edit.set_text(directory_path) # selected_filename = os.path.basename(filename) app4.window(title_re='Select a batch file') \ .File_name_Edit.set_text(filename) # app4.window(title_re='Select a batch file').File_name_Edit.set_text(filename) # app4.window(title_re='Select a batch file').print_control_identifiers() # app4.window(title_re='Select a batch file').type_keys('%o') batch_splitbutton1 = app4.window(title_re='Select a batch file') \ .child_window(auto_id='1', control_type="SplitButton") from pywinauto.controls.win32_controls import ButtonWrapper ButtonWrapper(batch_splitbutton1).click() time.sleep(60) del app4 # use the location of the BatchList.txt to extract the local authority. It's two from the end. local_authority = filename.split("\\")[-2] # print(local_authority) logger.info('starting to assign attributes for ' + local_authority) # Load the human name to database name csv table lookup_table = '//trllimited/data/INF_ScannerQA/Audit_Reports/Tools/LA_to_NRCD_Name.csv' la_lookup_table = pd.read_csv(lookup_table, index_col='Audit_Report_name', dtype={'INDEX': str}) la_db_name: str = la_lookup_table.loc[local_authority, "NRCD_Name"] logger.info('DB name for the LA is ' + la_db_name) # app.window(best_match='National Roads Condition Database - Version*') \ # .child_window(best_match='Local Authority Attribute', control_type="Group").print_control_identifiers() time.sleep(15) # app.window(best_match='National Roads Condition Database - Version *') \ # .child_window(title="Local Authority Attribute", control_type="Group") \ # .child_window(best_match='3',control_type="ComboBox").type_keys("%{DOWN}") # app.window(best_match='National Roads Condition Database - Version*') \ # .child_window(best_match='Local Authority Attribute', control_type="Group") \ # .child_window(auto_id='6', control_type="ComboBox").select(la_db_name) # print(la_db_name) batch_combobox1 = app.window(best_match='National Roads Condition Database - Version*') \ .child_window(best_match='Local Authority Attribute', control_type="Group") \ .child_window(auto_id='6', control_type="ComboBox").wait('exists enabled visible ready') from pywinauto.controls.win32_controls import ComboBoxWrapper ComboBoxWrapper(batch_combobox1).select(la_db_name) batch_combobox2 = app.window(best_match='National Roads Condition Database - Version*') \ .child_window(best_match='Local Authority Attribute', control_type="Group") \ .child_window(auto_id='4', control_type="ComboBox") # .wait('exists enabled visible ready') ComboBoxWrapper(batch_combobox2).select(" 2020/21") time.sleep(15) # print(survey_year) app.window(best_match='National Roads Condition Database - Version*') \ .child_window(title="Assign Local Authority", auto_id="5", control_type="Button") \ .click() logger.info('waiting for LA assignment to complete') time.sleep(60) # the following contains 10000 seconds. This is to stop the wait timing out, it retries each 90 secs # but the attributes should be finished in under 6 hours... or even one hour. app.window(best_match='National Roads Condition Database - Version*') \ .child_window(title='NRCD', control_type="Window") \ .child_window(title="OK", auto_id="2", control_type="Button") \ .wait("exists ready", timeout=10000, retry_interval=90) app.window(best_match='National Roads Condition Database - Version*') \ .child_window(title='NRCD', control_type="Window") \ .child_window(title="OK", auto_id="2", control_type="Button").click() app.window(best_match='National Roads Condition Database - Version*') \ .child_window(title="Exit", auto_id="11", control_type="Button").click() return
def data_loading(app, file_path_variable): # from pywinauto.controls.win32_controls import ComboBoxWrapper # click on the loading button app.window(best_match='National Roads Condition Database - Version*', top_level_only=True).child_window(best_match='Loading').click() # if the file_path_variable directory contains a file 'BatchList' use the 'Select Batch File' # else use 'Create Batch file' if os.path.isfile(file_path_variable + '/BatchList.txt'): filename = file_path_variable + '/BatchList.txt' print("\nfile name exists using Select", filename) time.sleep(30) app.window(best_match='National Roads Condition Database - Version', top_level_only=True) \ .child_window(best_match='Select Batch file').click() filename = filename.replace('/', '\\') print("\nfile exists", filename) time.sleep(15) app2 = Application(backend="uia").connect( title_re='Select a batch file', visible_only=True) print("\nConnect app2 filename is ", filename) # edit_text_box1 = app2.window(title_re='Select a batch file') \ # .child_window(best_match="File name:") # from pywinauto.controls.win32_controls import EditWrapper # EditWrapper(edit_text_box1).set_text(filename) # app2.window(title_re='Select a batch file').type_keys(filename, with_spaces=True) app2.window( title_re='Select a batch file').File_name_Edit.set_text(filename) # app2.window(title_re='Select a batch file').print_control_identifiers() # app2.window(title_re='Select a batch file').type_keys('%o') batch_split_button2 = app2.window(title_re='Select a batch file') \ .child_window(auto_id='1', control_type="SplitButton") from pywinauto.controls.win32_controls import ButtonWrapper ButtonWrapper(batch_split_button2).click() # app2.window(title_re='Select a batch file').OpenSplitButton.click_input # app2.window(title_re='Select a batch file') \ # .child_window(title='Pane1') \ # .child_window(title='Open', auto_id=1).click() # .child_window(title='Open', auto_id=1, control_type="UIA_SplitButtonControlTypeId").click() # .child_window(title='SplitButton6').click() del app2 else: # else pick the first .hmd file and use 'Create Batch File' print("\nBatchfile file missing") # app.window(best_match='National Roads Condition Database - Version', top_level_only=True).child_window( # best_match='OK').click() #filename = filename.replace('/', '\\') file_search_variable = (file_path_variable + '/*.hmd').replace( '/', '\\') print("\nfile_search_variable = ", file_search_variable) filename = glob.glob(file_search_variable) filename = filename[1] print("\nFile found : ", filename[1]) time.sleep(20) # click on 'Create Batch File' then OK on the following window app.window(best_match='National Roads Condition Database - Version *', top_level_only=True) \ .child_window(best_match='Create Batch file').click() time.sleep(30) app.window(best_match='National Roads Condition Database - Version *') \ .child_window(best_match='NRCD') \ .child_window(best_match='OK').click() # app.window(best_match='National Roads Condition Database Version *') \ # .child_window(best_match='OK').click() time.sleep(30) # There will be a file selection window. Connect to it (it's not part of NRCD) # So it's a new application. app3 = Application(backend="uia").connect( title='Create a file in the required directory') print("\nconnect app3") time.sleep(15) # edit_text_box2 = app3.window(title_re='Select a batch file') \ # .child_window(best_match="File name:") # from pywinauto.controls.win32_controls import EditWrapper # EditWrapper(edit_text_box2).set_text(filename) # put the filename that was found into the filename box app3.window(title_re='Create a file in the required directory') \ .File_name_Edit.set_text(filename) # app3.window(title_re='Create a file in the required directory').type_keys(filename[0], with_spaces=True) # app3.window(title_re='Create a file in the required directory').print_control_identifiers() # app3.window(title_re='Create a file in the required directory') \ # .Open3_SplitButton.click() # Click on the open button, this is a bit more involved so that it works with a locked screen. batch_split_button1 = app3.window(title_re='Create a file in the required directory') \ .child_window(auto_id='1', control_type="SplitButton") from pywinauto.controls.win32_controls import ButtonWrapper ButtonWrapper(batch_split_button1).click() # child_window(title="Open", auto_id="1", control_type="SplitButton") # .child_window(best_match='Open3').click() del app3 # if the file_path_variable directory string contains WDM if "WDM" in file_path_variable: # then Survey Contractor = WDM survey_contractor: str = "WDM" # else if the directory string contains 'G-L' select survey contractor 'Ginger-Lehmann' elif "G-L" in file_path_variable: survey_contractor: str = "Ginger-Lehmann" # it's not one of the two we know about. Should another contractor start surveying then add another 'elif' else: survey_contractor = "Unknown" print(survey_contractor) # ComboBoxWrapper(group_control.child_window(auto_id="24", # control_type="ComboBox")).select(la_db_name) # app.window(best_match='National Roads Condition Database', # top_level_only=True).print_control_identifiers() # batch_combobox1 = app.window(best_match='National Roads Condition Database - Version*') \ # .child_window(best_match='Local Authority Attribute', control_type="Group") \ # .child_window(title="OK", auto_id="6", control_type="Button")\ # .wait('exists enabled visible ready') # from pywinauto.controls.uia_controls import ComboBoxWrapper # from pywinauto.controls.win32_controls import EditWrapper # batch_combobox1 = app.window(best_match='National Roads Condition Database - Version*') \ # .child_window(best_match='Local Authority Attribute', control_type="Group") \ # .child_window(title="Survey Contractor", auto_id="1", control_type="Group") \ # .child_window(title="OK", auto_id="6", control_type="Button") # best_match='National Roads Condition Database', # top_level_only=True).child_window(best_match='Survey Contractor' # app.window(best_match='National Roads Condition Database', # top_level_only=True).child_window(best_match='Survey Contractor').Edit.type_keys(surveycontractor) from pywinauto.controls.win32_controls import ComboBoxWrapper surveyor_combobox = app.window(best_match='National Roads Condition Database') \ .child_window(best_match='Survey Contractor', control_type='Group') \ .child_window(auto_id="3", control_type="ComboBox") # .child_window(title="Survey Contractor", auto_id="5", control_type="Edit") # EditWrapper(surveyor_menu).set_text(survey_contractor) ComboBoxWrapper(surveyor_combobox).select(survey_contractor) # contractor_combobox = app.window(best_match='National Roads Condition Database', # top_level_only=True).child_window(best_match='Survey Contractor') # ComboBoxWrapper(contractor_combobox).select(survey_contractor) # contractor_combobox.Survey_Contractor_Edit.set_text(survey_contractor) # batch_combobox2 = app.window(best_match='National Roads Condition Database - Version*') \ # .child_window(best_match='Local Authority Attribute', control_type="Group") \ # .child_window(auto_id='4', control_type="ComboBox") # .wait('exists enabled visible ready') # click 'OK' to close the data loading window as we have all the appropriate details entered in the window. app.window(best_match='National Roads Condition Database') \ .child_window(best_match='OK').click() # back on the NRCD main screen, click the process radio button then the actual 'Process' button app.window(best_match='National Roads Condition Database - Version *', top_level_only=True).child_window(best_match='Process').click() # print(filename) # The log entry contains the first file to be loaded (the rest will not appear and NRCD uses the # batchfile to find them logger.info('Starting loading with ' + filename[0]) time.sleep(60) # wait for the loading to finish. It checks the number of windows open for NECD.exe. If these are less than # two the section is complete, otherwise it loops. while nrcd_running_check("2"): logger.info('waiting for loading to complete') time.sleep(300) logger.info('loading completed') return # back to main
def fitting(app): from pywinauto.controls.win32_controls import ComboBoxWrapper from pywinauto.controls.win32_controls import ButtonWrapper # from pywinauto.controls import uia_controls # from pywinauto.controls import common_controls main_screen = app.window( best_match='National Roads Condition Database - V*') main_screen_ProcessCheckbox = main_screen.child_window( title="Process", auto_id="15", control_type="CheckBox") main_screen_ProcessCheckbox2 = main_screen.child_window( title="Process", auto_id="16", control_type="CheckBox") main_screen_ProcessCheckbox3 = main_screen.child_window( title="Process", auto_id="17", control_type="CheckBox") main_screen_ProcessCheckbox4 = main_screen.child_window( title="Process", auto_id="18", control_type="CheckBox") ButtonWrapper(main_screen_ProcessCheckbox).uncheck_by_click() ButtonWrapper(main_screen_ProcessCheckbox2).uncheck_by_click() ButtonWrapper(main_screen_ProcessCheckbox3).uncheck_by_click() ButtonWrapper(main_screen_ProcessCheckbox4).uncheck_by_click() logger.info('starting fitting') time.sleep(30) app.window(best_match='National Roads Condition Database', top_level_only=True).child_window(best_match='Fitting').click() time.sleep(10) # set the check boxes for fitting the data using a grid. ButtonWrapper(app.window(best_match='National Roads Condition Database') .child_window(title="Fit unfitted data", auto_id="22", control_type="RadioButton")) \ .check_by_click() ButtonWrapper(app.window(best_match='National Roads Condition Database') .child_window(title="Fit using a grid", auto_id="14", control_type="RadioButton")) \ .check_by_click() ButtonWrapper(app.window(best_match='National Roads Condition Database') .child_window(title="SCANNER", auto_id="7", control_type="RadioButton")) \ .check_by_click() # and set the survey year batch_combobox24 = app.window(best_match='National Roads Condition Database - Version*') \ .child_window(best_match='Year options:', auto_id="21", control_type="Group") \ .child_window(auto_id='24', control_type="ComboBox") ComboBoxWrapper(batch_combobox24).select(" 2019/20") time.sleep(5) # with everything set click the OK button to return to the main window. main_screen.child_window(title="OK", auto_id="11", control_type="Button").click() time.sleep(15) # app.window(best_match='National Roads Condition Database - Version*') \ # .child_window(best_match='Year options', control_type="Group") \ # .child_window(control_type="ComboBox").wait('exists enabled visible ready') # main_screen_group = main_screen.child_window(auto_id="11", control_type="Group") # main_screen_ProcessCheckbox = main_screen.child_window(title="Process", auto_id="15", control_type="CheckBox") # main_screen_ProcessCheckbox2 = main_screen.child_window(title="Process", auto_id="16", control_type="CheckBox") # main_screen_ProcessCheckbox3 = main_screen.child_window(title="Process", auto_id="17", control_type="CheckBox") # main_screen_ProcessCheckbox4 = main_screen.child_window(title="Process", auto_id="18", control_type="CheckBox") # ButtonWrapper(main_screen_ProcessCheckbox).uncheck_by_click() # ButtonWrapper(main_screen_ProcessCheckbox2).uncheck_by_click() # ButtonWrapper(main_screen_ProcessCheckbox3).check_by_click() # ButtonWrapper(main_screen_ProcessCheckbox4).uncheck_by_click() # the 'process' click box is already set so click on the main scree Process button at the bottom # then wait for the fitting to complete. main_screen.Process.click() time.sleep(60) while nrcd_running_check("2"): logger.info('waiting for Fitting to complete') time.sleep(90) logger.info('fitting complete') return # to the main code block.