Wrapper over KLayout

edited April 2015 in General
Hi All,

I am currently trying to use KLayout from my external application Python. I initially built a webserver using Matthias suggestion inside KLayout using Ruby and then served the content but it is slow.

Now I am thinking to write a wrapper over the existing KLayout code. Since KLayout use Qt, it is hard to make a wrapper over it easily. So I am thinking to remove the dependencies like QFrame, QWidget which requires QApplication to be instantiated. But instantiating a QtApplication will put in a loop, so it wouldn't be possible to interact.

Aim:
-----
I have just my Python UI where i want to display GDS image and allow panning, zooming, measuring.

Thoughts:
------------
I thought of introducing my class(GPLayoutView) equivalent to the LayoutView except it does not inherit QFrame and proceeding all way down to other classes LayoutView depends on(like LayoutCanvas,ViewObject,etc,..).Finally exposing GPLayoutView to my python application will be enough.

I am a newbie, both to large source code and Qt. Please bear me if i am not being specific/clear. I could see the code is well written but i am finding it difficult to understand.

Am i proceeding in the right direction?

Thanks
Ganesh

Comments

  • edited November -1
    I'm sorry, I don't have the answer. (However I'm sure Matthias or others will have some advice.)

    But just a clarifying question:

    When you say: "I have just my Python UI where i want to display GDS image and allow panning, zooming, measuring." - it sounds like KLayout's "Viewer" mode. What functionality are you trying to add? And/or, what functionality are you trying to remove from KLayout?

    The reason I ask is: For trying to mash up KLayout with some custom functionality 'X', for most conceivable applications, it's likely easier to try to build functionality 'X' inside KLayout using KLayout's awesome scripting functionality, rather than trying to build functionality 'X' externally and then embed KLayout. The former has all the tools set up, and I can offer scripting advice if I knew more about your application. For the latter, you need to build all the tools (communication to and from 'X').

    David
  • edited April 2015
    David

    I am not trying to add any functionality. The whole reason of trying to embed the Viewer in Python is my application might need to work with the image like measuring distance, layer properties. Its hard for someone to switch between my app and KLayout for just measuring a distance.

    And David, "What do you mean by Viewer mode?"

    Ganesh
  • edited April 2015

    Hi Ganesh,

    you're basically trying to take the application apart which means understanding the dependencies of roughly 500k lines of code. That use case was not planned for and the interfaces at which you'd have to cut the application are internal, quite complex and hardly documented. These efforts will lead into the depths of a multi-threaded and highly optimized application. And you still will have to provide the glue code between your application and the KLayout internals. You'd have to turn the Python integration from an embedded interpreter into a Python extension. I guess your application is based on PyQt, which first of all is not compatible with the Qt binding KLayout uses, so you'd have to deal with the task of integrating external Qt objects into PyQt and so forth. A crazy effort for somebody not familiar with that. I can neither support that nor would I encourage you to start such an effort.

    And: please be aware that the code is licensed under the GPL - any reuse means you'd have to publish your code too. Using the tool as a separate engine is Ok, embedding code in any commercial application is not - unless you make your application GPL too. That's another good reason for not doing cherry picking from the application code.

    Matthias

  • edited November -1

    Ganesh,

    I see now that you have an existing python program and want to avoid rewriting it to run inside KLayout, so instead your idea was to have KLayout run inside your existing code.

    However please be aware that the latest bleeding edge KLayout also supports python. So it may be possible (and I would highly recommend this) to cut and paste the relevant parts of your python code and create macros/scripts inside Klayout to do what you want. There is very little you can't accomplish in terms of functionality going this route.

    If you have problems scripting inside KLayout using python (to see it, get the bleeding edge version and then go to Macro menu > Macro Development) then we can help. If you choose to try to go your original route, there is limited help available...

    "Viewer" mode is toggled by using File > Setup > Editing mode toggle box, and the restart KLayout. It is more lightweight and designed for only viewing, which is likely what you'll want.

    David

  • edited April 2015
    I have used Macros before. I will see what can be done.
    Thanks for your suggestions Matthias and David.



    Ganesh
Sign In or Register to comment.