def accept(self):
     '''
     User accepts -> opens the selected project.  
     '''
     if self._isOneProjectSelected():
         projectName = self._getSelectedProjectName()
         project.projectsManagerInstance().setCurrentProjectName(projectName)
     QDialog.accept(self)
 def removeProject(self):
     '''
     User asks to remove a project. Forward the erasure to the ProjectsManager.
     '''
     if self._isOneProjectSelected():
         selectedItem = self.projectsListWidget.takeItem(self.projectsListWidget.currentRow()) 
         projectName = str(selectedItem.text())
         project.projectsManagerInstance().removeProject(projectName)
 def removeProject(self):
     '''
     User asks to remove a project. Forward the erasure to the ProjectsManager.
     '''
     if self._isOneProjectSelected():
         selectedItem = self.projectsListWidget.takeItem(
             self.projectsListWidget.currentRow())
         projectName = str(selectedItem.text())
         project.projectsManagerInstance().removeProject(projectName)
 def accept(self):
     '''
     User accepts -> opens the selected project.  
     '''
     if self._isOneProjectSelected():
         projectName = self._getSelectedProjectName()
         project.projectsManagerInstance().setCurrentProjectName(
             projectName)
     QDialog.accept(self)
 def addFile(self):
     """
     User adds a File. The AddFileWindow is opened.
     """
     myAddFileWindow = AddFileWindow(self)
     myAddFileWindow.exec_()
     headerToInclude = myAddFileWindow.getSelectedHeaderToInclude()
     fileName = myAddFileWindow.getSelectedFileName()
     if fileName and headerToInclude:
         # else -> user cancelled
         self.doAddFile_(fileName, headerToInclude, refreshFile=True)
         self.currentProject.addTreeFile((fileName, headerToInclude))
         project.projectsManagerInstance().storeAllProjects()
 def addFile(self):
     '''
     User adds a File. The AddFileWindow is opened.
     '''
     myAddFileWindow = AddFileWindow(self)
     myAddFileWindow.exec_()
     headerToInclude = myAddFileWindow.getSelectedHeaderToInclude()
     fileName = myAddFileWindow.getSelectedFileName()
     if fileName and headerToInclude:
         #else -> user cancelled
         self.doAddFile_(fileName, headerToInclude, refreshFile=True)
         self.currentProject.addTreeFile((fileName, headerToInclude))
         project.projectsManagerInstance().storeAllProjects()
    def validateProject_(self):
        '''
        Validate project data selected by the user.
        '''
        theProjectsManager = project.projectsManagerInstance()
        name = str(self.projectNameTextEdit.toPlainText())
        
        if not self.isEditMode_() and theProjectsManager.existsProject(name):
            QMessageBox.about(self, 'ERROR','El nombre de proyecto ya está siendo usado. Por favor, escoja uno diferente.')
            self.projectNameTextEdit.setFocus()
            return False

        folder = str(self.projectsLocationEditBox.toPlainText())
        if not os.path.exists(folder):
            QMessageBox.about(self, 'ERROR','La ruta del proyecto es inválida. Por favor, seleccione una correcta.')
            self.projectsLocationEditBox.setFocus()
            return False

        if self.getSelectedLanguage_() == ProgramExecution.Languages.C_PLUS_PLUS:
            solutionFile = str(self.solutionEditBox.toPlainText())
            if not self.validateSolution_(solutionFile, warnToUser = True):
                return False
    
            cppProject = str(self.cppProjectEditBox.toPlainText())
            if not self.validateCppProject_(cppProject, warnToUser = True):
                return False

        mainFile = str(self.mainFileEditBox.toPlainText())
        if not self.validateMainFile_(mainFile, warnToUser = True):
            return False
            
        return True
    def doAddFile_(self, fileName, headerToInclude, refreshFile=False):
        """
        Add a source file to the project.
        """
        assert fileName and headerToInclude
        theProjectsManager = project.projectsManagerInstance()
        currentProject = theProjectsManager.getProject(theProjectsManager.getCurrentProjectName())
        myFileTreeItem = FileTreeItem(fileName, headerToInclude)
        myWidgetItem = AnnotationsTreeWidgetItem(myFileTreeItem)
        myWidgetItem.setText(0, fileName)
        myWidgetItem.setCheckState(0, Qt.Unchecked)
        self.projectExplorerTreeWidget.addTopLevelItem(myWidgetItem)
        language = currentProject.getLanguage()
        classes, functions = myFileTreeItem.getParser().getAllClassesAndFunctionsAnnotations(fileName, headerToInclude)

        for funcName, myAnnotationState in functions:
            myCheckedState = getCheckedStateFromAnnotation(myAnnotationState)
            myFunctionTreeItem = FunctionTreeItem(fileName, headerToInclude, funcName)
            myFuncWidgetItem = AnnotationsTreeWidgetItem(myFunctionTreeItem)
            myFuncWidgetItem.setText(0, funcName)
            myFuncWidgetItem.setCheckState(0, myCheckedState)
            myFuncWidgetItem.setIcon(0, QIcon("./images/code-function.ico"))
            myWidgetItem.addChild(myFuncWidgetItem)

        for className, myAnnotationState in classes:
            myCheckedState = getCheckedStateFromAnnotation(myAnnotationState)
            myClassTreeItem = ClassTreeItem(fileName, headerToInclude, className)
            myClassWidgetItem = AnnotationsTreeWidgetItem(myClassTreeItem)
            myClassWidgetItem.setText(0, className)
            myClassWidgetItem.setCheckState(0, myCheckedState)
            myClassWidgetItem.setIcon(0, QIcon("./images/code-class.ico"))
            myWidgetItem.addChild(myClassWidgetItem)

        if refreshFile:
            self.refreshFileContents(fileName)
