diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/frontEnd/Application.py | 17 | ||||
-rw-r--r-- | src/frontEnd/Workspace.py | 12 | ||||
-rw-r--r-- | src/kicadtoNgspice/DeviceModel.py | 9 | ||||
-rw-r--r-- | src/kicadtoNgspice/SubcircuitTab.py | 27 | ||||
-rw-r--r-- | src/modelEditor/ModelEditor.py | 126 | ||||
-rw-r--r-- | src/ngspicetoModelica/ModelicaUI.py | 12 | ||||
-rw-r--r-- | src/projManagement/newProject.py | 3 | ||||
-rw-r--r-- | src/projManagement/openProject.py | 9 | ||||
-rw-r--r-- | src/subcircuit/Subcircuit.py | 13 | ||||
-rw-r--r-- | src/subcircuit/openSub.py | 12 | ||||
-rw-r--r-- | src/subcircuit/uploadSub.py | 15 |
11 files changed, 187 insertions, 68 deletions
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py index 4edf7a9f..94bce4ae 100644 --- a/src/frontEnd/Application.py +++ b/src/frontEnd/Application.py @@ -13,7 +13,7 @@ # MODIFIED: Rahul Paknikar, rahulp@iitb.ac.in # ORGANIZATION: eSim Team at FOSSEE, IIT Bombay # CREATED: Tuesday 24 February 2015 -# REVISION: Saturday 01 August 2020 +# REVISION: Sunday 13 December 2020 # ========================================================================= import os @@ -293,13 +293,20 @@ class Application(QtWidgets.QMainWindow): text, ok = QtWidgets.QInputDialog.getText( self, 'New Project Info', 'Enter Project Name:' ) + updated = False + if ok: self.projname = (str(text)) self.project = NewProjectInfo() directory, filelist = self.project.createProject(self.projname) - self.obj_Mainview.obj_projectExplorer.addTreeNode( - directory, filelist) - else: + + if directory and filelist: + self.obj_Mainview.obj_projectExplorer.addTreeNode( + directory, filelist + ) + updated = True + + if not updated: print("No new project created") self.obj_appconfig.print_info('No new project created') try: @@ -714,7 +721,7 @@ class Application(QtWidgets.QMainWindow): 'Please select the project first. ' + 'You can either create a new project or open existing project' ) - self.exec_() + self.msg.exec_() def open_OMoptim(self): """ diff --git a/src/frontEnd/Workspace.py b/src/frontEnd/Workspace.py index 0a80d357..4d033539 100644 --- a/src/frontEnd/Workspace.py +++ b/src/frontEnd/Workspace.py @@ -13,7 +13,7 @@ # MODIFIED: Rahul Paknikar, rahulp@iitb.ac.in # ORGANIZATION: eSim Team at FOSSEE, IIT Bombay # CREATED: Wednesday 05 February 2015 -# REVISION: Saturday 25 July 2020 +# REVISION: Sunday 13 December 2020 # ========================================================================= from PyQt5 import QtCore, QtGui, QtWidgets @@ -172,7 +172,11 @@ class Workspace(QtWidgets.QWidget): def browseLocation(self): print("Function : Browse Location") - self.workspace_directory = QtWidgets.QFileDialog.getExistingDirectory( - self, "Browse Location", os.path.expanduser("~") + self.workspace_directory = QtCore.QDir.toNativeSeparators( + QtWidgets.QFileDialog.getExistingDirectory( + self, "Browse Location", os.path.expanduser("~") + ) ) - self.workspace_loc.setText(self.workspace_directory) + + if self.workspace_directory: + self.workspace_loc.setText(self.workspace_directory) diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index 1c77cabc..5fd4d829 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -1,4 +1,4 @@ -from PyQt5 import QtWidgets +from PyQt5 import QtWidgets, QtCore import os from xml.etree import ElementTree as ET from . import TrackWidget @@ -368,10 +368,15 @@ class DeviceModel(QtWidgets.QWidget): if os.name == 'nt': init_path = '' - self.libfile = QtWidgets.QFileDialog.getOpenFileName( + self.libfile = QtCore.QDir.toNativeSeparators( + QtWidgets.QFileDialog.getOpenFileName( self, "Open Library Directory", init_path + "library/deviceModelLibrary", "*.lib" )[0] + ) + + if not self.libfile: + return # Setting Library to Text Edit Line self.entry_var[self.widgetObjCount].setText(self.libfile) diff --git a/src/kicadtoNgspice/SubcircuitTab.py b/src/kicadtoNgspice/SubcircuitTab.py index 4c7179d3..6b98167d 100644 --- a/src/kicadtoNgspice/SubcircuitTab.py +++ b/src/kicadtoNgspice/SubcircuitTab.py @@ -1,4 +1,4 @@ -from PyQt5 import QtWidgets +from PyQt5 import QtWidgets, QtCore from . import TrackWidget from projManagement import Validation import os @@ -151,26 +151,36 @@ class SubcircuitTab(QtWidgets.QWidget): init_path = '' self.subfile = str( - QtWidgets.QFileDialog.getExistingDirectory( - self, "Open Subcircuit", - init_path + "library/SubcircuitLibrary") + QtCore.QDir.toNativeSeparators( + QtWidgets.QFileDialog.getExistingDirectory( + self, "Open Subcircuit", + init_path + "library/SubcircuitLibrary" + ) ) + ) + + if not self.subfile: + return + self.reply = self.obj_validation.validateSub( - self.subfile, self.numPorts[self.widgetObjCount - 1]) + self.subfile, self.numPorts[self.widgetObjCount - 1] + ) + if self.reply == "True": # Setting Library to Text Edit Line self.entry_var[self.widgetObjCount].setText(self.subfile) self.subName = self.subDetail[self.widgetObjCount] # Storing to track it during conversion - self.obj_trac.subcircuitTrack[self.subName] = self.subfile + elif self.reply == "PORT": self.msg = QtWidgets.QErrorMessage(self) self.msg.setModal(True) self.msg.setWindowTitle("Error Message") self.msg.showMessage( - "Please select a Subcircuit with correct number of ports.") + "Please select a Subcircuit with correct number of ports." + ) self.msg.exec_() elif self.reply == "DIREC": self.msg = QtWidgets.QErrorMessage(self) @@ -178,7 +188,8 @@ class SubcircuitTab(QtWidgets.QWidget): self.msg.setWindowTitle("Error Message") self.msg.showMessage( "Please select a valid Subcircuit directory " - "(Containing '.sub' file).") + "(Containing '.sub' file)." + ) self.msg.exec_() def trackSubcircuitWithoutButton(self, iter_value, path_value): diff --git a/src/modelEditor/ModelEditor.py b/src/modelEditor/ModelEditor.py index bf5687a7..cddcc78f 100644 --- a/src/modelEditor/ModelEditor.py +++ b/src/modelEditor/ModelEditor.py @@ -129,8 +129,20 @@ class ModelEditorclass(QtWidgets.QWidget): # Opens new dialog box text, ok = QtWidgets.QInputDialog.getText( - self, 'New Model', 'Enter Model Name:') + self, 'New Model', 'Enter Model Name:' + ) + if ok: + if not text: + print("Model name cannot be empty") + print("==================") + msg = QtWidgets.QErrorMessage(self) + msg.setModal(True) + msg.setWindowTitle("Error Message") + msg.showMessage('The model name cannot be empty') + msg.exec_() + return + self.newflag = 1 self.diode.setDisabled(False) self.bjt.setDisabled(False) @@ -140,7 +152,7 @@ class ModelEditorclass(QtWidgets.QWidget): self.magnetic.setDisabled(False) self.modelname = (str(text)) else: - pass + return # Validate if the file created exists already or not # Show error accordingly @@ -327,12 +339,15 @@ class ModelEditorclass(QtWidgets.QWidget): self.bjt.setDisabled(True) self.magnetic.setDisabled(True) try: - self.editfile = QtWidgets.QFileDialog.getOpenFileName( - self, "Open Library Directory", - self.init_path + "library/deviceModelLibrary", "*.lib" - )[0] - - self.createtable(self.editfile) + self.editfile = QtCore.QDir.toNativeSeparators( + QtWidgets.QFileDialog.getOpenFileName( + self, "Open Library Directory", + self.init_path + "library/deviceModelLibrary", "*.lib" + )[0] + ) + + if self.editfile: + self.createtable(self.editfile) except BaseException: print("No File selected for edit") @@ -422,30 +437,50 @@ class ModelEditorclass(QtWidgets.QWidget): - text1 => parameter, text2 => value ''' text1, ok = QtWidgets.QInputDialog.getText( - self, 'Parameter', 'Enter Parameter') + self, 'Parameter', 'Enter Parameter' + ) if ok: - if text1 in list(self.modeldict.keys()): + if not text1: + print("Parameter name cannot be empty") + print("==================") + msg = QtWidgets.QErrorMessage(self) + msg.setModal(True) + msg.setWindowTitle("Error Message") + msg.showMessage('The parameter name cannot be empty') + msg.exec_() + return + elif text1 in list(self.modeldict.keys()): self.msg = QtWidgets.QErrorMessage(self) self.msg.setModal(True) self.msg.setWindowTitle("Error Message") self.msg.showMessage( - "The paramaeter " + text1 + " is already in the list") + "The paramaeter " + text1 + " is already in the list" + ) self.msg.exec_() return text2, ok = QtWidgets.QInputDialog.getText( - self, 'Value', 'Enter Value') + self, 'Value', 'Enter Value' + ) if ok: + if not text2: + print("Value cannot be empty") + print("==================") + msg = QtWidgets.QErrorMessage(self) + msg.setModal(True) + msg.setWindowTitle("Error Message") + msg.showMessage('Value cannot be empty') + msg.exec_() + return + currentRowCount = self.modeltable.rowCount() self.modeltable.insertRow(currentRowCount) self.modeltable.setItem( - currentRowCount, 0, QTableWidgetItem(text1)) + currentRowCount, 0, QTableWidgetItem(text1) + ) self.modeltable.setItem( - currentRowCount, 1, QTableWidgetItem(text2)) + currentRowCount, 1, QTableWidgetItem(text2) + ) self.modeldict[str(text1)] = str(text2) - else: - pass - else: - pass def savemodelfile(self): ''' @@ -676,9 +711,20 @@ class ModelEditorclass(QtWidgets.QWidget): ''' self.savebtn.setDisabled(False) index = self.modeltable.currentIndex() - remove_item = self.modeltable.item(index.row(), 0).text() - self.modeltable.removeRow(index.row()) - del self.modeldict[str(remove_item)] + remove_item = self.modeltable.item(index.row(), 0) + + if remove_item: + remove_item = remove_item.text() + self.modeltable.removeRow(index.row()) + del self.modeldict[str(remove_item)] + else: + print("No parameter selected to remove") + print("==================") + msg = QtWidgets.QErrorMessage(self) + msg.setModal(True) + msg.setWindowTitle("Error Message") + msg.showMessage('No parameter selected to remove') + msg.exec_() def converttoxml(self): ''' @@ -696,10 +742,15 @@ class ModelEditorclass(QtWidgets.QWidget): model_dict = {} stringof = [] - self.libfile = QtWidgets.QFileDialog.getOpenFileName( - self, "Open Library Directory", - self.init_path + "library/deviceModelLibrary", "*.lib" - )[0] + self.libfile = QtCore.QDir.toNativeSeparators( + QtWidgets.QFileDialog.getOpenFileName( + self, "Open Library Directory", + self.init_path + "library/deviceModelLibrary", "*.lib" + )[0] + ) + + if not self.libfile: + return libopen = open(self.libfile) filedata = libopen.read().split() @@ -796,14 +847,25 @@ class ModelEditorclass(QtWidgets.QWidget): savepath = os.path.join(self.savepathtest, 'User Libraries') os.chdir(savepath) text, ok1 = QtWidgets.QInputDialog.getText( - self, 'Model Name', 'Enter Model Library Name') + self, 'Model Name', 'Enter Model Library Name' + ) if ok1: - tree.write(text + ".xml") - fileopen = open(text + ".lib", 'w') - f = open(self.libfile) - fileopen.write(f.read()) - f.close() - fileopen.close() + if not text: + print("Model library name cannot be empty") + print("==================") + msg = QtWidgets.QErrorMessage(self) + msg.setModal(True) + msg.setWindowTitle("Error Message") + msg.showMessage('The model library name cannot be empty') + msg.exec_() + else: + tree.write(text + ".xml") + fileopen = open(text + ".lib", 'w') + f = open(self.libfile) + fileopen.write(f.read()) + f.close() + fileopen.close() + os.chdir(defaultcwd) libopen.close() libopen1.close() diff --git a/src/ngspicetoModelica/ModelicaUI.py b/src/ngspicetoModelica/ModelicaUI.py index 8e2479c9..6cd736b7 100644 --- a/src/ngspicetoModelica/ModelicaUI.py +++ b/src/ngspicetoModelica/ModelicaUI.py @@ -45,9 +45,15 @@ class OpenModelicaEditor(QtWidgets.QWidget): self.show() def browseFile(self): - self.ngspiceNetlist = QtWidgets.QFileDialog.getOpenFileName( - self, 'Open Ngspice Netlist', BROWSE_LOCATION)[0] - self.FileEdit.setText(self.ngspiceNetlist) + temp = QtCore.QDir.toNativeSeparators( + QtWidgets.QFileDialog.getOpenFileName( + self, 'Open Ngspice Netlist', BROWSE_LOCATION + )[0] + ) + + if temp: + self.ngspiceNetlist = temp + self.FileEdit.setText(self.ngspiceNetlist) def callConverter(self): diff --git a/src/projManagement/newProject.py b/src/projManagement/newProject.py index ad29dc76..278cfbe3 100644 --- a/src/projManagement/newProject.py +++ b/src/projManagement/newProject.py @@ -124,6 +124,7 @@ class NewProjectInfo(QtWidgets.QWidget): ' existing project' ) self.msg.exec_() + return None, None elif self.reply == "CHECKNAME": self.msg = QtWidgets.QErrorMessage(self) @@ -132,6 +133,7 @@ class NewProjectInfo(QtWidgets.QWidget): self.msg.showMessage( 'The project name should not contain space between them') self.msg.exec_() + return None, None elif self.reply == "NONE": self.msg = QtWidgets.QErrorMessage(self) @@ -139,6 +141,7 @@ class NewProjectInfo(QtWidgets.QWidget): self.msg.setWindowTitle("Error Message") self.msg.showMessage('The project name cannot be empty') self.msg.exec_() + return None, None def cancelProject(self): self.close() diff --git a/src/projManagement/openProject.py b/src/projManagement/openProject.py index 04944d29..c5bc2dec 100644 --- a/src/projManagement/openProject.py +++ b/src/projManagement/openProject.py @@ -16,7 +16,7 @@ # REVISION: Sunday 26 July 2020 # ========================================================================= -from PyQt5 import QtWidgets +from PyQt5 import QtWidgets, QtCore from .Validation import Validation from configuration.Appconfig import Appconfig import os @@ -45,8 +45,11 @@ class OpenProjectInfo(QtWidgets.QWidget): """ self.obj_Appconfig = Appconfig() self.openDir = self.obj_Appconfig.default_workspace["workspace"] - self.projDir = QtWidgets.QFileDialog.getExistingDirectory( - self, "open", self.openDir) + self.projDir = QtCore.QDir.toNativeSeparators( + QtWidgets.QFileDialog.getExistingDirectory( + self, "open", self.openDir + ) + ) if self.obj_validation.validateOpenproj(self.projDir): self.obj_Appconfig.current_project['ProjectName'] = str( diff --git a/src/subcircuit/Subcircuit.py b/src/subcircuit/Subcircuit.py index 298ff96e..eb06e145 100644 --- a/src/subcircuit/Subcircuit.py +++ b/src/subcircuit/Subcircuit.py @@ -64,8 +64,19 @@ class Subcircuit(QtWidgets.QWidget): def newsch(self): text, ok = QtWidgets.QInputDialog.getText( - self, 'New Schematic', 'Enter Schematic Name:') + self, 'New Schematic', 'Enter Schematic Name:' + ) if ok: + if not text: + print("Schematic name cannot be empty") + print("==================") + msg = QtWidgets.QErrorMessage(self) + msg.setModal(True) + msg.setWindowTitle("Error Message") + msg.showMessage('The schematic name cannot be empty') + msg.exec_() + return + self.schematic_name = (str(text)) self.subcircuit = NewSub() self.subcircuit.createSubcircuit(self.schematic_name) diff --git a/src/subcircuit/openSub.py b/src/subcircuit/openSub.py index 63597661..f98fe69f 100644 --- a/src/subcircuit/openSub.py +++ b/src/subcircuit/openSub.py @@ -1,7 +1,7 @@ -from PyQt5 import QtWidgets +import os +from PyQt5 import QtWidgets, QtCore from configuration.Appconfig import Appconfig from projManagement.Worker import WorkerThread -import os # This class is called when User clicks on Edit Subcircuit Button. @@ -21,8 +21,12 @@ class openSub(QtWidgets.QWidget): if os.name == 'nt': init_path = '' - self.editfile = QtWidgets.QFileDialog.getExistingDirectory( - None, "Open File", init_path + "library/SubcircuitLibrary") + self.editfile = QtCore.QDir.toNativeSeparators( + QtWidgets.QFileDialog.getExistingDirectory( + None, "Open File", init_path + "library/SubcircuitLibrary" + ) + ) + if self.editfile: self.obj_Appconfig = Appconfig() self.obj_Appconfig.current_subcircuit['SubcircuitName'] \ diff --git a/src/subcircuit/uploadSub.py b/src/subcircuit/uploadSub.py index 13924bf3..5ae50df8 100644 --- a/src/subcircuit/uploadSub.py +++ b/src/subcircuit/uploadSub.py @@ -1,4 +1,4 @@ -from PyQt5 import QtWidgets +from PyQt5 import QtWidgets, QtCore from configuration.Appconfig import Appconfig from projManagement.Validation import Validation import os @@ -20,7 +20,7 @@ class UploadSub(QtWidgets.QWidget): def upload(self): """ - This method opens a dialogue box when Upload subcircuit button is + This method opens a dialog 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. @@ -30,11 +30,14 @@ class UploadSub(QtWidgets.QWidget): true if file has valid format or else it shows an error message. """ - editfile = QtWidgets.QFileDialog.getOpenFileName( - None, "Upload Subcircuit File", os.path.expanduser("~"), "*.sub" - )[0] + editfile = QtCore.QDir.toNativeSeparators( + QtWidgets.QFileDialog.getOpenFileName( + None, "Upload Subcircuit File", + os.path.expanduser("~"), "*.sub" + )[0] + ) - if editfile == '': + if not editfile: return upload = os.path.basename(editfile) |