switch layouts but without losing the handle

Hi,

I would like to switch layouts but without losing the handle
I have the following example code:

mw = pya.Application.instance().main_window()
mw.create_view()
ly1 =  pya.Layout()
ly1.read( "design1.oas")
ly2 =  pya.Layout()
ly2.read( "design2.oas")
mw.current_view().show_layout(ly1, False)
mw.current_view().show_layout(ly2, False)
mw.current_view().show_layout(ly1, False)

on the last line I am getting the error: Object has been destroyed already for argument #1 ('layout') in LayoutViewBase.show_layout

I understand from it that layoutview.show layout is then destroying the previous design
is there a way to switch layouts views without destroying them?

Comments

  • No, there is no such switch. Currently, "show_layout" will pass the ownership over the Layout object to the view.

    But you can pass a copy:

    mw.current_view().show_layout(ly1.dup(), False)
    

    If that is deleted, your original layout is left intact. But the copy and your original layout are detached. Still it's an option to display a layout object.

    Matthias

  • Thanks, I then rather went for the duplicate before the switch. ie:

    mw = pya.Application.instance().main_window()
    mw.create_view()
    ly1 =  pya.Layout()
    ly1.read( "design1.oas")
    ly2 =  pya.Layout()
    ly2.read( "design2.oas")
    mw.current_view().show_layout(ly1, False)
    # edit layout ly1
    ly1 =  ly1.dup()
    mw.current_view().show_layout(ly2, False)
    # edit layout ly2
    ly2 =  ly2.dup()
    mw.current_view().show_layout(ly1, False)
    
  • edited December 3

    Hi @jonathan,

    That's also an option.

    If you like, you can raise a ticket on GitHub. I think your request is reasonable, it's just not supported yet.
    It will just be a separate class, so a kind of layout wrapper.

    Matthias

  • I have only used Gitub once in the past. I have raised an issue: If it is done wrong or any other problem, let me know.
    in any case no big issue: the solution above works really well and after using it I do not see any performance issue.
    Thanks for the support!

  • Thanks, but where did you create it?

    The issue space for KLayout is here: https://github.com/KLayout/klayout/issues

    You can refer to this discussion. GitHub tickets are a good way to publicly discuss topics and refer to them in release notes.

    Matthias

  • Hi, I created the issue in KLayout/klayout

    here is the link to the issue:
    https://github.com/KLayout/klayout/issues/2243

    I can however not see it listed in KLayout/klayout/issues
    But I do not know what I am doing wrong.
    Maybe I need some approval that it is not spam?
    Sorry for being quite ignorant there.

Sign In or Register to comment.