summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice/Source.py
diff options
context:
space:
mode:
authorrahulp132020-02-23 17:06:49 +0530
committerrahulp132020-02-23 17:06:49 +0530
commitde3096c51107371de2361921dca8ee785e643fc3 (patch)
tree9383ca5dfa55da43e8a41d1a678b3127b476da59 /src/kicadtoNgspice/Source.py
parent567e3b725fcc9d22e27cfd854a573d3e64deaff1 (diff)
downloadeSim-de3096c51107371de2361921dca8ee785e643fc3.tar.gz
eSim-de3096c51107371de2361921dca8ee785e643fc3.tar.bz2
eSim-de3096c51107371de2361921dca8ee785e643fc3.zip
revert to xml from json
Diffstat (limited to 'src/kicadtoNgspice/Source.py')
-rw-r--r--src/kicadtoNgspice/Source.py122
1 files changed, 49 insertions, 73 deletions
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")