mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-09-30 09:17:41 +13:00
Merge pull request #339 from lechbaczynski/characterscount
- adding characters count. Implementing #334
This commit is contained in:
commit
0de131f392
3 changed files with 19 additions and 5 deletions
|
@ -60,6 +60,7 @@ class Outline(IntEnum):
|
||||||
textFormat = 15
|
textFormat = 15
|
||||||
revisions = 16
|
revisions = 16
|
||||||
customIcon = 17
|
customIcon = 17
|
||||||
|
charCount = 18
|
||||||
|
|
||||||
class Abstract(IntEnum):
|
class Abstract(IntEnum):
|
||||||
title = 0
|
title = 0
|
||||||
|
|
|
@ -80,6 +80,9 @@ class outlineItem(abstractItem):
|
||||||
def wordCount(self):
|
def wordCount(self):
|
||||||
return self._data.get(self.enum.wordCount, 0)
|
return self._data.get(self.enum.wordCount, 0)
|
||||||
|
|
||||||
|
def charCount(self):
|
||||||
|
return self._data.get(self.enum.charCount, 0)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{id}: {folder}{title}{children}".format(
|
return "{id}: {folder}{title}{children}".format(
|
||||||
id=self.ID(),
|
id=self.ID(),
|
||||||
|
@ -154,6 +157,7 @@ class outlineItem(abstractItem):
|
||||||
if column == E.text:
|
if column == E.text:
|
||||||
wc = F.wordCount(data)
|
wc = F.wordCount(data)
|
||||||
self.setData(E.wordCount, wc)
|
self.setData(E.wordCount, wc)
|
||||||
|
self.setData(E.charCount, len(data))
|
||||||
|
|
||||||
if column == E.compile:
|
if column == E.compile:
|
||||||
# Title changes when compile changes
|
# Title changes when compile changes
|
||||||
|
@ -195,9 +199,12 @@ class outlineItem(abstractItem):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
wc = 0
|
wc = 0
|
||||||
|
cc = 0
|
||||||
for c in self.children():
|
for c in self.children():
|
||||||
wc += F.toInt(c.data(self.enum.wordCount))
|
wc += F.toInt(c.data(self.enum.wordCount))
|
||||||
|
cc += F.toInt(c.data(self.enum.charCount))
|
||||||
self._data[self.enum.wordCount] = wc
|
self._data[self.enum.wordCount] = wc
|
||||||
|
self._data[self.enum.charCount] = cc
|
||||||
|
|
||||||
setGoal = F.toInt(self.data(self.enum.setGoal))
|
setGoal = F.toInt(self.data(self.enum.setGoal))
|
||||||
goal = F.toInt(self.data(self.enum.goal))
|
goal = F.toInt(self.data(self.enum.goal))
|
||||||
|
@ -467,6 +474,7 @@ class outlineItem(abstractItem):
|
||||||
|
|
||||||
# We don't want to write some datas (computed)
|
# We don't want to write some datas (computed)
|
||||||
XMLExclude = [enums.Outline.wordCount,
|
XMLExclude = [enums.Outline.wordCount,
|
||||||
|
enums.Outline.charCount,
|
||||||
enums.Outline.goal,
|
enums.Outline.goal,
|
||||||
enums.Outline.goalPercentage,
|
enums.Outline.goalPercentage,
|
||||||
enums.Outline.revisions]
|
enums.Outline.revisions]
|
||||||
|
|
|
@ -302,11 +302,14 @@ class mainEditor(QWidget, Ui_mainEditor):
|
||||||
|
|
||||||
wc = item.data(Outline.wordCount)
|
wc = item.data(Outline.wordCount)
|
||||||
goal = item.data(Outline.goal)
|
goal = item.data(Outline.goal)
|
||||||
|
chars = item.data(Outline.charCount) # len(item.data(Outline.text))
|
||||||
progress = item.data(Outline.goalPercentage)
|
progress = item.data(Outline.goalPercentage)
|
||||||
|
|
||||||
goal = uiParse(goal, None, int, lambda x: x>=0)
|
goal = uiParse(goal, None, int, lambda x: x>=0)
|
||||||
progress = uiParse(progress, 0.0, float)
|
progress = uiParse(progress, 0.0, float)
|
||||||
|
|
||||||
|
if not chars:
|
||||||
|
chars = 0
|
||||||
if not wc:
|
if not wc:
|
||||||
wc = 0
|
wc = 0
|
||||||
if goal:
|
if goal:
|
||||||
|
@ -319,13 +322,15 @@ class mainEditor(QWidget, Ui_mainEditor):
|
||||||
drawProgress(p, rect, progress, 2)
|
drawProgress(p, rect, progress, 2)
|
||||||
del p
|
del p
|
||||||
self.lblRedacProgress.setPixmap(self.px)
|
self.lblRedacProgress.setPixmap(self.px)
|
||||||
self.lblRedacWC.setText(self.tr("{} words / {} ").format(
|
self.lblRedacWC.setText(self.tr("({} chars) {} words / {} ").format(
|
||||||
locale.format_string("%d", wc, grouping=True),
|
locale.format("%d", chars, grouping=True),
|
||||||
locale.format_string("%d", goal, grouping=True)))
|
locale.format("%d", wc, grouping=True),
|
||||||
|
locale.format("%d", goal, grouping=True)))
|
||||||
else:
|
else:
|
||||||
self.lblRedacProgress.hide()
|
self.lblRedacProgress.hide()
|
||||||
self.lblRedacWC.setText(self.tr("{} words ").format(
|
self.lblRedacWC.setText(self.tr("({} chars) {} words ").format(
|
||||||
locale.format_string("%d", wc, grouping=True)))
|
locale.format("%d", chars, grouping=True),
|
||||||
|
locale.format("%d", wc, grouping=True)))
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# VIEWS
|
# VIEWS
|
||||||
|
|
Loading…
Reference in a new issue