Adding text on the layoutview images

edited May 1 in Python scripting

Hello, with the following code I am getting the image of a box that I draw.

My question: Is there a way to add text or title on the png image (I want to write dimensions and center coordinates of the box on top left corner of the png image)

       import pya

            # coordinates for the window to screenshot in µm
            l =-1.5   #       LOWER LEFT X
            r = 1.5    #    UPPER RIGHT X
            b = -2   #     LOWER LEFT Y
            t = 2    #          UPPER RIGHT Y

            dbu=1000

            mylayout=pya.Layout()
            layer=mylayout.layer(1,0)

            cell=mylayout.create_cell('Top_cell')   
            cell.shapes(layer).insert(pya.Box(l*dbu,b*dbu,r*dbu,t*dbu))  #LOWLX, LOWLY, UPRX, UPRY

            app = pya.Application.instance()
            mw = app.main_window()
            lv = mw.current_view()
            lv.zoom_box(pya.DBox(l, b, r, t))

            mylayout.write("File_name.oas")
            lv.save_image("image_file.png", 640, 480)

Thanks in advance!

Comments

  • Hi, Ege!

    I think you need to use LayoutView.get_image and then change resulted QImage. See also QImage Qt documentation.

  • Hello, Eugene!
    Thanks for the answer. I will take a look.

    By the way is there a way to read data from CSV files using pandas library? I can call libraries like numpy in Klayout but when I try to call pandas it says no module named pandas

  • Is cvs module accessible in KLayout?

  • Yes csv module works. Though is there a way to include pandas?

  • You could try to change PYTHONPATH environment variable before launching KLayout, but you need to make sure that Python versions are same in you system and KLayout.

  • It's KLAYOUT_PYTHONPATH, because PYTHONPATH is set by some installers and interferes with KLayout. KLayout reads "KLAYOUT_PYTHONPATH" therefore.

    But if you include binary packages, you're likely to fail if these packages are not compatible with the ABI KLayout employs (gcc mingw64). You will see a crash then.

    There is minimum maintenance for the Windows distribution currently. Please accept this or find some permanent maintainer for the Windows distribution. Windows deployment sucks and takes money (for code signing certificates for example). Please understand that I can't provide extended service here.

    Matthias

Sign In or Register to comment.