From b20731ebcb25eb67f3f2014e5f770cd8e5d51520 Mon Sep 17 00:00:00 2001 From: bzorn Date: Wed, 10 Apr 2024 14:22:39 +0300 Subject: [PATCH] added Progress Ring --- .../widgets/NlightContainers/manga_area.py | 19 ++++++++----------- .../widgets/NlightTemplates/BaseWidget.py | 13 ++++++++++--- .../widgets/NlightTemplates/Facial.py | 4 +++- .../widgets/NlightTemplates/Library.py | 4 +++- .../widgets/NlightTemplates/Shikimori.py | 4 +++- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/nlightreader/widgets/NlightContainers/manga_area.py b/nlightreader/widgets/NlightContainers/manga_area.py index 9d056da..e036403 100644 --- a/nlightreader/widgets/NlightContainers/manga_area.py +++ b/nlightreader/widgets/NlightContainers/manga_area.py @@ -1,19 +1,18 @@ from PySide6.QtCore import Qt, QThreadPool from PySide6.QtWidgets import ( QWidget, - QVBoxLayout, + QHBoxLayout, QGridLayout, - QSpacerItem, - QSizePolicy, ) from qfluentwidgets import ScrollArea from nlightreader.utils import Thread +from nlightreader.widgets.NlightContainers.content_container import AbstractContentContainer from nlightreader.widgets.NlightWidgets.manga_item import MangaItem -class MangaArea(ScrollArea): - def __init__(self, parent): +class MangaArea(ScrollArea, AbstractContentContainer): + def __init__(self): super().__init__() self.setWidgetResizable(True) self.setStyleSheet( @@ -29,7 +28,7 @@ def __init__(self, parent): self._scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents") self._scrollAreaWidgetContents.resizeEvent = self._scroll_resize_event - self._scroll_layout = QVBoxLayout(self._scrollAreaWidgetContents) + self._scroll_layout = QHBoxLayout(self._scrollAreaWidgetContents) self._scroll_layout.setSpacing(0) self._scroll_layout.setContentsMargins(0, 0, 0, 0) @@ -38,17 +37,12 @@ def __init__(self, parent): self._scroll_layout.addLayout(self._content_grid) - self._verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) - self._scroll_layout.addItem(self._verticalSpacer) self.setWidget(self._scrollAreaWidgetContents) self.manga_thread_pool = QThreadPool() self.manga_thread_pool.setMaxThreadCount(self._column_count) self._set_images_thread = Thread(target=self.partial_image_addition) - if parent is not None: - parent.addWidget(self) - def _scroll_resize_event(self, event): if event.oldSize().width() != event.size().width(): self.update_items() @@ -82,3 +76,6 @@ def delete_items(self): def update_items(self): size = self.size().width() // (self._column_count + 1) [item.set_size(size) for item in self._manga_items] + + def get_content_widget(self): + return self._scrollAreaWidgetContents diff --git a/nlightreader/widgets/NlightTemplates/BaseWidget.py b/nlightreader/widgets/NlightTemplates/BaseWidget.py index 12f3672..1c03eaf 100644 --- a/nlightreader/widgets/NlightTemplates/BaseWidget.py +++ b/nlightreader/widgets/NlightTemplates/BaseWidget.py @@ -1,7 +1,8 @@ import time -from PySide6.QtCore import Signal, QMutex, Slot +from PySide6.QtCore import Signal, Slot from PySide6.QtWidgets import QWidget +from qfluentwidgets import IndeterminateProgressRing from nlightreader.consts.enums import Nl from nlightreader.items import Manga, RequestForm @@ -15,12 +16,14 @@ class MangaItemBasedWidget(QWidget): def __init__(self, parent=None): super().__init__(parent=parent) - self.manga_area = MangaArea(None) + self.manga_area = MangaArea() self.mangas: list[Manga] = [] + self.progressRing = IndeterminateProgressRing() + self.progressRing.setVisible(False) + self._get_content_thread = Thread(target=self._get_content_thread_func, callback=self.update_content) - self.mutex = QMutex() self.catalog = None self.request_params = RequestForm() @@ -30,6 +33,8 @@ def setup(self): def update_content(self): self.manga_area.delete_items() items = [self.setup_manga_item(manga) for manga in self.mangas] + self.progressRing.stop() + self.progressRing.setVisible(False) self.manga_area.add_items(items) self.manga_area.update_items() @@ -52,6 +57,8 @@ def get_content(self): self._get_content_thread.terminate() self._get_content_thread.wait() self.manga_area.delete_items() + self.progressRing.setVisible(True) + self.progressRing.start() self._get_content_thread.start() def _get_content_thread_func(self): diff --git a/nlightreader/widgets/NlightTemplates/Facial.py b/nlightreader/widgets/NlightTemplates/Facial.py index 23aaf36..54dd99b 100644 --- a/nlightreader/widgets/NlightTemplates/Facial.py +++ b/nlightreader/widgets/NlightTemplates/Facial.py @@ -23,7 +23,9 @@ def __init__(self, parent=None): self.setObjectName("FormFacial") - self.manga_area = MangaArea(self.ui.items_layout) + self.manga_area = MangaArea() + self.manga_area.install(self.ui.items_layout) + self.manga_area.get_content_widget().layout().addWidget(self.progressRing) self.ui.next_btn.clicked.connect(self.turn_page_next) self.ui.prev_btn.clicked.connect(self.turn_page_prev) diff --git a/nlightreader/widgets/NlightTemplates/Library.py b/nlightreader/widgets/NlightTemplates/Library.py index 16e8181..51a18f2 100644 --- a/nlightreader/widgets/NlightTemplates/Library.py +++ b/nlightreader/widgets/NlightTemplates/Library.py @@ -18,7 +18,9 @@ def __init__(self, parent=None): self.setObjectName("FormLibrary") - self.manga_area = MangaArea(self.ui.items_layout) + self.manga_area = MangaArea() + self.manga_area.install(self.ui.items_layout) + self.manga_area.get_content_widget().layout().addWidget(self.progressRing) self.ui.planned_btn.clicked.connect(lambda: self.change_list(Nl.LibList.planned)) self.ui.reading_btn.clicked.connect(lambda: self.change_list(Nl.LibList.reading)) diff --git a/nlightreader/widgets/NlightTemplates/Shikimori.py b/nlightreader/widgets/NlightTemplates/Shikimori.py index c7c4426..7db59f9 100644 --- a/nlightreader/widgets/NlightTemplates/Shikimori.py +++ b/nlightreader/widgets/NlightTemplates/Shikimori.py @@ -23,7 +23,9 @@ def __init__(self, parent=None): self.setObjectName("FormShikimori") - self.manga_area = MangaArea(self.ui.items_layout) + self.manga_area = MangaArea() + self.manga_area.install(self.ui.items_layout) + self.manga_area.get_content_widget().layout().addWidget(self.progressRing) self.ui.planned_btn.clicked.connect(lambda: self.change_list(Nl.LibList.planned)) self.ui.reading_btn.clicked.connect(lambda: self.change_list(Nl.LibList.reading))