def paint(self, painter, option, index):
        painter.save()
        if not index.isValid():
            QSqlRelationalDelegate.paint(self, painter, option, index)

        if index.column() in self.__dates:
            value = QDate.fromString(index.model().data(index, Qt.DisplayRole),
                                     Qt.ISODate)
            value = value.toString(Qt.SystemLocaleLongDate)
            align = Qt.AlignHCenter | Qt.AlignVCenter
            if option.state and QStyle.State_Active:
                if option.state & QStyle.State_Selected:
                    palette = QPalette.HighlightedText
                else:
                    palette = QPalette.WindowText
            else:
                palette = QPalette.WindowText

            QApplication.style().drawItemText(painter, option.rect, align,
                                              option.palette, True, value,
                                              palette)
        else:
            QSqlRelationalDelegate.paint(self, painter, option, index)

        painter.restore()
    def sizeHint(self, option, index):
        size = QSqlRelationalDelegate.sizeHint(self, option, index)
        if index.isValid() and index.column() in self.__dates:
            value = QDate.fromString(index.model().data(index, Qt.DisplayRole),
                 Qt.ISODate)
            value = value.toString(Qt.SystemLocaleLongDate)
            fm = QFontMetrics(QApplication.font())

            return QSize(fm.width(value) + 5, size.height())
        else:
            return size
    def sizeHint(self, option, index):
        size = QSqlRelationalDelegate.sizeHint(self, option, index)
        if index.isValid() and index.column() in self.__dates:
            value = QDate.fromString(index.model().data(index, Qt.DisplayRole),
                                     Qt.ISODate)
            value = value.toString(Qt.SystemLocaleLongDate)
            fm = QFontMetrics(QApplication.font())

            return QSize(fm.width(value) + 5, size.height())
        else:
            return size
Exemplo n.º 4
0
    def miseAJour(self):
        u"""Liste les absences pouvant donner lieu à un email de rappel"""
        self._ui.cbAbsence.clear()

        # Vérification des mails à envoyer
        req = QSqlQuery()
        sql = MailSQL.construitRequeteComptage(self.__conf["duree"])
        if req.exec_(sql):
            req.next()
            nbMails = req.record().value(0)
        else:
            # TODO log
            print req.lastError().text()
            print req.lastQuery()
            print "Erreur de requête"
            return
        label = str(nbMails) + " absence"
        if nbMails == 0:
            label += " :"
            self._ui.lAbsence.setText(label)
            self._ui.leSujet.setText("")
            self._ui.teCorps.setText("")
            self.__activerUi(False)
            self._ui.pbEnvoyer.setText("Envoyer")
            return
        else:
            self.__activerUi(True)

        if nbMails > 1:
            label += "s"
        label += " :"
        self._ui.lAbsence.setText(label)

        sql = MailSQL.construitRequeteListe(self.__conf["duree"])
        if not req.exec_(sql):
            print req.lastError().text()
            print req.lastQuery()
            print "Erreur de requête"
        else:
            self.__absences = []
            while (req.next()):
                absence = {}
                rec = req.record()
                absence = {}
                absence["id"] = rec.value(0)
                absence["date"] = QDate.fromString(rec.value(1), Qt.ISODate)
                absence["nom"] = rec.value(2)
                absence["adresse"] = rec.value(3)
                self.__absences.append(absence)
                item = absence["nom"] + " le "
                item += absence["date"].toString(Qt.SystemLocaleLongDate)
                self._ui.cbAbsence.addItem(item)
