From a9881ed8d1d3d9c65ad0aa3695acafdf17adf252 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 17 Apr 2023 12:48:25 -0300 Subject: [PATCH] [Eeschema][ERC][KiCad 7][No interposer] Added workaround --- kiauto/ui_automation.py | 9 ++++---- src/eeschema_do | 46 +++++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/kiauto/ui_automation.py b/kiauto/ui_automation.py index f784f68..657426e 100644 --- a/kiauto/ui_automation.py +++ b/kiauto/ui_automation.py @@ -415,7 +415,7 @@ def wait_point(cfg): input('Press a key') -def capture_window_region(window_id, x, y, w, h, name): +def capture_window_region(window_id, x, y, w, h, name, to_capture=None): """ Capture a region of a window to a file """ geometry = '{}x{}+{}+{}'.format(w, h, x, y) logger.debug('Capturing region {} from window {}'.format(geometry, window_id)) @@ -423,7 +423,8 @@ def capture_window_region(window_id, x, y, w, h, name): if not shutil.which('import'): logger.error("import isn't installed, please install it.\nThis is part of ImageMagick and GraphicsMagic packages.") sys.exit(MISSING_TOOL) - res = check_output(['import', '-window', str(window_id), '-crop', geometry, name], stderr=DEVNULL).decode() + res = check_output(['import', '-window', str(window_id), '-crop', geometry, name], stderr=DEVNULL, + timeout=to_capture).decode() logger.debug('Import output: ' + res) @@ -434,10 +435,10 @@ def wait_window_get_ref(window_id, x, y, w, h): capture_window_region(window_id, x, y, w, h, "wait_ref.png") -def wait_window_change(window_id, x, y, w, h, time_out): +def wait_window_change(window_id, x, y, w, h, time_out, to_capture): """ Waits for a change in a window region """ for i in range(int(time_out + 0.9)): - capture_window_region(window_id, x, y, w, h, "current.png") + capture_window_region(window_id, x, y, w, h, "current.png", to_capture) current = os.path.join(img_tmp_dir, "current.png") wait_ref = os.path.join(img_tmp_dir, "wait_ref.png") difference = os.path.join(img_tmp_dir, "difference.png") diff --git a/src/eeschema_do b/src/eeschema_do index 2c487bc..59615cd 100755 --- a/src/eeschema_do +++ b/src/eeschema_do @@ -417,8 +417,10 @@ def eeschema_run_erc_schematic_5_1_i(cfg): def eeschema_run_erc_schematic_6_0_n(cfg): # Open the ERC dialog keys = ['key', 'Escape', 'ctrl+shift+i'] - id = open_dialog_with_retry('Open Tools->Electrical Rules Checker', keys, 'Electrical Rules Checker dialog', - 'Electrical Rules Checker', cfg) + erc_name = 'Electrical Rules Checker dialog' + erc_title = 'Electrical Rules Checker' + erc_msg = 'Open Tools->Electrical Rules Checker' + id = open_dialog_with_retry(erc_msg, keys, erc_name, erc_title, cfg) wait_point(cfg) # Run the ERC logger.info('Run ERC') @@ -428,13 +430,44 @@ def eeschema_run_erc_schematic_6_0_n(cfg): # # Currently is impossible to know when it finished. # - wait_window_change(id[0], 108, 27, 100, 10, 45*cfg.time_out_scale) + try_again = False + try: + wait_window_change(id[0], 108, 27, 100, 10, 45*cfg.time_out_scale, 3*cfg.time_out_scale) + except subprocess.TimeoutExpired: + try_again = True + if try_again: + # KiCad 7.0.2 bug, closes ERC dialog after finishing + logger.warning('Time out capturing from the '+erc_name+', trying to open it again') + id = open_dialog_with_retry(erc_msg, keys, erc_name, erc_title, cfg) # Save the report logger.info('Open the save dialog') wait_point(cfg) - xdotool(['key', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Return']) + keys_save = ['key', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Return'] + xdotool(keys_save) # Wait for the save dialog - wait_for_window('ERC File save dialog', 'Save Report to File') + try_again = False + try: + wait_for_window('ERC File save dialog', 'Save Report to File') + except RuntimeError: + if cfg.ki7: + try_again = True + else: + raise + if try_again: + # KiCad 7.0.2 bug, closes ERC dialog after finishing + found = False + try: + wait_for_window(erc_name, erc_title, timeout=1) + found = True + except RuntimeError: + pass + if found: + logger.error(erc_name+' not responding') + exit(EESCHEMA_ERROR) + logger.warning(erc_name+' suddenly closed, trying to open it again') + id = open_dialog_with_retry(erc_msg, keys, erc_name, erc_title, cfg) + xdotool(keys_save) + wait_for_window('ERC File save dialog', 'Save Report to File') # Paste the name logger.info('Pasting output file') wait_point(cfg) @@ -635,7 +668,8 @@ def create_eeschema_config(cfg): eeconf['appearance'] = {"show_sexpr_file_convert_warning": False, "color_theme": cfg.color_theme.lower()} eeconf['window'] = {"size_x": cfg.rec_width, "size_y": cfg.rec_height, # Select the user grid and the provided grid. X/Y the same. - "grid": {"last_size": 7, "user_grid_x": "%d mil" % cfg.grid, "user_grid_y": "%d mil" % cfg.grid}} + "grid": {"last_size": 7, "user_grid_x": "%d mil" % cfg.grid, + "user_grid_y": "%d mil" % cfg.grid}} text = json.dumps(eeconf) text_file.write(text) logger.debug(text)