Problem with saving screenshots while changing layers/groups visibility

Hi, Matthias!

I tried to make multiple screenshots after changing layers/group visibility in script. Looks like LayoutView.update_content do not update view properly when group was not visible.

First screenshot taken for layer from visible group (Nested 1) is fine, but second, for layer from invisible group (Nested 2), is empty.

Script is:

import pya

main_window = pya.Application.instance().main_window()
current_view = main_window.current_view()
for index in range(1, 3):
    suffix = f'{index}'
    for layer_properties in current_view.each_layer():
        layer_properties.visible = layer_properties.name.endswith(suffix)
        print(layer_properties.name, layer_properties.visible)
    current_view.update_content()
    current_view.get_image(800, 600).save(f'Screenshot.{index}.png')

It was run with KLayout 0.28.11 with attached session/layout: klayout -u Session.txt -r script.py

Comments

  • Hi EugeneZelenko

    Add a process_events before get_image should able to solved this issue

        current_view.update_content()
        pya.Application.instance().process_events()
        current_view.get_image(800, 600).save(f'Screenshot.{index}.png')
    
  • Hi!

    Thank your for help! It works!

    But will be good idea to reflect this in documentation (LayoutView.update_content?).

  • Dear all,

    Wasn't that an issue before somewhere?

    "process_events" is required as it triggers the repaint event that actually does the rendering.
    But basically "update_content" could imply "process_events".

    Matthias

  • Thanks to the test case I could debug this issue and found a way to avoid the "process_events" call. This patch will be released in the next minor release. Even "update_content()" is no longer required.

    Matthias

  • Hi, Matthias!

    Thank you for quick fix! It'll really simplify end-user code.

  • I believe so :)

    It's actually released yesterday. There is some background processing happening and the single-threaded synchronous get_image etc. methods now take care of finishing these tasks before they deliver the image data.

    Thanks for reporting the problem and the nicely prepared test case.

    Matthias

Sign In or Register to comment.