コード例 #1
0
    def updateStatusBar(self):
        if self._index:
            item = self._index.internalPointer()

        wc = item.data(Outline.wordCount.value)
        goal = item.data(Outline.goal.value)
        pg = item.data(Outline.goalPercentage.value)

        if goal:
            rect = self.lblProgress.geometry()
            rect = QRect(QPoint(0, 0), rect.size())
            self.px = QPixmap(rect.size())
            self.px.fill(Qt.transparent)
            p = QPainter(self.px)
            drawProgress(p, rect, pg, 2)
            p.end()
            self.lblProgress.setPixmap(self.px)
            self.lblWC.setText(self.tr("{} words / {}").format(wc, goal))
        else:
            self.lblProgress.hide()
            self.lblWC.setText(self.tr("{} words").format(wc))

        self.locker.setWordCount(wc)
        # If there's a goal, then we update the locker target's number of word accordingly
        # (also if there is a word count, we deduce it.
        if goal and not self.locker.isLocked():
            if wc and goal - wc > 0:
                self.locker.spnWordTarget.setValue(goal - wc)
            elif not wc:
                self.locker.spnWordTarget.setValue(goal)
コード例 #2
0
    def updateStatusBar(self):
        if self._index:
            item = self._index.internalPointer()

        wc = item.data(Outline.wordCount.value)
        goal = item.data(Outline.goal.value)
        pg = item.data(Outline.goalPercentage.value)

        if goal:
            rect = self.lblProgress.geometry()
            rect = QRect(QPoint(0, 0), rect.size())
            self.px = QPixmap(rect.size())
            self.px.fill(Qt.transparent)
            p = QPainter(self.px)
            drawProgress(p, rect, pg, 2)
            p.end()
            self.lblProgress.setPixmap(self.px)
            self.lblWC.setText(self.tr("{} words / {}").format(wc, goal))
        else:
            self.lblProgress.hide()
            self.lblWC.setText(self.tr("{} words").format(wc))

        self.locker.setWordCount(wc)
        # If there's a goal, then we update the locker target's number of word accordingly
        # (also if there is a word count, we deduce it.
        if goal and not self.locker.isLocked():
            if wc and goal - wc > 0:
                self.locker.spnWordTarget.setValue(goal - wc)
            elif not wc:
                self.locker.spnWordTarget.setValue(goal)
コード例 #3
0
    def updateStats(self):

        if not self.currentEditor():
            return

        index = self.currentEditor().currentIndex
        if index.isValid():
            item = index.internalPointer()
        else:
            item = self.mw.mdlOutline.rootItem

        if not item:
            item = self.mw.mdlOutline.rootItem

        wc = item.data(Outline.wordCount)
        goal = item.data(Outline.goal)
        progress = item.data(Outline.goalPercentage)

        goal = uiParse(goal, None, int, lambda x: x >= 0)
        progress = uiParse(progress, 0.0, float)

        if not wc:
            wc = 0
        if goal:
            self.lblRedacProgress.show()
            rect = self.lblRedacProgress.geometry()
            rect = QRect(QPoint(0, 0), rect.size())
            self.px = QPixmap(rect.size())
            self.px.fill(Qt.transparent)
            p = QPainter(self.px)
            drawProgress(p, rect, progress, 2)
            del p
            self.lblRedacProgress.setPixmap(self.px)
            self.lblRedacWC.setText(
                self.tr("{} words / {} ").format(
                    locale.format_string("%d", wc, grouping=True),
                    locale.format_string("%d", goal, grouping=True)))
        else:
            self.lblRedacProgress.hide()
            self.lblRedacWC.setText(
                self.tr("{} words ").format(
                    locale.format_string("%d", wc, grouping=True)))
コード例 #4
0
ファイル: mainEditor.py プロジェクト: olivierkes/manuskript
    def updateStats(self):

        if not self.currentEditor():
            return

        index = self.currentEditor().currentIndex
        if index.isValid():
            item = index.internalPointer()
        else:
            item = self.mw.mdlOutline.rootItem

        if not item:
            item = self.mw.mdlOutline.rootItem

        wc = item.data(Outline.wordCount)
        goal = item.data(Outline.goal)
        progress = item.data(Outline.goalPercentage)
        # mw = qApp.activeWindow()

        if not wc:
            wc = 0
        if goal:
            self.lblRedacProgress.show()
            rect = self.lblRedacProgress.geometry()
            rect = QRect(QPoint(0, 0), rect.size())
            self.px = QPixmap(rect.size())
            self.px.fill(Qt.transparent)
            p = QPainter(self.px)
            drawProgress(p, rect, progress, 2)
            del p
            self.lblRedacProgress.setPixmap(self.px)
            self.lblRedacWC.setText(self.tr("{} words / {} ").format(
                    locale.format_string("%d", wc, grouping=True),
                    locale.format_string("%d", goal, grouping=True)))
        else:
            self.lblRedacProgress.hide()
            self.lblRedacWC.setText(self.tr("{} words ").format(
                    locale.format_string("%d", wc, grouping=True)))