Example #9
0
def getCurrentProject():
    '''
    Get current project from the manager.
    '''
    theProjectsManager = project.projectsManagerInstance()
    currentProjectName = theProjectsManager.getCurrentProjectName()
    assert currentProjectName
    return theProjectsManager.getProject(currentProjectName)
def getCurrentProject():
    '''
    Get current project from the manager.
    '''
    theProjectsManager = project.projectsManagerInstance()
    currentProjectName = theProjectsManager.getCurrentProjectName()
    assert currentProjectName 
    return theProjectsManager.getProject(currentProjectName)
    def loadControls(self):
        '''
        Initial load of this window's controls.
        '''
        self.removeProjectButton.setEnabled(False)
        self.confirmationButtonBox.button(QDialogButtonBox.Open).setEnabled(False)
        allProjects = project.projectsManagerInstance().getAllProjects()

        projectNames = sorted(allProjects.keys())
        for projectName in projectNames:
            self.projectsListWidget.addItem(projectName)
    def loadCurrentProject(self):
        '''
        Load the current project in this window.
        '''
        def loadFilesIntoTree():
            '''
            Load source files in annotations tree.
            '''
            self.projectExplorerTreeWidget.clear()
            #TODO GERVA: por ahora solo cargo el main
            #despues guardo el resto de los archivos
            mainFile = self.currentProject.getMainFile()
            mainFunction = self.currentProject.getMainFunction()
            mainFileCaption = "MAIN: " + mainFile

            myFileTreeItem = FileTreeItem(mainFile, headerToInclude='')
            myWidgetItem = AnnotationsTreeWidgetItem(myFileTreeItem,
                                                     mayAnnotate=False)
            myFont = myWidgetItem.font(0)
            myFont.setBold(True)
            myWidgetItem.setFont(0, myFont)
            myWidgetItem.setText(0, mainFileCaption)
            myWidgetItem.setCheckState(0, Qt.Unchecked)
            self.projectExplorerTreeWidget.addTopLevelItem(myWidgetItem)

            myFunctionTreeItem = FunctionTreeItem(mainFile, '', mainFunction)
            myFuncWidgetItem = AnnotationsTreeWidgetItem(myFunctionTreeItem,
                                                         mayAnnotate=False)
            myFont = myFuncWidgetItem.font(0)
            myFont.setBold(True)
            myFuncWidgetItem.setFont(0, myFont)
            myFuncWidgetItem.setText(0, mainFunction)
            myFuncWidgetItem.setCheckState(0, Qt.Unchecked)
            myWidgetItem.addChild(myFuncWidgetItem)

            for fileToAnnotate, headerToInclude in self.currentProject.getTreeFiles(
            ):
                self.doAddFile_(fileToAnnotate,
                                headerToInclude,
                                refreshFile=False)

            self.refreshFileContents(mainFile)

        theProjectsManager = project.projectsManagerInstance()
        currentProjectName = theProjectsManager.getCurrentProjectName()
        if currentProjectName:
            self.currentProject = theProjectsManager.getProject(
                currentProjectName)
            loadFilesIntoTree()
            self.refreshExecutionsTree()
            self.setVisibleProjectWidgets(True)
        else:
            self.currentProject = None
            self.setVisibleProjectWidgets(False)
    def loadControls(self):
        '''
        Initial load of this window's controls.
        '''
        self.removeProjectButton.setEnabled(False)
        self.confirmationButtonBox.button(
            QDialogButtonBox.Open).setEnabled(False)
        allProjects = project.projectsManagerInstance().getAllProjects()

        projectNames = sorted(allProjects.keys())
        for projectName in projectNames:
            self.projectsListWidget.addItem(projectName)
