Esempio n. 1
0
  def __readEncoding(self, xmlReader):

    # Create a encoding from parameters
    encoding = Encoding()
    encoding.dataSourceFieldName = self.__getStringAttribute(xmlReader.attributes(), 'dataSourceFieldName')
    encoding.dataSourceFieldDataType = self.__getStringAttribute(xmlReader.attributes(), 'dataSourceFieldDataType')
    encoding.enableInference = self.__getBooleanAttribute(xmlReader.attributes(), 'enableInference')
    encoding.encoderModule = self.__getStringAttribute(xmlReader.attributes(), 'encoderModule')
    encoding.encoderClass = self.__getStringAttribute(xmlReader.attributes(), 'encoderClass')
    encoding.encoderParams = self.__getStringAttribute(xmlReader.attributes(), 'encoderParams')
    encoding.encoderFieldName = self.__getStringAttribute(xmlReader.attributes(), 'encoderFieldName')
    encoding.encoderFieldDataType = self.__getStringAttribute(xmlReader.attributes(), 'encoderFieldDataType')
    token = xmlReader.readNext()

    return encoding
Esempio n. 2
0
    def __readEncoding(self, xmlReader):

        # Create a encoding from parameters
        encoding = Encoding()
        encoding.dataSourceFieldName = self.__getStringAttribute(
            xmlReader.attributes(), 'dataSourceFieldName')
        encoding.dataSourceFieldDataType = self.__getStringAttribute(
            xmlReader.attributes(), 'dataSourceFieldDataType')
        encoding.enableInference = self.__getBooleanAttribute(
            xmlReader.attributes(), 'enableInference')
        encoding.encoderModule = self.__getStringAttribute(
            xmlReader.attributes(), 'encoderModule')
        encoding.encoderClass = self.__getStringAttribute(
            xmlReader.attributes(), 'encoderClass')
        encoding.encoderParams = self.__getStringAttribute(
            xmlReader.attributes(), 'encoderParams')
        encoding.encoderFieldName = self.__getStringAttribute(
            xmlReader.attributes(), 'encoderFieldName')
        encoding.encoderFieldDataType = self.__getStringAttribute(
            xmlReader.attributes(), 'encoderFieldDataType')
        token = xmlReader.readNext()

        return encoding
  def __buttonOk_Click(self, event):
    """
    Check if values changed and save the,.
    """

    encoderParamsDict = collections.OrderedDict()
    if self.textBoxDataSourceFieldName.text() == '':
      QtGui.QMessageBox.warning(self, "Warning", "Record field name was not specified.")
      return
    elif self.textBoxEncoderModule.text() == '':
      QtGui.QMessageBox.warning(self, "Warning", "Encoder module was not specified.")
      return
    elif self.textBoxEncoderClass.text() == '':
      QtGui.QMessageBox.warning(self, "Warning", "Encoder class was not specified.")
      return
    elif self.textBoxEncoderFieldName.text() == '':
      QtGui.QMessageBox.warning(self, "Warning", "Encoder field name was not specified.")
      return
    elif self.duplicatedFieldName(self.textBoxEncoderFieldName.text()):
      QtGui.QMessageBox.warning(self, "Warning", "Encoder field name already is used by other encoding.")
      return
    else:
      gridData = self.dataGridEncoderParams.model().data
      for row in range(len(gridData)):
        if gridData[row][0] != '':
          # Valid parameter name
          try:
            gridData[row][0] = gridData[row][0].toString()
          except:
            pass
          param = str(gridData[row][0])
          validExpr = QtCore.QRegExp('[a-zA-Z0-9_]+')
          if not validExpr.exactMatch(param):
            QtGui.QMessageBox.warning(self, "Warning", "'" + param + "' is not a valid name.")
            return

          # Valid parameter value
          try:
            gridData[row][1] = gridData[row][1].toString()
          except:
            pass
          value = str(gridData[row][1])
          if len(value) == 0:
            QtGui.QMessageBox.warning(self, "Warning", "'" + param + "' value is empty.")
            return

          # Add param name and its value to dictionary
          encoderParamsDict[param] = value

    dataSourceFieldName = str(self.textBoxDataSourceFieldName.text())
    dataSourceFieldDataType = str(self.comboBoxDataSourceFieldDataType.currentText())
    enableInference = self.checkBoxEnableInference.isChecked()
    encoderModule = str(self.textBoxEncoderModule.text())
    encoderClass = str(self.textBoxEncoderClass.text())
    encoderParams = json.dumps(encoderParamsDict)
    encoderFieldName = str(self.textBoxEncoderFieldName.text())
    encoderFieldDataType = str(self.comboBoxEncoderFieldDataType.currentText())

    # Remove double quotes from param values
    encoderParams = encoderParams.replace("\"", "'")
    encoderParams = encoderParams.replace("True", "true")
    encoderParams = encoderParams.replace("False", "false")

    # If this is a new encoding get it from list else create a new one
    if self.encodingIdx >= 0:
      encoding = self.encodings[self.encodingIdx]
    else:
      encoding = Encoding()
      self.encodings.append(encoding)

    # If anything has changed
    if encoding.dataSourceFieldName != dataSourceFieldName or encoding.dataSourceFieldDataType != dataSourceFieldDataType or encoding.enableInference != enableInference or encoding.encoderModule != encoderModule or encoding.encoderClass != encoderClass or encoding.encoderParams != encoderParams or encoding.encoderFieldName != encoderFieldName or encoding.encoderFieldDataType != encoderFieldDataType:
      # Set encoding params with controls values
      encoding.dataSourceFieldName = dataSourceFieldName
      encoding.dataSourceFieldDataType = dataSourceFieldDataType
      encoding.enableInference = enableInference
      encoding.encoderModule = encoderModule
      encoding.encoderClass = encoderClass
      encoding.encoderParams = encoderParams
      encoding.encoderFieldName = encoderFieldName
      encoding.encoderFieldDataType = encoderFieldDataType

      self.accept()

    self.close()
