示例#1
0
    def setData(self, column, data, role=Qt.DisplayRole):
        if role not in [Qt.DisplayRole, Qt.EditRole, Qt.CheckStateRole]:
            print(column, column == Outline.text.value, data, role)
            return

        if column == Outline.text.value and self.isFolder():
            # Folder have no text
            return

        if column == Outline.goal.value:
            self._data[Outline.setGoal] = toInt(data) if toInt(data) > 0 else ""

        # Checking if we will have to recount words
        updateWordCount = False
        if column in [Outline.wordCount.value, Outline.goal.value, Outline.setGoal.value]:
            updateWordCount = not Outline(column) in self._data or self._data[Outline(column)] != data

        # Stuff to do before
        if column == Outline.text.value:
            self.addRevision()

        # Setting data
        self._data[Outline(column)] = data

        # Stuff to do afterwards
        if column == Outline.text.value:
            wc = wordCount(data)
            self.setData(Outline.wordCount.value, wc)

        if column == Outline.compile.value:
            self.emitDataChanged(cols=[Outline.title.value, Outline.compile.value], recursive=True)

        if updateWordCount:
            self.updateWordCount()
示例#2
0
    def setData(self, column, data, role=Qt.DisplayRole):

        E = self.enum

        if column == E.text and self.isFolder():
            # Folder have no text
            return

        if column == E.goal:
            self._data[E.setGoal] = F.toInt(data) if F.toInt(data) > 0 else ""

        # Checking if we will have to recount words
        updateWordCount = False
        if column in [E.wordCount, E.charCount, E.goal, E.setGoal]:
            updateWordCount = not column in self._data or self._data[
                column] != data

        # Stuff to do before
        if column == E.text:
            self.addRevision()

        # Calling base class implementation
        abstractItem.setData(self, column, data, role)

        # Stuff to do afterwards
        if column == E.text:
            wc = F.wordCount(data)
            cc = F.charCount(data, settings.countSpaces)
            self.setData(E.wordCount, wc)
            self.setData(E.charCount, cc)

        if column == E.compile:
            # Title changes when compile changes
            self.emitDataChanged(cols=[E.title, E.compile], recursive=True)

        if column == E.customIcon:
            # If custom icon changed, we tell views to update title (so that
            # icons will be updated as well)
            self.emitDataChanged(cols=[E.title])

        if updateWordCount:
            self.updateWordCount()
示例#3
0
    def setData(self, column, data, role=Qt.DisplayRole):
        if role not in [Qt.DisplayRole, Qt.EditRole, Qt.CheckStateRole]:
            print(column, column == Outline.text.value, data, role)
            return

        if column == Outline.text.value and self.isFolder():
            # Folder have no text
            return

        if column == Outline.goal.value:
            self._data[Outline.setGoal] = toInt(
                data) if toInt(data) > 0 else ""

        # Checking if we will have to recount words
        updateWordCount = False
        if column in [
                Outline.wordCount.value, Outline.goal.value,
                Outline.setGoal.value
        ]:
            updateWordCount = not Outline(
                column) in self._data or self._data[Outline(column)] != data

        # Stuff to do before
        if column == Outline.text.value:
            self.addRevision()

        # Setting data
        self._data[Outline(column)] = data

        # Stuff to do afterwards
        if column == Outline.text.value:
            wc = wordCount(data)
            self.setData(Outline.wordCount.value, wc)

        if column == Outline.compile.value:
            self.emitDataChanged(
                cols=[Outline.title.value, Outline.compile.value],
                recursive=True)

        if updateWordCount:
            self.updateWordCount()
示例#4
0
    def setData(self, column, data, role=Qt.DisplayRole):

        E = self.enum

        if column == E.text and self.isFolder():
            # Folder have no text
            return

        if column == E.goal:
            self._data[E.setGoal] = F.toInt(data) if F.toInt(data) > 0 else ""

        # Checking if we will have to recount words
        updateWordCount = False
        if column in [E.wordCount, E.goal, E.setGoal]:
            updateWordCount = not column in self._data or self._data[column] != data

        # Stuff to do before
        if column == E.text:
            self.addRevision()

        # Calling base class implementation
        abstractItem.setData(self, column, data, role)

        # Stuff to do afterwards
        if column == E.text:
            wc = F.wordCount(data)
            self.setData(E.wordCount, wc)

        if column == E.compile:
            # Title changes when compile changes
            self.emitDataChanged(cols=[E.title, E.compile],
                                 recursive=True)

        if column == E.customIcon:
            # If custom icon changed, we tell views to update title (so that
            # icons will be updated as well)
            self.emitDataChanged(cols=[E.title])

        if updateWordCount:
            self.updateWordCount()
示例#5
0
    def wordCount(self, i):

        src = {
            0: self.txtSummarySentence,
            1: self.txtSummaryPara,
            2: self.txtSummaryPage,
            3: self.txtSummaryFull
        }[i]

        lbl = {
            0: self.lblSummaryWCSentence,
            1: self.lblSummaryWCPara,
            2: self.lblSummaryWCPage,
            3: self.lblSummaryWCFull
        }[i]

        wc = wordCount(src.toPlainText())
        if i in [2, 3]:
            pages = self.tr(" (~{} pages)").format(int(wc / 25) / 10.)
        else:
            pages = ""
        lbl.setText(self.tr("Words: {}{}").format(wc, pages))
示例#6
0
    def wordCount(self, i):

        src = {
            0: self.txtSummarySentence,
            1: self.txtSummaryPara,
            2: self.txtSummaryPage,
            3: self.txtSummaryFull
        }[i]

        lbl = {
            0: self.lblSummaryWCSentence,
            1: self.lblSummaryWCPara,
            2: self.lblSummaryWCPage,
            3: self.lblSummaryWCFull
        }[i]

        wc = wordCount(src.toPlainText())
        if i in [2, 3]:
            pages = self.tr(" (~{} pages)").format(int(wc / 25) / 10.)
        else:
            pages = ""
        lbl.setText(self.tr("Words: {}{}").format(wc, pages))
示例#7
0
def test_wordCount():
    assert F.wordCount("In the beginning was the word.") == 6
    assert F.wordCount("") == 0
示例#8
0
def test_wordCount():
    assert F.wordCount("In the beginning was the word.") == 6
    assert F.wordCount("") == 0