Glade Reference


Programming Glade in Python

The entire Glade database and much of the UI is wrapped in Python using SWIG. This means you can write Python scripts to automate tasks - PCells (parameterised cells) are a good example. Why Python? Well it is an object-oriented language and so it wraps C++ well, unlike some other interpreted languages.

You can enter python commands directly at the command line. Some useful ones:

    getSelectedSet()

returns a python list of the selected objects. You can print information about an object using the print command:

    objs = getSelectedSet()
    for obj in objs :
       print obj


To get the current cellview, use:

    cv = getEditCellView()

 

To open a library, use:

    lib = getLibByName("myLib")

 

To open a cellView, use:

# 'r' opens an existing cell for read, 'a' opens an existing cell for edit, 'w' creates a new cell.
    cv = lib.dbOpenCellView("myCell", "layout", 'a')

 

Some python bindings require arrays of coordinates. You can use the python intarray(number_of_elements) function to create an array with a specified size.

 

The command line interpreter

The message window at the bottom of the Glade main window is split into two parts: the message pane, which shows messages and output from the Python interpreter. You can use the Right Mouse Button to copy text from the message pane. Below the message pane is the command line. You can type Python commands into the command line.

 

The Python command line supports various control characters to assist in typing in Python commands:

Left Arrow - move the cursor one character left.

Right Arrow - move the cursor one character right.

Up arrow - retrieve previous command (or clear line if no previous command)

Down arrow - retrieve next command (or clear line if no next command)

Home - move the cursor to the start of the line

End - move the cursor to the end of the line

Ctrl-A - select all text on the line

Ctrl-C - copy the selected text to the clipboard

Ctrl-V - paste the clipboard to the line

Ctrl-X - delete the selected text

Ctrl-Z - undo the last editing operation

Ctrl-Y - redo the last editing operation

 

Writing Python scripts

An example of a Python script follows. At present, the python bindings are not completely undocumented. Don't forget that Python relies on indentation for e.g. for and while loops!

     # Example python script
     print 'Starting script...'

     #
     # Create a new library, called 'fred'
     lib = library("fred")
     #
     # Create a new cellView in this library
     cv = lib.dbOpenCellView("test", "layout", 'w')
     #
     # A rectangle. By default database units are 0.001 micron
     width = 10000
     pitch = width * 2
     r = Rect(0, 0, 0, 0)
     #
     # Create four rectangles on layer 1
     layer = 1
     for i in range(2) :
     	for j in range(2) :
       		r.setLeft(j * pitch) 
       		r.setRight(j * pitch + width)
       		r.setBottom(i * pitch)
       		r.setTop(i * pitch + width)
       		cv.dbCreateRect(r, layer);
     #
     # Update the cellView after creating any objects
     cv.update()
     #
     # Open the cellView for display
     ui().openCellView("fred", "test", "layout")
     #
     # Do a region query
     q = cv.bBox()
     objs = cv.dbGetOverlaps(q, layer)
     obj = objs.first()
     while obj :
      	print 'found object ', obj.objName(), ' with origin = (', obj.left(), obj.bottom(), ')'
      	obj = objs.next()
     #
     print 'Finished script...'

 

Database reference

The following sections of the database bindings have been documented. More will be added when time permits.

Contents|Index

Copyright © Peardrop Design 2020.