Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
MainWindow/PluginRoot classes mixed #191
As internally KLayout internally identifies MainWindow with PluginRoot, but does not expose this identity as an implementation detail, the Python class mapping is getting messed up.
One symptom is the result of
which is a MainWindow object, but does not implementat the PluginRoot object. The other way has been reported too: "pya.MainWindow.instance()" apparently returns a "PluginRoot" object as well (https://www.klayout.de/forum/discussion/1140/the-return-type-of-pya-mainwindow-instance-is-sometimes-wrong#latest).
added a commit
Nov 13, 2018
I now better understood what's going on and there is a workaround.
Actually, the wrong class gets assigned because the first time, a C++ object is bound in Python space, the type will be assigned. In this case, there are two types that apply (MainWindow and PluginRoot). So if the MainWindow object is bound the first time in MainWindow context (i.e. through "pya.MainWindow.instance()", it gets MainWindow class. If it's bound the first time in "PluginRoot" context, it gets "PluginRoot" class. The latter happens implicitly for example for the "root" parameter in "PluginFactory.create_plugin".
Consider this code from https://www.klayout.de/forum/discussion/1151/capture-a-mouse-click-and-its-location#latest:
When the plugin is created, the "root" argument of "create_plugin" will bind the MainWindow object to PluginRoot unless it was bound otherwise. Hence there is a simple workaround by explicitly binding before "create_plugin" is called:
Please note that this is only because of the ambiguity of MainWindow/PluginRoot. All other objects are not affected by this issue.