diff options
author | nilshah98 | 2019-06-07 12:48:36 +0530 |
---|---|---|
committer | nilshah98 | 2019-06-13 12:18:39 +0530 |
commit | daffbbb29757deff785c13a429b4c03fe3f25fba (patch) | |
tree | c4a368dcb4e218f06c0594e57d1b4d1a7f395972 /src/frontEnd | |
parent | 554cbd5ed063e0ab1bb8fc127a43ccbe3a5a1e92 (diff) | |
download | eSim-daffbbb29757deff785c13a429b4c03fe3f25fba.tar.gz eSim-daffbbb29757deff785c13a429b4c03fe3f25fba.tar.bz2 eSim-daffbbb29757deff785c13a429b4c03fe3f25fba.zip |
Rename feature ported
Diffstat (limited to 'src/frontEnd')
-rw-r--r-- | src/frontEnd/ProjectExplorer.py | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/src/frontEnd/ProjectExplorer.py b/src/frontEnd/ProjectExplorer.py index 3a2ed2cc..658ea12e 100644 --- a/src/frontEnd/ProjectExplorer.py +++ b/src/frontEnd/ProjectExplorer.py @@ -6,7 +6,15 @@ from configuration.Appconfig import Appconfig # This is main class for Project Explorer Area. class ProjectExplorer(QtGui.QWidget): - """ """ + """ + This class contains function: + a)One work as a constructor(__init__). + b)For saving data. + c)for renaming project. + d)for refreshing project. + e)for removing project. + f) for saving data. + """ def __init__(self): """ @@ -90,6 +98,8 @@ class ProjectExplorer(QtGui.QWidget): menu = QtGui.QMenu() if level == 0: + renameProject = menu.addAction(self.tr("Rename Project")) + renameProject.triggered.connect(self.renameProject) deleteproject = menu.addAction(self.tr("Remove Project")) deleteproject.triggered.connect(self.removeProject) refreshproject = menu.addAction(self.tr("Refresh")) @@ -160,6 +170,10 @@ class ProjectExplorer(QtGui.QWidget): # This function is saving data before it closes the given file. def save_data(self): + """ + This function first opens file in write-mode, when write + operation is performed it closes that file and then window. + """ self.fopen = open(self.filePath, 'w') self.fopen.write(self.text.toPlainText()) self.fopen.close() @@ -168,7 +182,9 @@ 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( @@ -208,3 +224,43 @@ class ProjectExplorer(QtGui.QWidget): self.obj_appconfig.project_explorer[self.filePath] = filelistnew json.dump(self.obj_appconfig.project_explorer, open(self.obj_appconfig.dictPath, 'w')) + + #""" + def renameProject(self): + indexItem = self.treewidget.currentIndex() + baseFileName = str(indexItem.data()) + newBaseFileName, ok = QtGui.QInputDialog.getText(self, 'Rename Project', 'Project Name:', + QtGui.QLineEdit.Normal, baseFileName) + if ok and newBaseFileName: + 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 + + # 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(): + self.addTreeNode(parent, children) + # """ |