It looks like you're new here. If you want to get involved, click one of these buttons!
import pya
pya.MainWindow.instance().create_layout(0)
Doesn't work on my site. It gives following error message:
AttributeError: module 'pya' has no attribute 'MainWindow'
I have built klayout from master using the internal script "build.sh".
installDir/pymod is added to my PYTHONPATH.
Here is the list of symbols imported from pya:
[ 'AbsoluteProgress', 'AbstractProgress', 'ArgType', 'Box', 'Cell', 'CellInstArray', 'CellMapping', 'Circuit', 'Class', 'CompoundRegionOperationNode', 'Connectivity', 'CplxTrans', 'DBox', 'DCellInstArray', 'DCplxTrans', 'DEdge', 'DEdgePair', 'DPath', 'DPoint', 'DPolygon', 'DSimplePolygon', 'DText', 'DTrans', 'DVector', 'DeepShapeStore', 'Device', 'DeviceAbstract', 'DeviceAbstractRef', 'DeviceClass', 'DeviceClassBJT3Transistor', 'DeviceClassBJT4Transistor', 'DeviceClassCapacitor', 'DeviceClassCapacitorWithBulk', 'DeviceClassDiode', 'DeviceClassFactory', 'DeviceClassInductor', 'DeviceClassMOS3Transistor', 'DeviceClassMOS4Transistor', 'DeviceClassResistor', 'DeviceClassResistorWithBulk', 'DeviceExtractorBJT3Transistor', 'DeviceExtractorBJT4Transistor', 'DeviceExtractorBase', 'DeviceExtractorCapacitor', 'DeviceExtractorCapacitorWithBulk', 'DeviceExtractorDiode', 'DeviceExtractorMOS3Transistor', 'DeviceExtractorMOS4Transistor', 'DeviceExtractorResistor', 'DeviceExtractorResistorWithBulk', 'DeviceParameterDefinition', 'DeviceReconnectedTerminal', 'DeviceTerminalDefinition', 'Edge', 'EdgePair', 'EdgePairs', 'EdgeProcessor', 'Edges', 'EmptyClass', 'EqualDeviceParameters', 'Executable', 'ExecutableBase', 'Expression', 'ExpressionContext', 'GenericDeviceCombiner', 'GenericDeviceExtractor', 'GenericDeviceParameterCompare', 'GenericNetlistCompareLogger', 'GlobPattern', 'HAlign', 'ICplxTrans', 'IMatrix2d', 'IMatrix3d', 'InstElement', 'Instance', 'Interpreter', 'LEFDEFReaderConfiguration', 'LayerInfo', 'LayerMap', 'LayerMapping', 'Layout', 'LayoutDiff', 'LayoutMetaInfo', 'LayoutQuery', 'LayoutQueryIterator', 'LayoutToNetlist', 'LayoutVsSchematic', 'Library', 'LoadLayoutOptions', 'Logger', 'Manager', 'Matrix2d', 'Matrix3d', 'Method', 'MethodOverload', 'Net', 'NetElement', 'NetPinRef', 'NetSubcircuitPinRef', 'NetTerminalRef', 'NetTracer', 'NetTracerTechnology', 'Netlist', 'NetlistCompareLogger', 'NetlistComparer', 'NetlistCrossReference', 'NetlistDeviceExtractorError', 'NetlistDeviceExtractorLayerDefinition', 'NetlistObject', 'NetlistReader', 'NetlistSpiceReader', 'NetlistSpiceReaderDelegate', 'NetlistSpiceWriter', 'NetlistSpiceWriterDelegate', 'NetlistWriter', 'PCellDeclaration', 'PCellDeclarationHelper', 'PCellDeclaration_Native', 'PCellParameterDeclaration', 'ParentInstArray', 'ParseElementComponentsData', 'ParseElementData', 'Path', 'Pin', 'Point', 'Polygon', 'PreferredOrientation', 'Progress', 'RdbCategory', 'RdbCell', 'RdbItem', 'RdbItemValue', 'RdbReference', 'Recipe', 'RecursiveInstanceIterator', 'RecursiveShapeIterator', 'Region', 'RelativeProgress', 'ReportDatabase', 'SaveLayoutOptions', 'Shape', 'ShapeCollection', 'ShapeProcessor', 'Shapes', 'SimplePolygon', 'SubCircuit', 'Technology', 'TechnologyComponent', 'Text', 'TextGenerator', 'Texts', 'TileOutputReceiver', 'TileOutputReceiverBase', 'TilingProcessor', 'Timer', 'Trans', 'TrapezoidDecompositionMode', 'Utils', 'VAlign', 'VCplxTrans', 'Value', 'Vector', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', __path__', '__spec__']
"MainWindow" is not in the list. Am I missing something ?
Comments
Hi,
The main window instance can be obtained with: Application.instance().main_window()
Cheers,
Tomas
Hello tomas2004, thanks for looking into my problem.
Unfortunately also Application is not provided by the pya module (at least on my site):
I have just reinstalled the package "klayout_0.27.9-1_amd64.deb" to compare it with my local build.
I have seen that this package doesn't include any pya module but it still defines the klayout module.
After this installation I could write (in a python shell):
The same imports work also in my local build (with the additional of import pya).
They define a lot of symbols but I can not find any MainWindow nor any Application.
May you please tell me what has to be done, on Linux, to make it possible the creation of a klayout window from a python script ?
The closest thing I could find is QMainWindow in klayout.QtWidgets. But the command:
gives the error: "AttributeError: type object 'QMainWindow' has no attribute 'instance'"
A small progress, I have found MainWindow in klayout.lay:
But the result of:
is None.
@wsteffe The pymod is not working like the built-in Python interpreter. Those are entirely different things.
First of all, the pymods are separated into different modules. "pya" was already taken, so these modules are "klayout.db", etc. There are separate modules to reduce the overhead when loading the core features like "klayout.db" and enable Qt-less builds for PyPI.
When using the pymods, you need to import "klayout.lay", "klayout.db" etc.
MainWindow is in "klayout.lay" (this is indicated in the class documentation under 'module'). But you cannot use it - there is no MainWindow instance in pure Python. Neither is there a QApplication object. You can create simple UIs similar to what PyQt does, but currently you cannot regenerate a full KLayout application if this is what you are looking for.
Matthias
Thanks Matthias. Now it is clear.
I do not need to use a graphical view with the associated Application. The database is sufficient for my script. It was strange also for me that I had to use a layoutView to iterate over the layers data.
But this is the way suggested by you in the thread:
https://www.klayout.de/forum/discussion/1467/iterating-through-layers-with-particular-name.
This thread was the first thing I found entering "klayout iterate layout layers" in google.