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(-) (limited to 'src/kicadtoNgspice') 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