From 2aa65fc815a23cf3855be92ba0fa83cc402df940 Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Thu, 15 Sep 2022 23:53:15 +0200 Subject: [PATCH] Added pretty label for template goal Signed-off-by: TheJackiMonster --- manuskript/data/goal.py | 5 +++- manuskript/data/template.py | 10 ++++++++ manuskript/ui/startupWindow.py | 10 +++++--- ui/startup.glade | 42 ++++++++++++++++++++++++++++------ 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/manuskript/data/goal.py b/manuskript/data/goal.py index 6a1fea94..648892e1 100644 --- a/manuskript/data/goal.py +++ b/manuskript/data/goal.py @@ -16,9 +16,12 @@ class Goal: self.value = max(value, 0) self.kind = kind + def prettyString(self): + return str(self.value) + " " + self.kind.name.lower() + def __str__(self): if self.kind != GoalKind.WORDS: - return str(self.value) + " " + self.kind.name.lower() + return self.prettyString() else: return str(self.value) diff --git a/manuskript/data/template.py b/manuskript/data/template.py index f4dded29..329a9e00 100644 --- a/manuskript/data/template.py +++ b/manuskript/data/template.py @@ -61,6 +61,16 @@ class Template: self.goal = Goal(value) + def getGoalString(self): + if self.goal is None: + return "?" + + value = self.goal.value + for level in self.levels: + value = value * level.size + + return Goal(value, self.goal.kind).prettyString() + @classmethod def getDefaultTemplates(cls): templates = list() diff --git a/manuskript/ui/startupWindow.py b/manuskript/ui/startupWindow.py index 26d4293a..15573e57 100644 --- a/manuskript/ui/startupWindow.py +++ b/manuskript/ui/startupWindow.py @@ -33,6 +33,7 @@ class StartupWindow(AbstractDialog): self.templateSelections = list() self.templateLevelsListbox = None + self.goalLabel = None self.addLevelButton = None self.addGoalButton = None @@ -89,6 +90,7 @@ class StartupWindow(AbstractDialog): self.templateLevelsListbox = builder.get_object("template_levels_listbox") + self.goalLabel = builder.get_object("goal_label") self.addLevelButton = builder.get_object("add_level_button") self.addGoalButton = builder.get_object("add_goal_button") @@ -107,18 +109,20 @@ class StartupWindow(AbstractDialog): for level in self.template.levels: entry = TemplateEntry(self) - entry.bindTemplate(template, level) + entry.bindTemplate(self.template, level) self.templateLevelsListbox.add(entry.widget) entry.show() - if template.goal is not None: + if self.template.goal is not None: entry = TemplateEntry(self) - entry.bindTemplate(template) + entry.bindTemplate(self.template) self.templateLevelsListbox.add(entry.widget) entry.show() + self.goalLabel.set_text(self.template.getGoalString()) + def templateSelectionChanged(self, selection: Gtk.TreeSelection): model, tree_iter = selection.get_selected() diff --git a/ui/startup.glade b/ui/startup.glade index 9130eb8f..a2ffaf35 100644 --- a/ui/startup.glade +++ b/ui/startup.glade @@ -336,12 +336,40 @@ False 4 - + True False - Total: ? words (~? pages) - end - 0 + 2 + 4 + + + True + False + Total: + end + 0 + + + + + + False + True + 0 + + + + + True + False + 0 + + + True + True + 1 + + True @@ -431,7 +459,7 @@ True False - 6 + 4 True @@ -477,7 +505,7 @@ True False - 6 + 4 True @@ -520,7 +548,7 @@ True False - 6 + 4 True