Esempio n. 4
0
    def __buttonOk_Click(self, event):
        """
    Check if values changed and save the,.
    """

        encoderParamsDict = collections.OrderedDict()
        if self.textBoxDataSourceFieldName.text() == '':
            QtGui.QMessageBox.warning(self, "Warning",
                                      "Record field name was not specified.")
            return
        elif self.textBoxEncoderModule.text() == '':
            QtGui.QMessageBox.warning(self, "Warning",
                                      "Encoder module was not specified.")
            return
        elif self.textBoxEncoderClass.text() == '':
            QtGui.QMessageBox.warning(self, "Warning",
                                      "Encoder class was not specified.")
            return
        elif self.textBoxEncoderFieldName.text() == '':
            QtGui.QMessageBox.warning(self, "Warning",
                                      "Encoder field name was not specified.")
            return
        elif self.duplicatedFieldName(self.textBoxEncoderFieldName.text()):
            QtGui.QMessageBox.warning(
                self, "Warning",
                "Encoder field name already is used by other encoding.")
            return
        else:
            gridData = self.dataGridEncoderParams.model().data
            for row in range(len(gridData)):
                if gridData[row][0] != '':
                    # Valid parameter name
                    try:
                        gridData[row][0] = gridData[row][0].toString()
                    except:
                        pass
                    param = str(gridData[row][0])
                    validExpr = QtCore.QRegExp('[a-zA-Z0-9_]+')
                    if not validExpr.exactMatch(param):
                        QtGui.QMessageBox.warning(
                            self, "Warning",
                            "'" + param + "' is not a valid name.")
                        return

                    # Valid parameter value
                    try:
                        gridData[row][1] = gridData[row][1].toString()
                    except:
                        pass
                    value = str(gridData[row][1])
                    if len(value) == 0:
                        QtGui.QMessageBox.warning(
                            self, "Warning", "'" + param + "' value is empty.")
                        return

                    # Add param name and its value to dictionary
                    encoderParamsDict[param] = value

        dataSourceFieldName = str(self.textBoxDataSourceFieldName.text())
        dataSourceFieldDataType = str(
            self.comboBoxDataSourceFieldDataType.currentText())
        enableInference = self.checkBoxEnableInference.isChecked()
        encoderModule = str(self.textBoxEncoderModule.text())
        encoderClass = str(self.textBoxEncoderClass.text())
        encoderParams = json.dumps(encoderParamsDict)
        encoderFieldName = str(self.textBoxEncoderFieldName.text())
        encoderFieldDataType = str(
            self.comboBoxEncoderFieldDataType.currentText())

        # Remove double quotes from param values
        encoderParams = encoderParams.replace("\"", "'")
        encoderParams = encoderParams.replace("True", "true")
        encoderParams = encoderParams.replace("False", "false")

        # If this is a new encoding get it from list else create a new one
        if self.encodingIdx >= 0:
            encoding = self.encodings[self.encodingIdx]
        else:
            encoding = Encoding()
            self.encodings.append(encoding)

        # If anything has changed
        if encoding.dataSourceFieldName != dataSourceFieldName or encoding.dataSourceFieldDataType != dataSourceFieldDataType or encoding.enableInference != enableInference or encoding.encoderModule != encoderModule or encoding.encoderClass != encoderClass or encoding.encoderParams != encoderParams or encoding.encoderFieldName != encoderFieldName or encoding.encoderFieldDataType != encoderFieldDataType:
            # Set encoding params with controls values
            encoding.dataSourceFieldName = dataSourceFieldName
            encoding.dataSourceFieldDataType = dataSourceFieldDataType
            encoding.enableInference = enableInference
            encoding.encoderModule = encoderModule
            encoding.encoderClass = encoderClass
            encoding.encoderParams = encoderParams
            encoding.encoderFieldName = encoderFieldName
            encoding.encoderFieldDataType = encoderFieldDataType

            self.accept()

        self.close()