def on_init_command_reply_currentIndexChanged(self, text):
     if self.init_commands_list.currentItem():
         current_init_cmd = self.init_commands_list.currentItem().cmd
         current_reply_name = current_init_cmd.reply.name
         
         if str(text) == current_reply_name:
             self._clear_init_command_reply()
             self._load_init_command_reply(current_init_cmd, str(text))
             
         else:
             reply = QMessageBox.warning(None,
                 self.trUtf8("Changing reply packet"),
                 self.trUtf8("""Selecting a different reply packet will delete all configured reply packet values. Are you sure you want to continue?"""),
                 QMessageBox.StandardButtons(\
                     QMessageBox.No | \
                     QMessageBox.Yes),
                 QMessageBox.No)
             
             if reply == QMessageBox.Yes:
                 self._clear_init_command_reply()
                 self._load_init_command_reply(current_init_cmd, str(text))
             else:
                 self.init_command_reply.setCurrentIndex(
                     self.init_command_reply.findText(current_reply_name))
Example #2
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