diff --git a/src/main/python/plotlyst/events.py b/src/main/python/plotlyst/events.py index 2731a04d5..b9231d11d 100644 --- a/src/main/python/plotlyst/events.py +++ b/src/main/python/plotlyst/events.py @@ -120,6 +120,11 @@ class NovelSyncEvent(Event): novel: NovelDescriptor +@dataclass +class CloseNovelEvent(Event): + novel: NovelDescriptor + + @dataclass class PlotCreatedEvent(Event): pass diff --git a/src/main/python/plotlyst/view/main_window.py b/src/main/python/plotlyst/view/main_window.py index 58da2d2de..a855e961e 100644 --- a/src/main/python/plotlyst/view/main_window.py +++ b/src/main/python/plotlyst/view/main_window.py @@ -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 @@ -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() @@ -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): @@ -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): @@ -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) diff --git a/src/main/python/plotlyst/view/manuscript_view.py b/src/main/python/plotlyst/view/manuscript_view.py index 0bc09af5a..07fc1485e 100644 --- a/src/main/python/plotlyst/view/manuscript_view.py +++ b/src/main/python/plotlyst/view/manuscript_view.py @@ -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 @@ -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 @@ -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 diff --git a/src/main/python/plotlyst/view/widget/manuscript.py b/src/main/python/plotlyst/view/widget/manuscript.py index c22d602f5..6ef4f3b91 100644 --- a/src/main/python/plotlyst/view/widget/manuscript.py +++ b/src/main/python/plotlyst/view/widget/manuscript.py @@ -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: @@ -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) diff --git a/ui/manuscript_context_menu_widget.ui b/ui/manuscript_context_menu_widget.ui index 810b77424..614d35dde 100644 --- a/ui/manuscript_context_menu_widget.ui +++ b/ui/manuscript_context_menu_widget.ui @@ -113,7 +113,7 @@ - To set a new language, the applicaton needs to be shut down. + To set a new language, the novel needs to be closed. true @@ -132,7 +132,7 @@ PointingHandCursor - Apply and shut down + Close novel true