From 6391fbe70bbabd8f17aa74dd6c58758d29dedab1 Mon Sep 17 00:00:00 2001 From: Jay Mistry Date: Sat, 21 Aug 2021 01:04:26 +0530 Subject: Adding Hex Upload --- src/kicadtoNgspice/DeviceModel.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index 5fd4d829..4140b180 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -2,7 +2,7 @@ from PyQt5 import QtWidgets, QtCore import os from xml.etree import ElementTree as ET from . import TrackWidget - +import subprocess class DeviceModel(QtWidgets.QWidget): """ @@ -103,7 +103,7 @@ class DeviceModel(QtWidgets.QWidget): except BaseException: pass - transgrid.addWidget(self.entry_var[self.count], self.row, 1) + jfetgrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtWidgets.QPushButton("Add") self.addbtn.setObjectName("%d" % self.count) self.addbtn.clicked.connect(self.trackLibrary) @@ -114,11 +114,11 @@ class DeviceModel(QtWidgets.QWidget): else: self.trackLibraryWithoutButton(self.count, path_name) - transgrid.addWidget(self.addbtn, self.row, 2) - transbox.setLayout(transgrid) + jfetgrid.addWidget(self.addbtn, self.row, 2) + jfetbox.setLayout(transgrid) # CSS - transbox.setStyleSheet(" \ + jfetbox.setStyleSheet(" \ QGroupBox { border: 1px solid gray; border-radius: \ 9px; margin-top: 0.5em; } \ QGroupBox::title { subcontrol-origin: margin; left:\ @@ -172,6 +172,7 @@ class DeviceModel(QtWidgets.QWidget): self.addbtn.clicked.connect(self.trackLibrary) self.deviceDetail[self.count] = words[0] + if self.entry_var[self.count].text() == "": pass else: @@ -229,8 +230,8 @@ class DeviceModel(QtWidgets.QWidget): except BaseException: pass - jfetgrid.addWidget(self.entry_var[self.count], self.row, 1) - self.addbtn = QtWidgets.QPushButton("Add") + #jfetgrid.addWidget(self.entry_var[self.count], self.row, 1) + self.addbtn = QtWidgets.QPushButton("Upload hex file") self.addbtn.setObjectName("%d" % self.count) self.addbtn.clicked.connect(self.trackLibrary) self.deviceDetail[self.count] = words[0] @@ -400,6 +401,10 @@ class DeviceModel(QtWidgets.QWidget): else: self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile + + + + def trackLibraryWithoutButton(self, iter_value, path_value): """ This function is use to keep track of all Device Model widget -- cgit From 02054d31c801d0e87938f914ae117056db599822 Mon Sep 17 00:00:00 2001 From: Jay Mistry Date: Sat, 21 Aug 2021 01:09:26 +0530 Subject: Hex Upload code --- src/kicadtoNgspice/Model.py | 116 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 4 deletions(-) diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py index 0c821190..5421bc7c 100644 --- a/src/kicadtoNgspice/Model.py +++ b/src/kicadtoNgspice/Model.py @@ -1,15 +1,55 @@ -from PyQt5 import QtWidgets +from PyQt5 import QtWidgets, QtCore, QtGui +from PyQt5.QtCore import QObject, pyqtSlot from . import TrackWidget from xml.etree import ElementTree as ET import os - +import sys class Model(QtWidgets.QWidget): """ - This class creates Model Tab of KicadtoNgspice window. The widgets are created dynamically in the Model Tab. """ + def addHex(self): + """ + This function is use to keep track of all Device Model widget + """ + #print("Calling Track Device Model Library funtion") + + + init_path = '../../../' + if os.name == 'nt': + init_path = '' + + self.hexfile = QtCore.QDir.toNativeSeparators( + QtWidgets.QFileDialog.getOpenFileName( + self, "Open Hex Directory", + init_path + "home", "*.hex" + )[0] + ) + self.text = open(self.hexfile).read() + chosen_file_path = os.path.abspath(self.hexfile) + print(os.path.abspath(self.hexfile)) + + def uploadHex(self): + """ + This function is use to keep track of all Device Model widget + """ + #print("Calling Track Device Model Library funtion") + path1 = os.path.expanduser('~') + path2 = '/ngspice-nghdl/src/xspice/icm/ghdl' + init_path = path1 + path2 + if os.name == 'nt': + init_path = '' + self.hexloc = QtWidgets.QFileDialog.getExistingDirectory( + self, "Open Hex Directory", + init_path) + print(self.hexloc) + self.file = open(self.hexloc+"/hex.txt","w") + self.file.write(self.text) + self.file.close() + def __init__(self, schematicInfo, modelList, clarg1): QtWidgets.QWidget.__init__(self) @@ -46,7 +86,8 @@ class Model(QtWidgets.QWidget): # for storing line edit details position details self.start = 0 self.end = 0 - + self.entry_var = {} + self.text = "" # Creating GUI dynamically for Model tab self.grid = QtWidgets.QGridLayout() self.setLayout(self.grid) @@ -60,6 +101,8 @@ class Model(QtWidgets.QWidget): modelgrid = QtWidgets.QGridLayout() modelbox.setTitle(line[5]) self.start = self.nextcount + + # line[7] is parameter dictionary holding parameter tags. i = 0 for key, value in line[7].items(): @@ -90,6 +133,38 @@ class Model(QtWidgets.QWidget): temp_tag.append(self.nextcount) self.nextcount = self.nextcount + 1 self.nextrow = self.nextrow + 1 + if 'upload_hex_file:1' in tag_dict: + self.addbtn = QtWidgets.QPushButton("Add Hex File") + self.addbtn.setObjectName("%d" % self.nextcount) + self.addbtn.clicked.connect(self.addHex) + modelgrid.addWidget(self.addbtn, self.nextrow, 2) + modelbox.setLayout(modelgrid) + + # CSS + modelbox.setStyleSheet(" \ + QGroupBox { border: 1px solid gray; border-radius:\ + 9px; margin-top: 0.5em; } \ + QGroupBox::title { subcontrol-origin: margin; left:\ + 10px; padding: 0 3px 0 3px; } \ + ") + + self.grid.addWidget(modelbox) + self.addbtn = QtWidgets.QPushButton("Upload Hex File") + self.addbtn.setObjectName("%d" % self.nextcount) + self.addbtn.clicked.connect(self.uploadHex) + modelgrid.addWidget(self.addbtn, self.nextrow, 3) + modelbox.setLayout(modelgrid) + + # CSS + modelbox.setStyleSheet(" \ + QGroupBox { border: 1px solid gray; border-radius:\ + 9px; margin-top: 0.5em; } \ + QGroupBox::title { subcontrol-origin: margin; left:\ + 10px; padding: 0 3px 0 3px; } \ + ") + + self.grid.addWidget(modelbox) + tag_dict[key] = temp_tag else: @@ -102,6 +177,7 @@ class Model(QtWidgets.QWidget): self.obj_trac.model_entry_var[self.nextcount], self.nextrow, 1 ) + try: for child in root: @@ -111,9 +187,42 @@ class Model(QtWidgets.QWidget): i = i + 1 except BaseException: pass + + tag_dict[key] = self.nextcount self.nextcount = self.nextcount + 1 self.nextrow = self.nextrow + 1 + if 'upload_hex_file:1' in tag_dict: + self.addbtn = QtWidgets.QPushButton("Add Hex File") + self.addbtn.setObjectName("%d" % self.nextcount) + self.addbtn.clicked.connect(self.addHex) + modelgrid.addWidget(self.addbtn, self.nextrow, 2) + modelbox.setLayout(modelgrid) + + # CSS + modelbox.setStyleSheet(" \ + QGroupBox { border: 1px solid gray; border-radius:\ + 9px; margin-top: 0.5em; } \ + QGroupBox::title { subcontrol-origin: margin; left:\ + 10px; padding: 0 3px 0 3px; } \ + ") + + self.grid.addWidget(modelbox) + self.addbtn = QtWidgets.QPushButton("Upload Hex File") + self.addbtn.setObjectName("%d" % self.nextcount) + self.addbtn.clicked.connect(self.uploadHex) + modelgrid.addWidget(self.addbtn, self.nextrow, 3) + modelbox.setLayout(modelgrid) + + # CSS + modelbox.setStyleSheet(" \ + QGroupBox { border: 1px solid gray; border-radius:\ + 9px; margin-top: 0.5em; } \ + QGroupBox::title { subcontrol-origin: margin; left:\ + 10px; padding: 0 3px 0 3px; } \ + ") + + self.grid.addWidget(modelbox) self.end = self.nextcount - 1 modelbox.setLayout(modelgrid) @@ -157,7 +266,6 @@ class Model(QtWidgets.QWidget): for itr in self.obj_trac.modelTrack: if itr == lst: check = 1 - if check == 0: self.obj_trac.modelTrack.append(lst) -- cgit From 7c8e78e94a082e0628d5c150e32e9060d9700c2a Mon Sep 17 00:00:00 2001 From: Jay Mistry Date: Sat, 21 Aug 2021 01:10:23 +0530 Subject: Hex Upload Code --- src/kicadtoNgspice/Model.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py index 5421bc7c..1270f072 100644 --- a/src/kicadtoNgspice/Model.py +++ b/src/kicadtoNgspice/Model.py @@ -10,6 +10,7 @@ class Model(QtWidgets.QWidget): - This class creates Model Tab of KicadtoNgspice window. The widgets are created dynamically in the Model Tab. """ + #by Sumanto and Jay def addHex(self): """ This function is use to keep track of all Device Model widget @@ -31,6 +32,7 @@ class Model(QtWidgets.QWidget): chosen_file_path = os.path.abspath(self.hexfile) print(os.path.abspath(self.hexfile)) + #By Sumanto and Jay def uploadHex(self): """ This function is use to keep track of all Device Model widget -- cgit From 4350c795428cd22c150509aa488557c7fa1c0771 Mon Sep 17 00:00:00 2001 From: Jay Mistry Date: Sat, 21 Aug 2021 01:11:51 +0530 Subject: Hex Upload Code --- src/kicadtoNgspice/DeviceModel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index 4140b180..1dc9dcce 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -230,6 +230,7 @@ class DeviceModel(QtWidgets.QWidget): except BaseException: pass + #By Sumanto and Jay #jfetgrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtWidgets.QPushButton("Upload hex file") self.addbtn.setObjectName("%d" % self.count) -- cgit From 630b3dfbd3ec67ba62264407a2e959c33969b7c3 Mon Sep 17 00:00:00 2001 From: Jay Mistry Date: Sat, 21 Aug 2021 14:12:56 +0530 Subject: Update DeviceModel.py --- src/kicadtoNgspice/DeviceModel.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index 1dc9dcce..5fd4d829 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -2,7 +2,7 @@ from PyQt5 import QtWidgets, QtCore import os from xml.etree import ElementTree as ET from . import TrackWidget -import subprocess + class DeviceModel(QtWidgets.QWidget): """ @@ -103,7 +103,7 @@ class DeviceModel(QtWidgets.QWidget): except BaseException: pass - jfetgrid.addWidget(self.entry_var[self.count], self.row, 1) + transgrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtWidgets.QPushButton("Add") self.addbtn.setObjectName("%d" % self.count) self.addbtn.clicked.connect(self.trackLibrary) @@ -114,11 +114,11 @@ class DeviceModel(QtWidgets.QWidget): else: self.trackLibraryWithoutButton(self.count, path_name) - jfetgrid.addWidget(self.addbtn, self.row, 2) - jfetbox.setLayout(transgrid) + transgrid.addWidget(self.addbtn, self.row, 2) + transbox.setLayout(transgrid) # CSS - jfetbox.setStyleSheet(" \ + transbox.setStyleSheet(" \ QGroupBox { border: 1px solid gray; border-radius: \ 9px; margin-top: 0.5em; } \ QGroupBox::title { subcontrol-origin: margin; left:\ @@ -172,7 +172,6 @@ class DeviceModel(QtWidgets.QWidget): self.addbtn.clicked.connect(self.trackLibrary) self.deviceDetail[self.count] = words[0] - if self.entry_var[self.count].text() == "": pass else: @@ -230,9 +229,8 @@ class DeviceModel(QtWidgets.QWidget): except BaseException: pass - #By Sumanto and Jay - #jfetgrid.addWidget(self.entry_var[self.count], self.row, 1) - self.addbtn = QtWidgets.QPushButton("Upload hex file") + jfetgrid.addWidget(self.entry_var[self.count], self.row, 1) + self.addbtn = QtWidgets.QPushButton("Add") self.addbtn.setObjectName("%d" % self.count) self.addbtn.clicked.connect(self.trackLibrary) self.deviceDetail[self.count] = words[0] @@ -402,10 +400,6 @@ class DeviceModel(QtWidgets.QWidget): else: self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile - - - - def trackLibraryWithoutButton(self, iter_value, path_value): """ This function is use to keep track of all Device Model widget -- cgit From 905335093997fae2c48f3d6cbc2178e6832dc481 Mon Sep 17 00:00:00 2001 From: Jay Mistry Date: Sat, 21 Aug 2021 14:20:41 +0530 Subject: Update Model.py --- src/kicadtoNgspice/Model.py | 191 ++++++++++++++++++++++++-------------------- 1 file changed, 106 insertions(+), 85 deletions(-) diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py index 1270f072..7bed33c2 100644 --- a/src/kicadtoNgspice/Model.py +++ b/src/kicadtoNgspice/Model.py @@ -1,131 +1,148 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- from PyQt5 import QtWidgets, QtCore, QtGui from PyQt5.QtCore import QObject, pyqtSlot -from . import TrackWidget +from import TrackWidget from xml.etree import ElementTree as ET import os import sys + class Model(QtWidgets.QWidget): + """ - This class creates Model Tab of KicadtoNgspice window. The widgets are created dynamically in the Model Tab. """ - #by Sumanto and Jay + + # by Sumanto and Jay + def addHex(self): """ This function is use to keep track of all Device Model widget """ - #print("Calling Track Device Model Library funtion") - + + # print("Calling Track Device Model Library funtion") init_path = '../../../' if os.name == 'nt': init_path = '' - self.hexfile = QtCore.QDir.toNativeSeparators( - QtWidgets.QFileDialog.getOpenFileName( - self, "Open Hex Directory", - init_path + "home", "*.hex" - )[0] - ) + self.hexfile = \ + QtCore.QDir.toNativeSeparators(QtWidgets.QFileDialog.getOpenFileName(self, + 'Open Hex Directory', init_path + 'home', '*.hex')[0]) self.text = open(self.hexfile).read() chosen_file_path = os.path.abspath(self.hexfile) - print(os.path.abspath(self.hexfile)) + print os.path.abspath(self.hexfile) + + # By Sumanto and Jay - #By Sumanto and Jay def uploadHex(self): """ This function is use to keep track of all Device Model widget """ - #print("Calling Track Device Model Library funtion") + + # print("Calling Track Device Model Library funtion") + path1 = os.path.expanduser('~') path2 = '/ngspice-nghdl/src/xspice/icm/ghdl' init_path = path1 + path2 if os.name == 'nt': init_path = '' - self.hexloc = QtWidgets.QFileDialog.getExistingDirectory( - self, "Open Hex Directory", - init_path) - print(self.hexloc) - self.file = open(self.hexloc+"/hex.txt","w") + self.hexloc = QtWidgets.QFileDialog.getExistingDirectory(self, + 'Open Hex Directory', init_path) + print self.hexloc + self.file = open(self.hexloc + '/hex.txt', 'w') self.file.write(self.text) self.file.close() - - def __init__(self, schematicInfo, modelList, clarg1): + + def __init__( + self, + schematicInfo, + modelList, + clarg1, + ): QtWidgets.QWidget.__init__(self) # Processing for getting previous values + kicadFile = clarg1 (projpath, filename) = os.path.split(kicadFile) project_name = os.path.basename(projpath) check = 1 try: - f = open( - os.path.join( - projpath, - project_name + - "_Previous_Values.xml"), - 'r') + 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": + if child.tag == 'model': root = child - except BaseException: + check = 0 - print("Model Previous Values XML is Empty") + print 'Model Previous Values XML is Empty' # Creating track widget object + self.obj_trac = TrackWidget.TrackWidget() # for increasing row and counting/tracking line edit widget + self.nextrow = 0 self.nextcount = 0 # for storing line edit details position details + self.start = 0 self.end = 0 self.entry_var = {} - self.text = "" + self.text = '' + # Creating GUI dynamically for Model tab + self.grid = QtWidgets.QGridLayout() self.setLayout(self.grid) for line in modelList: + # print "ModelList Item:",line # Adding title label for model # Key: Tag name,Value:Entry widget number + tag_dict = {} modelbox = QtWidgets.QGroupBox() modelgrid = QtWidgets.QGridLayout() modelbox.setTitle(line[5]) self.start = self.nextcount - - + # line[7] is parameter dictionary holding parameter tags. + i = 0 - for key, value in line[7].items(): + for (key, value) in line[7].items(): + # Check if value is iterable - if not isinstance(value, str) and hasattr(value, '__iter__'): + + if not isinstance(value, str) and hasattr(value, + '__iter__'): + # For tag having vector value + temp_tag = [] for item in value: paramLabel = QtWidgets.QLabel(item) modelgrid.addWidget(paramLabel, self.nextrow, 0) - self.obj_trac.model_entry_var[self.nextcount] = ( + self.obj_trac.model_entry_var[self.nextcount] = \ QtWidgets.QLineEdit() - ) - modelgrid.addWidget( - self.obj_trac.model_entry_var - [self.nextcount], self.nextrow, 1) + 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]: + 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 @@ -136,93 +153,106 @@ class Model(QtWidgets.QWidget): self.nextcount = self.nextcount + 1 self.nextrow = self.nextrow + 1 if 'upload_hex_file:1' in tag_dict: - self.addbtn = QtWidgets.QPushButton("Add Hex File") - self.addbtn.setObjectName("%d" % self.nextcount) + self.addbtn = \ + QtWidgets.QPushButton('Add Hex File') + self.addbtn.setObjectName('%d' + % self.nextcount) self.addbtn.clicked.connect(self.addHex) - modelgrid.addWidget(self.addbtn, self.nextrow, 2) + modelgrid.addWidget(self.addbtn, + self.nextrow, 2) modelbox.setLayout(modelgrid) # CSS + modelbox.setStyleSheet(" \ QGroupBox { border: 1px solid gray; border-radius:\ 9px; margin-top: 0.5em; } \ QGroupBox::title { subcontrol-origin: margin; left:\ 10px; padding: 0 3px 0 3px; } \ - ") + " + ) self.grid.addWidget(modelbox) - self.addbtn = QtWidgets.QPushButton("Upload Hex File") - self.addbtn.setObjectName("%d" % self.nextcount) + self.addbtn = \ + QtWidgets.QPushButton('Upload Hex File') + self.addbtn.setObjectName('%d' + % self.nextcount) self.addbtn.clicked.connect(self.uploadHex) - modelgrid.addWidget(self.addbtn, self.nextrow, 3) + modelgrid.addWidget(self.addbtn, + self.nextrow, 3) modelbox.setLayout(modelgrid) # CSS + modelbox.setStyleSheet(" \ QGroupBox { border: 1px solid gray; border-radius:\ 9px; margin-top: 0.5em; } \ QGroupBox::title { subcontrol-origin: margin; left:\ 10px; padding: 0 3px 0 3px; } \ - ") + " + ) self.grid.addWidget(modelbox) tag_dict[key] = temp_tag - else: + paramLabel = QtWidgets.QLabel(value) modelgrid.addWidget(paramLabel, self.nextrow, 0) - self.obj_trac.model_entry_var[self.nextcount] = ( + self.obj_trac.model_entry_var[self.nextcount] = \ QtWidgets.QLineEdit() - ) - modelgrid.addWidget( - self.obj_trac.model_entry_var[self.nextcount], - self.nextrow, 1 - ) - + 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) + 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 except BaseException: pass - - + tag_dict[key] = self.nextcount self.nextcount = self.nextcount + 1 self.nextrow = self.nextrow + 1 if 'upload_hex_file:1' in tag_dict: - self.addbtn = QtWidgets.QPushButton("Add Hex File") - self.addbtn.setObjectName("%d" % self.nextcount) + self.addbtn = \ + QtWidgets.QPushButton('Add Hex File') + self.addbtn.setObjectName('%d' % self.nextcount) self.addbtn.clicked.connect(self.addHex) - modelgrid.addWidget(self.addbtn, self.nextrow, 2) + modelgrid.addWidget(self.addbtn, self.nextrow, + 2) modelbox.setLayout(modelgrid) # CSS + modelbox.setStyleSheet(" \ QGroupBox { border: 1px solid gray; border-radius:\ 9px; margin-top: 0.5em; } \ QGroupBox::title { subcontrol-origin: margin; left:\ 10px; padding: 0 3px 0 3px; } \ - ") + " + ) self.grid.addWidget(modelbox) - self.addbtn = QtWidgets.QPushButton("Upload Hex File") - self.addbtn.setObjectName("%d" % self.nextcount) + self.addbtn = \ + QtWidgets.QPushButton('Upload Hex File') + self.addbtn.setObjectName('%d' % self.nextcount) self.addbtn.clicked.connect(self.uploadHex) - modelgrid.addWidget(self.addbtn, self.nextrow, 3) + modelgrid.addWidget(self.addbtn, self.nextrow, + 3) modelbox.setLayout(modelgrid) # CSS + modelbox.setStyleSheet(" \ QGroupBox { border: 1px solid gray; border-radius:\ 9px; margin-top: 0.5em; } \ QGroupBox::title { subcontrol-origin: margin; left:\ 10px; padding: 0 3px 0 3px; } \ - ") + " + ) self.grid.addWidget(modelbox) @@ -230,29 +260,19 @@ class Model(QtWidgets.QWidget): modelbox.setLayout(modelgrid) # CSS + modelbox.setStyleSheet(" \ QGroupBox { border: 1px solid gray; border-radius: \ 9px; margin-top: 0.5em; } \ QGroupBox::title { subcontrol-origin: margin; left:\ 10px; padding: 0 3px 0 3px; } \ - ") + " + ) self.grid.addWidget(modelbox) - ''' - Listing all - line[0] = index - line[1] = compLine - line[2] = modelname #Change from compType to modelname - line[3] = compName - line[4] = comment - line[5] = title - line[6] = type i.e analog or digital - Now adding start,end and tag_dict which will be line[7], - line[8] and line[9] respectively - ''' - # This keeps the track of Model Tab Widget + lst = [ line[0], line[1], @@ -263,7 +283,8 @@ class Model(QtWidgets.QWidget): line[6], self.start, self.end, - tag_dict] + tag_dict, + ] check = 0 for itr in self.obj_trac.modelTrack: if itr == lst: -- cgit From ecd4f41efb20c31c9207d86e872205e72a1a4b08 Mon Sep 17 00:00:00 2001 From: Jay Mistry Date: Sun, 29 Aug 2021 23:44:47 +0530 Subject: Adding hex upload for MCU circuits Two modules defined 'addHex' and 'uploadHex' are responsible for navigating the .hex file from the workspace and uploading the same in the specified folder.--- src/kicadtoNgspice/Model.py | 158 +++++++++++++++++++++++--------------------- 1 file changed, 84 insertions(+), 74 deletions(-) diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py index 7bed33c2..1389e556 100644 --- a/src/kicadtoNgspice/Model.py +++ b/src/kicadtoNgspice/Model.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- from PyQt5 import QtWidgets, QtCore, QtGui from PyQt5.QtCore import QObject, pyqtSlot -from import TrackWidget +from . import TrackWidget from xml.etree import ElementTree as ET import os import sys @@ -24,16 +24,17 @@ class Model(QtWidgets.QWidget): # print("Calling Track Device Model Library funtion") - init_path = '../../../' - if os.name == 'nt': - init_path = '' + init_path = "../../../" + if os.name == "nt": + init_path = "" - self.hexfile = \ - QtCore.QDir.toNativeSeparators(QtWidgets.QFileDialog.getOpenFileName(self, - 'Open Hex Directory', init_path + 'home', '*.hex')[0]) + self.hexfile = QtCore.QDir.toNativeSeparators( + QtWidgets.QFileDialog.getOpenFileName( + self, "Open Hex Directory", init_path + "home", "*.hex" + )[0] + ) self.text = open(self.hexfile).read() chosen_file_path = os.path.abspath(self.hexfile) - print os.path.abspath(self.hexfile) # By Sumanto and Jay @@ -44,16 +45,16 @@ class Model(QtWidgets.QWidget): # print("Calling Track Device Model Library funtion") - path1 = os.path.expanduser('~') - path2 = '/ngspice-nghdl/src/xspice/icm/ghdl' + path1 = os.path.expanduser("~") + path2 = "/ngspice-nghdl/src/xspice/icm/ghdl" init_path = path1 + path2 - if os.name == 'nt': - init_path = '' + if os.name == "nt": + init_path = "" - self.hexloc = QtWidgets.QFileDialog.getExistingDirectory(self, - 'Open Hex Directory', init_path) - print self.hexloc - self.file = open(self.hexloc + '/hex.txt', 'w') + self.hexloc = QtWidgets.QFileDialog.getExistingDirectory( + self, "Open Hex Directory", init_path + ) + self.file = open(self.hexloc + "/hex.txt", "w") self.file.write(self.text) self.file.close() @@ -62,7 +63,7 @@ class Model(QtWidgets.QWidget): schematicInfo, modelList, clarg1, - ): + ): QtWidgets.QWidget.__init__(self) @@ -73,17 +74,19 @@ class Model(QtWidgets.QWidget): project_name = os.path.basename(projpath) check = 1 try: - f = open(os.path.join(projpath, project_name - + '_Previous_Values.xml'), 'r') + 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': + if child.tag == "model": root = child except BaseException: check = 0 - print 'Model Previous Values XML is Empty' + print("Model Previous Values XML is Empty") # Creating track widget object @@ -99,7 +102,7 @@ class Model(QtWidgets.QWidget): self.start = 0 self.end = 0 self.entry_var = {} - self.text = '' + self.text = "" # Creating GUI dynamically for Model tab @@ -125,8 +128,7 @@ class Model(QtWidgets.QWidget): # Check if value is iterable - if not isinstance(value, str) and hasattr(value, - '__iter__'): + if not isinstance(value, str) and hasattr(value, "__iter__"): # For tag having vector value @@ -134,15 +136,21 @@ class Model(QtWidgets.QWidget): for item in value: paramLabel = QtWidgets.QLabel(item) modelgrid.addWidget(paramLabel, self.nextrow, 0) - self.obj_trac.model_entry_var[self.nextcount] = \ - QtWidgets.QLineEdit() - modelgrid.addWidget(self.obj_trac.model_entry_var[self.nextcount], - self.nextrow, 1) + self.obj_trac.model_entry_var[ + self.nextcount + ] = QtWidgets.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]: + 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 @@ -152,45 +160,43 @@ class Model(QtWidgets.QWidget): temp_tag.append(self.nextcount) self.nextcount = self.nextcount + 1 self.nextrow = self.nextrow + 1 - if 'upload_hex_file:1' in tag_dict: - self.addbtn = \ - QtWidgets.QPushButton('Add Hex File') - self.addbtn.setObjectName('%d' - % self.nextcount) + if "upload_hex_file:1" in tag_dict: + self.addbtn = QtWidgets.QPushButton("Add Hex File") + self.addbtn.setObjectName("%d" % self.nextcount) self.addbtn.clicked.connect(self.addHex) - modelgrid.addWidget(self.addbtn, - self.nextrow, 2) + modelgrid.addWidget(self.addbtn, self.nextrow, 2) modelbox.setLayout(modelgrid) # CSS - modelbox.setStyleSheet(" \ + modelbox.setStyleSheet( + " \ QGroupBox { border: 1px solid gray; border-radius:\ 9px; margin-top: 0.5em; } \ - QGroupBox::title { subcontrol-origin: margin; left:\ + QGroupBox::title {subcontrol-origin: margin; left:\ 10px; padding: 0 3px 0 3px; } \ " - ) + ) self.grid.addWidget(modelbox) - self.addbtn = \ - QtWidgets.QPushButton('Upload Hex File') - self.addbtn.setObjectName('%d' - % self.nextcount) + self.addbtn = QtWidgets.QPushButton( + "Upload Hex File" + ) + self.addbtn.setObjectName("%d" % self.nextcount) self.addbtn.clicked.connect(self.uploadHex) - modelgrid.addWidget(self.addbtn, - self.nextrow, 3) + modelgrid.addWidget(self.addbtn, self.nextrow, 3) modelbox.setLayout(modelgrid) # CSS - modelbox.setStyleSheet(" \ + modelbox.setStyleSheet( + " \ QGroupBox { border: 1px solid gray; border-radius:\ 9px; margin-top: 0.5em; } \ - QGroupBox::title { subcontrol-origin: margin; left:\ + QGroupBox::title {subcontrol-origin: margin; left:\ 10px; padding: 0 3px 0 3px; } \ " - ) + ) self.grid.addWidget(modelbox) @@ -199,16 +205,21 @@ class Model(QtWidgets.QWidget): paramLabel = QtWidgets.QLabel(value) modelgrid.addWidget(paramLabel, self.nextrow, 0) - self.obj_trac.model_entry_var[self.nextcount] = \ - QtWidgets.QLineEdit() - modelgrid.addWidget(self.obj_trac.model_entry_var[self.nextcount], - self.nextrow, 1) + self.obj_trac.model_entry_var[ + self.nextcount + ] = QtWidgets.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) + 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 except BaseException: pass @@ -216,43 +227,41 @@ class Model(QtWidgets.QWidget): tag_dict[key] = self.nextcount self.nextcount = self.nextcount + 1 self.nextrow = self.nextrow + 1 - if 'upload_hex_file:1' in tag_dict: - self.addbtn = \ - QtWidgets.QPushButton('Add Hex File') - self.addbtn.setObjectName('%d' % self.nextcount) + if "upload_hex_file:1" in tag_dict: + self.addbtn = QtWidgets.QPushButton("Add Hex File") + self.addbtn.setObjectName("%d" % self.nextcount) self.addbtn.clicked.connect(self.addHex) - modelgrid.addWidget(self.addbtn, self.nextrow, - 2) + modelgrid.addWidget(self.addbtn, self.nextrow, 2) modelbox.setLayout(modelgrid) # CSS - modelbox.setStyleSheet(" \ + modelbox.setStyleSheet( + " \ QGroupBox { border: 1px solid gray; border-radius:\ 9px; margin-top: 0.5em; } \ QGroupBox::title { subcontrol-origin: margin; left:\ 10px; padding: 0 3px 0 3px; } \ " - ) + ) self.grid.addWidget(modelbox) - self.addbtn = \ - QtWidgets.QPushButton('Upload Hex File') - self.addbtn.setObjectName('%d' % self.nextcount) + self.addbtn = QtWidgets.QPushButton("Upload Hex File") + self.addbtn.setObjectName("%d" % self.nextcount) self.addbtn.clicked.connect(self.uploadHex) - modelgrid.addWidget(self.addbtn, self.nextrow, - 3) + modelgrid.addWidget(self.addbtn, self.nextrow, 3) modelbox.setLayout(modelgrid) # CSS - modelbox.setStyleSheet(" \ + modelbox.setStyleSheet( + " \ QGroupBox { border: 1px solid gray; border-radius:\ 9px; margin-top: 0.5em; } \ QGroupBox::title { subcontrol-origin: margin; left:\ 10px; padding: 0 3px 0 3px; } \ " - ) + ) self.grid.addWidget(modelbox) @@ -261,13 +270,14 @@ class Model(QtWidgets.QWidget): # CSS - modelbox.setStyleSheet(" \ + modelbox.setStyleSheet( + " \ QGroupBox { border: 1px solid gray; border-radius: \ 9px; margin-top: 0.5em; } \ QGroupBox::title { subcontrol-origin: margin; left:\ 10px; padding: 0 3px 0 3px; } \ " - ) + ) self.grid.addWidget(modelbox) @@ -284,7 +294,7 @@ class Model(QtWidgets.QWidget): self.start, self.end, tag_dict, - ] + ] check = 0 for itr in self.obj_trac.modelTrack: if itr == lst: -- cgit