Exemplo n.º 5
0
    def miseAJour(self):
        u"""Liste les absences pouvant donner lieu à un email de rappel"""
        self._ui.cbAbsence.clear()

        # Vérification des mails à envoyer
        req = QSqlQuery()
        sql = MailSQL.construitRequeteComptage(self.__conf["duree"])
        if req.exec_(sql):
            req.next()
            nbMails = req.record().value(0)
        else:
            # TODO log
            print req.lastError().text()
            print req.lastQuery()
            print "Erreur de requête"
            return
        label = str(nbMails) + " absence"
        if nbMails == 0:
            label += " :"
            self._ui.lAbsence.setText(label)
            self._ui.leSujet.setText("")
            self._ui.teCorps.setText("")
            self.__activerUi(False)
            self._ui.pbEnvoyer.setText("Envoyer")
            return
        else:
            self.__activerUi(True)

        if nbMails > 1:
            label += "s"
        label += " :"
        self._ui.lAbsence.setText(label)

        sql = MailSQL.construitRequeteListe(self.__conf["duree"])
        if not req.exec_(sql):
            print req.lastError().text()
            print req.lastQuery()
            print "Erreur de requête"
        else:
            self.__absences = []
            while (req.next()):
                absence = {}
                rec = req.record()
                absence = {}
                absence["id"] = rec.value(0)
                absence["date"] = QDate.fromString(rec.value(1), Qt.ISODate)
                absence["nom"] = rec.value(2)
                absence["adresse"] = rec.value(3)
                self.__absences.append(absence)
                item = absence["nom"] + " le "
                item += absence["date"].toString(Qt.SystemLocaleLongDate)
                self._ui.cbAbsence.addItem(item)
    def setEditorData(self, editor, index):
        if not index.isValid():
            QSqlRelationalDelegate.setEditorData(self, editor, index)
            return

        if index.column() in self.__dates:
            value = QDate.fromString(index.model().data(index, Qt.DisplayRole),
                 Qt.ISODate)
            editor.setCalendarPopup(True)
            editor.setDate(value)
        elif index.column() in self.__booleens:
            value = index.model().data(index, Qt.EditRole)
            if value == "oui":
                value = True
            else:
                value = False
            editor.setChecked(value)
        elif index.column() in self.__numbers:
            value = index.model().data(index, Qt.EditRole)
            spinBox = editor
            spinBox.setValue(value)
        else:
            QSqlRelationalDelegate.setEditorData(self, editor, index)
    def setEditorData(self, editor, index):
        if not index.isValid():
            QSqlRelationalDelegate.setEditorData(self, editor, index)
            return

        if index.column() in self.__dates:
            value = QDate.fromString(index.model().data(index, Qt.DisplayRole),
                                     Qt.ISODate)
            editor.setCalendarPopup(True)
            editor.setDate(value)
        elif index.column() in self.__booleens:
            value = index.model().data(index, Qt.EditRole)
            if value == "oui":
                value = True
            else:
                value = False
            editor.setChecked(value)
        elif index.column() in self.__numbers:
            value = index.model().data(index, Qt.EditRole)
            spinBox = editor
            spinBox.setValue(value)
        else:
            QSqlRelationalDelegate.setEditorData(self, editor, index)
    def paint(self, painter, option, index):
        painter.save()
        if not index.isValid():
            QSqlRelationalDelegate.paint(self, painter, option, index)

        if index.column() in self.__dates:
            value = QDate.fromString(index.model().data(index, Qt.DisplayRole),
                 Qt.ISODate)
            value = value.toString(Qt.SystemLocaleLongDate)
            align = Qt.AlignHCenter | Qt.AlignVCenter
            if option.state and QStyle.State_Active:
                if option.state & QStyle.State_Selected:
                    palette = QPalette.HighlightedText
                else:
                    palette = QPalette.WindowText
            else:
                palette = QPalette.WindowText

            QApplication.style().drawItemText(painter, option.rect, align,
                option.palette, True, value, palette)
        else:
            QSqlRelationalDelegate.paint(self, painter, option, index)

        painter.restore()
Exemplo n.º 9
0
def fromDatetoQDate(date):
    """Returns the QDate object generated from datatime.date object"""
    return QDate.fromString(date.isoformat(), 'yyyy-MM-dd')
Exemplo n.º 10
0
 def msgSuppression(self, index):
     row = index.row()
     nom = index.sibling(row, 2).data()
     date = QDate.fromString(index.sibling(row, 1).data(), Qt.ISODate)
     return u"Supprimer l'absence de " + nom + " du " + date.toString(Qt.SystemLocaleLongDate) + " ?"
Exemplo n.º 11
0
def fromDatetoQDate(date):
    """Returns the QDate object generated from datatime.date object"""
    return QDate.fromString(date.isoformat(), 'yyyy-MM-dd')
Exemplo n.º 12
0
 def msgSuppression(self, index):
     row = index.row()
     nom = index.sibling(row, 2).data()
     date = QDate.fromString(index.sibling(row, 1).data(), Qt.ISODate)
     return u"Supprimer l'absence de " + nom + " du " + date.toString(
         Qt.SystemLocaleLongDate) + " ?"