Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

the return type of pya.MainWindow.instance() is sometimes wrong.

edited October 31 in Python scripting

I am now developing a python plugin upon klayout, but for the following code:

import pya
main_window = pya.MainWindow.instance()
print(main_window.__class__)

sometimes it will print class 'pya.PluginRoot'.

and if I stop the program and run it again, sometimes it will get the correct result. e.g. class 'pya.MainWindow'.

I don't know why. I get the code from master branch in git about one month ago.
And I also download the klayout-0.25.5 from this website and build it. But the result is same.

Comments

  • Hi William,

    PluginRoot is an interface implemented by MainWindow, but it's not exposed as a base class of MainWindow. So that may explain this duality. MainWindow is a superset of plugin root, so that should not hurt. But maybe it's possible to reduce the Python MainWindow object to PluginRoot under some circumstances. The only way I can think of are related the "root" argument in PluginFactory#create_plugin - for example if you store this value in some variable, the MainWindow object may incorrectly be identified with this PluginRoot object. That's the magic of C++/Python bridging.

    Matthias

  • Hi William,

    I am considering this an actual bug. There is a ticket for this: https://github.com/klayoutmatthias/klayout/issues/191.

    Matthias

  • Hi, Matthias

    Thanks for your comment.

    William.

  • Hi William,

    I have published a simple workaround for this issue in the GitHub ticket. Maybe this helps.

    Matthias

Sign In or Register to comment.