From bfcd31c7c14519d29cf5b2c813899fc63bc5cf32 Mon Sep 17 00:00:00 2001 From: anjalijaiswal08 Date: Tue, 25 Jun 2019 15:38:20 +0530 Subject: Uploading Subcircuit feature added --- src/ngspiceSimulation/NgspiceWidget.py | 4 +- src/ngspiceSimulation/pythonPlotting.py | 4 +- src/projManagement/Validation.py | 45 ++++++++++++++++ src/subcircuit/uploadSub.py | 94 +++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 src/subcircuit/uploadSub.py diff --git a/src/ngspiceSimulation/NgspiceWidget.py b/src/ngspiceSimulation/NgspiceWidget.py index 1d5c974f..a963c51f 100644 --- a/src/ngspiceSimulation/NgspiceWidget.py +++ b/src/ngspiceSimulation/NgspiceWidget.py @@ -9,8 +9,8 @@ class NgspiceWidget(QtGui.QWidget): def __init__(self, command, projPath): """ - 1)Creates constructor for NgspiceWidget class. - 2)Checks whether OS is linux or windows + - Creates constructor for NgspiceWidget class. + - Checks whether OS is linux or windows and creates NgSpice window accordingly. """ QtGui.QWidget.__init__(self) diff --git a/src/ngspiceSimulation/pythonPlotting.py b/src/ngspiceSimulation/pythonPlotting.py index b9474403..22f2100a 100644 --- a/src/ngspiceSimulation/pythonPlotting.py +++ b/src/ngspiceSimulation/pythonPlotting.py @@ -14,10 +14,10 @@ import numpy as np # This class creates Python Plotting window class plotWindow(QtGui.QMainWindow): - ''' + """ This class defines python plotting window, its features, buttons, colors, AC and DC analysis, plotting etc. - ''' + """ def __init__(self, fpath, projectName): """This create constructor for plotWindow class.""" diff --git a/src/projManagement/Validation.py b/src/projManagement/Validation.py index 65103282..a3b12ecd 100644 --- a/src/projManagement/Validation.py +++ b/src/projManagement/Validation.py @@ -186,3 +186,48 @@ class Validation: Example, nghdl, eeschema... """ return distutils.spawn.find_executable(toolName) is not None + + def validateSubcir(self, projDir): + """ + This function checks for valid format of .sub file. + Correct format of file is: + - File should start with **.subckt <filename>** + - End with **.ends <filename>** + Function is passed with the file of path it checks the + file line by line untill it get .subckt as its first word + and then check for second word is it <fileName> or not. + + Then it checks for second last line if it is ".ends + <filename>" it return True if conditions satisfy else + return False. + + """ + projName = os.path.basename(str(projDir)) + fileName = projName[:-4] + req_line = ".ends" + " " + str(fileName) + f = open(projDir, 'r') + + flag1 = False + flag2 = False + + for line in f: + word = line.split(' ') + if word[0] == "*": + continue + if word[0] == ".subckt": + break + + if word[1] == fileName: + flag1 = True + + with open(projDir, 'r') as m: + lines = m.read().splitlines() + last_line = lines[-2] + + if req_line == last_line: + flag2 = True + + if flag1 == True and flag2 == True: + return "True" + else: + return "False" diff --git a/src/subcircuit/uploadSub.py b/src/subcircuit/uploadSub.py new file mode 100644 index 00000000..940e13c8 --- /dev/null +++ b/src/subcircuit/uploadSub.py @@ -0,0 +1,94 @@ +from PyQt4 import QtGui +from configuration.Appconfig import Appconfig +from projManagement.Validation import Validation +import os +import shutil + + +class UploadSub(QtGui.QWidget): + """This class contain function for """ + + def __init__(self): + super(UploadSub, self).__init__() + self.obj_validation = Validation() + self.obj_appconfig = Appconfig() + + def upload(self): + """ + This method opens a dialogue box when Upload subcircuit button is + clicked and after entering folder name, it opens directory system + to chose file for folder, it only shows file with extension .sub + and with the name of project entered earlier as folder name. + + It then validates file if it is in proper format or not, for it + the file is passed to the function **validateSub** and it returns + true if file has valid format or else it shows an error message. + """ + text, ok = QtGui.QInputDialog.getText( + self, 'Subcircuit Info', 'Enter Subcircuit Name:') + + if ok: + projname = (str(text)) + create_subcircuit = projname + subcircuit_path = (os.path.join(os.path.abspath('..'), 'SubcircuitLibrary', create_subcircuit)) + + if subcircuit_path == "": + self.reply = "NONE" + else: + self.reply = self.obj_validation.validateNewproj(str(subcircuit_path)) + + if self.reply == "VALID": + print("Validated: Creating subcircuit directory") + os.mkdir(subcircuit_path) + editfile = str( + QtGui.QFileDialog.getOpenFileName( + None, "Upload File", os.path.expanduser("~"), (projname + ".sub"))) + + upload = os.path.basename(editfile) + print("===================") + print("Current path of subcircuit file is " + editfile) + print("===================") + print("Selected file is " + upload) + print("===================") + self.valid = self.obj_validation.validateSubcir(str(editfile)) + print("===================") + + if self.valid is True: + print("Right file format!!!") + print("===================") + subcircuit = (os.path.join(subcircuit_path, upload)) + print("Final path of file is " + subcircuit) + print("===================") + print("Copying file from " + editfile + " to " + subcircuit) + print("===================") + shutil.copy(editfile, subcircuit) + else: + self.msg = QtGui.QErrorMessage(self) + self.msg.showMessage( + "Content of file does not meet the required format.\ + Please make sure file starts with * .subckt \ + " + upload + "** and ends with **.ends \ + " + upload + "**") + self.msg.setWindowTitle("Error Message") + print("Invalid file format") + print("===================") + print("Removing directory " + subcircuit_path) + print("===================") + os.rmdir(subcircuit_path) + + elif self.reply == "CHECKEXIST": + print("Project name already exists.") + print("==========================") + msg = QtGui.QErrorMessage(self) + msg.showMessage( + "The project already exist. Please select \ + the different name or delete existing project") + msg.setWindowTitle("Error Message") + + elif self.reply == "CHECKNAME": + print("Name can not contain space between them") + print("===========================") + msg = QtGui.QErrorMessage(self) + msg.showMessage( + 'The project name should not contain space between them') + msg.setWindowTitle("Error Message") -- cgit From 70528947ee2f03e60c8ccb397270413668a434ac Mon Sep 17 00:00:00 2001 From: anjalijaiswal08 Date: Tue, 25 Jun 2019 17:05:01 +0530 Subject: Minor changes --- src/subcircuit/uploadSub.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/subcircuit/uploadSub.py b/src/subcircuit/uploadSub.py index 940e13c8..28912fbe 100644 --- a/src/subcircuit/uploadSub.py +++ b/src/subcircuit/uploadSub.py @@ -6,7 +6,12 @@ import shutil class UploadSub(QtGui.QWidget): - """This class contain function for """ + """ + This class contain function for ulaoding subcircuits + in Subcircuit library present in src folder. + A folder is created in src/SubcircuitLibrary + and desired file is moved to that folder. + """ def __init__(self): super(UploadSub, self).__init__() -- cgit From 4aa019362ae4e133995f6d9ba5727207224f9b8e Mon Sep 17 00:00:00 2001 From: anjalijaiswal08 Date: Wed, 26 Jun 2019 03:25:04 +0530 Subject: half commited --- src/subcircuit/uploadSub.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/subcircuit/uploadSub.py b/src/subcircuit/uploadSub.py index 28912fbe..a59066a7 100644 --- a/src/subcircuit/uploadSub.py +++ b/src/subcircuit/uploadSub.py @@ -38,11 +38,11 @@ class UploadSub(QtGui.QWidget): subcircuit_path = (os.path.join(os.path.abspath('..'), 'SubcircuitLibrary', create_subcircuit)) if subcircuit_path == "": - self.reply = "NONE" + reply = "NONE" else: - self.reply = self.obj_validation.validateNewproj(str(subcircuit_path)) + reply = self.obj_validation.validateNewproj(str(subcircuit_path)) - if self.reply == "VALID": + if reply == "VALID": print("Validated: Creating subcircuit directory") os.mkdir(subcircuit_path) editfile = str( @@ -81,7 +81,7 @@ class UploadSub(QtGui.QWidget): print("===================") os.rmdir(subcircuit_path) - elif self.reply == "CHECKEXIST": + elif reply == "CHECKEXIST": print("Project name already exists.") print("==========================") msg = QtGui.QErrorMessage(self) @@ -90,7 +90,7 @@ class UploadSub(QtGui.QWidget): the different name or delete existing project") msg.setWindowTitle("Error Message") - elif self.reply == "CHECKNAME": + elif reply == "CHECKNAME": print("Name can not contain space between them") print("===========================") msg = QtGui.QErrorMessage(self) -- cgit From 482929a8aa2c879073477610dc15d945f5c309f6 Mon Sep 17 00:00:00 2001 From: anjalijaiswal08 Date: Wed, 26 Jun 2019 03:31:35 +0530 Subject: second commited --- src/subcircuit/Subcircuit.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/subcircuit/Subcircuit.py b/src/subcircuit/Subcircuit.py index d2e7ec5a..1e5b667f 100644 --- a/src/subcircuit/Subcircuit.py +++ b/src/subcircuit/Subcircuit.py @@ -4,6 +4,7 @@ from projManagement.Validation import Validation from subcircuit.newSub import NewSub from subcircuit.openSub import openSub from subcircuit.convertSub import convertSub +from subcircuit.uploadSub import UploadSub # This class creates Subcircuit GUI. @@ -41,11 +42,17 @@ class Subcircuit(QtGui.QWidget): '<b>To convert Subcircuit Kicad Netlist to Ngspice Netlist</b>') self.convertbtn.setFixedSize(200, 40) self.convertbtn.clicked.connect(self.convertsch) + self.uploadbtn = QtGui.QPushButton('Upload a Subcircuit') + self.uploadbtn.setToolTip( + '<b>To Upload a subcircuit</b>') + self.uploadbtn.setFixedSize(180, 38) + self.uploadbtn.clicked.connect(self.uploadSub) self.hbox = QtGui.QHBoxLayout() self.hbox.addWidget(self.newbtn) self.hbox.addWidget(self.editbtn) self.hbox.addWidget(self.convertbtn) + self.hbox.addWidget(self.uploadbtn) self.hbox.addStretch(1) self.vbox = QtGui.QVBoxLayout() @@ -73,3 +80,7 @@ class Subcircuit(QtGui.QWidget): def convertsch(self): self.obj_convertsubcircuit = convertSub(self.obj_dockarea) self.obj_convertsubcircuit.createSub() + + def uploadSub(self): + self.obj_uploadsubcircuit = UploadSub() + self.obj_uploadsubcircuit.upload() -- cgit From d6f29f511cf28a8d9800b6aa2a742d67e106ba4d Mon Sep 17 00:00:00 2001 From: anjalijaiswal08 Date: Wed, 26 Jun 2019 03:46:41 +0530 Subject: second commited --- src/subcircuit/Subcircuit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcircuit/Subcircuit.py b/src/subcircuit/Subcircuit.py index 1e5b667f..8f55ea13 100644 --- a/src/subcircuit/Subcircuit.py +++ b/src/subcircuit/Subcircuit.py @@ -52,7 +52,7 @@ class Subcircuit(QtGui.QWidget): self.hbox.addWidget(self.newbtn) self.hbox.addWidget(self.editbtn) self.hbox.addWidget(self.convertbtn) - self.hbox.addWidget(self.uploadbtn) + self.hbox.addWidget(self.uploadbtn) self.hbox.addStretch(1) self.vbox = QtGui.QVBoxLayout() -- cgit From 24148f36807eb1c5dbe6a6edb623e58313521534 Mon Sep 17 00:00:00 2001 From: anjalijaiswal08 Date: Thu, 27 Jun 2019 01:01:46 +0530 Subject: changes need to be commited --- src/projManagement/Validation.py | 136 +++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 63 deletions(-) diff --git a/src/projManagement/Validation.py b/src/projManagement/Validation.py index a3b12ecd..ebaea625 100644 --- a/src/projManagement/Validation.py +++ b/src/projManagement/Validation.py @@ -1,4 +1,3 @@ - # ========================================================================= # # FILE: Validation.py @@ -21,12 +20,25 @@ import os import re import distutils.spawn +""" +This is Validation class use for validating Project. +e.g if .proj is present in project directory +or if new project name is already exist in workspace etc +""" + class Validation: """ - This is Validation class use for validating Project. - e.g if .proj is present in project directory - or if new project name is already exist in workspace etc + Takes as input the path of the project and checks if + projName.proj file exists + projName is same as the folder selected + + @params + :projDir => contains the path of the project folder selected to open + + @return + True => If the folder contains the projName.proj file + False => If the folder doesn't contain projName.proj file """ def __init__(self): @@ -34,17 +46,7 @@ class Validation: def validateOpenproj(self, projDir): """ - Takes as input the path of the project and checks if - projName.proj file exists - projName is same as the folder selected - - @params - :projDir => contains the path of the project folder selected\ - to open - - @return - True => If the folder contains the projName.proj file - False => If the folder doesn't contain projName.proj file + This function validate Open Project Information. """ print("Function: Validating Open Project Information") projName = os.path.basename(str(projDir)) @@ -55,17 +57,21 @@ class Validation: else: return False - def validateNewproj(self, projDir): - """ - Validate new project created + """ + Validate new project created - @params - :projDir => Contains path of the new projDir created + @params + :projDir => Contains path of the new projDir created - @return - :"CHECKEXIST" => If smae project name folder exists - :"CHECKNAME" => If space is there in name - :"VALID" => If valid project name given + @return + :"CHECKEXIST" => If smae project name folder exists + :"CHECKNAME" => If space is there in name + :"VALID" => If valid project name given + """ + + def validateNewproj(self, projDir): + """ + This Project Validate New Project Information """ print("Function: Validating New Project Information") @@ -79,18 +85,22 @@ class Validation: else: return "VALID" - def validateKicad(self, projDir): - """ - Validate if projDir is set appropriately in the function calling file - and if Kicad components are present + """ + Validate if projDir is set appropriately in the function calling file + and if Kicad components are present - @params - :projDir => the path of the project directory, passed from - the calling function + @params + :projDir => the path of the project directory, passed from + the calling function - @return - True - False + @return + True + False + """ + + def validateKicad(self, projDir): + """ + This function validate if Kicad components are present """ print("FUnction : Validating for Kicad components") if projDir is None: @@ -98,17 +108,21 @@ class Validation: else: return True - def validateCir(self, projDir): - """ - Validate if cir file present in the directory with the appropriate .cir - file name, same as the project directory base + """ + Validate if cir file present in the directory with the appropriate .cir + file name, same as the project directory base - @params - :projDir => the path to the project directory + @params + :projDir => the path to the project diretory - @return - True - False + @return + True + False + """ + + def validateCir(self, projDir): + """ + This function checks if ".cir" file is present. """ projName = os.path.basename(str(projDir)) lookCir = os.path.join(str(projDir), projName + ".cir") @@ -161,17 +175,7 @@ class Validation: return "DIREC" def validateCirOut(self, projDir): - """ - This function checks if ".cir.out" file is present. - - @params - :projDir => the path of the project directory, passed from - the calling function - - @return - True - False - """ + """This function checks if ".cir.out" file is present.""" projName = os.path.basename(str(projDir)) lookCirOut = os.path.join(str(projDir), projName + ".cir.out") # Check existence of project @@ -181,10 +185,7 @@ class Validation: return False def validateTool(self, toolName): - """ - This function check if tool is present in the system, - Example, nghdl, eeschema... - """ + """This function check if tool is present in the system.""" return distutils.spawn.find_executable(toolName) is not None def validateSubcir(self, projDir): @@ -210,15 +211,24 @@ class Validation: flag1 = False flag2 = False + # Checks if file is empty or not. + if os.stat(projDir).st_size == 0: + print("File is empty") + print("===================") + return False + for line in f: word = line.split(' ') if word[0] == "*": continue if word[0] == ".subckt": + word = line.split(' ') break - if word[1] == fileName: + if word[0] == ".subckt" and word[1] == fileName: flag1 = True + else: + return False with open(projDir, 'r') as m: lines = m.read().splitlines() @@ -227,7 +237,7 @@ class Validation: if req_line == last_line: flag2 = True - if flag1 == True and flag2 == True: - return "True" - else: - return "False" + if flag1 is True and flag2 is True: + return True + + return False -- cgit From b6effcc4c38520de2459f428dd4c5dae1e76f71f Mon Sep 17 00:00:00 2001 From: anjalijaiswal08 Date: Thu, 27 Jun 2019 10:52:26 +0530 Subject: done --- src/projManagement/Validation.py | 46 +++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/projManagement/Validation.py b/src/projManagement/Validation.py index ebaea625..d270da6e 100644 --- a/src/projManagement/Validation.py +++ b/src/projManagement/Validation.py @@ -28,6 +28,7 @@ or if new project name is already exist in workspace etc class Validation: + """ Takes as input the path of the project and checks if projName.proj file exists @@ -205,11 +206,9 @@ class Validation: """ projName = os.path.basename(str(projDir)) fileName = projName[:-4] - req_line = ".ends" + " " + str(fileName) - f = open(projDir, 'r') - flag1 = False - flag2 = False + first = True + last_line = [] # Checks if file is empty or not. if os.stat(projDir).st_size == 0: @@ -217,27 +216,30 @@ class Validation: print("===================") return False - for line in f: - word = line.split(' ') - if word[0] == "*": - continue - if word[0] == ".subckt": - word = line.split(' ') - break + with open(projDir, 'r') as f: + for line in f: + word = line.split() + if len(word) == 0 or word[0][0] == "*": + continue + # print(word) + # print(word[0], word[1]) + if first: + if word[0] == ".subckt" and word[1] == fileName: + first = False + else: + print("First line not found") + return False + else: + last_line = word - if word[0] == ".subckt" and word[1] == fileName: - flag1 = True - else: + if first is True: + print("First line not found") return False - with open(projDir, 'r') as m: - lines = m.read().splitlines() - last_line = lines[-2] - - if req_line == last_line: - flag2 = True - - if flag1 is True and flag2 is True: + print(last_line) + if len(last_line) >= 2 and last_line[0] == ".ends" and \ + last_line[1] == fileName: return True + print("Last line not found") return False -- cgit From 17e8d542ab9cb7c1c91fb2ef7c23ff8d556d4138 Mon Sep 17 00:00:00 2001 From: anjalijaiswal08 Date: Thu, 27 Jun 2019 11:02:57 +0530 Subject: uploading subcircuit done --- src/projManagement/Validation.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/projManagement/Validation.py b/src/projManagement/Validation.py index d270da6e..f2d84314 100644 --- a/src/projManagement/Validation.py +++ b/src/projManagement/Validation.py @@ -28,7 +28,6 @@ or if new project name is already exist in workspace etc class Validation: - """ Takes as input the path of the project and checks if projName.proj file exists @@ -221,8 +220,6 @@ class Validation: word = line.split() if len(word) == 0 or word[0][0] == "*": continue - # print(word) - # print(word[0], word[1]) if first: if word[0] == ".subckt" and word[1] == fileName: first = False -- cgit From 5be7aa383b3982be2ceacfa747e2f2f3a2ea90bc Mon Sep 17 00:00:00 2001 From: anjalijaiswal08 Date: Thu, 27 Jun 2019 11:07:04 +0530 Subject: Pep8 changes --- src/subcircuit/uploadSub.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/subcircuit/uploadSub.py b/src/subcircuit/uploadSub.py index a59066a7..dfabea8d 100644 --- a/src/subcircuit/uploadSub.py +++ b/src/subcircuit/uploadSub.py @@ -35,19 +35,22 @@ class UploadSub(QtGui.QWidget): if ok: projname = (str(text)) create_subcircuit = projname - subcircuit_path = (os.path.join(os.path.abspath('..'), 'SubcircuitLibrary', create_subcircuit)) + subcircuit_path = (os.path.join(os.path.abspath('..'), + 'SubcircuitLibrary', create_subcircuit)) if subcircuit_path == "": reply = "NONE" else: - reply = self.obj_validation.validateNewproj(str(subcircuit_path)) + reply = self.obj_validation.validateNewproj(str( + subcircuit_path)) if reply == "VALID": print("Validated: Creating subcircuit directory") os.mkdir(subcircuit_path) editfile = str( QtGui.QFileDialog.getOpenFileName( - None, "Upload File", os.path.expanduser("~"), (projname + ".sub"))) + None, "Upload File", os.path.expanduser("~"), + (projname + ".sub"))) upload = os.path.basename(editfile) print("===================") @@ -64,7 +67,10 @@ class UploadSub(QtGui.QWidget): subcircuit = (os.path.join(subcircuit_path, upload)) print("Final path of file is " + subcircuit) print("===================") - print("Copying file from " + editfile + " to " + subcircuit) + print("Copying file from " + + editfile + + " to " + + subcircuit) print("===================") shutil.copy(editfile, subcircuit) else: -- cgit From 0811375e0a4769ef0e31efbd85418ccc1d41816e Mon Sep 17 00:00:00 2001 From: anjalijaiswal08 Date: Thu, 27 Jun 2019 14:24:50 +0530 Subject: removed needless lines --- src/frontEnd/ProjectExplorer.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/frontEnd/ProjectExplorer.py b/src/frontEnd/ProjectExplorer.py index 638b3147..8832cb41 100644 --- a/src/frontEnd/ProjectExplorer.py +++ b/src/frontEnd/ProjectExplorer.py @@ -99,8 +99,6 @@ class ProjectExplorer(QtGui.QWidget): menu = QtGui.QMenu() if level == 0: - renameProject = menu.addAction(self.tr("Rename Project")) - renameProject.triggered.connect(self.renameProject) deleteproject = menu.addAction(self.tr("Remove Project")) deleteproject.triggered.connect(self.removeProject) refreshproject = menu.addAction(self.tr("Refresh")) -- cgit