diff options
author | Sunil Shetye | 2019-07-01 12:17:50 +0530 |
---|---|---|
committer | GitHub | 2019-07-01 12:17:50 +0530 |
commit | 4540e4674cbf5c5986bbd0dd81a4d379207e8b3f (patch) | |
tree | 095f995d82f204332ba61087a25b1cf77b48feb4 | |
parent | 57d843c500d3a45de95fbac9c2a04c8a3670fb2a (diff) | |
parent | 70876a368e69d799bbe431254bd1a4ce7cea090c (diff) | |
download | eSim-4540e4674cbf5c5986bbd0dd81a4d379207e8b3f.tar.gz eSim-4540e4674cbf5c5986bbd0dd81a4d379207e8b3f.tar.bz2 eSim-4540e4674cbf5c5986bbd0dd81a4d379207e8b3f.zip |
Merge pull request #113 from sunilshetye/subcircuit
directly select filename
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | src/frontEnd/Application.py | 4 | ||||
-rw-r--r-- | src/projManagement/Validation.py | 10 | ||||
-rw-r--r-- | src/subcircuit/uploadSub.py | 136 |
4 files changed, 68 insertions, 83 deletions
@@ -5,3 +5,4 @@ esim-start.sh esim.desktop nghdl +tags diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py index 7478264a..4f77a321 100755 --- a/src/frontEnd/Application.py +++ b/src/frontEnd/Application.py @@ -214,8 +214,8 @@ class Application(QtGui.QMainWindow): 2. If 'No' is pressed: - the program just continues as it was doing earlier. ''' - exit_msg = "Are you sure you want to exit the program\ - ? All unsaved data will be lost." + exit_msg = "Are you sure you want to exit the program?" \ + " All unsaved data will be lost." reply = QtGui.QMessageBox.question( self, 'Message', exit_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) diff --git a/src/projManagement/Validation.py b/src/projManagement/Validation.py index f2d84314..451fe831 100644 --- a/src/projManagement/Validation.py +++ b/src/projManagement/Validation.py @@ -188,7 +188,7 @@ class Validation: """This function check if tool is present in the system.""" return distutils.spawn.find_executable(toolName) is not None - def validateSubcir(self, projDir): + def validateSubcir(self, projDir, fileName): """ This function checks for valid format of .sub file. Correct format of file is: @@ -203,8 +203,6 @@ class Validation: return False. """ - projName = os.path.basename(str(projDir)) - fileName = projName[:-4] first = True last_line = [] @@ -212,7 +210,6 @@ class Validation: # Checks if file is empty or not. if os.stat(projDir).st_size == 0: print("File is empty") - print("===================") return False with open(projDir, 'r') as f: @@ -224,7 +221,7 @@ class Validation: if word[0] == ".subckt" and word[1] == fileName: first = False else: - print("First line not found") + print("First line not found:", word) return False else: last_line = word @@ -233,10 +230,9 @@ class Validation: print("First line not found") return False - 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") + print("Last line not found:", last_line) return False diff --git a/src/subcircuit/uploadSub.py b/src/subcircuit/uploadSub.py index dfabea8d..00cc9df0 100644 --- a/src/subcircuit/uploadSub.py +++ b/src/subcircuit/uploadSub.py @@ -29,77 +29,65 @@ class UploadSub(QtGui.QWidget): 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 == "": - reply = "NONE" - else: - 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"))) - - 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 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 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") + + editfile = QtGui.QFileDialog.getOpenFileName( + None, "Upload Subcircuit File", os.path.expanduser("~"), "*.sub") + + if editfile == '': + return + + upload = os.path.basename(editfile) + create_subcircuit, ext = os.path.splitext(upload) + + if ext != '.sub': + self.msg = QtGui.QErrorMessage(self) + self.msg.showMessage("Please ensure that filename ends with .sub") + self.msg.setWindowTitle("Error Message") + print("Invalid filename") + return + + valid = self.obj_validation.validateSubcir(editfile, create_subcircuit) + if not valid: + self.msg = QtGui.QErrorMessage(self) + self.msg.showMessage( + "Content of file does not meet the required format.\ + Please ensure that file starts with **.subckt \ + " + create_subcircuit + "** and ends with **.ends \ + " + create_subcircuit + "**") + self.msg.setWindowTitle("Error Message") + print("Invalid file format") + return + + subcircuit_path = os.path.join( + os.path.abspath('..'), 'SubcircuitLibrary', create_subcircuit) + + reply = self.obj_validation.validateNewproj(subcircuit_path) + + if reply == "VALID": + print("Validated: Creating subcircuit directory") + os.makedirs(subcircuit_path) + subcircuit = os.path.join(subcircuit_path, upload) + + print("===================") + print("Current path of subcircuit file is " + editfile) + print("Selected file is " + upload) + print("Final path of file is " + subcircuit) + print("===================") + shutil.copy(editfile, subcircuit) + + elif 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 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") |