Example #14
0
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        theProjectsManager = project.projectsManagerInstance()
        self.currentProject_ = theProjectsManager.getProject(
            theProjectsManager.getCurrentProjectName())
        self.userHasEditedHeader_ = False

        self.selectedHeaderToInclude_ = ""
        self.selectedFileName_ = ""
        self.setupUi(self)
        self.createActions()
        self.loadControls()
    def closeProject(self):
        '''
        User closes the current project.
        Inform to the ProjectsManager that the current project is null,
        and make invisible the project-related controls.
        '''
        self.storeCurrentProject()
        self.currentProject = None
        theProjectsManager = project.projectsManagerInstance()
        theProjectsManager.setCurrentProjectName(None)

        self.setVisibleProjectWidgets(False)
    def closeProject(self):
        """
        User closes the current project.
        Inform to the ProjectsManager that the current project is null,
        and make invisible the project-related controls.
        """
        self.storeCurrentProject()
        self.currentProject = None
        theProjectsManager = project.projectsManagerInstance()
        theProjectsManager.setCurrentProjectName(None)

        self.setVisibleProjectWidgets(False)
    def loadCurrentProject(self):
        """
        Load the current project in this window.
        """

        def loadFilesIntoTree():
            """
            Load source files in annotations tree.
            """
            self.projectExplorerTreeWidget.clear()
            # TODO GERVA: por ahora solo cargo el main
            # despues guardo el resto de los archivos
            mainFile = self.currentProject.getMainFile()
            mainFunction = self.currentProject.getMainFunction()
            mainFileCaption = "MAIN: " + mainFile

            myFileTreeItem = FileTreeItem(mainFile, headerToInclude="")
            myWidgetItem = AnnotationsTreeWidgetItem(myFileTreeItem, mayAnnotate=False)
            myFont = myWidgetItem.font(0)
            myFont.setBold(True)
            myWidgetItem.setFont(0, myFont)
            myWidgetItem.setText(0, mainFileCaption)
            myWidgetItem.setCheckState(0, Qt.Unchecked)
            self.projectExplorerTreeWidget.addTopLevelItem(myWidgetItem)

            myFunctionTreeItem = FunctionTreeItem(mainFile, "", mainFunction)
            myFuncWidgetItem = AnnotationsTreeWidgetItem(myFunctionTreeItem, mayAnnotate=False)
            myFont = myFuncWidgetItem.font(0)
            myFont.setBold(True)
            myFuncWidgetItem.setFont(0, myFont)
            myFuncWidgetItem.setText(0, mainFunction)
            myFuncWidgetItem.setCheckState(0, Qt.Unchecked)
            myWidgetItem.addChild(myFuncWidgetItem)

            for fileToAnnotate, headerToInclude in self.currentProject.getTreeFiles():
                self.doAddFile_(fileToAnnotate, headerToInclude, refreshFile=False)

            self.refreshFileContents(mainFile)

        theProjectsManager = project.projectsManagerInstance()
        currentProjectName = theProjectsManager.getCurrentProjectName()
        if currentProjectName:
            self.currentProject = theProjectsManager.getProject(currentProjectName)
            loadFilesIntoTree()
            self.refreshExecutionsTree()
            self.setVisibleProjectWidgets(True)
        else:
            self.currentProject = None
            self.setVisibleProjectWidgets(False)
