mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 07:34:16 +02:00
screenshots button
This commit is contained in:
@@ -417,6 +417,12 @@ class AppsTable(QTableWidget):
|
||||
|
||||
item.addWidget(IconButton(icon_path=resource.get_path('img/app_info.svg'), action=get_info, background='#2E68D3', tooltip=self.i18n['action.info.tooltip']))
|
||||
|
||||
if pkg.model.has_screenshots():
|
||||
def get_screenshots():
|
||||
self.window.get_screenshots(pkg)
|
||||
|
||||
item.addWidget(IconButton(icon_path=resource.get_path('img/camera.svg'), action=get_screenshots, background='purple', tooltip=self.i18n['action.screenshots.tooltip']))
|
||||
|
||||
def handle_click():
|
||||
self.show_pkg_settings(pkg)
|
||||
|
||||
|
||||
30
bauh/view/qt/screenshots.py
Normal file
30
bauh/view/qt/screenshots.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from typing import List
|
||||
|
||||
from PyQt5.QtGui import QIcon, QPixmap
|
||||
from PyQt5.QtWidgets import QDialog, QLabel, QVBoxLayout
|
||||
|
||||
from bauh.api.abstract.cache import MemoryCache
|
||||
from bauh.view.qt.view_model import PackageView
|
||||
|
||||
|
||||
class ScreenshotsDialog(QDialog):
|
||||
|
||||
def __init__(self, pkg: PackageView, icon_cache: MemoryCache, i18n: dict, screenshots: List[QPixmap]):
|
||||
super(ScreenshotsDialog, self).__init__()
|
||||
self.setWindowTitle(str(pkg))
|
||||
|
||||
icon_data = icon_cache.get(pkg.model.icon_url)
|
||||
|
||||
if icon_data and icon_data.get('icon'):
|
||||
self.setWindowIcon(icon_data.get('icon'))
|
||||
else:
|
||||
self.setWindowIcon(QIcon(pkg.model.get_type_icon_path()))
|
||||
|
||||
self.setLayout(QVBoxLayout())
|
||||
|
||||
if screenshots:
|
||||
lb = QLabel()
|
||||
lb.setPixmap(screenshots[0])
|
||||
self.layout().addWidget(lb)
|
||||
|
||||
self.adjustSize()
|
||||
@@ -5,6 +5,7 @@ from typing import List, Type, Set
|
||||
|
||||
import requests
|
||||
from PyQt5.QtCore import QThread, pyqtSignal
|
||||
from PyQt5.QtGui import QImage, QPixmap
|
||||
|
||||
from bauh.api.abstract.cache import MemoryCache
|
||||
from bauh.api.abstract.controller import SoftwareManager
|
||||
@@ -12,6 +13,7 @@ from bauh.api.abstract.handler import ProcessWatcher
|
||||
from bauh.api.abstract.model import PackageStatus, SoftwarePackage, PackageAction
|
||||
from bauh.api.abstract.view import InputViewComponent, MessageType
|
||||
from bauh.api.exception import NoInternetException
|
||||
from bauh.api.http import HttpClient
|
||||
from bauh.view.qt import commons
|
||||
from bauh.view.qt.view_model import PackageView
|
||||
|
||||
@@ -480,3 +482,32 @@ class CustomAction(AsyncAction):
|
||||
self.pkg = None
|
||||
self.custom_action = None
|
||||
self.root_password = None
|
||||
|
||||
|
||||
class GetScreenshots(AsyncAction):
|
||||
|
||||
def __init__(self, manager: SoftwareManager, http_client: HttpClient, pkg: PackageView = None):
|
||||
super(GetScreenshots, self).__init__()
|
||||
self.pkg = pkg
|
||||
self.manager = manager
|
||||
self.http_client = http_client
|
||||
|
||||
def run(self):
|
||||
if self.pkg:
|
||||
imgs = []
|
||||
screenshots = self.manager.get_screenshots(self.pkg.model)
|
||||
|
||||
if screenshots:
|
||||
for url in screenshots:
|
||||
res = self.http_client.get(url)
|
||||
|
||||
if res and res.status_code == 200:
|
||||
pixmap = QPixmap()
|
||||
pixmap.loadFromData(res.content)
|
||||
imgs.append(pixmap)
|
||||
break # TODO load all
|
||||
|
||||
self.notify_finished({'pkg': self.pkg, 'screenshots': imgs})
|
||||
|
||||
self.pkg = None
|
||||
|
||||
|
||||
@@ -14,8 +14,11 @@ from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager
|
||||
from bauh.api.abstract.model import SoftwarePackage, PackageAction
|
||||
from bauh.api.abstract.view import MessageType
|
||||
from bauh.api.http import HttpClient
|
||||
from bauh.commons.html import bold
|
||||
from bauh.view.core.config import Configuration
|
||||
from bauh.view.core.controller import GenericSoftwareManager
|
||||
from bauh.view.qt.screenshots import ScreenshotsDialog
|
||||
from bauh.view.util import util, resource
|
||||
from bauh.view.qt import dialog, commons, qt_utils
|
||||
from bauh.view.qt.about import AboutDialog
|
||||
@@ -29,7 +32,7 @@ from bauh.view.qt.root import is_root, ask_root_password
|
||||
from bauh.view.qt.styles import StylesComboBox
|
||||
from bauh.view.qt.thread import UpdateSelectedApps, RefreshApps, UninstallApp, DowngradeApp, GetAppInfo, \
|
||||
GetAppHistory, SearchPackages, InstallPackage, AnimateProgress, VerifyModels, FindSuggestions, ListWarnings, \
|
||||
AsyncAction, LaunchApp, ApplyFilters, CustomAction
|
||||
AsyncAction, LaunchApp, ApplyFilters, CustomAction, GetScreenshots
|
||||
from bauh.view.qt.view_model import PackageView
|
||||
from bauh.view.qt.view_utils import load_icon
|
||||
|
||||
@@ -48,7 +51,7 @@ class ManageWindow(QWidget):
|
||||
|
||||
def __init__(self, i18n: dict, icon_cache: MemoryCache, manager: SoftwareManager, disk_cache: bool,
|
||||
download_icons: bool, screen_size, suggestions: bool, display_limit: int, config: Configuration,
|
||||
context: ApplicationContext, notifications: bool, tray_icon=None):
|
||||
context: ApplicationContext, notifications: bool, http_client: HttpClient, tray_icon=None):
|
||||
super(ManageWindow, self).__init__()
|
||||
self.i18n = i18n
|
||||
self.manager = manager
|
||||
@@ -65,6 +68,7 @@ class ManageWindow(QWidget):
|
||||
self.config = config
|
||||
self.context = context
|
||||
self.notifications = notifications
|
||||
self.http_client = http_client
|
||||
|
||||
self.icon_app = QIcon(resource.get_path('img/logo.svg'))
|
||||
self.resize(ManageWindow.__BASE_HEIGHT__, ManageWindow.__BASE_HEIGHT__)
|
||||
@@ -213,6 +217,7 @@ class ManageWindow(QWidget):
|
||||
self.thread_suggestions = self._bind_async_action(FindSuggestions(man=self.manager), finished_call=self._finish_search, only_finished=True)
|
||||
self.thread_run_app = self._bind_async_action(LaunchApp(self.manager), finished_call=self._finish_run_app, only_finished=False)
|
||||
self.thread_custom_action = self._bind_async_action(CustomAction(manager=self.manager), finished_call=self._finish_custom_action)
|
||||
self.thread_screenshots = self._bind_async_action(GetScreenshots(self.manager, http_client), finished_call=self._finish_get_screenshots)
|
||||
|
||||
self.thread_apply_filters = ApplyFilters()
|
||||
self.thread_apply_filters.signal_finished.connect(self._finish_apply_filters_async)
|
||||
@@ -811,6 +816,24 @@ class ManageWindow(QWidget):
|
||||
self.thread_get_info.app = pkg
|
||||
self.thread_get_info.start()
|
||||
|
||||
def get_screenshots(self, pkg: PackageView):
|
||||
self._handle_console_option(False)
|
||||
self._begin_action(self.i18n['manage_window.status.screenshots'].format(bold(pkg.model.name)))
|
||||
|
||||
self.thread_screenshots.pkg = pkg
|
||||
self.thread_screenshots.start()
|
||||
|
||||
def _finish_get_screenshots(self, res: dict):
|
||||
self.finish_action()
|
||||
|
||||
if res.get('screenshots'):
|
||||
diag = ScreenshotsDialog(pkg=res['pkg'], icon_cache=self.icon_cache, i18n=self.i18n, screenshots=res['screenshots'])
|
||||
diag.exec_()
|
||||
else:
|
||||
dialog.show_message(title=self.i18n['error'],
|
||||
body=self.i18n['popup.screenshots.no_screenshot.body'].format(bold(res['pkg'].model.name)),
|
||||
type_=MessageType.ERROR)
|
||||
|
||||
def get_app_history(self, app: dict):
|
||||
self._handle_console_option(False)
|
||||
self._begin_action(self.i18n['manage_window.status.history'])
|
||||
|
||||
Reference in New Issue
Block a user