Fix word count for template selection (fix #1163)

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
TheJackiMonster 2023-12-07 15:34:01 +01:00
parent 5f3933bde2
commit 14392909c3
No known key found for this signature in database
GPG key ID: D850A5F772E880F9

View file

@ -355,31 +355,41 @@ class welcome(QWidget, Ui_welcome):
Also, updates self.template, which is used to create the items when Also, updates self.template, which is used to create the items when
calling self.createFile. calling self.createFile.
""" """
total = 1
# Searching for every spinboxes on the widget, and multiplying # Searching for every spinboxes on the widget, and multiplying
# their values to get the number of words. # their values to get the number of words.
for s in self.findChildren(QSpinBox, QRegExp(".*"), for s in self.findChildren(QSpinBox, QRegExp(".*"),
Qt.FindChildrenRecursively): 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 # Update self.template to reflect the changed count values
templateIndex = s.property("templateIndex")
self.template[1][templateIndex] = ( self.template[1][templateIndex] = (
s.value(), s.value(),
self.template[1][templateIndex][1]) self.template[1][templateIndex][1])
for t in self.findChildren(QLineEdit, QRegExp(".*"), for t in self.findChildren(QLineEdit, QRegExp(".*"),
Qt.FindChildrenRecursively): Qt.FindChildrenRecursively):
# Update self.template to reflect the changed name values
templateIndex = t.property("templateIndex") templateIndex = t.property("templateIndex")
if templateIndex != None : if (not templateIndex) or (templateIndex >= len(self.template[1])):
self.template[1][templateIndex] = ( continue
# Update self.template to reflect the changed name values
self.template[1][templateIndex] = (
self.template[1][templateIndex][0], self.template[1][templateIndex][0],
t.text()) t.text())
total = 0
for row in self.template[1]:
try:
val = int(row[0])
except ValueError:
continue
if total == 1: if total == 0:
total = 0 total = val
else:
total *= val
self.lblTotal.setText(self.tr("<b>Total:</b> {} words (~ {} pages)").format( self.lblTotal.setText(self.tr("<b>Total:</b> {} words (~ {} pages)").format(
locale.format_string("%d", total, grouping=True), locale.format_string("%d", total, grouping=True),