Example #18
0
    def accept(self):
        '''
        User accept. If data is valid, store the project with the help of the ProjectManager.  
        '''
        ok = self.validateProject_()
        if not ok:
            return

        theProjectsManager = project.projectsManagerInstance()
        name = str(self.projectNameTextEdit.toPlainText())
        projectsFolder = str(self.projectsLocationEditBox.toPlainText())
        folder = os.path.join(projectsFolder, name)
        language = self.getSelectedLanguage_()
        solutionFile = str(self.solutionEditBox.toPlainText())
        cppProject = str(self.cppProjectEditBox.toPlainText())
        mainFile = str(self.mainFileEditBox.toPlainText())
        mainFunction = str(self.mainFunctionComboBox.currentText())
        compilingCommand = str(self.compilingCommandEditBox.toPlainText())
        exeCommand = str(self.exeCommandTextEdit.toPlainText())

        aProject = project.Project(name, folder, language, solutionFile,
                                   mainFile, mainFunction, exeCommand, [],
                                   cppProject, compilingCommand)
        #Annotate main file before adding it to the tree

        if self.isEditMode_():
            #If main function changed, unannotate previous main function
            previousMainFunction = self.projectToEdit_.getMainFunction()
            if mainFunction != previousMainFunction:
                mySourceCodeParser = SourceCodeParser(language, mainFile,
                                                      previousMainFunction)
                mySourceCodeParser.unAnnotateMainFile()

        mySourceCodeParser = SourceCodeParser(language, mainFile, mainFunction)
        mainBackupFileName = mainFile + ".bkp"
        shutil.copyfile(mainFile, mainBackupFileName)

        dumpFileName = os.path.join(aProject.getExecutionsFolder(),
                                    name + ".json")
        mySourceCodeParser.annotateMainFile(dumpFileName)

        if language == ProgramExecution.Languages.C_PLUS_PLUS:
            self.addBraCustomInfoToCppProject_(cppProject)

        theProjectsManager.storeProject(aProject)
        theProjectsManager.setCurrentProjectName(aProject.getName())
        QDialog.accept(self)
    def accept(self):
        '''
        User accept. If data is valid, store the project with the help of the ProjectManager.  
        '''
        ok = self.validateProject_()
        if not ok:
            return
        
        theProjectsManager = project.projectsManagerInstance()
        name = str(self.projectNameTextEdit.toPlainText())
        projectsFolder = str(self.projectsLocationEditBox.toPlainText())
        folder = os.path.join(projectsFolder, name)
        language = self.getSelectedLanguage_()
        solutionFile = str(self.solutionEditBox.toPlainText())
        cppProject = str(self.cppProjectEditBox.toPlainText())
        mainFile = str(self.mainFileEditBox.toPlainText())
        mainFunction = str(self.mainFunctionComboBox.currentText())
        compilingCommand = str(self.compilingCommandEditBox.toPlainText())
        exeCommand = str(self.exeCommandTextEdit.toPlainText())
        
        aProject = project.Project(name, folder, language, solutionFile, mainFile, mainFunction, exeCommand, [], cppProject, compilingCommand)
        #Annotate main file before adding it to the tree
        
        if self.isEditMode_():
            #If main function changed, unannotate previous main function
            previousMainFunction = self.projectToEdit_.getMainFunction()
            if mainFunction != previousMainFunction:
                mySourceCodeParser = SourceCodeParser(language, mainFile, previousMainFunction)
                mySourceCodeParser.unAnnotateMainFile()
        
        mySourceCodeParser = SourceCodeParser(language, mainFile, mainFunction)
        mainBackupFileName = mainFile + ".bkp"
        shutil.copyfile(mainFile, mainBackupFileName)
            
        dumpFileName = os.path.join(aProject.getExecutionsFolder(), name + ".json")
        mySourceCodeParser.annotateMainFile(dumpFileName)
        
        if language == ProgramExecution.Languages.C_PLUS_PLUS:
            self.addBraCustomInfoToCppProject_(cppProject)

        theProjectsManager.storeProject(aProject)
        theProjectsManager.setCurrentProjectName(aProject.getName())
        QDialog.accept(self)
    def doAddFile_(self, fileName, headerToInclude, refreshFile=False):
        '''
        Add a source file to the project.
        '''
        assert fileName and headerToInclude
        theProjectsManager = project.projectsManagerInstance()
        currentProject = theProjectsManager.getProject(
            theProjectsManager.getCurrentProjectName())
        myFileTreeItem = FileTreeItem(fileName, headerToInclude)
        myWidgetItem = AnnotationsTreeWidgetItem(myFileTreeItem)
        myWidgetItem.setText(0, fileName)
        myWidgetItem.setCheckState(0, Qt.Unchecked)
        self.projectExplorerTreeWidget.addTopLevelItem(myWidgetItem)
        language = currentProject.getLanguage()
        classes, functions = myFileTreeItem.getParser(
        ).getAllClassesAndFunctionsAnnotations(fileName, headerToInclude)

        for funcName, myAnnotationState in functions:
            myCheckedState = getCheckedStateFromAnnotation(myAnnotationState)
            myFunctionTreeItem = FunctionTreeItem(fileName, headerToInclude,
                                                  funcName)
            myFuncWidgetItem = AnnotationsTreeWidgetItem(myFunctionTreeItem)
            myFuncWidgetItem.setText(0, funcName)
            myFuncWidgetItem.setCheckState(0, myCheckedState)
            myFuncWidgetItem.setIcon(0, QIcon("./images/code-function.ico"))
            myWidgetItem.addChild(myFuncWidgetItem)

        for className, myAnnotationState in classes:
            myCheckedState = getCheckedStateFromAnnotation(myAnnotationState)
            myClassTreeItem = ClassTreeItem(fileName, headerToInclude,
                                            className)
            myClassWidgetItem = AnnotationsTreeWidgetItem(myClassTreeItem)
            myClassWidgetItem.setText(0, className)
            myClassWidgetItem.setCheckState(0, myCheckedState)
            myClassWidgetItem.setIcon(0, QIcon("./images/code-class.ico"))
            myWidgetItem.addChild(myClassWidgetItem)

        if refreshFile:
            self.refreshFileContents(fileName)
