Skip to content

Commit

Permalink
Fix word count for template selection (fix #1163)
Browse files Browse the repository at this point in the history
Signed-off-by: TheJackiMonster <[email protected]>
  • Loading branch information
TheJackiMonster committed Dec 7, 2023
1 parent 5f3933b commit 1439290
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions manuskript/ui/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,31 +355,41 @@ def updateWordCount(self):
Also, updates self.template, which is used to create the items when
calling self.createFile.
"""
total = 1

# Searching for every spinboxes on the widget, and multiplying
# their values to get the number of words.
for s in self.findChildren(QSpinBox, QRegExp(".*"),
Qt.FindChildrenRecursively):
total = total * s.value()
templateIndex = s.property("templateIndex")
if (not templateIndex) or (templateIndex >= len(self.template[1])):
continue

# Update self.template to reflect the changed count values
templateIndex = s.property("templateIndex")
self.template[1][templateIndex] = (
s.value(),
self.template[1][templateIndex][1])

for t in self.findChildren(QLineEdit, QRegExp(".*"),
Qt.FindChildrenRecursively):
# Update self.template to reflect the changed name values
templateIndex = t.property("templateIndex")
if templateIndex != None :
self.template[1][templateIndex] = (
if (not templateIndex) or (templateIndex >= len(self.template[1])):
continue

# Update self.template to reflect the changed name values
self.template[1][templateIndex] = (
self.template[1][templateIndex][0],
t.text())

if total == 1:
total = 0

total = 0
for row in self.template[1]:
try:
val = int(row[0])
except ValueError:
continue

if total == 0:
total = val
else:
total *= val

self.lblTotal.setText(self.tr("<b>Total:</b> {} words (~ {} pages)").format(
locale.format_string("%d", total, grouping=True),
Expand Down

0 comments on commit 1439290

Please sign in to comment.