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/DeviceModel.py | 42 +++++++++++++-------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) (limited to 'src/kicadtoNgspice/DeviceModel.py') diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index 7f63a43b..41faa6f0 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -1,6 +1,5 @@ from PyQt4 import QtGui import os -# from xml.etree import ElementTree as ET import json from . import TrackWidget @@ -12,13 +11,13 @@ class DeviceModel(QtGui.QWidget): transistor and jfet. - Same function as the subCircuit file, except for this takes different parameters in the if block - - - q TRANSISTOR - - - d DIODE - - - j JFET - - - m MOSFET + - q TRANSISTOR + - d DIODE + - j JFET + - m MOSFET - Other 2 functions same as the ones in subCircuit - - - trackLibrary - - - trackLibraryWithoutButton + - trackLibrary + - trackLibraryWithoutButton """ def __init__(self, schematicInfo, clarg1): @@ -62,14 +61,14 @@ class DeviceModel(QtGui.QWidget): # Set Layout self.grid = QtGui.QGridLayout() self.setLayout(self.grid) - print("Reading Device model details from Schematic") + # print("Reading Device model details from Schematic") for eachline in schematicInfo: print("=========================================") print(eachline) words = eachline.split() if eachline[0] == 'q': - print("Device Model Transistor: ", words[0]) + # print("Device Model Transistor: ", words[0]) self.devicemodel_dict_beg[words[0]] = self.count transbox = QtGui.QGroupBox() transgrid = QtGui.QGridLayout() @@ -85,8 +84,6 @@ class DeviceModel(QtGui.QWidget): try: for key in json_data["deviceModel"]: if key == words[0]: - # print "DEVICE MODEL MATCHING---",child.tag[0],\ - # child.tag[1],eachline[0],eachline[1] try: if os.path.exists( json_data["deviceModel"][key][0]): @@ -128,7 +125,7 @@ class DeviceModel(QtGui.QWidget): self.grid.addWidget(transbox) - # Adding Device Details + # Adding Device Details # # Increment row and widget count self.row = self.row + 1 @@ -136,7 +133,7 @@ class DeviceModel(QtGui.QWidget): self.count = self.count + 1 elif eachline[0] == 'd': - print("Device Model Diode:", words[0]) + # print("Device Model Diode:", words[0]) self.devicemodel_dict_beg[words[0]] = self.count diodebox = QtGui.QGroupBox() diodegrid = QtGui.QGridLayout() @@ -151,8 +148,6 @@ class DeviceModel(QtGui.QWidget): try: for key in json_data["deviceModel"]: if key == words[0]: - # print "DEVICE MODEL MATCHING---",child.tag[0],\ - # child.tag[1],eachline[0],eachline[1] try: if os.path.exists( json_data["deviceModel"][key][0]): @@ -193,7 +188,7 @@ class DeviceModel(QtGui.QWidget): self.grid.addWidget(diodebox) - # Adding Device Details + # Adding Device Details # # Increment row and widget count self.row = self.row + 1 @@ -201,7 +196,7 @@ class DeviceModel(QtGui.QWidget): self.count = self.count + 1 elif eachline[0] == 'j': - print("Device Model JFET:", words[0]) + # print("Device Model JFET:", words[0]) self.devicemodel_dict_beg[words[0]] = self.count jfetbox = QtGui.QGroupBox() jfetgrid = QtGui.QGridLayout() @@ -216,8 +211,6 @@ class DeviceModel(QtGui.QWidget): try: for key in json_data["deviceModel"]: if key == words[0]: - # print "DEVICE MODEL MATCHING---",child.tag[0],\ - # child.tag[1],eachline[0],eachline[1] try: if os.path.exists( json_data["deviceModel"][key][0]): @@ -258,7 +251,8 @@ class DeviceModel(QtGui.QWidget): self.grid.addWidget(jfetbox) - # Adding Device Details + # Adding Device Details # + # Increment row and widget count self.row = self.row + 1 self.devicemodel_dict_end[words[0]] = self.count @@ -329,8 +323,6 @@ class DeviceModel(QtGui.QWidget): try: for key in json_data["deviceModel"]: if key == words[0]: - # print "DEVICE MODEL MATCHING---",child.tag[0],\ - # child.tag[1],eachline[0],eachline[1] while i <= end: self.entry_var[i].setText( json_data["deviceModel"][key][i - beg]) @@ -367,7 +359,6 @@ class DeviceModel(QtGui.QWidget): """ print("Calling Track Device Model Library funtion") sending_btn = self.sender() - # print "Object Called is ",sending_btn.objectName() self.widgetObjCount = int(sending_btn.objectName()) self.libfile = str( @@ -376,14 +367,12 @@ class DeviceModel(QtGui.QWidget): "Open Library Directory", "../deviceModelLibrary", "*.lib")) - # print "Selected Library File :",self.libfile # Setting Library to Text Edit Line self.entry_var[self.widgetObjCount].setText(self.libfile) self.deviceName = self.deviceDetail[self.widgetObjCount] # Storing to track it during conversion - if self.deviceName[0] == 'm': width = str(self.entry_var[self.widgetObjCount + 1].text()) length = str(self.entry_var[self.widgetObjCount + 2].text()) @@ -406,19 +395,16 @@ class DeviceModel(QtGui.QWidget): This function is use to keep track of all Device Model widget """ print("Calling Track Library function Without Button") - # print "Object Called is ",sending_btn.objectName() self.widgetObjCount = iter_value print("self.widgetObjCount-----", self.widgetObjCount) self.libfile = path_value print("PATH VALUE", path_value) - # print "Selected Library File :",self.libfile # Setting Library to Text Edit Line self.entry_var[self.widgetObjCount].setText(self.libfile) self.deviceName = self.deviceDetail[self.widgetObjCount] # Storing to track it during conversion - if self.deviceName[0] == 'm': width = str(self.entry_var[self.widgetObjCount + 1].text()) length = str(self.entry_var[self.widgetObjCount + 2].text()) -- cgit From 567e3b725fcc9d22e27cfd854a573d3e64deaff1 Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Fri, 21 Feb 2020 12:39:52 +0530 Subject: restructured code - pyinstaller --- src/kicadtoNgspice/DeviceModel.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/kicadtoNgspice/DeviceModel.py') diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index 41faa6f0..65e09753 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -363,9 +363,8 @@ class DeviceModel(QtGui.QWidget): self.libfile = str( QtGui.QFileDialog.getOpenFileName( - self, - "Open Library Directory", - "../deviceModelLibrary", + self, "Open Library Directory", + "library/deviceModelLibrary", "*.lib")) # Setting Library to Text Edit Line -- 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/DeviceModel.py | 87 +++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 41 deletions(-) (limited to 'src/kicadtoNgspice/DeviceModel.py') diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index 65e09753..d548f289 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -1,6 +1,6 @@ from PyQt4 import QtGui import os -import json +from xml.etree import ElementTree as ET from . import TrackWidget @@ -32,12 +32,15 @@ class DeviceModel(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 == "devicemodel": + root = child except BaseException: - print("Device Model Previous JSON is Empty") + print("Device Model Previous XML is Empty") QtGui.QWidget.__init__(self) @@ -82,16 +85,16 @@ class DeviceModel(QtGui.QWidget): global path_name try: - for key in json_data["deviceModel"]: - if key == words[0]: + for child in root: + if child.tag[0] == eachline[0] \ + and child.tag[1] == eachline[1]: + # print("DEVICE MODEL MATCHING---", child.tag[0], \ + # child.tag[1], eachline[0], eachline[1]) try: - if os.path.exists( - json_data["deviceModel"][key][0]): - self.entry_var[self.count].setText( - json_data["deviceModel"][key][0]) - path_name = ( - json_data["deviceModel"][key][0] - ) + if os.path.exists(child[0].text): + self.entry_var[self.count] \ + .setText(child[0].text) + path_name = child[0].text else: self.entry_var[self.count].setText("") except BaseException: @@ -146,16 +149,16 @@ class DeviceModel(QtGui.QWidget): self.entry_var[self.count].setText("") # global path_name try: - for key in json_data["deviceModel"]: - if key == words[0]: + for child in root: + if child.tag[0] == eachline[0] \ + and child.tag[1] == eachline[1]: + # print("DEVICE MODEL MATCHING---", child.tag[0], \ + # child.tag[1], eachline[0], eachline[1]) try: - if os.path.exists( - json_data["deviceModel"][key][0]): - path_name = ( - json_data["deviceModel"][key][0] - ) - self.entry_var[self.count].setText( - json_data["deviceModel"][key][0]) + if os.path.exists(child[0].text): + path_name = child[0].text + self.entry_var[self.count] \ + .setText(child[0].text) else: self.entry_var[self.count].setText("") except BaseException: @@ -209,16 +212,16 @@ class DeviceModel(QtGui.QWidget): self.entry_var[self.count].setText("") # global path_name try: - for key in json_data["deviceModel"]: - if key == words[0]: + for child in root: + if child.tag[0] == eachline[0] \ + and child.tag[1] == eachline[1]: + # print("DEVICE MODEL MATCHING---", child.tag[0], \ + # child.tag[1], eachline[0], eachline[1]) try: - if os.path.exists( - json_data["deviceModel"][key][0]): - self.entry_var[self.count].setText( - json_data["deviceModel"][key][0]) - path_name = ( - json_data["deviceModel"][key][0] - ) + if os.path.exists(child[0].text): + self.entry_var[self.count] \ + .setText(child[0].text) + path_name = child[0].text else: self.entry_var[self.count].setText("") except BaseException: @@ -319,19 +322,21 @@ class DeviceModel(QtGui.QWidget): self.devicemodel_dict_end[words[0]] = self.count self.count = self.count + 1 mosfetbox.setLayout(mosfetgrid) + # global path_name try: - for key in json_data["deviceModel"]: - if key == words[0]: + for child in root: + if child.tag[0] == eachline[0] \ + and child.tag[1] == eachline[1]: + # print("DEVICE MODEL MATCHING---", child.tag[0], \ + # child.tag[1], eachline[0], eachline[1]) while i <= end: - self.entry_var[i].setText( - json_data["deviceModel"][key][i - beg]) + self.entry_var[i].setText(child[i-beg].text) if (i - beg) == 0: - if os.path.exists( - json_data["deviceModel"][key][0]): - path_name = ( - json_data["deviceModel"][key][0] - ) + if os.path.exists(child[0].text): + self.entry_var[i] \ + .setText(child[i-beg].text) + path_name = child[i-beg].text else: self.entry_var[i].setText("") i = i + 1 -- cgit From 9fcc73d1b18aa763bb918a392a152688cf1fb1ea Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Mon, 2 Mar 2020 16:25:34 +0530 Subject: resolve issue with incorrect library paths --- src/kicadtoNgspice/DeviceModel.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src/kicadtoNgspice/DeviceModel.py') diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index d548f289..c4ea9a22 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -86,10 +86,9 @@ class DeviceModel(QtGui.QWidget): try: for child in root: - if child.tag[0] == eachline[0] \ - and child.tag[1] == eachline[1]: - # print("DEVICE MODEL MATCHING---", child.tag[0], \ - # child.tag[1], eachline[0], eachline[1]) + if child.tag == words[0]: + # print("DEVICE MODEL MATCHING---", \ + # child.tag, words[0]) try: if os.path.exists(child[0].text): self.entry_var[self.count] \ @@ -150,10 +149,9 @@ class DeviceModel(QtGui.QWidget): # global path_name try: for child in root: - if child.tag[0] == eachline[0] \ - and child.tag[1] == eachline[1]: - # print("DEVICE MODEL MATCHING---", child.tag[0], \ - # child.tag[1], eachline[0], eachline[1]) + if child.tag == words[0]: + # print("DEVICE MODEL MATCHING---", \ + # child.tag, words[0]) try: if os.path.exists(child[0].text): path_name = child[0].text @@ -213,10 +211,9 @@ class DeviceModel(QtGui.QWidget): # global path_name try: for child in root: - if child.tag[0] == eachline[0] \ - and child.tag[1] == eachline[1]: - # print("DEVICE MODEL MATCHING---", child.tag[0], \ - # child.tag[1], eachline[0], eachline[1]) + if child.tag == words[0]: + # print("DEVICE MODEL MATCHING---", \ + # child.tag, words[0]) try: if os.path.exists(child[0].text): self.entry_var[self.count] \ @@ -326,10 +323,9 @@ class DeviceModel(QtGui.QWidget): # global path_name try: for child in root: - if child.tag[0] == eachline[0] \ - and child.tag[1] == eachline[1]: - # print("DEVICE MODEL MATCHING---", child.tag[0], \ - # child.tag[1], eachline[0], eachline[1]) + if child.tag == words[0]: + # print("DEVICE MODEL MATCHING---", \ + # child.tag, words[0]) while i <= end: self.entry_var[i].setText(child[i-beg].text) if (i - beg) == 0: -- cgit