コード例 #5
0
def test_several():

    from PyQt5.QtGui import QPainter, QPixmap, QIcon, QColor
    from PyQt5.QtCore import QRect

    # drawProgress
    px = QPixmap(10, 10)
    F.drawProgress(QPainter(px), QRect(0, 0, 100, 100), 0.5)

    # colorFromProgress
    a = F.colorFromProgress(0.1)
    b = F.colorFromProgress(0.5)
    c = F.colorFromProgress(1.0)
    d = F.colorFromProgress(1.5)
    assert a != b != c != d

    # iconColor & iconFromColor & iconFromColorString
    icon = F.iconFromColorString("#ff0000")
    assert F.iconColor(icon).name().lower() == "#ff0000"

    # themeIcon
    assert F.themeIcon("text") != None
    assert F.themeIcon("nonexistingname") != None

    # randomColor
    c1 = F.randomColor()
    c2 = F.randomColor(c1)
    assert c1.name() != c2.name()

    # mixColors
    c1 = QColor("#FFF")
    c2 = QColor("#000")
    assert F.mixColors(c1, c2).name() == "#7f7f7f"

    # colorifyPixmap
    assert F.colorifyPixmap(px, c1) != None
コード例 #6
0
    def paint(self, painter, option, index):
        if not index.isValid():
            return QStyledItemDelegate.paint(self, painter, option, index)

        QStyledItemDelegate.paint(self, painter, option, index)

        item = index.internalPointer()

        if not item.data(Outline.goal):
            return

        p = toFloat(item.data(Outline.goalPercentage))

        typ = item.data(Outline.type)

        level = item.level()
        if self.rootIndex and self.rootIndex.isValid():
            level -= self.rootIndex.internalPointer().level() + 1

        margin = 5
        height = max(min(option.rect.height() - 2 * margin, 12) - 2 * level, 6)

        painter.save()

        rect = option.rect.adjusted(margin, margin, -margin, -margin)

        # Move
        rect.translate(level * rect.width() / 10, 0)
        rect.setWidth(rect.width() - level * rect.width() / 10)

        rect.setHeight(height)
        rect.setTop(option.rect.top() + (option.rect.height() - height) / 2)

        drawProgress(painter, rect, p)  # from functions

        painter.restore()
コード例 #7
0
def test_several():

    from PyQt5.QtGui import QPainter, QPixmap, QIcon, QColor
    from PyQt5.QtCore import QRect

    # drawProgress
    px = QPixmap(10, 10)
    F.drawProgress(QPainter(px), QRect(0, 0, 100, 100), 0.5)

    # colorFromProgress
    a = F.colorFromProgress(0.1)
    b = F.colorFromProgress(0.5)
    c = F.colorFromProgress(1.0)
    d = F.colorFromProgress(1.5)
    assert a != b != c != d

    # iconColor & iconFromColor & iconFromColorString
    icon = F.iconFromColorString("#ff0000")
    assert F.iconColor(icon).name().lower() == "#ff0000"

    # themeIcon
    assert F.themeIcon("text") is not None
    assert F.themeIcon("nonexistingname") is not None

    # randomColor
    c1 = F.randomColor()
    c2 = F.randomColor(c1)
    assert c1.name() != c2.name()

    # mixColors
    c1 = QColor("#FFF")
    c2 = QColor("#000")
    assert F.mixColors(c1, c2).name() == "#7f7f7f"

    # colorifyPixmap
    assert F.colorifyPixmap(px, c1) != None
コード例 #8
0
    def paint(self, painter, option, index):
        if not index.isValid():
            return QStyledItemDelegate.paint(self, painter, option, index)

        QStyledItemDelegate.paint(self, painter, option, index)

        item = index.internalPointer()

        if not item.data(Outline.goal.value):
            return

        p = toFloat(item.data(Outline.goalPercentage.value))

        typ = item.data(Outline.type.value)

        level = item.level()
        if self.rootIndex and self.rootIndex.isValid():
            level -= self.rootIndex.internalPointer().level() + 1

        margin = 5
        height = max(min(option.rect.height() - 2 * margin, 12) - 2 * level, 6)

        painter.save()

        rect = option.rect.adjusted(margin, margin, -margin, -margin)

        # Move
        rect.translate(level * rect.width() / 10, 0)
        rect.setWidth(rect.width() - level * rect.width() / 10)

        rect.setHeight(height)
        rect.setTop(option.rect.top() + (option.rect.height() - height) / 2)

        drawProgress(painter, rect, p)  # from functions

        painter.restore()