Example #21
0
    def validateProject_(self):
        '''
        Validate project data selected by the user.
        '''
        theProjectsManager = project.projectsManagerInstance()
        name = str(self.projectNameTextEdit.toPlainText())

        if not self.isEditMode_() and theProjectsManager.existsProject(name):
            QMessageBox.about(
                self, 'ERROR',
                'El nombre de proyecto ya está siendo usado. Por favor, escoja uno diferente.'
            )
            self.projectNameTextEdit.setFocus()
            return False

        folder = str(self.projectsLocationEditBox.toPlainText())
        if not os.path.exists(folder):
            QMessageBox.about(
                self, 'ERROR',
                'La ruta del proyecto es inválida. Por favor, seleccione una correcta.'
            )
            self.projectsLocationEditBox.setFocus()
            return False

        if self.getSelectedLanguage_(
        ) == ProgramExecution.Languages.C_PLUS_PLUS:
            solutionFile = str(self.solutionEditBox.toPlainText())
            if not self.validateSolution_(solutionFile, warnToUser=True):
                return False

            cppProject = str(self.cppProjectEditBox.toPlainText())
            if not self.validateCppProject_(cppProject, warnToUser=True):
                return False

        mainFile = str(self.mainFileEditBox.toPlainText())
        if not self.validateMainFile_(mainFile, warnToUser=True):
            return False

        return True
 def storeCurrentProject(self):
     '''
     Store current project (in the ProjectsManager).
     '''
     theProjectsManager = project.projectsManagerInstance()
     theProjectsManager.storeAllProjects()
 def storeCurrentProject(self):
     """
     Store current project (in the ProjectsManager).
     """
     theProjectsManager = project.projectsManagerInstance()
     theProjectsManager.storeAllProjects()