From cb55e59de7ee4383c04edfae7c39ad9ae9552b36 Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Fri, 14 Feb 2020 15:16:35 +0530 Subject: common code for Win and Linux, merged py2 changes --- src/kicadtoNgspice/Source.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/kicadtoNgspice/Source.py') diff --git a/src/kicadtoNgspice/Source.py b/src/kicadtoNgspice/Source.py index 26555197..6c5ae637 100644 --- a/src/kicadtoNgspice/Source.py +++ b/src/kicadtoNgspice/Source.py @@ -1,7 +1,6 @@ import os from PyQt4 import QtGui from . import TrackWidget -# from xml.etree import ElementTree as ET import json @@ -13,7 +12,7 @@ class Source(QtGui.QWidget): def __init__(self, sourcelist, sourcelisttrack, clarg1): QtGui.QWidget.__init__(self) self.obj_track = TrackWidget.TrackWidget() - # Variable + # Variables self.count = 1 self.clarg1 = clarg1 self.start = 0 @@ -45,10 +44,10 @@ class Source(QtGui.QWidget): - Each line in sourcelist corresponds to a source - According to the source type modify the source and add it to the tab """ - print("============================================================") + """print("============================================================") print("SOURCE LIST TRACK", sourcelisttrack) print("SOURCE LIST", sourcelist) - print("============================================================") + print("============================================================")""" kicadFile = self.clarg1 (projpath, filename) = os.path.split(kicadFile) project_name = os.path.basename(projpath) @@ -71,10 +70,8 @@ class Source(QtGui.QWidget): if sourcelist: for line in sourcelist: - # print "Voltage source line index: ",line[0] print("SourceList line: ", line) track_id = line[0] - # print "track_id is ",track_id if line[2] == 'ac': acbox = QtGui.QGroupBox() acbox.setTitle(line[3]) @@ -372,7 +369,7 @@ class Source(QtGui.QWidget): else: print("No source is present in your circuit") - print("============================================================") + # print("============================================================") # This is used to keep the track of dynamically created widget self.obj_track.sourcelisttrack["ITEMS"] = sourcelisttrack self.obj_track.source_entry_var["ITEMS"] = self.entry_var -- cgit From b173d88ac0059b67e60a042293b1e486c9620d8a Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Fri, 14 Feb 2020 17:21:28 +0530 Subject: pep8 compliant --- src/kicadtoNgspice/Source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/kicadtoNgspice/Source.py') diff --git a/src/kicadtoNgspice/Source.py b/src/kicadtoNgspice/Source.py index 6c5ae637..e76118d4 100644 --- a/src/kicadtoNgspice/Source.py +++ b/src/kicadtoNgspice/Source.py @@ -47,7 +47,7 @@ class Source(QtGui.QWidget): """print("============================================================") print("SOURCE LIST TRACK", sourcelisttrack) print("SOURCE LIST", sourcelist) - print("============================================================")""" + print("===========================================================")""" kicadFile = self.clarg1 (projpath, filename) = os.path.split(kicadFile) project_name = os.path.basename(projpath) -- cgit From de3096c51107371de2361921dca8ee785e643fc3 Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Sun, 23 Feb 2020 17:06:49 +0530 Subject: revert to xml from json --- src/kicadtoNgspice/Source.py | 122 +++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 73 deletions(-) (limited to 'src/kicadtoNgspice/Source.py') diff --git a/src/kicadtoNgspice/Source.py b/src/kicadtoNgspice/Source.py index e76118d4..fdcd4adc 100644 --- a/src/kicadtoNgspice/Source.py +++ b/src/kicadtoNgspice/Source.py @@ -1,7 +1,7 @@ import os from PyQt4 import QtGui from . import TrackWidget -import json +from xml.etree import ElementTree as ET class Source(QtGui.QWidget): @@ -57,16 +57,19 @@ class Source(QtGui.QWidget): os.path.join( projpath, project_name + - "_Previous_Values.json"), + "_Previous_Values.xml"), 'r') - data = f.read() - json_data = json.loads(data) - + tree = ET.parse(f) + parent_root = tree.getroot() + for child in parent_root: + if child.tag == "source": + root = child except BaseException: - print("Source Previous Values JSON is Empty") + print("Source Previous Values XML is Empty") self.grid = QtGui.QGridLayout() self.setLayout(self.grid) + xml_num = 0 if sourcelist: for line in sourcelist: @@ -85,34 +88,23 @@ class Source(QtGui.QWidget): self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setMaximumWidth(150) acgrid.addWidget(self.entry_var[self.count], self.row, 1) - self.entry_var[self.count].setText("") - self.count += 1 - - self.entry_var[self.count] = QtGui.QLineEdit() - self.entry_var[self.count].setMaximumWidth(150) + self.entry_var[self.count + 1] = QtGui.QLineEdit() + self.entry_var[self.count + 1].setMaximumWidth(150) acgrid.addWidget( - self.entry_var[self.count], self.row + 1, 1) + self.entry_var[self.count+1], self.row + 1, 1) self.entry_var[self.count].setText("") - self.count += 1 - + self.entry_var[self.count+1].setText("") try: - for key in json_data["source"]: + for child in root: templist1 = line[1] templist2 = templist1.split(' ') - if key == templist2[0] and \ - json_data["source"][key]["type"]\ - == line[2]: - self.entry_var[self.count - 2].setText( - str( - json_data - ["source"][key]["values"][0] - ["Amplitude"])) - self.entry_var[self.count - 1].setText( - str( - json_data["source"][key] - ["values"][1]["Phase"])) - + if child.tag == templist2[0] and \ + child.text == line[2]: + self.entry_var[self.count] \ + .setText(str(child[0].text)) + self.entry_var[self.count + 1] \ + .setText(str(child[1].text)) except BaseException: pass # Value Need to check previuouse value @@ -138,6 +130,7 @@ class Source(QtGui.QWidget): dcbox = QtGui.QGroupBox() dcbox.setTitle(line[3]) dcgrid = QtGui.QGridLayout() + self.row = self.row + 1 self.start = self.count label = QtGui.QLabel(line[4]) dcgrid.addWidget(label, self.row, 0) @@ -148,18 +141,14 @@ class Source(QtGui.QWidget): self.entry_var[self.count].setText("") try: - for key in json_data["source"]: + for child in root: templist1 = line[1] templist2 = templist1.split(' ') - if key == templist2[0] and \ - json_data["source"][key]["type"]\ - == line[2]: - self.entry_var[self.count].setText( - str( - json_data["source"][key] - ["values"][0]["Value"])) - + if child.tag == templist2[0] \ + and child.text == line[2]: + self.entry_var[self.count] \ + .setText(str(child[0].text)) except BaseException: pass @@ -197,17 +186,13 @@ class Source(QtGui.QWidget): self.entry_var[self.count].setText("") try: - for key in json_data["source"]: + for child in root: templist1 = line[1] templist2 = templist1.split(' ') - if key == templist2[0] and \ - json_data["source"][key]["type"]\ - == line[2]: - self.entry_var[self.count].setText( - str( - list(json_data["source"] - [key]["values"] - [it - 4].values())[0])) + if child.tag == templist2[0] \ + and child.text == line[2]: + self.entry_var[self.count] \ + .setText(str(child[it-4].text)) except BaseException: pass @@ -244,17 +229,13 @@ class Source(QtGui.QWidget): self.entry_var[self.count].setText("") try: - for key in json_data["source"]: + for child in root: templist1 = line[1] templist2 = templist1.split(' ') - - if key == templist2[0] and \ - json_data["source"][key]["type"]\ - == line[2]: - self.entry_var[self.count].setText( - str(list( - json_data["source"][key] - ["values"][it - 4].values())[0])) + if child.tag == templist2[0] \ + and child.text == line[2]: + self.entry_var[self.count] \ + .setText(str(child[it-4].text)) except BaseException: pass @@ -288,15 +269,13 @@ class Source(QtGui.QWidget): self.entry_var[self.count].setText("") try: - for key in json_data["source"]: + for child in root: templist1 = line[1] templist2 = templist1.split(' ') - if key == templist2[0] and \ - json_data["source"][key]["type"] \ - == line[2]: - self.entry_var[self.count].setText( - str(json_data["source"][key] - ["values"][0]["Enter in pwl format"])) + if child.tag == templist2[0] \ + and child.text == line[2]: + self.entry_var[self.count] \ + .setText(str(child[0].text)) except BaseException: pass @@ -333,19 +312,13 @@ class Source(QtGui.QWidget): self.entry_var[self.count].setText("") try: - for key in json_data["source"]: + for child in root: templist1 = line[1] templist2 = templist1.split(' ') - if key == templist2[0] and \ - json_data["source"][key]["type"]\ - == line[2]: - self.entry_var[self.count].setText( - str( - list( - json_data["source"][key] - ["values"][it - 4].values())[0] - ) - ) + if child.tag == templist2[0] \ + and child.text == line[2]: + self.entry_var[self.count] \ + .setText(str(child[it-4].text)) except BaseException: pass @@ -366,6 +339,9 @@ class Source(QtGui.QWidget): sourcelisttrack.append( [track_id, 'exp', self.start, self.end]) + self.count = self.count + 1 + xml_num = xml_num + 1 + else: print("No source is present in your circuit") -- cgit From a62f5472f9220e51ede51c4d2b98ec154b08f4eb Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Mon, 2 Mar 2020 16:28:11 +0530 Subject: removed str displaying 'None' on fields --- src/kicadtoNgspice/Source.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/kicadtoNgspice/Source.py') diff --git a/src/kicadtoNgspice/Source.py b/src/kicadtoNgspice/Source.py index fdcd4adc..e42899e3 100644 --- a/src/kicadtoNgspice/Source.py +++ b/src/kicadtoNgspice/Source.py @@ -102,9 +102,9 @@ class Source(QtGui.QWidget): if child.tag == templist2[0] and \ child.text == line[2]: self.entry_var[self.count] \ - .setText(str(child[0].text)) + .setText(child[0].text) self.entry_var[self.count + 1] \ - .setText(str(child[1].text)) + .setText(child[1].text) except BaseException: pass # Value Need to check previuouse value @@ -148,7 +148,7 @@ class Source(QtGui.QWidget): if child.tag == templist2[0] \ and child.text == line[2]: self.entry_var[self.count] \ - .setText(str(child[0].text)) + .setText(child[0].text) except BaseException: pass @@ -192,7 +192,7 @@ class Source(QtGui.QWidget): if child.tag == templist2[0] \ and child.text == line[2]: self.entry_var[self.count] \ - .setText(str(child[it-4].text)) + .setText(child[it-4].text) except BaseException: pass @@ -235,7 +235,7 @@ class Source(QtGui.QWidget): if child.tag == templist2[0] \ and child.text == line[2]: self.entry_var[self.count] \ - .setText(str(child[it-4].text)) + .setText(child[it-4].text) except BaseException: pass @@ -275,7 +275,7 @@ class Source(QtGui.QWidget): if child.tag == templist2[0] \ and child.text == line[2]: self.entry_var[self.count] \ - .setText(str(child[0].text)) + .setText(child[0].text) except BaseException: pass @@ -318,7 +318,7 @@ class Source(QtGui.QWidget): if child.tag == templist2[0] \ and child.text == line[2]: self.entry_var[self.count] \ - .setText(str(child[it-4].text)) + .setText(child[it-4].text) except BaseException: pass -- cgit