Skip to content

Commit

Permalink
Edit target word count
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Jul 27, 2023
1 parent 3c37b70 commit 84451e1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
11 changes: 6 additions & 5 deletions src/main/python/plotlyst/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
three_act_structure, SceneStoryBeat, Tag, default_general_tags, TagType, \
default_tag_types, LanguageSettings, ImportOrigin, NovelPreferences, Goal, CharacterPreferences, TagReference, \
ScenePlotReferenceData, MiceQuotient, SceneDrive, WorldBuilding, Board, \
default_big_five_values, CharacterPlan
default_big_five_values, CharacterPlan, ManuscriptGoals
from src.main.python.plotlyst.core.template import Role, exclude_if_empty, exclude_if_black
from src.main.python.plotlyst.env import app_env

Expand Down Expand Up @@ -197,8 +197,9 @@ class NovelInfo:
synopsis: Optional['Document'] = None
version: ApplicationNovelVersion = ApplicationNovelVersion.R0
prefs: NovelPreferences = field(default_factory=NovelPreferences)
world: WorldBuilding = WorldBuilding()
board: Board = Board()
world: WorldBuilding = field(default_factory=WorldBuilding)
board: Board = field(default_factory=Board)
manuscript_goals: ManuscriptGoals = field(default_factory=ManuscriptGoals)


@dataclass
Expand Down Expand Up @@ -526,7 +527,7 @@ def fetch_novel(self, id: uuid.UUID) -> Novel:
story_structures=novel_info.story_structures, character_profiles=novel_info.character_profiles,
conflicts=conflicts, goals=[x for x in novel_info.goals if str(x.id) in goal_ids], tags=tags_dict,
documents=novel_info.documents, premise=novel_info.premise, synopsis=novel_info.synopsis,
prefs=novel_info.prefs)
prefs=novel_info.prefs, manuscript_goals=novel_info.manuscript_goals)

world_path = self.novels_dir.joinpath(str(novel_info.id)).joinpath('world.json')
if os.path.exists(world_path):
Expand Down Expand Up @@ -564,7 +565,7 @@ def _persist_novel(self, novel: Novel):
tag_types=list(novel.tags.keys()),
documents=novel.documents,
premise=novel.premise, synopsis=novel.synopsis,
version=LATEST_VERSION, prefs=novel.prefs)
version=LATEST_VERSION, prefs=novel.prefs, manuscript_goals=novel.manuscript_goals)

self.__persist_info(self.novels_dir, novel_info)
self._persist_world(novel.id, novel.world)
Expand Down
6 changes: 6 additions & 0 deletions src/main/python/plotlyst/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,11 @@ class NovelPreferences:
panels: PanelPreferences = field(default_factory=PanelPreferences)


@dataclass
class ManuscriptGoals:
target_wc: int = 80000


@dataclass
class Novel(NovelDescriptor):
story_structures: List[StoryStructure] = field(default_factory=list)
Expand All @@ -1791,6 +1796,7 @@ class Novel(NovelDescriptor):
prefs: NovelPreferences = field(default_factory=NovelPreferences)
world: WorldBuilding = field(default_factory=WorldBuilding)
board: Board = field(default_factory=Board)
manuscript_goals: ManuscriptGoals = field(default_factory=ManuscriptGoals)

def pov_characters(self) -> List[Character]:
pov_ids = set()
Expand Down
20 changes: 14 additions & 6 deletions src/main/python/plotlyst/view/manuscript_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,14 @@ def __init__(self, novel: Novel):
self._btnContext = tool_btn(IconRegistry.context_icon(), 'Manuscript settings')
transparent(self._btnContext)

self.ui.lblGoal.setText('<html><b>80 000</b> words')
self.ui.btnEditGoal.setIcon(IconRegistry.edit_icon())
transparent(self.ui.btnEditGoal)
decr_icon(self.ui.btnEditGoal, 2)
self.ui.btnEditGoal.installEventFilter(OpacityEventFilter(self.ui.btnEditGoal))
self.ui.btnEditGoal.installEventFilter(ButtonPressResizeEventFilter(self.ui.btnEditGoal))
self.ui.btnEditGoal.clicked.connect(self._edit_wc_goal)

self._chartProgress = ProgressChart(maxValue=80000,
self._chartProgress = ProgressChart(maxValue=self.novel.manuscript_goals.target_wc,
title_prefix=icon_to_html_img(IconRegistry.goal_icon(PLOTLYST_MAIN_COLOR)),
color=PLOTLYST_MAIN_COLOR,
titleColor=PLOTLYST_MAIN_COLOR,
Expand Down Expand Up @@ -337,13 +336,20 @@ def _scene_title_changed(self, scene: Scene):
emit_event(SceneChangedEvent(self, scene))

def _edit_wc_goal(self):
goal, changed = QInputDialog.getInt(self.ui.btnEditGoal, 'Edit word count target', 'Edit word count target',
value=80000,
goal, changed = QInputDialog.getInt(self.ui.btnEditGoal, 'Word count goal', 'Edit word count target',
value=self.novel.manuscript_goals.target_wc,
min=1000, max=10000000, step=1000)
if changed:
self.ui.lblGoal.setText(f'<html><b>{goal}</b> words')
self.novel.manuscript_goals.target_wc = goal
self.repo.update_novel(self.novel)
self._refresh_target_wc()

def _side_bar_toggled(self, btn, toggled: bool):
def _refresh_target_wc(self):
self.ui.lblGoal.setText(f'<html><b>{self.novel.manuscript_goals.target_wc}</b> words')
self._chartProgress.setMaxValue(self.novel.manuscript_goals.target_wc)
self._chartProgress.refresh()

def _side_bar_toggled(self, _, toggled: bool):
btn = self._btnGroupSideBar.checkedButton()
if btn is None:
qtanim.collapse(self.ui.wdgSide)
Expand All @@ -355,6 +361,8 @@ def _side_bar_toggled(self, btn, toggled: bool):
if btn is self.ui.btnReadability:
# self.ui.stackSide.setCurrentWidget(self.ui.pageReadability)
self._analysis_clicked(self.ui.btnReadability.isChecked())
elif btn is self.ui.btnGoals:
self._refresh_target_wc()
# elif btn is self.ui.btnSceneInfo:
# self.ui.stackSide.setCurrentWidget(self.ui.pageInfo)

Expand Down
9 changes: 9 additions & 0 deletions ui/manuscript_view.ui
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="Emoji" name="emojiGoal">
<property name="toolTip">
<string>Manuscript word count target</string>
</property>
<property name="text">
<string/>
</property>
Expand All @@ -475,6 +478,9 @@
</item>
<item>
<widget class="QLabel" name="lblGoal">
<property name="toolTip">
<string>Manuscript word count target</string>
</property>
<property name="text">
<string/>
</property>
Expand All @@ -485,6 +491,9 @@
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="toolTip">
<string>Edit manuscript word count goal</string>
</property>
<property name="text">
<string/>
</property>
Expand Down

0 comments on commit 84451e1

Please sign in to comment.