Exemple #1
0
    def setText(self, txt):
        d = Qt.QDate()
        ret = None
        month = None
        day = None
        year = None
        val = None
        regexp = Qt.QRegExp(
            "[0-9][0-9](-|//)[0-9][0-9](-|//)[0-9][0-9][0-9][0-9]")

        if self.dataType_ == self.DataType.String:
            # if aqApp.multiLangEnabled() and txt: #FIXME
            if txt:
                self.text_ = txt.decode("utf8")
                if self.text_ == txt:
                    self.text_ = FLUtil.translate(self, "app", txt)
            else:
                self.text_ = txt
        elif self.dataType_ == self.DataType.Integer:
            val = float(txt)
            if val < 0.5 and val > -0.5 and self.blankZero_:
                self.text_ = Qt.QString("")
            else:
                self.text_ = round(val, 0)
                self.formatNegValue()
                if (self.comma_):
                    self.formatCommas()
        elif self.dataType_ == self.DataType.Float:
            val = float(txt)
            if val < 0.0000001 and val > -0.0000001 and self.blankZero_:
                self.text_ = Qt.QString("")
            else:
                self.text_ = round(val, self.precision_)
                self.formatNegValue()
                if (self.comma_):
                    self.formatCommas()
        elif self.dataType_ == self.DataType.Date:
            if not txt:
                self.text_ = Qt.QString("")
            else:
                regexp.search(txt[0:])
                ret = regexp.matchedLength()

                if ret == -1:
                    year = txt[:4]
                    day = txt[2:]
                    month = txt[5:7]

                    if int(year) != 0 and int(month) != 0 and int(day) != 0:
                        d.setYMD(int(year), int(month), int(day))
                        self.text_ = MUtil.formatDate(d, self.format_)
                    else:
                        self.text_ = Qt.QString("")
                else:
                    self.text_ = txt
        elif self.dataType_ == self.DataType.Currency:
            val = float(txt)
            if val < 0.01 and val > -0.01 and self.blankZero_:
                self.text_ = Qt.QString("")
            else:
                self.text_ = round(val, 2)
                self.formatNegValue()
                if self.comma_:
                    self.formatCommas()
                self.text_ = self.text_ + str(self.currency_)
        elif self.dataType_ == self.DataType.Pixmap:
            if txt and not self.paintFunction_:
                if not self.pixmap_:
                    self.pixmap_ = Qt.QPixmap()
                if Qt.QPixmapCache.find(txt[:100], self.pixmap_):
                    if Qt.QFile.exists(txt):
                        self.pixmap_.load(txt)
                    else:
                        self.pixmap_.loadFromData(txt)
                    if not self.pixmap_.isNull():
                        Qt.QPixmapCache.insert(txt[:100], self.pixmap_)
                if self.pixmap_.isNull():
                    self.pixmap_ = False
            else:
                if self.pixmap_:
                    self.pixmap_ = False
        elif self.dataType_ == self.DataType.Codbar:
            if txt and not self.paintFunction_:
                cb = FLCodBar(txt, self.codbarType_, 10, 1, 0, 0, True,
                              Qt.black, Qt.white, self.codbarRes_)
                if not self.pixmap_:
                    self.pixmap_ = Qt.QPixmap()
                if not cb.pixmap().isNull():
                    self.pixmap_ = cb.pixmap()
                else:
                    self.pixmap_ = False
            else:
                if self.pixmap_:
                    self.pixmap_ = False
        elif self.dataType_ == self.DataType.Bool:
            if txt.toUpper() == "FALSE" or txt.toUpper() == "F":
                self.text_ = FLUtil.translate(self, "app", "No")
            else:
                self.text_ = FLUtil.translate(self, "app", "Sí")