LayoutView.on_selection_changed behavior

It looks like LayoutView.on_selection_changed callback is not called when selection changed from some objects to none of them. I'd like to perform some action (like window hiding) is such scenario.

Comments

  • Hi Eugene,

    thanks for reporting this. I'll verify that and create a ticket if necessary. I recall I have seen this issue myself, but I'm not sure. Maybe it's already fixed in master.

    Matthias

  • Hi, Matthias!

    I tried 0.26.9 and I was not correct in original problem description. LayoutView.on_selection_changed is called when object(s) is/are unselected, but LayoutView.has_object_selection is still True

    Test code:

    import pya
    
    main_window = pya.Application.instance().main_window()
    current_view = main_window.current_view()
    
    def on_selection_changed(main_window, current_view):
       count = 0
       for selected_object in current_view.each_object_selected():
          count += 1
       if current_view.has_object_selection:
          main_window.message('Select {0}'.format(count), 2000)
       else:
          main_window.message('Unselect', 2000)
    
    current_view.on_selection_changed = \
       lambda __main_window=main_window, __current_view=current_view: \
       on_selection_changed(__main_window, __current_view)
    
  • @EugeneZelenko thanks a lot for the code!

    The problem still persists on master. As a workaround I'd suggest to check for "view.each_object_selected().size == 0". But of course "has_object_selection" should work.

    I have created a ticket for this: https://github.com/KLayout/klayout/issues/703

    I hope it's easy to fix.

    Thanks,

    Matthias

  • Hi, Matthias!

    Thank you for help!

    As workaround I use early return from current_view.each_object_selected() loop in on_selection_changed handler when object is selected, and code handling no objects selected situation is located after loop.

    Eugene.

Sign In or Register to comment.