Build QT UI in python module to run DRC

Hi there!

I am currently trying to write some python UI module, basically using a bunch of checkboxes for the DRC file that you wanna execute, and once you checked the check box then you press a button, it will start to execute the bunch of DRC file. \

I wonder what the API call for running the DRC file in the python module.

Thank you very much
Andy

Comments

  • Yes, exactly. This is your friend :)

    Matthias

  • That's all the way to the bottom of the turtle-pond, yep.
    Turtles, turtles, turtles.

    Please post your work once you get it solved so the
    less (or not at all) clueful among us, can get some
    traction.

  • edited June 2022

    yes here is some stack overflow level sample code for people who just getting started

      def button_clicked(self, checked):
    
            basePath = r"C:\Users\KLayout\drc\10-Corner85.lydrc"
            testPath = r"C:\Users\KLayout\drc"
            runArray = []
            for x in os.listdir(testPath):
                if(getattr(self, x).isChecked() == True):
                    print(os.path.join(testPath, x))
                    runArray.append(os.path.join(testPath, x))
            for i in runArray:
                pya.Macro(i).run()
    

    pya.Macro(i).run is the key to it

    also here is something interesting how to pass a variable to the macro that you wanna run

        def button_clicked(self, checked):
            outputPath = r"D:\All_Code\PythonCode\klayout\code\output_prompt.py"
            testParm = pya.Value(20)
            someInterpreter = pya.Interpreter().python_interpreter().define_variable("peepee", testParm)
            pya.Macro(outputPath).run()
            self.image.setText("GIGGITY")
    

    here is the code inside output_prompt.py

    print(peepee.value + 30)
    

    and the output is 50

  • Hi Matthias,

    Does this work in the "import klayout, pya" external Python mode? I installed the SiEPIC-EBeam-PDK using PyPI, and try to run the DRC

     m = pya.Macro.new(drc_script)
     m.run()
    

    and get this error:

     RuntimeError: Can't run macro (no interpreter): /Users/lukasc/.pyenv/versions/3.11.1/lib/python3.11/site-packages/siepic_ebeam_pdk/drc/SiEPIC_EBeam_DRC.lydrc in Macro.run
    
  • Hi Lukas,

    problem is that the Python module does not come with a Ruby interpreter and that is the basis of DRC scripts.

    Obviously it is not a good idea to embed Ruby into a Python module. Apart from being freaky, this will not work as Ruby wants to take over the top level stack frame for their garbage collector implementation.

    I'm afraid the only option is to run DRC as a KLayout subprocess.

    Matthias

  • Thank you.

Sign In or Register to comment.