Issues with KLayout Main Window vs Qt window


I am working on this small program where I have a Qt Dialog open alongside the workspace in editor mode. I am trying to create shapes with a button based on different options and then run some tests. But now I can't seem to even do the most basic things after I put the GUI together with my KLayout functions.

In one file I have the code for basic Layout creation and creating all my cells first. I normally ran this on its own but recently made it its own function so that I can use it in the GUI:
`def startUpFunction():
global layoutview
global V
global L
layoutview = pya.LayoutView.current()
V = pya.CellView().active().view()
L =

# create a layer
layer_index = L.insert_layer(pya.LayerInfo(5,0))
pya.LayerInfo(1,0).name = 'Outer Die Area'
pya.LayerInfo(2,0).name = 'Initial Available Area'
pya.LayerInfo(3,0).name = 'External Gate Runner Space'
pya.LayerInfo(4,0).name = 'Internal Gate Runner'
pya.LayerInfo(5,0).name = 'Areas Needed for Bond Pad Openings'

# create a cell
top = L.create_cell("Top")

available_area_cell = L.create_cell("Available Area")
inst =, pya.Trans())

initial_die_cell = L.create_cell("Initial Die")
inst =, pya.Trans())

Here's some of the Qt code for the GUI:
`if True or ('bpoDialog' not in globals()): # Just here for testing purposes
compNum = 0

#setup scroll area
scroll = pya.QScrollArea()
scroll.minimumWidth = 1250
scroll.windowTitle = 'BPO Tool Inputs'

bpoDialog = pya.QDialog(pya.Application.instance().main_window())
bpoDialog.windowTitle = 'BPO Tool Inputs'
bpoDialog.setModal(False) #pya.Qt.NonModal

grid = pya.QGridLayout(bpoDialog)

# addWidget( item, row, column, rowspan, columnspan )

row = 0

startUpButton = pya.QPushButton('CLICK TO START PROGRAM', bpoDialog)
grid.addWidget(startUpButton, row, 0, 1, 5)

And here's what that looks like:

When I try to run my function for the Available area:
`def availableAreaCreation(die_length, die_width, v_blocking):

total_die_area = (die_width/1000) * (die_length/1000)  # um inputs must be converted 

if total_die_area >= 10:  # if die area is over 10mm^2
    corner_curvature_radius = 500  # Corner radius of curvature in units of um
else:  # die area less than 10mm^2
    corner_curvature_radius = 200  # Corner radius of curvature in units of um

dicing_street_width = 80.0  # ET rings distance to die outer edge is ~80um (includes channel stop, etc.)
ext_source_runner_width = 20.0  # source runner (external) width is ~20um
edge_termination_rings_width_prop = 10.0  # ET rings width is ~10um per 100V of blocking voltage

available_area_length = die_length - 2*(dicing_street_width +
                             ext_source_runner_width + ((v_blocking/100) * edge_termination_rings_width_prop))

available_area_width = die_width - 2*(dicing_street_width +
                             ext_source_runner_width + ((v_blocking/100) * edge_termination_rings_width_prop))

# add a shape
die_points = [pya.DPoint(-die_width/2,-die_length/2), pya.DPoint(die_width/2,-die_length/2), 
                              pya.DPoint(die_width/2,die_length/2), pya.DPoint(-die_width/2,die_length/2)]

inner_area_points = [pya.DPoint(-available_area_width/2,-available_area_length/2), pya.DPoint(available_area_width/2,-available_area_length/2), 
                        pya.DPoint(available_area_width/2,available_area_length/2), pya.DPoint(-available_area_width/2,available_area_length/2)]

inner_area_poly = pya.DPolygon(inner_area_points).round_corners(0, corner_curvature_radius,64)
inner_bbox_temp = inner_area_poly.bbox()

die_poly = pya.DPolygon(die_points).insert_hole(inner_bbox_temp).round_corners(corner_curvature_radius, 0,64)

initial_die_cell.shapes(L.layer(1,0)).insert(die_poly) # pya.LayerInfo(1,0)

# select the top cell in the view, set up the view's layer list and
# fit the viewport to the extensions of our layout
layoutview.select_cell(top.cell_index(), 0)

I get the error saying "initial_die_area" is not defined. Which doesn't make any sense because I have also tried making all of those cells and everything global and that doesn't seem to work either. I'm guessing that my code might be accidentally trying to look for things on the Qt Layout rather than the actual KLayout workspace? It confused me a bit how the Qt dialog is created using that pya.QDialog(pya.Application.instance().main_window()) and figured that might be causing issues. I definitely have something wrong, but not sure what. I appreciate any help.


  • Kyle


  • Hi Kyle,

    thanks for sharing the code, but I think, parts are missing.

    Basically, QLayout and Layout are different things and I cannot imagine they get confused. Your code appears to be correct on first glance, and the generation of the QDialog is fine. QDialog needs a reference to the main window (a QWindow object) so the dialog pops up connected to this window. There is no link to the Layout object here.

    When looking into the code you provided, I do not see "initial_die_area" anywhere. Is that supposed to be a function or variable and where is it defined and how to you access it?


Sign In or Register to comment.