Skip to content

Commit

Permalink
Close novel upon language change instead of shutting down the app
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Jul 27, 2023
1 parent 07d94d4 commit b3bf031
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/main/python/plotlyst/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class NovelSyncEvent(Event):
novel: NovelDescriptor


@dataclass
class CloseNovelEvent(Event):
novel: NovelDescriptor


@dataclass
class PlotCreatedEvent(Event):
pass
Expand Down
9 changes: 5 additions & 4 deletions src/main/python/plotlyst/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
emit_info
from src.main.python.plotlyst.event.handler import EventLogHandler, event_dispatcher
from src.main.python.plotlyst.events import NovelDeletedEvent, \
NovelUpdatedEvent, OpenDistractionFreeMode, ExitDistractionFreeMode
NovelUpdatedEvent, OpenDistractionFreeMode, ExitDistractionFreeMode, CloseNovelEvent
from src.main.python.plotlyst.resources import resource_manager, ResourceType, ResourceDownloadedEvent
from src.main.python.plotlyst.service.cache import acts_registry
from src.main.python.plotlyst.service.dir import select_new_project_directory
Expand Down Expand Up @@ -156,7 +156,8 @@ def __init__(self, *args, **kwargs):
HomeTopLevelButtonTourEvent, NovelEditorDisplayTourEvent, AllNovelViewsTourEvent,
GeneralNovelViewTourEvent,
CharacterViewTourEvent, ScenesViewTourEvent, DocumentsViewTourEvent,
ManuscriptViewTourEvent, AnalysisViewTourEvent, BoardViewTourEvent)
ManuscriptViewTourEvent, AnalysisViewTourEvent, BoardViewTourEvent,
CloseNovelEvent)

self._init_views()

Expand Down Expand Up @@ -237,7 +238,7 @@ def handle_novel_navbar_tour_event(event_: BaseNovelViewTourEvent, btn: QAbstrac
btn.click()
self._tour_service.addWidget(btn, event_)

if isinstance(event, NovelDeletedEvent):
if isinstance(event, (NovelDeletedEvent, CloseNovelEvent)):
if self.novel and event.novel.id == self.novel.id:
self.close_novel()
elif isinstance(event, NovelUpdatedEvent):
Expand All @@ -259,7 +260,6 @@ def handle_novel_navbar_tour_event(event_: BaseNovelViewTourEvent, btn: QAbstrac
elif isinstance(event, TutorialNovelCloseTourEvent):
if self.novel and self.novel.tutorial:
self.close_novel()
self.home_mode.setChecked(True)
elif isinstance(event, NovelEditorDisplayTourEvent):
self._tour_service.addWidget(self.pageOutline, event)
elif isinstance(event, NovelTopLevelButtonTourEvent):
Expand All @@ -286,6 +286,7 @@ def handle_novel_navbar_tour_event(event_: BaseNovelViewTourEvent, btn: QAbstrac
def close_novel(self):
self.novel = None
self._clear_novel_views()
self.home_mode.setChecked(True)

def _toggle_fullscreen(self, on: bool):
self.wdgNavBar.setHidden(on)
Expand Down
7 changes: 3 additions & 4 deletions src/main/python/plotlyst/view/manuscript_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import qtanim
from PyQt6.QtCore import QTimer, Qt
from PyQt6.QtGui import QColor
from PyQt6.QtWidgets import QApplication
from overrides import overrides
from qthandy import translucent, bold, margins, spacer, vline, transparent, vspacer, decr_icon
from qthandy.filter import OpacityEventFilter
Expand All @@ -32,7 +31,7 @@
from src.main.python.plotlyst.core.domain import Scene
from src.main.python.plotlyst.event.core import emit_event, emit_critical, emit_info, Event
from src.main.python.plotlyst.events import NovelUpdatedEvent, SceneChangedEvent, OpenDistractionFreeMode, \
ChapterChangedEvent, SceneDeletedEvent, ExitDistractionFreeMode, NovelSyncEvent
ChapterChangedEvent, SceneDeletedEvent, ExitDistractionFreeMode, NovelSyncEvent, CloseNovelEvent
from src.main.python.plotlyst.resources import ResourceType
from src.main.python.plotlyst.service.grammar import language_tool_proxy
from src.main.python.plotlyst.service.persistence import flush_or_fail
Expand Down Expand Up @@ -377,11 +376,11 @@ def _adverb_highlight_toggled(self, toggled: bool):
self.ui.textEdit.setWordTagHighlighterEnabled(toggled)

def _language_changed(self, lang: str):
emit_info('Application is shutting down. Persist workspace...')
emit_info('Novel is getting closed. Persist workspace...')
self.novel.lang_settings.lang = lang
self.repo.update_project_novel(self.novel)
flush_or_fail()
QTimer.singleShot(1000, QApplication.exit)
emit_event(CloseNovelEvent(self, self.novel))

def _is_empty_page(self) -> bool:
return self.ui.stackedWidget.currentWidget() == self.ui.pageEmpty
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/plotlyst/view/widget/manuscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def __init__(self, novel: Novel, parent=None):
self.cbUkrainian.setChecked(True)

self.btnShutDown.clicked.connect(self._languageChanged)
self.btnShutDown.installEventFilter(ButtonPressResizeEventFilter(self.btnShutDown))

@overrides
def mouseReleaseEvent(self, a0: QtGui.QMouseEvent) -> None:
Expand All @@ -293,7 +294,7 @@ def _showShutdownOption(self):
qtanim.glow(self.btnShutDown, loop=3)

def _languageChanged(self):
self.btnShutDown.setText('Shutting down ...')
self.btnShutDown.setText('Closing...')
self.lblShutdownHint.setHidden(True)
spin(self.btnShutDown, color='white')
qtanim.glow(self.btnShutDown, loop=15)
Expand Down
4 changes: 2 additions & 2 deletions ui/manuscript_context_menu_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<item>
<widget class="QLabel" name="lblShutdownHint">
<property name="text">
<string>To set a new language, the applicaton needs to be shut down.</string>
<string>To set a new language, the novel needs to be closed.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand All @@ -132,7 +132,7 @@
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Apply and shut down</string>
<string>Close novel</string>
</property>
<property name="base" stdset="0">
<bool>true</bool>
Expand Down

0 comments on commit b3bf031

Please sign in to comment.