New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MainWindow/PluginRoot classes mixed #191

Closed
klayoutmatthias opened this Issue Nov 5, 2018 · 4 comments

Comments

Projects
None yet
1 participant
@klayoutmatthias
Owner

klayoutmatthias commented Nov 5, 2018

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

pya.PluginRoot.instance()

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).

@klayoutmatthias

This comment has been minimized.

Owner

klayoutmatthias commented Nov 5, 2018

There is one more issue found during this fix was PluginRoot#get_config which is broken.

The workaround is to use "Application#get_config" which is the more popular method anyway.

@klayoutmatthias

This comment has been minimized.

Owner

klayoutmatthias commented Nov 5, 2018

See pull request #192

klayoutmatthias added a commit that referenced this issue Nov 13, 2018

Merge pull request #192 from klayoutmatthias/issue-191
First solution provided for ticket #191
@klayoutmatthias

This comment has been minimized.

Owner

klayoutmatthias commented Nov 14, 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:

class SetOriginOnMouseClickPluginFactory(pya.PluginFactory):

  def __init__(self):
    super(SetOriginOnMouseClickPluginFactory, self).__init__()
    pya.MainWindow.instance()  # (workaround for bug 191)
    self.register(-1000, "set_origin", "Cell Origin")
    
  def create_plugin(self, manager, root, view):
    return SetOriginOnMouseClickPlugin()

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:

class SetOriginOnMouseClickPluginFactory(pya.PluginFactory):

  def __init__(self):
    super(SetOriginOnMouseClickPluginFactory, self).__init__()

    # (workaround for bug 191)
    # will bind the MainWindow object to the MainWindow class before anything bad happens
    pya.MainWindow.instance()  

    self.register(-1000, "set_origin", "Cell Origin")
    
  def create_plugin(self, manager, root, view):
    return SetOriginOnMouseClickPlugin()

Please note that this is only because of the ambiguity of MainWindow/PluginRoot. All other objects are not affected by this issue.

Matthias

@klayoutmatthias

This comment has been minimized.

Owner

klayoutmatthias commented Nov 18, 2018

Fixed in master branch. Will be released with 0.25.6.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Dec 9, 2018

mef
Updated cad/klayout 0.25.4 to 0.25.6
0.25.6          (2018-11-23):

* Enhancement: klayoutmatthias/klayout#199
       Added an option to export DXF polygons as LINE objects
* Bugfix: klayoutmatthias/klayout#198
       Stitching of DXF contours wasn't taking nearest neighbours
* Bugfix: klayoutmatthias/klayout#191
       MainWindow/PluginRoot classes got mixed up
       As a side effect of this fix, layout views can now
       be configured individually. This wasn't working
       consistently before.

0.25.5          (2018-10-20):

* Bugfix: klayoutmatthias/klayout#162
       GDS2 LIBNAME was not maintained on "File/Save".
* Bugfix: klayoutmatthias/klayout#166
       Internal error when writing GDS files (breaking of polygons)
* Bugfix: klayoutmatthias/klayout#172
       DEF reader did not pull vias from LEF
* Bugfix: klayoutmatthias/klayout#174
       Performance issue with many layers with width >1
* Bugfix: klayoutmatthias/klayout#176
       Painting issue with texts
* Bugfix: klayoutmatthias/klayout#185
       Hash values available as __hash__ standard method now
       for Python
* Bugfix: some potential memory corruption issues fixed
       During the efforts for making the code base compatible
       with MSVC, some potential candidates for memory corruption
       have been identified and fixed.
       These fixes are included in this release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment