diff options
author | anjalijaiswal08 | 2019-06-25 15:38:20 +0530 |
---|---|---|
committer | anjalijaiswal08 | 2019-06-27 12:27:37 +0530 |
commit | bfcd31c7c14519d29cf5b2c813899fc63bc5cf32 (patch) | |
tree | dc91bf104b4b0d207326b23ee690e8e92a78f5ef /src/subcircuit | |
parent | b9957bac0e86410007b0b728e58edeca5aa52d85 (diff) | |
download | eSim-bfcd31c7c14519d29cf5b2c813899fc63bc5cf32.tar.gz eSim-bfcd31c7c14519d29cf5b2c813899fc63bc5cf32.tar.bz2 eSim-bfcd31c7c14519d29cf5b2c813899fc63bc5cf32.zip |
Uploading Subcircuit feature added
Diffstat (limited to 'src/subcircuit')
-rw-r--r-- | src/subcircuit/uploadSub.py | 94 |
1 files changed, 94 insertions, 0 deletions
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") |