diff options
Diffstat (limited to 'src/kicadtoNgspice/Model.py')
-rw-r--r-- | src/kicadtoNgspice/Model.py | 85 |
1 files changed, 43 insertions, 42 deletions
diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py index 25a23d8c..11d65c03 100644 --- a/src/kicadtoNgspice/Model.py +++ b/src/kicadtoNgspice/Model.py @@ -1,8 +1,7 @@ - from PyQt4 import QtGui - +import json import TrackWidget -from xml.etree import ElementTree as ET +#from xml.etree import ElementTree as ET import os @@ -18,19 +17,15 @@ class Model(QtGui.QWidget): #Processing for getting previous values kicadFile = clarg1 - (projpath,filename)=os.path.split(kicadFile) - project_name=os.path.basename(projpath) - check=1 + (projpath,filename) = os.path.split(kicadFile) + project_name = os.path.basename(projpath) + try: - f=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'r') - tree=ET.parse(f) - parent_root=tree.getroot() - for child in parent_root: - if child.tag=="model": - root=child + f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + data = f.read() + json_data = json.loads(data) except: - check=0 - print "Model Previous Values XML is Empty" + print "Model Previous Values JSON is Empty" @@ -54,12 +49,12 @@ class Model(QtGui.QWidget): #Adding title label for model #Key: Tag name,Value:Entry widget number tag_dict = {} - modelbox=QtGui.QGroupBox() - modelgrid=QtGui.QGridLayout() + modelbox = QtGui.QGroupBox() + modelgrid = QtGui.QGridLayout() modelbox.setTitle(line[5]) - self.start=self.nextcount + self.start = self.nextcount #line[7] is parameter dictionary holding parameter tags. - i=0 + i = 0 for key,value in line[7].iteritems(): #print "Key : ",key #print "Value : ",value @@ -69,36 +64,42 @@ class Model(QtGui.QWidget): temp_tag = [] for item in value: paramLabel = QtGui.QLabel(item) - modelgrid.addWidget(paramLabel,self.nextrow,0) - self.obj_trac.model_entry_var[self.nextcount]= QtGui.QLineEdit() - modelgrid.addWidget(self.obj_trac.model_entry_var[self.nextcount],self.nextrow,1) + modelgrid.addWidget(paramLabel, self.nextrow, 0) + self.obj_trac.model_entry_var[self.nextcount] = QtGui.QLineEdit() + modelgrid.addWidget(self.obj_trac.model_entry_var[self.nextcount], self.nextrow, 1) + try: - for child in root: - if child.text==line[2] and child.tag==line[3]: - self.obj_trac.model_entry_var[self.nextcount].setText(child[i].text) - i=i+1 + for mod in json_data["model"]: + if json_data["model"][mod]["type"] == line[2] and mod == line[3]: + self.obj_trac.model_entry_var[self.nextcount].setText(str(json_data["model"][mod]["values"][i].values()[0])) + i = i + 1 except: pass + temp_tag.append(self.nextcount) - self.nextcount = self.nextcount+1 - self.nextrow = self.nextrow+1 + self.nextcount = self.nextcount + 1 + self.nextrow = self.nextrow + 1 tag_dict[key] = temp_tag + else: paramLabel = QtGui.QLabel(value) - modelgrid.addWidget(paramLabel,self.nextrow,0) - self.obj_trac.model_entry_var[self.nextcount]= QtGui.QLineEdit() - modelgrid.addWidget(self.obj_trac.model_entry_var[self.nextcount],self.nextrow,1) + modelgrid.addWidget(paramLabel, self.nextrow, 0) + self.obj_trac.model_entry_var[self.nextcount] = QtGui.QLineEdit() + modelgrid.addWidget(self.obj_trac.model_entry_var[self.nextcount], self.nextrow, 1) + try: - for child in root: - if child.text==line[2] and child.tag==line[3]: - self.obj_trac.model_entry_var[self.nextcount].setText(child[i].text) - i=i+1 + for mod in json_data["model"]: + if json_data["model"][mod]["type"] == line[2] and mod == line[3]: + self.obj_trac.model_entry_var[self.nextcount].setText(str(json_data["model"][mod]["values"][i].values()[0])) + i = i + 1 except: pass + tag_dict[key] = self.nextcount - self.nextcount = self.nextcount+1 - self.nextrow = self.nextrow+1 - self.end= self.nextcount-1 + self.nextcount = self.nextcount + 1 + self.nextrow = self.nextrow + 1 + + self.end = self.nextcount - 1 #print "End",self.end modelbox.setLayout(modelgrid) @@ -123,13 +124,13 @@ class Model(QtGui.QWidget): ''' #This keeps the track of Model Tab Widget - lst=[line[0],line[1],line[2],line[3],line[4],line[5],line[6],self.start,self.end,tag_dict] - check=0 + lst = [line[0], line[1], line[2], line[3], line[4], line[5], line[6], self.start, self.end, tag_dict] + check = 0 for itr in self.obj_trac.modelTrack: - if itr==lst: - check=1 + if itr == lst: + check = 1 - if check==0: + if check == 0: self.obj_trac.modelTrack.append(lst) #print "The tag dictionary : ",tag_dict |