Skip to content

Commit

Permalink
Fixed pcbnew_do export problems
Browse files Browse the repository at this point in the history
- when the PCB name contained "print" in the name.
  • Loading branch information
set-soft committed Nov 16, 2021
1 parent a799eda commit e6d46a9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- pcbnew_do export problems when the PCB name contained "print" in the name.

## [1.5.9] - 2021-11-16
### Changed
Expand Down
47 changes: 29 additions & 18 deletions src/pcbnew_do
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def wait_pcbew_start(cfg):
failed_focuse = False
other = None
try:
wait_pcbnew(args.wait_start, [TITLE_CONFIRMATION, TITLE_WARNING, TITLE_ERROR], cfg.popen_obj)
id = wait_pcbnew(args.wait_start, [TITLE_CONFIRMATION, TITLE_WARNING, TITLE_ERROR], cfg.popen_obj)
except RuntimeError: # pragma: no cover
logger.debug('Time-out waiting for pcbnew, will retry')
failed_focuse = True
Expand All @@ -159,10 +159,14 @@ def wait_pcbew_start(cfg):
if other == TITLE_WARNING: # pragma: no cover
dismiss_warning()
try:
wait_pcbnew(5)
id = wait_pcbnew(5)
except RuntimeError: # pragma: no cover
logger.error('Time-out waiting for pcbnew, giving up')
exit(PCBNEW_ERROR)
if len(id) > 1:
logger.error('More than one PCBNew windows detected')
exit(PCBNEW_ERROR)
return id[0]


def exit_pcbnew(cfg):
Expand Down Expand Up @@ -192,14 +196,14 @@ def exit_pcbnew(cfg):
wait_point(cfg)


def open_print_dialog(cfg, print_dialog_keys):
def open_print_dialog(cfg, print_dialog_keys, id_pcbnew):
# Open the KiCad Print dialog
logger.info('Open File->Print')
wait_point(cfg)
xdotool(['key']+print_dialog_keys)
retry = False
try:
id = wait_for_window('Print dialog', 'Print')
id = wait_for_window('Print dialog', 'Print', skip_id=id_pcbnew)
except RuntimeError: # pragma: no cover
# Perhaps the fill took too muchm try again
retry = True
Expand All @@ -209,11 +213,17 @@ def open_print_dialog(cfg, print_dialog_keys):
logger.info('Open File->Print (retrying)')
wait_point(cfg)
xdotool(['key']+print_dialog_keys)
id = wait_for_window('Print dialog', 'Print')
return id
id = wait_for_window('Print dialog', 'Print', skip_id=id_pcbnew)
if len(id) == 1:
# Only 1 window matched, the print dialog
return id[0]
if len(id) > 2:
logger.error('Too much windows with similar names')
exit(PCBNEW_ERROR)
return id[1] if id[0] == id_pcbnew else id[0]


def print_layers(cfg):
def print_layers(cfg, id_pcbnew):
if cfg.kicad_version >= KICAD_VERSION_5_99:
print_dialog_keys = ['ctrl+p']
else:
Expand All @@ -227,16 +237,16 @@ def print_layers(cfg):
wait_point(cfg)
# Make sure KiCad is responding
# We open the dialog and then we close it
id = open_print_dialog(cfg, print_dialog_keys)
id_print_dialog = open_print_dialog(cfg, print_dialog_keys, id_pcbnew)
xdotool(['key', 'Escape'])
wait_not_focused(id[0])
wait_not_focused(id_print_dialog)
wait_pcbnew()
# Now we fill the zones
xdotool(['key', 'b'])
# Wait for complation
sleep(1)
wait_pcbnew()
id = open_print_dialog(cfg, print_dialog_keys)
id_pcbnew = wait_pcbnew()
id_print_dialog = open_print_dialog(cfg, print_dialog_keys, id_pcbnew)
# Open the gtk print dialog
wait_point(cfg)
# Two possible options here:
Expand All @@ -246,7 +256,8 @@ def print_layers(cfg):
# From there Return prints and Escape closes the window.
xdotool(['key', 'shift+Tab', 'shift+Tab', 'shift+Tab', 'shift+Tab', 'Return'])
# Check it is open
id2 = wait_for_window('Printer dialog', '^(Print|%s)$' % cfg.print_dlg_name, skip_id=id[0])
id2 = wait_for_window('Printer dialog', '^(Print|%s)$' % cfg.print_dlg_name, skip_id=id_print_dialog)
id_printer_dialog = id2[1] if id2[0] == id_print_dialog else id2[0]
wait_point(cfg)
# List of printers
xdotool(['key', 'Tab',
Expand All @@ -265,7 +276,7 @@ def print_layers(cfg):
'Return'])
# Back to print
wait_not_focused(id_sel_f[0])
wait_for_window('Printer dialog', '^(Print|%s)$' % cfg.print_dlg_name, skip_id=id[0])
wait_for_window('Printer dialog', '^(Print|%s)$' % cfg.print_dlg_name, skip_id=id_print_dialog)
wait_point(cfg)
xdotool(['key',
# Format options
Expand All @@ -276,14 +287,14 @@ def print_layers(cfg):
'Return'])
# Wait until the file is created
wait_for_file_created_by_process(cfg.pcbnew_pid, cfg.output_file)
wait_not_focused(id2[1])
wait_not_focused(id_printer_dialog)
# Now we should be in the KiCad Print dialog again
id = wait_for_window('Print dialog', 'Print')
wait_for_window('Print dialog', 'Print')
wait_point(cfg)
# Close the dialog
# We are in one of the layer columns, here Escape works
xdotool(['key', 'Escape'])
wait_not_focused(id2[0])
wait_not_focused(id_print_dialog)
# Exit
exit_pcbnew(cfg)

Expand Down Expand Up @@ -702,12 +713,12 @@ if __name__ == '__main__':
stdout=flog_out, start_new_session=True) as pcbnew_proc:
cfg.pcbnew_pid = pcbnew_proc.pid
cfg.popen_obj = pcbnew_proc
wait_pcbew_start(cfg)
id_pcbnew = wait_pcbew_start(cfg)
if pcbnew_proc.poll() is not None:
do_retry = True
else:
if args.command == 'export':
print_layers(cfg)
print_layers(cfg, id_pcbnew)
else: # run_drc
run_drc(cfg)
error_level = process_drc_out(cfg)
Expand Down

0 comments on commit e6d46a9

Please sign in to comment.