summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSunil Shetye2019-06-27 17:06:52 +0530
committerGitHub2019-06-27 17:06:52 +0530
commit9fca9eec6fd4ee2001361d2b459d13dcb0a8a924 (patch)
tree4c23d5d525f835933459388ed2bfce8d7b053f9c /src
parenta620e3f94c46f02d7ee1b58bdb5fb7cc8e7be2f1 (diff)
parent9e3dbaf428a899e34490cbfcb11ca7c9bb7af60a (diff)
downloadeSim-9fca9eec6fd4ee2001361d2b459d13dcb0a8a924.tar.gz
eSim-9fca9eec6fd4ee2001361d2b459d13dcb0a8a924.tar.bz2
eSim-9fca9eec6fd4ee2001361d2b459d13dcb0a8a924.zip
Merge pull request #104 from anjalijaiswal08/RenameProject
Rename project Done
Diffstat (limited to 'src')
-rwxr-xr-xsrc/frontEnd/Application.py5
-rw-r--r--src/frontEnd/ProjectExplorer.py155
-rw-r--r--src/ngspiceSimulation/pythonPlotting.py2
-rw-r--r--src/projManagement/newProject.py13
-rw-r--r--src/projManagement/openProject.py1
-rw-r--r--src/subcircuit/convertSub.py8
-rw-r--r--src/subcircuit/newSub.py5
-rw-r--r--src/subcircuit/openSub.py6
8 files changed, 134 insertions, 61 deletions
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py
index ef8a4a7d..7478264a 100755
--- a/src/frontEnd/Application.py
+++ b/src/frontEnd/Application.py
@@ -31,15 +31,15 @@ from PyQt4.Qt import QSize
import sys
import os
-# Its our main window of application.
-
+# Its our main window of application.
class Application(QtGui.QMainWindow):
"""This class initializes all objects used in this file(Application.py)."""
global project_name
def __init__(self, *args):
"""Initialize main Application window."""
+
# Calling __init__ of super class
QtGui.QMainWindow.__init__(self, *args)
@@ -349,6 +349,7 @@ class Application(QtGui.QMainWindow):
"ngspice taking too long, check netlist file")
# Calling Python Plotting
+
try:
self.obj_Mainview.obj_dockarea.plottingEditor()
except Exception as e:
diff --git a/src/frontEnd/ProjectExplorer.py b/src/frontEnd/ProjectExplorer.py
index 8832cb41..4627d294 100644
--- a/src/frontEnd/ProjectExplorer.py
+++ b/src/frontEnd/ProjectExplorer.py
@@ -2,6 +2,7 @@ from PyQt4 import QtGui, QtCore
import os
import json
from configuration.Appconfig import Appconfig
+from projManagement.Validation import Validation
# This is main class for Project Explorer Area.
@@ -25,6 +26,7 @@ class ProjectExplorer(QtGui.QWidget):
"""
QtGui.QWidget.__init__(self)
self.obj_appconfig = Appconfig()
+ self.obj_validation = Validation()
self.treewidget = QtGui.QTreeWidget()
self.window = QtGui.QVBoxLayout()
header = QtGui.QTreeWidgetItem(["Projects", "path"])
@@ -181,9 +183,6 @@ class ProjectExplorer(QtGui.QWidget):
# This function removes the project in explorer area by right
# clicking on project and selecting remove option.
def removeProject(self):
- """
-
- """
self.indexItem = self.treewidget.currentIndex()
self.filePath = str(
self.indexItem.sibling(
@@ -202,7 +201,6 @@ class ProjectExplorer(QtGui.QWidget):
# This function refresh the project in explorer area by right
# clicking on project and selecting refresh option.
def refreshProject(self):
- """ """
self.indexItem = self.treewidget.currentIndex()
self.filePath = str(
self.indexItem.sibling(
@@ -224,51 +222,116 @@ class ProjectExplorer(QtGui.QWidget):
json.dump(self.obj_appconfig.project_explorer,
open(self.obj_appconfig.dictPath, 'w'))
- '''def renameProject(self):
- indexItem = self.treewidget.currentIndex()
- baseFileName = str(indexItem.data())
+ def renameProject(self):
+ """
+ This function renames the project present in project explorer area
+ it validates first:
+
+ - If project names is not empty.
+ - Project name does not contain spaces between them.
+ - Project name is different between what it was earlier.
+ - Project name should not exist.
+
+ And after project name is changed it recreates
+ the project explorer tree.
+ """
+ self.indexItem = self.treewidget.currentIndex()
+ self.baseFileName = str(self.indexItem.data())
newBaseFileName, ok = QtGui.QInputDialog.getText(
- self, 'Rename Project', 'Project Name:',
- QtGui.QLineEdit.Normal, baseFileName
- )
+ self, 'Rename Project', 'Project Name:', QtGui.QLineEdit.Normal,
+ self.baseFileName
+ )
if ok and newBaseFileName:
+ print(newBaseFileName)
+ print("=================")
newBaseFileName = str(newBaseFileName)
- projectPath, projectFiles = list(
- self.obj_appconfig.project_explorer.items())[indexItem.row()]
- updatedProjectFiles = []
- # rename files matching project name
- for projectFile in projectFiles:
- if baseFileName in projectFile:
- oldFilePath = os.path.join(projectPath, projectFile)
- projectFile = projectFile.replace(
- baseFileName, newBaseFileName, 1)
- newFilePath = os.path.join(projectPath, projectFile)
- print ("Renaming " + oldFilePath + " to " + newFilePath)
- os.rename(oldFilePath, newFilePath)
-
- updatedProjectFiles.append(projectFile)
-
- # rename project folder
- updatedProjectPath = newBaseFileName.join(
- projectPath.rsplit(baseFileName, 1))
- print ("Renaming " + projectPath + " to " + updatedProjectPath)
- os.rename(projectPath, updatedProjectPath)
-
- # update project_explorer dictionary
- del self.obj_appconfig.project_explorer[projectPath]
- self.obj_appconfig.project_explorer[updatedProjectPath] = (
- updatedProjectFiles
- )
+ 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
- # save project_explorer dictionary on disk
- json.dump(self.obj_appconfig.project_explorer,
- open(self.obj_appconfig.dictPath, 'w'))
+ updatedProjectFiles = []
- # recreate project explorer tree
- self.treewidget.clear()
- for parent, children in (
- self.obj_appconfig.project_explorer.items()
- ):
- self.addTreeNode(parent, children)
- '''
+ self.workspace = self.obj_appconfig.default_workspace['workspace']
+ newBaseFileName = str(newBaseFileName).rstrip().lstrip()
+ projDir = os.path.join(self.workspace, str(newBaseFileName))
+
+ if newBaseFileName == "":
+ print("Project name can not be empty")
+ print("==================")
+ msg = QtGui.QErrorMessage(self)
+ msg.showMessage('The project name cannot be empty')
+ msg.setWindowTitle("Error Message")
+
+ elif self.baseFileName == newBaseFileName:
+ print("Project name has to be different")
+ print("==================")
+ msg = QtGui.QErrorMessage(self)
+ msg.showMessage('The project name has to be different')
+ msg.setWindowTitle("Error Message")
+
+ else:
+ reply = self.obj_validation.validateNewproj(str(projDir))
+
+ if reply == "VALID":
+ # rename project folder
+ updatedProjectPath = newBaseFileName.join(
+ projectPath.rsplit(self.baseFileName, 1))
+ print("Renaming " + projectPath + " to "
+ + updatedProjectPath)
+ os.rename(projectPath, updatedProjectPath)
+
+ # 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)
+ newFilePath = os.path.join(
+ updatedProjectPath, projectFile)
+ print("Renaming " + oldFilePath + " to"
+ + newFilePath)
+ os.rename(oldFilePath, newFilePath)
+ updatedProjectFiles.append(projectFile)
+
+ # update project_explorer dictionary
+ del self.obj_appconfig.project_explorer[projectPath]
+ self.obj_appconfig.project_explorer[updatedProjectPath] = \
+ updatedProjectFiles
+
+ # save project_explorer dictionary on disk
+ json.dump(self.obj_appconfig.project_explorer, open(
+ self.obj_appconfig.dictPath, 'w'))
+
+ # recreate project explorer tree
+ self.treewidget.clear()
+ for parent, children in \
+ self.obj_appconfig.project_explorer.items():
+ if os.path.exists(parent):
+ self.addTreeNode(parent, children)
+
+ elif reply == "CHECKEXIST":
+ print("Project name already exists.")
+ print("==========================")
+ msg = QtGui.QErrorMessage(self)
+ msg.showMessage(
+ 'The project "'
+ + newBaseFileName
+ + '" 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")
diff --git a/src/ngspiceSimulation/pythonPlotting.py b/src/ngspiceSimulation/pythonPlotting.py
index 22f2100a..bbcc981f 100644
--- a/src/ngspiceSimulation/pythonPlotting.py
+++ b/src/ngspiceSimulation/pythonPlotting.py
@@ -381,6 +381,7 @@ class plotWindow(QtGui.QMainWindow):
self.axes.set_ylabel('Voltage(V)-->')
else:
self.axes.set_ylabel('Current(I)-->')
+
self.axes.grid(True)
self.canvas.draw()
self.combo = []
@@ -697,6 +698,7 @@ class DataExtraction:
self.msg = QtGui.QErrorMessage(None)
self.msg.showMessage('Error in Analysis File.')
self.msg.setWindowTitle("Error Message:openFile")
+
d = self.numberFinder(fpath)
d1 = int(d[0] + 1)
d2 = int(d[1])
diff --git a/src/projManagement/newProject.py b/src/projManagement/newProject.py
index 44a7a69a..6f8de2b9 100644
--- a/src/projManagement/newProject.py
+++ b/src/projManagement/newProject.py
@@ -1,4 +1,3 @@
-
# =========================================================================
#
# FILE: newProject.py
@@ -45,11 +44,17 @@ class NewProjectInfo(QtGui.QWidget):
- CHECKNAME
- NONE
- @params
+ @params
:projName => name of the project created passed from
frontEnd/Application new_project()
+ @return
+ :dirs => The directories inside the project folder
+ :filelist => The files inside the project folder
- @return
+ @params
+ :projName => name of the project created passed from
+ frontEnd/Application new_project()
+ @return
:dirs => The directories inside the project folder
:filelist => The files inside the project folder
@@ -83,7 +88,7 @@ class NewProjectInfo(QtGui.QWidget):
self.msg = QtGui.QErrorMessage(self)
self.msg.showMessage(
'Unable to create project. Please make sure you have'
- + 'write permission on '
+ + ' write permission on '
+ self.workspace)
self.msg.setWindowTitle("Error Message")
f.write("schematicFile " + self.projName + ".sch\n")
diff --git a/src/projManagement/openProject.py b/src/projManagement/openProject.py
index 9c31bf31..23e2c361 100644
--- a/src/projManagement/openProject.py
+++ b/src/projManagement/openProject.py
@@ -1,4 +1,3 @@
-
# =========================================================================
#
# FILE: openProject.py
diff --git a/src/subcircuit/convertSub.py b/src/subcircuit/convertSub.py
index 49f5a54f..7bdccfb2 100644
--- a/src/subcircuit/convertSub.py
+++ b/src/subcircuit/convertSub.py
@@ -44,12 +44,12 @@ class convertSub(QtGui.QWidget):
else:
self.msg = QtGui.QErrorMessage(None)
self.msg.showMessage(
- 'The subcircuit does not contain any Kicad netlist\
- file for conversion.')
+ 'The subcircuit does not contain any Kicad netlist file'
+ + ' for conversion.')
self.msg.setWindowTitle("Error Message")
else:
self.msg = QtGui.QErrorMessage(None)
self.msg.showMessage(
- 'Please select the subcircuit first. You can either create \
- new subcircuit or open existing subcircuit')
+ 'Please select the subcircuit first. You can either create'
+ + ' new subcircuit or open existing subcircuit')
self.msg.setWindowTitle("Error Message")
diff --git a/src/subcircuit/newSub.py b/src/subcircuit/newSub.py
index 678b023d..bd88064a 100644
--- a/src/subcircuit/newSub.py
+++ b/src/subcircuit/newSub.py
@@ -8,7 +8,10 @@ import os
# This class is called when User create new Project.
class NewSub(QtGui.QWidget):
"""
- Contains functions to create directory and validate file names.
+ Contains functions to check :
+ - Name of project should not be blank.
+ - Name should not contain space between them.
+ - Name does not match with existing project.
"""
def __init__(self):
diff --git a/src/subcircuit/openSub.py b/src/subcircuit/openSub.py
index bebd28a1..dd6e31ac 100644
--- a/src/subcircuit/openSub.py
+++ b/src/subcircuit/openSub.py
@@ -21,9 +21,9 @@ class openSub(QtGui.QWidget):
None, "Open File", "../SubcircuitLibrary"))
if self.editfile:
self.obj_Appconfig = Appconfig()
- self.obj_Appconfig.current_subcircuit['SubcircuitName'] = (
- self.editfile
- )
+ self.obj_Appconfig.current_subcircuit['SubcircuitName'] \
+ = self.editfile
+
self.schname = os.path.basename(self.editfile)
self.editfile = os.path.join(self.editfile, self.schname)
self.cmd = "eeschema " + self.editfile + ".sch "