Skip to content

Commit

Permalink
[Eeschema][ERC][KiCad 7][No interposer] Added workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
set-soft committed Apr 17, 2023
1 parent 1679e9d commit a9881ed
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
9 changes: 5 additions & 4 deletions kiauto/ui_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,16 @@ 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))
name = os.path.join(img_tmp_dir, 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)


Expand All @@ -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")
Expand Down
46 changes: 40 additions & 6 deletions src/eeschema_do
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a9881ed

Please sign in to comment.