Skip to content

Commit

Permalink
added Progress Ring
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonzorn committed Apr 10, 2024
1 parent d0cd53b commit b20731e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
19 changes: 8 additions & 11 deletions nlightreader/widgets/NlightContainers/manga_area.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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)

Expand All @@ -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()
Expand Down Expand Up @@ -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
13 changes: 10 additions & 3 deletions nlightreader/widgets/NlightTemplates/BaseWidget.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion nlightreader/widgets/NlightTemplates/Facial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion nlightreader/widgets/NlightTemplates/Library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion nlightreader/widgets/NlightTemplates/Shikimori.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit b20731e

Please sign in to comment.