[ui] feature: themes

This commit is contained in:
Vinicius Moreira
2020-11-27 15:52:57 -03:00
parent 813c812030
commit 60228eec97
176 changed files with 11941 additions and 2985 deletions

View File

@@ -4,11 +4,12 @@ from typing import List
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QPixmap, QCursor
from PyQt5.QtWidgets import QDialog, QLabel, QPushButton, QToolBar, QVBoxLayout, QProgressBar, QApplication
from PyQt5.QtWidgets import QDialog, QLabel, QPushButton, QVBoxLayout, QProgressBar, QApplication, QWidget, \
QSizePolicy, QHBoxLayout
from bauh.api.abstract.cache import MemoryCache
from bauh.api.http import HttpClient
from bauh.view.qt import qt_utils, styles
from bauh.view.qt import qt_utils
from bauh.view.qt.components import new_spacer
from bauh.view.qt.thread import AnimateProgress
from bauh.view.qt.view_model import PackageView
@@ -17,9 +18,6 @@ from bauh.view.util.translation import I18n
class ScreenshotsDialog(QDialog):
MAX_HEIGHT = 600
MAX_WIDTH = 800
def __init__(self, pkg: PackageView, http_client: HttpClient, icon_cache: MemoryCache, i18n: I18n, screenshots: List[QPixmap], logger: logging.Logger):
super(ScreenshotsDialog, self).__init__()
self.setWindowTitle(str(pkg))
@@ -27,12 +25,11 @@ class ScreenshotsDialog(QDialog):
self.logger = logger
self.loaded_imgs = []
self.download_threads = []
self.resize(1280, 720)
self.i18n = i18n
self.http_client = http_client
self.progress_bar = QProgressBar()
self.progress_bar.setObjectName('progress_screenshots')
self.progress_bar.setCursor(QCursor(Qt.WaitCursor))
self.progress_bar.setStyleSheet(styles.PROGRESS_BAR)
self.progress_bar.setMaximumHeight(10 if QApplication.instance().style().objectName().lower() == 'windows' else 6)
self.progress_bar.setTextVisible(False)
self.thread_progress = AnimateProgress()
@@ -50,39 +47,48 @@ class ScreenshotsDialog(QDialog):
self.setWindowIcon(QIcon(pkg.model.get_type_icon_path()))
self.setLayout(QVBoxLayout())
self.layout().addWidget(new_spacer())
self.img = QLabel()
self.img.setObjectName('image')
self.layout().addWidget(self.img)
self.layout().addWidget(new_spacer())
self.bottom_bar = QToolBar()
self.container_buttons = QWidget()
self.container_buttons.setObjectName('buttons_container')
self.container_buttons.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
self.container_buttons.setContentsMargins(0, 0, 0, 0)
self.container_buttons.setLayout(QHBoxLayout())
self.bt_back = QPushButton(' < ' + self.i18n['screenshots.bt_back.label'].capitalize())
self.bt_back.setObjectName('back')
self.bt_back.setCursor(QCursor(Qt.PointingHandCursor))
self.bt_back.clicked.connect(self.back)
self.ref_bt_back = self.bottom_bar.addWidget(self.bt_back)
self.bottom_bar.addWidget(new_spacer(50))
self.container_buttons.layout().addWidget(self.bt_back)
self.container_buttons.layout().addWidget(new_spacer())
self.img_label = QLabel()
self.img_label.setCursor(QCursor(Qt.WaitCursor))
self.img_label.setStyleSheet('QLabel { font-weight: bold; text-align: center }')
self.ref_img_label = self.bottom_bar.addWidget(self.img_label)
self.ref_img_label.setVisible(False)
self.ref_progress_bar = self.bottom_bar.addWidget(self.progress_bar)
self.bottom_bar.addWidget(new_spacer(50))
self.container_buttons.layout().addWidget(self.progress_bar)
self.container_buttons.layout().addWidget(new_spacer())
self.bt_next = QPushButton(self.i18n['screenshots.bt_next.label'].capitalize() + ' > ')
self.bt_next.setObjectName('next')
self.bt_next.setCursor(QCursor(Qt.PointingHandCursor))
self.bt_next.clicked.connect(self.next)
self.ref_bt_next = self.bottom_bar.addWidget(self.bt_next)
self.container_buttons.layout().addWidget(self.bt_next)
self.layout().addWidget(self.bottom_bar)
self.layout().addWidget(self.container_buttons)
self.img_idx = 0
screen_size = QApplication.primaryScreen().size()
self.max_img_width = int(screen_size.width() * 0.585651537)
self.max_img_height = int(screen_size.height() * 0.78125)
for idx, s in enumerate(self.screenshots):
t = Thread(target=self._download_img, args=(idx, s), daemon=True)
t.start()
self.resize(self.max_img_width, self.max_img_height)
self._load_img()
qt_utils.centralize(self)
def _update_progress(self, val: int):
self.progress_bar.setValue(val)
@@ -92,32 +98,28 @@ class ScreenshotsDialog(QDialog):
img = self.loaded_imgs[self.img_idx]
if isinstance(img, QPixmap):
self.img_label.setText('')
self.img.setText('')
self.img.setPixmap(img)
else:
self.img_label.setText(img)
self.img.setText(img)
self.img.setPixmap(QPixmap())
self.img.unsetCursor()
self.thread_progress.stop = True
self.ref_progress_bar.setVisible(False)
self.ref_img_label.setVisible(True)
self.progress_bar.setVisible(False)
else:
self.img.setPixmap(QPixmap())
self.img.setCursor(QCursor(Qt.WaitCursor))
self.ref_img_label.setVisible(False)
self.ref_progress_bar.setVisible(True)
self.img.setText('{}...'.format(self.i18n['screenshots.image.loading']))
self.progress_bar.setVisible(True)
self.thread_progress.start()
if len(self.screenshots) == 1:
self.ref_bt_back.setVisible(False)
self.ref_bt_next.setVisible(False)
self.bt_back.setVisible(False)
self.bt_next.setVisible(False)
else:
self.ref_bt_back.setEnabled(self.img_idx != 0)
self.ref_bt_next.setEnabled(self.img_idx != len(self.screenshots) - 1)
self.adjustSize()
qt_utils.centralize(self)
self.bt_back.setEnabled(self.img_idx != 0)
self.bt_next.setEnabled(self.img_idx != len(self.screenshots) - 1)
def _download_img(self, idx: int, url: str):
self.logger.info('Downloading image [{}] from {}'.format(idx, url))
@@ -133,8 +135,8 @@ class ScreenshotsDialog(QDialog):
pixmap = QPixmap()
pixmap.loadFromData(res.content)
if pixmap.size().height() > self.MAX_HEIGHT or pixmap.size().width() > self.MAX_WIDTH:
pixmap = pixmap.scaled(self.MAX_WIDTH, self.MAX_HEIGHT, Qt.KeepAspectRatio, Qt.SmoothTransformation)
if pixmap.size().height() > self.max_img_height or pixmap.size().width() > self.max_img_width:
pixmap = pixmap.scaled(self.max_img_width, self.max_img_height, Qt.KeepAspectRatio, Qt.SmoothTransformation)
self.loaded_imgs.append(pixmap)