示例#1
0
def detect_python_path():
    if (IS_WINDOWS and PYTHON_EXEC_CONFIGURED_BY_USER) or not IS_WINDOWS:
        return []

    suggested = []
    dirs = []
    try:
        drives = [
            QDir.toNativeSeparators(d.absolutePath()) for d in QDir.drives()
        ]

        for drive in drives:
            info = QFileInfo(drive)
            if info.isReadable():
                dirs += [
                    os.path.join(drive, folder) for folder in os.listdir(drive)
                ]
        for folder in dirs:
            file_path = os.path.join(folder, "python.exe")
            if ("python" in folder.lower()) and os.path.exists(file_path):
                suggested.append(file_path)
    except:
        print("Detection couldnt be executed")
    finally:
        return suggested
示例#2
0
    def populateModel( self ):
        " Populates the browser model "

        self.clear()
        self.addItem( TreeViewSysPathItem( self.rootItem ) )
        self.addItem( TreeViewDirectoryItem( self.rootItem, QDir.homePath() ) )
        for dname in QDir.drives():
            self.addItem( TreeViewDirectoryItem( self.rootItem,
                                                 dname.absoluteFilePath() ) )
        self.__populateProjectTopLevelDirs()
        return
示例#3
0
def detect_python_path():
    if (IS_WINDOWS and PYTHON_EXEC_CONFIGURED_BY_USER) or not IS_WINDOWS:
        return []

    suggested = []
    try:
        drives = [QDir.toNativeSeparators(d.absolutePath()) for d in QDir.drives()]
        dirs = []
        for drive in drives:
            info = QFileInfo(drive)
            if info.isReadable():
                dirs += [os.path.join(drive, folder) for folder in os.listdir(drive)]
        for folder in dirs:
            file_path = os.path.join(folder, "python.exe")
            if ("Python" in folder) and os.path.exists(file_path):
                suggested.append(file_path)
    except:
        print("Detection couldnt be executed")

    return suggested
示例#4
0
    def __selectFile(self, extension):
        " Picks a file of a certain extension "
        dialog = QFileDialog(self, 'Save flowchart as')
        dialog.setFileMode(QFileDialog.AnyFile)
        dialog.setLabelText(QFileDialog.Accept, "Save")
        dialog.setNameFilter(extension.upper() + " files (*." +
                             extension.lower() + ")")
        urls = []
        for dname in QDir.drives():
            urls.append(QUrl.fromLocalFile(dname.absoluteFilePath()))
        urls.append(QUrl.fromLocalFile(QDir.homePath()))
        project = GlobalData().project
        if project.isLoaded():
            urls.append(QUrl.fromLocalFile(project.getProjectDir()))
        dialog.setSidebarUrls(urls)

        suggestedFName = self.__parentWidget.getFileName()
        if '.' in suggestedFName:
            dotIndex = suggestedFName.rindex('.')
            suggestedFName = suggestedFName[:dotIndex]

        dialog.setDirectory(self.__getDefaultSaveDir())
        dialog.selectFile(suggestedFName + "." + extension.lower())
        dialog.setOption(QFileDialog.DontConfirmOverwrite, False)
        if dialog.exec_() != QDialog.Accepted:
            return None

        fileNames = dialog.selectedFiles()
        fileName = os.path.abspath(str(fileNames[0]))
        if os.path.isdir(fileName):
            logging.error("A file must be selected")
            return None

        if "." not in fileName:
            fileName += "." + extension.lower()

        # Check permissions to write into the file or to a directory
        if os.path.exists(fileName):
            # Check write permissions for the file
            if not os.access(fileName, os.W_OK):
                logging.error("There is no write permissions for " + fileName)
                return None
        else:
            # Check write permissions to the directory
            dirName = os.path.dirname(fileName)
            if not os.access(dirName, os.W_OK):
                logging.error("There is no write permissions for the "
                              "directory " + dirName)
                return None

        if os.path.exists(fileName):
            res = QMessageBox.warning(
                self, "Save flowchart as",
                "<p>The file <b>" + fileName + "</b> already exists.</p>",
                QMessageBox.StandardButtons(QMessageBox.Abort
                                            | QMessageBox.Save),
                QMessageBox.Abort)
            if res == QMessageBox.Abort or res == QMessageBox.Cancel:
                return None

        # All prerequisites are checked, return a file name
        return fileName
示例#5
0
    def __selectFile( self, extension ):
        " Picks a file of a certain extension "
        dialog = QFileDialog( self, 'Save flowchart as' )
        dialog.setFileMode( QFileDialog.AnyFile )
        dialog.setLabelText( QFileDialog.Accept, "Save" )
        dialog.setNameFilter( extension.upper() + " files (*." +
                              extension.lower() + ")" )
        urls = []
        for dname in QDir.drives():
            urls.append( QUrl.fromLocalFile( dname.absoluteFilePath() ) )
        urls.append( QUrl.fromLocalFile( QDir.homePath() ) )
        project = GlobalData().project
        if project.isLoaded():
            urls.append( QUrl.fromLocalFile( project.getProjectDir() ) )
        dialog.setSidebarUrls( urls )

        suggestedFName = self.__parentWidget.getFileName()
        if '.' in suggestedFName:
            dotIndex = suggestedFName.rindex( '.' )
            suggestedFName = suggestedFName[ : dotIndex ]

        dialog.setDirectory( self.__getDefaultSaveDir() )
        dialog.selectFile( suggestedFName + "." + extension.lower() )
        dialog.setOption( QFileDialog.DontConfirmOverwrite, False )
        if dialog.exec_() != QDialog.Accepted:
            return None

        fileNames = dialog.selectedFiles()
        fileName = os.path.abspath( str( fileNames[0] ) )
        if os.path.isdir( fileName ):
            logging.error( "A file must be selected" )
            return None

        if "." not in fileName:
            fileName += "." + extension.lower()

        # Check permissions to write into the file or to a directory
        if os.path.exists( fileName ):
            # Check write permissions for the file
            if not os.access( fileName, os.W_OK ):
                logging.error( "There is no write permissions for " + fileName )
                return None
        else:
            # Check write permissions to the directory
            dirName = os.path.dirname( fileName )
            if not os.access( dirName, os.W_OK ):
                logging.error( "There is no write permissions for the "
                               "directory " + dirName )
                return None

        if os.path.exists( fileName ):
            res = QMessageBox.warning( self, "Save flowchart as",
                    "<p>The file <b>" + fileName + "</b> already exists.</p>",
                    QMessageBox.StandardButtons( QMessageBox.Abort |
                                                 QMessageBox.Save ),
                    QMessageBox.Abort )
            if res == QMessageBox.Abort or res == QMessageBox.Cancel:
                return None

        # All prerequisites are checked, return a file name
        return fileName