summaryrefslogtreecommitdiff
path: root/src/frontEnd/ProjectExplorer.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontEnd/ProjectExplorer.py')
-rw-r--r--src/frontEnd/ProjectExplorer.py128
1 files changed, 70 insertions, 58 deletions
diff --git a/src/frontEnd/ProjectExplorer.py b/src/frontEnd/ProjectExplorer.py
index 4627d294..c733c9b1 100644
--- a/src/frontEnd/ProjectExplorer.py
+++ b/src/frontEnd/ProjectExplorer.py
@@ -35,20 +35,22 @@ class ProjectExplorer(QtGui.QWidget):
# CSS
self.treewidget.setStyleSheet(" \
+ QTreeView { border-radius: 15px; border: 1px \
+ solid gray; padding: 5px; width: 200px; height: 150px; }\
QTreeView::branch:has-siblings:!adjoins-item { \
- border-image: url(../../images/vline.png) 0;} \
+ border-image: url(images/vline.png) 0;} \
QTreeView::branch:has-siblings:adjoins-item { \
- border-image: url(../../images/branch-more.png) 0; } \
+ border-image: url(images/branch-more.png) 0; } \
QTreeView::branch:!has-children:!has-siblings:adjoins-item { \
- border-image: url(../../images/branch-end.png) 0; } \
+ border-image: url(images/branch-end.png) 0; } \
QTreeView::branch:has-children:!has-siblings:closed, \
QTreeView::branch:closed:has-children:has-siblings { \
border-image: none; \
- image: url(../../images/branch-closed.png); } \
+ image: url(images/branch-closed.png); } \
QTreeView::branch:open:has-children:!has-siblings, \
QTreeView::branch:open:has-children:has-siblings { \
border-image: none; \
- image: url(../../images/branch-open.png); } \
+ image: url(images/branch-open.png); } \
")
for parents, children in list(
@@ -61,7 +63,8 @@ class ProjectExplorer(QtGui.QWidget):
)
for files in children:
QtGui.QTreeWidgetItem(
- parentnode, [files, os.path.join(parents, files)])
+ parentnode, [files, os.path.join(parents, files)]
+ )
self.window.addWidget(self.treewidget)
self.treewidget.doubleClicked.connect(self.openProject)
@@ -74,7 +77,8 @@ class ProjectExplorer(QtGui.QWidget):
os.path.join(parents)
pathlist = parents.split(os.sep)
parentnode = QtGui.QTreeWidgetItem(
- self.treewidget, [pathlist[-1], parents])
+ self.treewidget, [pathlist[-1], parents]
+ )
for files in children:
QtGui.QTreeWidgetItem(
parentnode, [files, os.path.join(parents, files)]
@@ -90,7 +94,6 @@ class ProjectExplorer(QtGui.QWidget):
) = []
def openMenu(self, position):
-
indexes = self.treewidget.selectedIndexes()
if len(indexes) > 0:
level = 0
@@ -101,6 +104,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"))
@@ -115,9 +120,8 @@ class ProjectExplorer(QtGui.QWidget):
self.indexItem = self.treewidget.currentIndex()
filename = str(self.indexItem.data())
self.filePath = str(
- self.indexItem.sibling(
- self.indexItem.row(),
- 1).data())
+ self.indexItem.sibling(self.indexItem.row(), 1).data()
+ )
self.obj_appconfig.print_info(
'The current project is ' + self.filePath)
@@ -130,16 +134,15 @@ class ProjectExplorer(QtGui.QWidget):
self.save = QtGui.QPushButton('Save and Exit')
self.save.setDisabled(True)
self.windowgrid = QtGui.QGridLayout()
- # if (os.path.isfile(str(self.filePath))) == True:
+
if (os.path.isfile(str(self.filePath))):
self.fopen = open(str(self.filePath), 'r')
lines = self.fopen.read()
self.text.setText(lines)
QtCore.QObject.connect(
- self.text,
- QtCore.SIGNAL("textChanged()"),
- self.enable_save)
+ self.text, QtCore.SIGNAL("textChanged()"), self.enable_save
+ )
vbox_main = QtGui.QVBoxLayout(self.textwindow)
vbox_main.addWidget(self.text)
@@ -165,29 +168,30 @@ class ProjectExplorer(QtGui.QWidget):
self.obj_appconfig.current_project['ProjectName']]
) = []
- # This function is enabling save button option.
def enable_save(self):
+ """This function enables save button option."""
self.save.setEnabled(True)
- # 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 it closes window.
+ This function saves data before it closes the given file.
+ It first opens file in write-mode, write operation is performed, \
+ closes that file and then it closes window.
"""
self.fopen = open(self.filePath, 'w')
self.fopen.write(self.text.toPlainText())
self.fopen.close()
self.textwindow.close()
- # This function removes the project in explorer area by right
- # clicking on project and selecting remove option.
def removeProject(self):
+ """
+ This function removes the project in explorer area by right \
+ clicking on project and selecting remove option.
+ """
self.indexItem = self.treewidget.currentIndex()
self.filePath = str(
- self.indexItem.sibling(
- self.indexItem.row(),
- 1).data())
+ self.indexItem.sibling(self.indexItem.row(), 1).data()
+ )
self.int = self.indexItem.row()
self.treewidget.takeTopLevelItem(self.int)
@@ -196,16 +200,17 @@ class ProjectExplorer(QtGui.QWidget):
del self.obj_appconfig.project_explorer[str(self.filePath)]
json.dump(self.obj_appconfig.project_explorer,
- open(self.obj_appconfig.dictPath, 'w'))
+ open(self.obj_appconfig.dictPath["path"], 'w'))
- # This function refresh the project in explorer area by right
- # clicking on project and selecting refresh option.
def refreshProject(self):
+ """
+ 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())
+ self.indexItem.sibling(self.indexItem.row(), 1).data()
+ )
filelistnew = os.listdir(os.path.join(self.filePath))
parentnode = self.treewidget.currentItem()
count = parentnode.childCount()
@@ -214,33 +219,31 @@ class ProjectExplorer(QtGui.QWidget):
items.removeChild(items.child(0))
for files in filelistnew:
QtGui.QTreeWidgetItem(
- parentnode, [
- files, os.path.join(
- self.filePath, files)])
+ parentnode, [files, os.path.join(self.filePath, files)]
+ )
self.obj_appconfig.project_explorer[self.filePath] = filelistnew
json.dump(self.obj_appconfig.project_explorer,
- open(self.obj_appconfig.dictPath, 'w'))
+ open(self.obj_appconfig.dictPath["path"], 'w'))
def renameProject(self):
"""
- This function renames the project present in project explorer area
- it validates first:
+ 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.
+ 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,
- self.baseFileName
- )
+ self, 'Rename Project', 'Project Name:',
+ QtGui.QLineEdit.Normal, self.baseFileName
+ )
if ok and newBaseFileName:
print(newBaseFileName)
print("=================")
@@ -261,19 +264,23 @@ class ProjectExplorer(QtGui.QWidget):
newBaseFileName = str(newBaseFileName).rstrip().lstrip()
projDir = os.path.join(self.workspace, str(newBaseFileName))
- if newBaseFileName == "":
- print("Project name can not be empty")
+ if not newBaseFileName.strip():
+ print("Project name cannot be empty")
print("==================")
msg = QtGui.QErrorMessage(self)
- msg.showMessage('The project name cannot be empty')
+ msg.setModal(True)
msg.setWindowTitle("Error Message")
+ msg.showMessage('The project name cannot be empty')
+ msg.exec_()
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.setModal(True)
msg.setWindowTitle("Error Message")
+ msg.showMessage('The project name has to be different')
+ msg.exec_()
else:
reply = self.obj_validation.validateNewproj(str(projDir))
@@ -282,8 +289,8 @@ class ProjectExplorer(QtGui.QWidget):
# rename project folder
updatedProjectPath = newBaseFileName.join(
projectPath.rsplit(self.baseFileName, 1))
- print("Renaming " + projectPath + " to "
- + updatedProjectPath)
+ print("Renaming " + projectPath + " to " +
+ updatedProjectPath)
os.rename(projectPath, updatedProjectPath)
# rename files matching project name
@@ -295,8 +302,8 @@ class ProjectExplorer(QtGui.QWidget):
self.baseFileName, newBaseFileName, 1)
newFilePath = os.path.join(
updatedProjectPath, projectFile)
- print("Renaming " + oldFilePath + " to"
- + newFilePath)
+ print("Renaming " + oldFilePath + " to" +
+ newFilePath)
os.rename(oldFilePath, newFilePath)
updatedProjectFiles.append(projectFile)
@@ -307,7 +314,7 @@ class ProjectExplorer(QtGui.QWidget):
# save project_explorer dictionary on disk
json.dump(self.obj_appconfig.project_explorer, open(
- self.obj_appconfig.dictPath, 'w'))
+ self.obj_appconfig.dictPath["path"], 'w'))
# recreate project explorer tree
self.treewidget.clear()
@@ -320,18 +327,23 @@ class ProjectExplorer(QtGui.QWidget):
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.setModal(True)
msg.setWindowTitle("Error Message")
+ msg.showMessage(
+ 'The project "' + newBaseFileName +
+ '" already exist. Please select a different name or' +
+ ' delete existing project'
+ )
+ msg.exec_()
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.setModal(True)
msg.setWindowTitle("Error Message")
+ msg.showMessage(
+ 'The project name should not ' +
+ 'contain space between them'
+ )
+ msg.exec_()