def createSchematicLib(self): if Appconfig.esimFlag == 1: if not self.errorFlag: print('Creating library files................................') schematicLib = AutoSchematic(self.modelname) schematicLib.createKicadLibrary() else: QtGui.QMessageBox.critical( self, 'Error', '''Cannot create Schematic Library of ''' + '''your model. Resolve the <b>errors</b> shown on ''' + '''console of NGHDL window. ''' ) else: QtGui.QMessageBox.information( self, 'Message', '''<b>Important Message</b><br/><br/>''' + '''To create Schematic Library of your model, ''' + '''use NGHDL through <b>eSim</b> ''' )
def createSchematicLib(self): if os.name == "nt": shutil.copy("ghdl/ghdl.cm", "../../../../lib/ngspice/") os.chdir(self.cur_dir) if Appconfig.esimFlag == 1: if not self.errorFlag: print('Creating library files................................') schematicLib = AutoSchematic(self, self.modelname) schematicLib.createKicadLibrary() else: QtWidgets.QMessageBox.critical( self, 'Error', '''Cannot create Schematic Library of ''' + '''your model. Resolve the <b>errors</b> shown on ''' + '''console of NGHDL window. ''') else: QtWidgets.QMessageBox.information( self, 'Message', '''<b>Important Message</b><br/><br/>''' + '''To create Schematic Library of your model, ''' + '''use NGHDL through <b>eSim</b> ''')
def createSchematicLib(self): if Appconfig.esimFlag == 1: print('Creating library files.................................') schematicLib = AutoSchematic(self.modelname) schematicLib.createKicadLibrary()
class Mainwindow(QtGui.QWidget): def __init__(self): #super(Mainwindow, self).__init__() QtGui.QMainWindow.__init__(self) print "Initializing.........." self.home = os.path.expanduser("~") licensefile = os.path.join( os.path.join(self.home, Appconfig.nghdl_src_loc), "LICENSE") fileopen = open(licensefile, 'r') print fileopen.read() self.parser = SafeConfigParser() self.parser.read( os.path.join(self.home, Appconfig.nghdl_src_loc + '/config.ini')) self.file_list = [] #to keep the supporting files self.initUI() def initUI(self): self.uploadbtn = QtGui.QPushButton('Upload') self.uploadbtn.clicked.connect(self.uploadModle) self.exitbtn = QtGui.QPushButton('Exit') self.exitbtn.clicked.connect(self.closeWindow) self.browsebtn = QtGui.QPushButton('Browse') self.browsebtn.clicked.connect(self.browseFile) self.addbtn = QtGui.QPushButton('Add Files') self.addbtn.clicked.connect(self.addFiles) self.removebtn = QtGui.QPushButton('Remove Files') self.removebtn.clicked.connect(self.removeFiles) self.ledit = QtGui.QLineEdit(self) self.sedit = QtGui.QTextEdit(self) self.process = QtCore.QProcess(self) #self.terminal = QtGui.QWidget(self) self.termedit = QtGui.QTextEdit(self) self.termedit.setReadOnly(1) pal = QtGui.QPalette() bgc = QtGui.QColor(0, 0, 0) pal.setColor(QtGui.QPalette.Base, bgc) self.termedit.setPalette(pal) self.termedit.setStyleSheet("QTextEdit {color:white}") #self.process.start('xterm',['-into', str(self.terminal.winId())]) #Creating gridlayout grid = QtGui.QGridLayout() grid.setSpacing(5) grid.addWidget(self.ledit, 1, 0) grid.addWidget(self.browsebtn, 1, 1) grid.addWidget(self.sedit, 2, 0, 4, 1) grid.addWidget(self.addbtn, 2, 1) grid.addWidget(self.removebtn, 3, 1) #grid.addWidget(self.terminal, 6, 0,10,1) grid.addWidget(self.termedit, 6, 0, 10, 1) grid.addWidget(self.uploadbtn, 17, 0) grid.addWidget(self.exitbtn, 17, 1) self.setLayout(grid) self.setGeometry(300, 300, 600, 600) self.setWindowTitle("Ngspice Digital Model Creator") #self.setWindowIcon(QtGui.QIcon('logo.png')) self.show() def closeWindow(self): try: self.process.close() except: pass print "Close button clicked" quit() def browseFile(self): print "Browse button clicked" self.filename = QtGui.QFileDialog.getOpenFileName( self, 'Open File', '.') print "Path file :", self.filename self.ledit.setText(self.filename) def addFiles(self): print "Add Files button clicked" title = self.addbtn.text() for file in QtGui.QFileDialog.getOpenFileNames(self, title): print "Supporting file :", file self.sedit.append(str(file)) self.file_list.append(file) def removeFiles(self): self.fileRemover = FileRemover(self) #check extensions of all supporting files def checkSupportFiles(self): nonvhdl_count = 0 for file in self.file_list: extension = os.path.splitext(str(file))[1] if extension != ".vhdl": nonvhdl_count += 1 self.file_list.remove(file) if nonvhdl_count > 0: QtGui.QMessageBox.about( self, 'Message', '''<b>Important Message.</b><br/><br/>This accepts only <b>.vhdl</b> file ''' ) def createModelDirectory(self): print "Create Model Directory Called" self.digital_home = self.parser.get('NGSPICE', 'DIGITAL_MODEL') print "Digital Home", self.digital_home os.chdir(self.digital_home) print "Current Working Directory Changed to", os.getcwd() self.modelname = os.path.basename(str(self.filename)).split('.')[0] print "Model name is :", self.modelname # Looking if model directory is present or not if os.path.isdir(self.modelname): print "Model Already present" ret = QtGui.QMessageBox.critical( self, "Critical", '''<b>The Model already exist.Do you want to overwrite it?</b><br/> <b>If yes press ok else cancel it and change the name of you vhdl file</b>''', QtGui.QMessageBox.Ok, QtGui.QMessageBox.Cancel) if ret == QtGui.QMessageBox.Ok: print "Overwriting existing model" cmd = "rm -rf " + self.modelname #process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) subprocess.call(cmd, shell=True) os.mkdir(self.modelname) else: print "Exiting application" quit() else: print "Creating new model directory" os.mkdir(self.modelname) def addingModelInModpath(self): print "Adding Model in Modpath file", self.modelname, self.digital_home #Adding name of model in the modpath file #Check if the string is already in the file with open(self.digital_home + "/modpath.lst", 'a+') as f: flag = 0 for line in f: if line.strip() == self.modelname: print "Found model" flag = 1 break else: pass if flag == 0: print "Adding model name into modpath.lst" f.write(self.modelname + "\n") else: print "Model name is already into modpath.lst" def createModelFiles(self): print "Create Model Files Called" os.chdir(self.cur_dir) print "Current Working directory changed to ", self.cur_dir cmd = "python ~/" + Appconfig.nghdl_src_loc + "/model_generation.py " + str( self.ledit.text()) stdouterr = os.popen4(cmd)[1].read() print stdouterr #Moving file to model directory path = self.digital_home + "/" + self.modelname shutil.move("cfunc.mod", path) shutil.move("ifspec.ifs", path) #Creating directory inside model directoy os.mkdir(path + "/DUTghdl/") shutil.move("connection_info.txt", path + "/DUTghdl/") shutil.move("start_server.sh", path + "/DUTghdl/") shutil.move("sock_pkg_create.sh", path + "/DUTghdl/") shutil.move(self.modelname + "_tb.vhdl", path + "/DUTghdl/") shutil.copy(str(self.filename), path + "/DUTghdl/") shutil.copy( os.path.join(self.home, Appconfig.nghdl_src_loc) + "/ghdlserver/compile.sh", path + "/DUTghdl/") shutil.copy( os.path.join(self.home, Appconfig.nghdl_src_loc) + "/ghdlserver/uthash.h", path + "/DUTghdl/") shutil.copy( os.path.join(self.home, Appconfig.nghdl_src_loc) + "/ghdlserver/ghdlserver.c", path + "/DUTghdl/") shutil.copy( os.path.join(self.home, Appconfig.nghdl_src_loc) + "/ghdlserver/ghdlserver.h", path + "/DUTghdl/") shutil.copy( os.path.join(self.home, Appconfig.nghdl_src_loc) + "/ghdlserver/Utility_Package.vhdl", path + "/DUTghdl/") shutil.copy( os.path.join(self.home, Appconfig.nghdl_src_loc) + "/ghdlserver/Vhpi_Package.vhdl", path + "/DUTghdl/") for file in self.file_list: shutil.copy(str(file), path + "/DUTghdl/") os.chdir(path + "/DUTghdl") subprocess.call("bash " + path + "/DUTghdl/compile.sh", shell=True) subprocess.call("chmod a+x start_server.sh", shell=True) subprocess.call("chmod a+x sock_pkg_create.sh", shell=True) os.remove("compile.sh") os.remove("ghdlserver.c") #os.remove("ghdlserver.h") #os.remove("Utility_Package.vhdl") #os.remove("Vhpi_Package.vhdl") #slot to redirect stdout to window console @QtCore.pyqtSlot() def readStdOutput(self): self.termedit.append( QtCore.QString(self.process.readAllStandardOutput())) def runMake(self): print "run Make Called" self.release_home = self.parser.get('NGSPICE', 'RELEASE') os.chdir(self.release_home) try: cmd = " make" print "Running Make" path = os.getcwd() #subprocess.call(cmd,shell=True) #command = "cd "+path +";"+cmd +";"+"make install" #command = "cd "+path +";"+cmd #self.args = ['-into', str(self.terminal.winId()),'-hold','+s','-e', command] #self.process.start('xterm', self.args) self.process.start(cmd) self.process.setProcessChannelMode(QtCore.QProcess.MergedChannels) QtCore.QObject.connect(self.process, QtCore.SIGNAL("readyReadStandardOutput()"), self, QtCore.SLOT("readStdOutput()")) print "pid ------ >", self.process.pid() #stdouterr = os.popen4(cmd)[1].read() #self.tedit.append(stdouterr) except: print "There is error in 'make' " quit() def runMakeInstall(self): print "run Make Install Called" try: cmd = " make install" print "Running Make Install" path = os.getcwd() print "cwd------------>", path #subprocess.call(cmd,shell=True) #command = "cd "+path+ ";"+cmd #self.args = ['-into', str(self.terminal.winId()),'-hold','-e', command] #self.process.start('xterm', self.args) #self.process.waitForFinished(-1) #stdouterr = os.popen4(cmd)[1].read() #self.tedit.append(stdouterr) try: self.process.close() except: pass self.process.finished.connect(self.createSchematicLib) self.process.start(cmd) self.process.setProcessChannelMode(QtCore.QProcess.MergedChannels) QtCore.QObject.connect(self.process, QtCore.SIGNAL("readyReadStandardOutput()"), self, QtCore.SLOT("readStdOutput()")) os.chdir(self.cur_dir) except: print "There is error during in 'make install' " quit() def createSchematicLib(self): if Appconfig.esimFlag == 1: print 'Creating library files.................................' self.schematicLib = AutoSchematic(self.modelname) self.schematicLib.createKicadLibrary() def uploadModle(self): print "Upload button clicked" try: self.process.close() except: pass try: self.file_extension = os.path.splitext(str(self.filename))[1] print "File extension", self.file_extension print "Parser Content:", self.parser.get('NGSPICE', 'NGSPICE_HOME') self.cur_dir = os.getcwd() print "My Current Working Directory", self.cur_dir self.checkSupportFiles() if self.file_extension == ".vhdl": self.createModelDirectory() self.addingModelInModpath() self.createModelFiles() self.runMake() self.runMakeInstall() else: QtGui.QMessageBox.about( self, 'Message', '''<b>Important Message.</b><br/><br/>This accepts only <b>.vhdl</b> file ''' ) except: QtGui.QMessageBox.about( self, 'Message', '''<b>Error</b><br/><br/> select a <b>.vhdl</b> file ''')
class Mainwindow(QtGui.QWidget): def __init__(self): #super(Mainwindow, self).__init__() QtGui.QMainWindow.__init__(self) print "Initializing.........." self.home = os.path.expanduser("~") licensefile = os.path.join(os.path.join(self.home, Appconfig.nghdl_src_loc), "LICENSE") fileopen = open(licensefile, 'r') print fileopen.read() self.parser = SafeConfigParser() self.parser.read(os.path.join(self.home, Appconfig.nghdl_src_loc+'/config.ini')) self.file_list = [] #to keep the supporting files self.initUI() def initUI(self): self.uploadbtn = QtGui.QPushButton('Upload') self.uploadbtn.clicked.connect(self.uploadModle) self.exitbtn = QtGui.QPushButton('Exit') self.exitbtn.clicked.connect(self.closeWindow) self.browsebtn = QtGui.QPushButton('Browse') self.browsebtn.clicked.connect(self.browseFile) self.addbtn = QtGui.QPushButton('Add Files') self.addbtn.clicked.connect(self.addFiles) self.removebtn = QtGui.QPushButton('Remove Files') self.removebtn.clicked.connect(self.removeFiles) self.ledit = QtGui.QLineEdit(self) self.sedit = QtGui.QTextEdit(self) self.process = QtCore.QProcess(self) #self.terminal = QtGui.QWidget(self) self.termedit = QtGui.QTextEdit(self) self.termedit.setReadOnly(1) pal = QtGui.QPalette() bgc = QtGui.QColor(0, 0, 0) pal.setColor(QtGui.QPalette.Base, bgc) self.termedit.setPalette(pal) self.termedit.setStyleSheet("QTextEdit {color:white}") #self.process.start('xterm',['-into', str(self.terminal.winId())]) #Creating gridlayout grid = QtGui.QGridLayout() grid.setSpacing(5) grid.addWidget(self.ledit, 1, 0) grid.addWidget(self.browsebtn, 1, 1) grid.addWidget(self.sedit, 2, 0, 4, 1) grid.addWidget(self.addbtn, 2, 1) grid.addWidget(self.removebtn, 3, 1) #grid.addWidget(self.terminal, 6, 0,10,1) grid.addWidget(self.termedit, 6, 0, 10, 1) grid.addWidget(self.uploadbtn, 17, 0) grid.addWidget(self.exitbtn,17, 1) self.setLayout(grid) self.setGeometry(300, 300, 600,600) self.setWindowTitle("Ngspice Digital Model Creator") #self.setWindowIcon(QtGui.QIcon('logo.png')) self.show() def closeWindow(self): try: self.process.close() except: pass print "Close button clicked" quit() def browseFile(self): print "Browse button clicked" self.filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.') print "Path file :", self.filename self.ledit.setText(self.filename) def addFiles(self): print "Add Files button clicked" title = self.addbtn.text() for file in QtGui.QFileDialog.getOpenFileNames(self, title): print "Supporting file :", file self.sedit.append(str(file)) self.file_list.append(file) def removeFiles(self): self.fileRemover = FileRemover(self) #check extensions of all supporting files def checkSupportFiles(self): nonvhdl_count = 0 for file in self.file_list: extension = os.path.splitext(str(file))[1] if extension != ".vhdl": nonvhdl_count += 1 self.file_list.remove(file) if nonvhdl_count > 0: QtGui.QMessageBox.about(self,'Message','''<b>Important Message.</b><br/><br/>This accepts only <b>.vhdl</b> file ''') def createModelDirectory(self): print "Create Model Directory Called" self.digital_home=self.parser.get('NGSPICE','DIGITAL_MODEL') print "Digital Home",self.digital_home os.chdir(self.digital_home) print "Current Working Directory Changed to",os.getcwd() self.modelname = os.path.basename(str(self.filename)).split('.')[0] print "Model name is :",self.modelname # Looking if model directory is present or not if os.path.isdir(self.modelname): print "Model Already present" ret = QtGui.QMessageBox.critical(self, "Critical",'''<b>The Model already exist.Do you want to overwrite it?</b><br/> <b>If yes press ok else cancel it and change the name of you vhdl file</b>''', QtGui.QMessageBox.Ok, QtGui.QMessageBox.Cancel) if ret == QtGui.QMessageBox.Ok: print "Overwriting existing model" cmd="rm -rf "+self.modelname #process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) subprocess.call(cmd, shell=True) os.mkdir(self.modelname) else: print "Exiting application" quit() else: print "Creating new model directory" os.mkdir(self.modelname) def addingModelInModpath(self): print "Adding Model in Modpath file",self.modelname,self.digital_home #Adding name of model in the modpath file #Check if the string is already in the file with open(self.digital_home+"/modpath.lst",'a+') as f: flag = 0 for line in f: if line.strip() == self.modelname: print "Found model" flag = 1 break else: pass if flag == 0: print "Adding model name into modpath.lst" f.write(self.modelname+"\n") else: print "Model name is already into modpath.lst" def createModelFiles(self): print "Create Model Files Called" os.chdir(self.cur_dir) print "Current Working directory changed to ",self.cur_dir cmd = "python ~/"+Appconfig.nghdl_src_loc+"/model_generation.py "+str(self.ledit.text()) stdouterr = os.popen4(cmd)[1].read() print stdouterr #Moving file to model directory path=self.digital_home+"/"+self.modelname shutil.move("cfunc.mod",path) shutil.move("ifspec.ifs",path) #Creating directory inside model directoy os.mkdir(path+"/DUTghdl/") shutil.move("connection_info.txt",path+"/DUTghdl/") shutil.move("start_server.sh",path+"/DUTghdl/") shutil.move("sock_pkg_create.sh",path+"/DUTghdl/") shutil.move(self.modelname+"_tb.vhdl",path+"/DUTghdl/") shutil.copy(str(self.filename),path+"/DUTghdl/") shutil.copy(os.path.join(self.home, Appconfig.nghdl_src_loc)+"/ghdlserver/compile.sh",path+"/DUTghdl/") shutil.copy(os.path.join(self.home, Appconfig.nghdl_src_loc)+"/ghdlserver/uthash.h",path+"/DUTghdl/") shutil.copy(os.path.join(self.home, Appconfig.nghdl_src_loc)+"/ghdlserver/ghdlserver.c",path+"/DUTghdl/") shutil.copy(os.path.join(self.home, Appconfig.nghdl_src_loc)+"/ghdlserver/ghdlserver.h",path+"/DUTghdl/") shutil.copy(os.path.join(self.home, Appconfig.nghdl_src_loc)+"/ghdlserver/Utility_Package.vhdl",path+"/DUTghdl/") shutil.copy(os.path.join(self.home, Appconfig.nghdl_src_loc)+"/ghdlserver/Vhpi_Package.vhdl",path+"/DUTghdl/") for file in self.file_list: shutil.copy(str(file), path+"/DUTghdl/") os.chdir(path+"/DUTghdl") subprocess.call("bash "+path+"/DUTghdl/compile.sh", shell=True) subprocess.call("chmod a+x start_server.sh",shell=True) subprocess.call("chmod a+x sock_pkg_create.sh",shell=True) os.remove("compile.sh") os.remove("ghdlserver.c") #os.remove("ghdlserver.h") #os.remove("Utility_Package.vhdl") #os.remove("Vhpi_Package.vhdl") #slot to redirect stdout to window console @QtCore.pyqtSlot() def readStdOutput(self): self.termedit.append(QtCore.QString(self.process.readAllStandardOutput())) def runMake(self): print "run Make Called" self.release_home=self.parser.get('NGSPICE','RELEASE') os.chdir(self.release_home) try: cmd = " make" print "Running Make" path = os.getcwd() #subprocess.call(cmd,shell=True) #command = "cd "+path +";"+cmd +";"+"make install" #command = "cd "+path +";"+cmd #self.args = ['-into', str(self.terminal.winId()),'-hold','+s','-e', command] #self.process.start('xterm', self.args) self.process.start(cmd) self.process.setProcessChannelMode(QtCore.QProcess.MergedChannels) QtCore.QObject.connect(self.process, QtCore.SIGNAL("readyReadStandardOutput()"), self, QtCore.SLOT("readStdOutput()")) print "pid ------ >",self.process.pid() #stdouterr = os.popen4(cmd)[1].read() #self.tedit.append(stdouterr) except: print "There is error in 'make' " quit() def runMakeInstall(self): print "run Make Install Called" try: cmd = " make install" print "Running Make Install" path = os.getcwd() print "cwd------------>", path #subprocess.call(cmd,shell=True) #command = "cd "+path+ ";"+cmd #self.args = ['-into', str(self.terminal.winId()),'-hold','-e', command] #self.process.start('xterm', self.args) #self.process.waitForFinished(-1) #stdouterr = os.popen4(cmd)[1].read() #self.tedit.append(stdouterr) try: self.process.close() except: pass self.process.finished.connect(self.createSchematicLib) self.process.start(cmd) self.process.setProcessChannelMode(QtCore.QProcess.MergedChannels) QtCore.QObject.connect(self.process, QtCore.SIGNAL("readyReadStandardOutput()"), self, QtCore.SLOT("readStdOutput()")) os.chdir(self.cur_dir) except: print "There is error during in 'make install' " quit() def createSchematicLib(self): if Appconfig.esimFlag == 1: print 'Creating library files.................................' self.schematicLib = AutoSchematic(self.modelname) self.schematicLib.createKicadLibrary() def uploadModle(self): print "Upload button clicked" try: self.process.close() except: pass try: self.file_extension = os.path.splitext(str(self.filename))[1] print "File extension",self.file_extension print "Parser Content:",self.parser.get('NGSPICE', 'NGSPICE_HOME') self.cur_dir = os.getcwd() print "My Current Working Directory",self.cur_dir self.checkSupportFiles() if self.file_extension == ".vhdl": self.createModelDirectory() self.addingModelInModpath() self.createModelFiles() self.runMake() self.runMakeInstall() else: QtGui.QMessageBox.about(self,'Message','''<b>Important Message.</b><br/><br/>This accepts only <b>.vhdl</b> file ''') except: QtGui.QMessageBox.about(self, 'Message','''<b>Error</b><br/><br/> select a <b>.vhdl</b> file ''')