summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRahul P2020-04-09 18:36:19 +0530
committerGitHub2020-04-09 18:36:19 +0530
commit6a0ef73be748b4e885d4288dede37fc76ad95158 (patch)
treeabf923d3c1559d26fc2324e53b2711907f433db9 /src
parent71d2ee1a0984569bd4069c953422144c3ce8f29b (diff)
parent26db6439a3038b92d23ade0a2bcf37ba57c87f7b (diff)
downloadeSim-6a0ef73be748b4e885d4288dede37fc76ad95158.tar.gz
eSim-6a0ef73be748b4e885d4288dede37fc76ad95158.tar.bz2
eSim-6a0ef73be748b4e885d4288dede37fc76ad95158.zip
Merge pull request #149 from rahulp13/master
resolved issues with rename and refresh projects, empty path
Diffstat (limited to 'src')
-rw-r--r--src/frontEnd/ProjectExplorer.py170
-rw-r--r--src/kicadtoNgspice/DeviceModel.py28
-rw-r--r--src/kicadtoNgspice/SubcircuitTab.py12
3 files changed, 140 insertions, 70 deletions
diff --git a/src/frontEnd/ProjectExplorer.py b/src/frontEnd/ProjectExplorer.py
index c733c9b1..f0227164 100644
--- a/src/frontEnd/ProjectExplorer.py
+++ b/src/frontEnd/ProjectExplorer.py
@@ -15,7 +15,6 @@ class ProjectExplorer(QtGui.QWidget):
- for renaming project.
- for refreshing project.
- for removing project.
- - for saving data.
"""
def __init__(self):
@@ -189,42 +188,57 @@ class ProjectExplorer(QtGui.QWidget):
clicking on project and selecting remove option.
"""
self.indexItem = self.treewidget.currentIndex()
- self.filePath = str(
+ filePath = str(
self.indexItem.sibling(self.indexItem.row(), 1).data()
)
self.int = self.indexItem.row()
self.treewidget.takeTopLevelItem(self.int)
- if self.obj_appconfig.current_project["ProjectName"] == self.filePath:
+ if self.obj_appconfig.current_project["ProjectName"] == filePath:
self.obj_appconfig.current_project["ProjectName"] = None
- del self.obj_appconfig.project_explorer[str(self.filePath)]
+ del self.obj_appconfig.project_explorer[filePath]
json.dump(self.obj_appconfig.project_explorer,
open(self.obj_appconfig.dictPath["path"], 'w'))
- def refreshProject(self):
+ def refreshProject(self, filePath=None):
"""
This function refresh the project in explorer area by right \
clicking on project and selecting refresh option.
"""
- self.indexItem = self.treewidget.currentIndex()
- self.filePath = str(
- self.indexItem.sibling(self.indexItem.row(), 1).data()
- )
- filelistnew = os.listdir(os.path.join(self.filePath))
- parentnode = self.treewidget.currentItem()
- count = parentnode.childCount()
- for i in range(count):
- for items in self.treewidget.selectedItems():
- items.removeChild(items.child(0))
- for files in filelistnew:
- QtGui.QTreeWidgetItem(
- parentnode, [files, os.path.join(self.filePath, files)]
+
+ if not filePath or filePath is None:
+ self.indexItem = self.treewidget.currentIndex()
+ filePath = str(
+ self.indexItem.sibling(self.indexItem.row(), 1).data()
)
- self.obj_appconfig.project_explorer[self.filePath] = filelistnew
- json.dump(self.obj_appconfig.project_explorer,
- open(self.obj_appconfig.dictPath["path"], 'w'))
+ if os.path.exists(filePath):
+ filelistnew = os.listdir(os.path.join(filePath))
+ parentnode = self.treewidget.currentItem()
+ count = parentnode.childCount()
+ for i in range(count):
+ for items in self.treewidget.selectedItems():
+ items.removeChild(items.child(0))
+ for files in filelistnew:
+ QtGui.QTreeWidgetItem(
+ parentnode, [files, os.path.join(filePath, files)]
+ )
+
+ self.obj_appconfig.project_explorer[filePath] = filelistnew
+ json.dump(self.obj_appconfig.project_explorer,
+ open(self.obj_appconfig.dictPath["path"], 'w'))
+ return True
+
+ else:
+ print("Selected project not found")
+ print("==================")
+ msg = QtGui.QErrorMessage(self)
+ msg.setModal(True)
+ msg.setWindowTitle("Error Message")
+ msg.showMessage('Selected project does not exist.')
+ msg.exec_()
+ return False
def renameProject(self):
"""
@@ -240,30 +254,18 @@ class ProjectExplorer(QtGui.QWidget):
"""
self.indexItem = self.treewidget.currentIndex()
self.baseFileName = str(self.indexItem.data())
+ filePath = str(
+ self.indexItem.sibling(self.indexItem.row(), 1).data()
+ )
+
newBaseFileName, ok = QtGui.QInputDialog.getText(
self, 'Rename Project', 'Project Name:',
QtGui.QLineEdit.Normal, self.baseFileName
)
+
if ok and newBaseFileName:
- print(newBaseFileName)
- print("=================")
newBaseFileName = str(newBaseFileName)
- i = -1
- for parents, children in list(
- self.obj_appconfig.project_explorer.items()):
- if os.path.exists(parents):
- i += 1
- if i == self.indexItem.row():
- projectPath, projectFiles = parents, children
- break
-
- updatedProjectFiles = []
-
- self.workspace = self.obj_appconfig.default_workspace['workspace']
- newBaseFileName = str(newBaseFileName).rstrip().lstrip()
- projDir = os.path.join(self.workspace, str(newBaseFileName))
-
if not newBaseFileName.strip():
print("Project name cannot be empty")
print("==================")
@@ -282,30 +284,94 @@ class ProjectExplorer(QtGui.QWidget):
msg.showMessage('The project name has to be different')
msg.exec_()
- else:
+ elif self.refreshProject(filePath):
+
+ projectPath = None
+ projectFiles = None
+
+ for parents, children in list(
+ self.obj_appconfig.project_explorer.items()):
+ if filePath == parents:
+ if os.path.exists(parents):
+ projectPath, projectFiles = parents, children
+ break
+
+ self.workspace = \
+ self.obj_appconfig.default_workspace['workspace']
+ newBaseFileName = str(newBaseFileName).rstrip().lstrip()
+ projDir = os.path.join(self.workspace, str(newBaseFileName))
+
reply = self.obj_validation.validateNewproj(str(projDir))
- if reply == "VALID":
+ if not (projectPath and projectFiles):
+ print("Selected project not found")
+ print("Project Path :", projectPath)
+ print("Project Files :", projectFiles)
+ print("==================")
+ msg = QtGui.QErrorMessage(self)
+ msg.setModal(True)
+ msg.setWindowTitle("Error Message")
+ msg.showMessage('Selected project does not exist.')
+ msg.exec_()
+
+ elif reply == "VALID":
# rename project folder
+ updatedProjectFiles = []
+
updatedProjectPath = newBaseFileName.join(
projectPath.rsplit(self.baseFileName, 1))
print("Renaming " + projectPath + " to " +
updatedProjectPath)
- os.rename(projectPath, updatedProjectPath)
+
+ # rename project folder
+ try:
+ os.rename(projectPath, updatedProjectPath)
+ except BaseException as e:
+ msg = QtGui.QErrorMessage(self)
+ msg.setModal(True)
+ msg.setWindowTitle("Error Message")
+ msg.showMessage(str(e))
+ msg.exec_()
+ return
# rename files matching project name
- for projectFile in projectFiles:
- if self.baseFileName in projectFile:
- oldFilePath = os.path.join(updatedProjectPath,
- projectFile)
- projectFile = projectFile.replace(
- self.baseFileName, newBaseFileName, 1)
+ try:
+ for projectFile in projectFiles:
+ if self.baseFileName in projectFile:
+ oldFilePath = os.path.join(updatedProjectPath,
+ projectFile)
+ projectFile = projectFile.replace(
+ self.baseFileName, newBaseFileName, 1)
+ newFilePath = os.path.join(
+ updatedProjectPath, projectFile)
+ print("Renaming " + oldFilePath + " to " +
+ newFilePath)
+ os.rename(oldFilePath, newFilePath)
+ updatedProjectFiles.append(projectFile)
+
+ except BaseException as e:
+ print("==================")
+ print("Error! Revert renaming project")
+
+ # Revert updatedProjectFiles
+ for projectFile in updatedProjectFiles:
newFilePath = os.path.join(
- updatedProjectPath, projectFile)
- print("Renaming " + oldFilePath + " to" +
- newFilePath)
- os.rename(oldFilePath, newFilePath)
- updatedProjectFiles.append(projectFile)
+ updatedProjectPath, projectFile)
+ projectFile = projectFile.replace(
+ newBaseFileName, self.baseFileName, 1)
+ oldFilePath = os.path.join(
+ updatedProjectPath, projectFile)
+ os.rename(newFilePath, oldFilePath)
+
+ # Revert project folder name
+ os.rename(updatedProjectPath, projectPath)
+ print("==================")
+ msg = QtGui.QErrorMessage(self)
+ msg.setModal(True)
+ msg.setWindowTitle("Error Message")
+ msg.showMessage(str(e))
+ msg.exec_()
+ return
# update project_explorer dictionary
del self.obj_appconfig.project_explorer[projectPath]
diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py
index c4ea9a22..31ff74f7 100644
--- a/src/kicadtoNgspice/DeviceModel.py
+++ b/src/kicadtoNgspice/DeviceModel.py
@@ -90,16 +90,16 @@ class DeviceModel(QtGui.QWidget):
# print("DEVICE MODEL MATCHING---", \
# child.tag, words[0])
try:
- if os.path.exists(child[0].text):
+ if child[0].text \
+ and os.path.exists(child[0].text):
self.entry_var[self.count] \
.setText(child[0].text)
path_name = child[0].text
else:
self.entry_var[self.count].setText("")
- except BaseException:
- print(
- "Error when set text of device\
- model transistor")
+ except BaseException as e:
+ print("Error when set text of device " +
+ "model transistor :", str(e))
except BaseException:
pass
@@ -153,15 +153,16 @@ class DeviceModel(QtGui.QWidget):
# print("DEVICE MODEL MATCHING---", \
# child.tag, words[0])
try:
- if os.path.exists(child[0].text):
+ if child[0].text \
+ and os.path.exists(child[0].text):
path_name = child[0].text
self.entry_var[self.count] \
.setText(child[0].text)
else:
self.entry_var[self.count].setText("")
- except BaseException:
- print("Error when set text of device\
- model diode")
+ except BaseException as e:
+ print("Error when set text of device " +
+ "model diode :", str(e))
except BaseException:
pass
@@ -215,15 +216,16 @@ class DeviceModel(QtGui.QWidget):
# print("DEVICE MODEL MATCHING---", \
# child.tag, words[0])
try:
- if os.path.exists(child[0].text):
+ if child[0].text \
+ and os.path.exists(child[0].text):
self.entry_var[self.count] \
.setText(child[0].text)
path_name = child[0].text
else:
self.entry_var[self.count].setText("")
- except BaseException:
- print("Error when set text of Device\
- Model JFET ")
+ except BaseException as e:
+ print("Error when set text of Device " +
+ "Model JFET :", str(e))
except BaseException:
pass
diff --git a/src/kicadtoNgspice/SubcircuitTab.py b/src/kicadtoNgspice/SubcircuitTab.py
index a191c639..d68cb97e 100644
--- a/src/kicadtoNgspice/SubcircuitTab.py
+++ b/src/kicadtoNgspice/SubcircuitTab.py
@@ -80,16 +80,18 @@ class SubcircuitTab(QtGui.QWidget):
# print("Subcircuit MATCHING---", child.tag[0], \
# child.tag[1], eachline[0],eachline[1])
try:
- if os.path.exists(child[0].text):
+ if child[0].text \
+ and os.path.exists(child[0].text):
self.entry_var[self.count] \
.setText(child[0].text)
path_name = child[0].text
else:
self.entry_var[self.count].setText("")
- except BaseException:
- print("Error when set text of subcircuit")
- except BaseException:
- print("Error before subcircuit")
+ except BaseException as e:
+ print("Error when set text of " +
+ "subcircuit :", str(e))
+ except BaseException as e:
+ print("Error before subcircuit :", str(e))
subgrid.addWidget(self.entry_var[self.count], self.row, 1)
self.addbtn = QtGui.QPushButton("Add")