-
Notifications
You must be signed in to change notification settings - Fork 205
klayout Standalone KLayout Python Module
The scope of this sub-project is to supply a standalone Python Module for the KLayout classes.
The KLayout application is not able to supply such a module without refactoring. Within the application context, Python is not standalone, but KLayout comes with a built-in Python interpreter. KLayout's classes in the "pya" module space are injected into that interpreter when starting the application. Python scripts must run in that environment when they want to use this extension.
The reasoning for this approach was the initial use case: Python (and Ruby) scripts were intended to extend and customize KLayout's functionality. The integrated interpreter approach is well suited for this kind of application.
Over time however, many other applications emerged, many of them just using KLayout's algorithms - without the user interface - plus other, external libraries. The integrated interpreter approach means such applications need to run within KLayout. This limitation has received some criticism as it forces users into the KLayout infrastructure. In addition, the need for integrating third-party components such as NumPy created a maintenance issue.
The solution to this problem is to supply a standalone Python module which can be used in third-party ecosystems such as PyCharm, Anaconda etc.
The goal of this project is to provide such a standalone module. Please examine KLayout Python Module for details about the current status.
A Python module that can be included into your project.
First stage: supply modules for the core features:
import klayout.db as db
box = db.DBox(0, 0, 1000, 2000)
print str(box)
Second stage: supply modules for the UI components and the necessary infrastructure (Qt binding etc.). Ideally interoperable with PyQt.
from klayout.QtCore import *
from klayout.QtGui import *
from klayout.QtWidgets import *
from klayout.lay import *
app = QApplication([ "my_app" ])
w = LayoutView()
w.load_layout("myfile.gds", False)
w.max_hier()
w.show()
app.exec_()
# ensures that w is destroyed before app.
# Otherwise Qt segfaults.
w = None
Here are some technical documents for this project: