add get_pixmap function
This commit is contained in:
parent
4cfe2bf336
commit
258fdabfec
|
@ -24,3 +24,5 @@ else:
|
|||
data_dir = os.path.expanduser("~/.local/share/rare/")
|
||||
if not os.path.exists(data_dir):
|
||||
os.makedirs(data_dir)
|
||||
|
||||
image_dir = os.path.join(data_dir, "images")
|
||||
|
|
|
@ -6,6 +6,7 @@ from PyQt5.QtWidgets import QDialog
|
|||
from requests.exceptions import ConnectionError
|
||||
|
||||
from custom_legendary.core import LegendaryCore
|
||||
from rare import image_dir
|
||||
from rare.components.dialogs.login import LoginDialog
|
||||
from rare.ui.components.dialogs.launch_dialog import Ui_LaunchDialog
|
||||
from rare.utils.utils import download_images
|
||||
|
@ -62,8 +63,8 @@ class LaunchDialog(QDialog, Ui_LaunchDialog):
|
|||
|
||||
def launch(self):
|
||||
# self.core = core
|
||||
if not os.path.exists(p := os.path.expanduser("~/.cache/rare/images")):
|
||||
os.makedirs(p)
|
||||
if not os.path.exists(image_dir):
|
||||
os.makedirs(image_dir)
|
||||
|
||||
if not self.offline:
|
||||
self.image_info.setText(self.tr("Downloading Images"))
|
||||
|
|
|
@ -2,7 +2,7 @@ import os
|
|||
import platform
|
||||
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
from PyQt5.QtGui import QPixmap, QKeyEvent
|
||||
from PyQt5.QtGui import QKeyEvent
|
||||
from PyQt5.QtWidgets import QWidget, QTabWidget, QMessageBox
|
||||
from qtawesome import icon
|
||||
|
||||
|
@ -14,7 +14,7 @@ from rare.ui.components.tabs.games.game_info.game_info import Ui_GameInfo
|
|||
from rare.utils.extra_widgets import SideTabBar
|
||||
from rare.utils.legendary_utils import VerifyThread
|
||||
from rare.utils.steam_grades import SteamWorker
|
||||
from rare.utils.utils import IMAGE_DIR, get_size
|
||||
from rare.utils.utils import get_size, get_pixmap
|
||||
|
||||
|
||||
class InfoTabs(QTabWidget):
|
||||
|
@ -133,19 +133,11 @@ class GameInfo(QWidget, Ui_GameInfo):
|
|||
|
||||
self.game_title.setText(f"<h2>{self.game.app_title}</h2>")
|
||||
|
||||
if os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/FinalArt.png"):
|
||||
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/FinalArt.png")
|
||||
elif os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxTall.png"):
|
||||
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxTall.png")
|
||||
elif os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxLogo.png"):
|
||||
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxLogo.png")
|
||||
else:
|
||||
# logger.warning(f"No Image found: {self.game.title}")
|
||||
pixmap = None
|
||||
if pixmap:
|
||||
w = 200
|
||||
pixmap = pixmap.scaled(w, int(w * 4 / 3))
|
||||
self.image.setPixmap(pixmap)
|
||||
pixmap = get_pixmap(app_name)
|
||||
|
||||
w = 200
|
||||
pixmap = pixmap.scaled(w, int(w * 4 / 3))
|
||||
self.image.setPixmap(pixmap)
|
||||
|
||||
self.app_name.setText(self.game.app_name)
|
||||
self.version.setText(self.game.app_version)
|
||||
|
|
|
@ -3,7 +3,7 @@ import os
|
|||
import platform
|
||||
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
from PyQt5.QtGui import QPixmap, QKeyEvent
|
||||
from PyQt5.QtGui import QKeyEvent
|
||||
from PyQt5.QtWidgets import QWidget, QTabWidget, QTreeView
|
||||
from qtawesome import icon
|
||||
|
||||
|
@ -13,7 +13,7 @@ from rare.ui.components.tabs.games.game_info.game_info import Ui_GameInfo
|
|||
from rare.utils.extra_widgets import SideTabBar
|
||||
from rare.utils.json_formatter import QJsonModel
|
||||
from rare.utils.steam_grades import SteamWorker
|
||||
from rare.utils.utils import IMAGE_DIR
|
||||
from rare.utils.utils import get_pixmap
|
||||
|
||||
|
||||
class UninstalledTabInfo(QTabWidget):
|
||||
|
@ -84,19 +84,10 @@ class UninstalledInfo(QWidget, Ui_GameInfo):
|
|||
|
||||
self.game_title.setText(f"<h2>{self.game.app_title}</h2>")
|
||||
|
||||
if os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/FinalArt.png"):
|
||||
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/FinalArt.png")
|
||||
elif os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxTall.png"):
|
||||
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxTall.png")
|
||||
elif os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxLogo.png"):
|
||||
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxLogo.png")
|
||||
else:
|
||||
# logger.warning(f"No Image found: {self.game.title}")
|
||||
pixmap = None
|
||||
if pixmap:
|
||||
w = 200
|
||||
pixmap = pixmap.scaled(w, int(w * 4 / 3))
|
||||
self.image.setPixmap(pixmap)
|
||||
pixmap = get_pixmap(app_name)
|
||||
w = 200
|
||||
pixmap = pixmap.scaled(w, int(w * 4 / 3))
|
||||
self.image.setPixmap(pixmap)
|
||||
|
||||
self.app_name.setText(self.game.app_name)
|
||||
self.version.setText(self.game.app_version)
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
import os
|
||||
from logging import getLogger
|
||||
|
||||
import psutil
|
||||
from PyQt5.QtCore import Qt, pyqtSignal, QSettings, QTimer
|
||||
from PyQt5.QtGui import QPixmap
|
||||
from PyQt5.QtWidgets import QScrollArea, QWidget, QLabel, QVBoxLayout, QStackedWidget
|
||||
|
||||
from custom_legendary.core import LegendaryCore
|
||||
from rare import data_dir
|
||||
from rare.components.tabs.games.game_widgets.base_installed_widget import BaseInstalledWidget
|
||||
from rare.components.tabs.games.game_widgets.installed_icon_widget import GameWidgetInstalled
|
||||
from rare.components.tabs.games.game_widgets.installed_list_widget import InstalledListWidget
|
||||
|
@ -15,7 +12,7 @@ from rare.components.tabs.games.game_widgets.uninstalled_icon_widget import Icon
|
|||
from rare.components.tabs.games.game_widgets.uninstalled_list_widget import ListWidgetUninstalled
|
||||
from rare.utils.extra_widgets import FlowLayout
|
||||
from rare.utils.models import InstallOptionsModel
|
||||
from rare.utils.utils import download_image
|
||||
from rare.utils.utils import download_image, get_uninstalled_pixmap, get_pixmap
|
||||
|
||||
logger = getLogger("Game list")
|
||||
|
||||
|
@ -74,7 +71,6 @@ class GameList(QStackedWidget):
|
|||
self.list_layout = QVBoxLayout()
|
||||
self.list_layout.addWidget(QLabel(self.info_text))
|
||||
|
||||
self.IMAGE_DIR = os.path.join(data_dir, "images")
|
||||
self.updates = []
|
||||
self.widgets = {}
|
||||
if not self.offline:
|
||||
|
@ -128,17 +124,11 @@ class GameList(QStackedWidget):
|
|||
self.filter(filter_games)
|
||||
|
||||
def add_uninstalled_widget(self, game):
|
||||
if os.path.exists(f"{self.IMAGE_DIR}/{game.app_name}/UninstalledArt.png"):
|
||||
pixmap = QPixmap(f"{self.IMAGE_DIR}/{game.app_name}/UninstalledArt.png")
|
||||
|
||||
if pixmap.isNull():
|
||||
logger.info(game.app_title + " has a corrupt image.")
|
||||
download_image(game, force=True)
|
||||
pixmap = QPixmap(f"{self.IMAGE_DIR}/{game.app_name}/UninstalledArt.png")
|
||||
else:
|
||||
logger.warning(f"No Image found: {game.app_title}")
|
||||
pixmap = get_uninstalled_pixmap(game.app_name)
|
||||
if pixmap.isNull():
|
||||
logger.info(game.app_title + " has a corrupt image. Reloading...")
|
||||
download_image(game, force=True)
|
||||
pixmap = QPixmap(f"{self.IMAGE_DIR}/{game.app_name}/UninstalledArt.png")
|
||||
pixmap = get_uninstalled_pixmap(game.app_name)
|
||||
|
||||
icon_widget = IconWidgetUninstalled(game, self.core, pixmap)
|
||||
icon_widget.show_uninstalled_info.connect(self.show_install_info)
|
||||
|
@ -151,20 +141,12 @@ class GameList(QStackedWidget):
|
|||
return icon_widget, list_widget
|
||||
|
||||
def add_installed_widget(self, igame):
|
||||
if os.path.exists(os.path.join(self.IMAGE_DIR, igame.app_name, "FinalArt.png")):
|
||||
pixmap = QPixmap(os.path.exists(os.path.join(self.IMAGE_DIR, igame.app_name, "FinalArt.png")))
|
||||
elif os.path.exists(os.path.join(self.IMAGE_DIR, igame.app_name, "DieselGameBoxTall.png")):
|
||||
pixmap = QPixmap(f"{self.IMAGE_DIR}/{igame.app_name}/DieselGameBoxTall.png")
|
||||
elif os.path.exists(os.path.join(self.IMAGE_DIR, igame.app_name, "DieselGameBoxLogo.png")):
|
||||
pixmap = QPixmap(os.path.join(self.IMAGE_DIR, igame.app_name, "DieselGameBoxLogo.png"))
|
||||
else:
|
||||
logger.warning(f"No Image found: {igame.title}")
|
||||
pixmap = QPixmap()
|
||||
pixmap = get_pixmap(igame.app_name)
|
||||
|
||||
if pixmap.isNull():
|
||||
logger.info(igame.title + " has a corrupt image.")
|
||||
download_image(self.core.get_game(igame.app_name), force=True)
|
||||
pixmap = QPixmap(f"{self.IMAGE_DIR}/{igame.app_name}/DieselGameBoxTall.png")
|
||||
pixmap = get_pixmap(igame.app_name)
|
||||
|
||||
icon_widget = GameWidgetInstalled(igame, self.core, pixmap, self.offline)
|
||||
# self.icon_layout.addWidget(icon_widget)
|
||||
|
@ -298,7 +280,6 @@ class GameList(QStackedWidget):
|
|||
|
||||
# QWidget().setLayout(self.icon_layout)
|
||||
|
||||
|
||||
igame = self.core.get_installed_game(app_name)
|
||||
self.add_installed_widget(igame)
|
||||
|
||||
|
|
|
@ -8,26 +8,25 @@ from logging import getLogger
|
|||
import requests
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
from PyQt5.QtCore import pyqtSignal, QLocale, QSettings
|
||||
from PyQt5.QtGui import QPalette, QColor
|
||||
from PyQt5.QtGui import QPalette, QColor, QPixmap
|
||||
|
||||
# Windows
|
||||
|
||||
if platform.system() == "Windows":
|
||||
from win32com.client import Dispatch
|
||||
|
||||
from rare import languages_path, resources_path
|
||||
from rare import languages_path, resources_path, image_dir
|
||||
# Mac not supported
|
||||
|
||||
from custom_legendary.core import LegendaryCore
|
||||
|
||||
logger = getLogger("Utils")
|
||||
s = QSettings("Rare", "Rare")
|
||||
IMAGE_DIR = s.value("img_dir", os.path.expanduser("~/.cache/rare/images"), type=str)
|
||||
|
||||
|
||||
def download_images(signal: pyqtSignal, core: LegendaryCore):
|
||||
if not os.path.isdir(IMAGE_DIR):
|
||||
os.makedirs(IMAGE_DIR)
|
||||
if not os.path.isdir(image_dir):
|
||||
os.makedirs(image_dir)
|
||||
logger.info("Create Image dir")
|
||||
|
||||
# Download Images
|
||||
|
@ -40,60 +39,60 @@ def download_images(signal: pyqtSignal, core: LegendaryCore):
|
|||
try:
|
||||
download_image(game)
|
||||
except json.decoder.JSONDecodeError:
|
||||
shutil.rmtree(f"{IMAGE_DIR}/{game.app_name}")
|
||||
shutil.rmtree(f"{image_dir}/{game.app_name}")
|
||||
download_image(game)
|
||||
signal.emit(i / len(game_list) * 100)
|
||||
|
||||
|
||||
def download_image(game, force=False):
|
||||
if force and os.path.exists(f"{IMAGE_DIR}/{game.app_name}"):
|
||||
shutil.rmtree(f"{IMAGE_DIR}/{game.app_name}")
|
||||
if not os.path.isdir(f"{IMAGE_DIR}/" + game.app_name):
|
||||
os.mkdir(f"{IMAGE_DIR}/" + game.app_name)
|
||||
if force and os.path.exists(f"{image_dir}/{game.app_name}"):
|
||||
shutil.rmtree(f"{image_dir}/{game.app_name}")
|
||||
if not os.path.isdir(f"{image_dir}/" + game.app_name):
|
||||
os.mkdir(f"{image_dir}/" + game.app_name)
|
||||
|
||||
# to git picture updates
|
||||
if not os.path.isfile(f"{IMAGE_DIR}/{game.app_name}/image.json"):
|
||||
if not os.path.isfile(f"{image_dir}/{game.app_name}/image.json"):
|
||||
json_data = {"DieselGameBoxTall": None, "DieselGameBoxLogo": None, "Thumbnail": None}
|
||||
else:
|
||||
json_data = json.load(open(f"{IMAGE_DIR}/{game.app_name}/image.json", "r"))
|
||||
json_data = json.load(open(f"{image_dir}/{game.app_name}/image.json", "r"))
|
||||
# Download
|
||||
for image in game.metadata["keyImages"]:
|
||||
if image["type"] == "DieselGameBoxTall" or image["type"] == "DieselGameBoxLogo" or image["type"] == "Thumbnail":
|
||||
if image["type"] not in json_data.keys():
|
||||
json_data[image["type"]] = None
|
||||
if json_data[image["type"]] != image["md5"] or not os.path.isfile(
|
||||
f"{IMAGE_DIR}/{game.app_name}/{image['type']}.png"):
|
||||
f"{image_dir}/{game.app_name}/{image['type']}.png"):
|
||||
# Download
|
||||
json_data[image["type"]] = image["md5"]
|
||||
# os.remove(f"{IMAGE_DIR}/{game.app_name}/{image['type']}.png")
|
||||
json.dump(json_data, open(f"{IMAGE_DIR}/{game.app_name}/image.json", "w"))
|
||||
# os.remove(f"{image_dir}/{game.app_name}/{image['type']}.png")
|
||||
json.dump(json_data, open(f"{image_dir}/{game.app_name}/image.json", "w"))
|
||||
logger.info(f"Download Image for Game: {game.app_title}")
|
||||
url = image["url"]
|
||||
with open(f"{IMAGE_DIR}/{game.app_name}/{image['type']}.png", "wb") as f:
|
||||
with open(f"{image_dir}/{game.app_name}/{image['type']}.png", "wb") as f:
|
||||
f.write(requests.get(url).content)
|
||||
try:
|
||||
img = Image.open(f"{IMAGE_DIR}/{game.app_name}/{image['type']}.png")
|
||||
img = Image.open(f"{image_dir}/{game.app_name}/{image['type']}.png")
|
||||
img = img.resize((200, int(200 * 4 / 3)))
|
||||
img.save(f"{IMAGE_DIR}/{game.app_name}/{image['type']}.png")
|
||||
img.save(f"{image_dir}/{game.app_name}/{image['type']}.png")
|
||||
except UnidentifiedImageError as e:
|
||||
logger.warning(e)
|
||||
|
||||
# scale and grey
|
||||
if not os.path.exists(os.path.join(IMAGE_DIR, game.app_name + '/UninstalledArt.png')):
|
||||
if not os.path.exists(os.path.join(image_dir, game.app_name + '/UninstalledArt.png')):
|
||||
|
||||
if os.path.exists(os.path.join(IMAGE_DIR, f"{game.app_name}/DieselGameBoxTall.png")):
|
||||
# finalArt = Image.open(f'{IMAGE_DIR}/' + game.app_name + '/DieselGameBoxTall.png')
|
||||
# finalArt.save(f'{IMAGE_DIR}/{game.app_name}/FinalArt.png')
|
||||
if os.path.exists(os.path.join(image_dir, f"{game.app_name}/DieselGameBoxTall.png")):
|
||||
# finalArt = Image.open(f'{image_dir}/' + game.app_name + '/DieselGameBoxTall.png')
|
||||
# finalArt.save(f'{image_dir}/{game.app_name}/FinalArt.png')
|
||||
# And same with the grayscale one
|
||||
|
||||
bg = Image.open(os.path.join(IMAGE_DIR, f"{game.app_name}/DieselGameBoxTall.png"))
|
||||
bg = Image.open(os.path.join(image_dir, f"{game.app_name}/DieselGameBoxTall.png"))
|
||||
uninstalledArt = bg.convert('L')
|
||||
uninstalledArt = uninstalledArt.resize((200, int(200 * 4 / 3)))
|
||||
uninstalledArt.save(f'{IMAGE_DIR}/{game.app_name}/UninstalledArt.png')
|
||||
elif os.path.isfile(f"{IMAGE_DIR}/{game.app_name}/DieselGameBoxLogo.png"):
|
||||
bg: Image.Image = Image.open(f"{IMAGE_DIR}/{game.app_name}/DieselGameBoxLogo.png")
|
||||
uninstalledArt.save(f'{image_dir}/{game.app_name}/UninstalledArt.png')
|
||||
elif os.path.isfile(f"{image_dir}/{game.app_name}/DieselGameBoxLogo.png"):
|
||||
bg: Image.Image = Image.open(f"{image_dir}/{game.app_name}/DieselGameBoxLogo.png")
|
||||
bg = bg.resize((int(bg.size[1] * 3 / 4), bg.size[1]))
|
||||
logo = Image.open(f'{IMAGE_DIR}/{game.app_name}/DieselGameBoxLogo.png').convert('RGBA')
|
||||
logo = Image.open(f'{image_dir}/{game.app_name}/DieselGameBoxLogo.png').convert('RGBA')
|
||||
wpercent = ((bg.size[0] * (3 / 4)) / float(logo.size[0]))
|
||||
hsize = int((float(logo.size[1]) * float(wpercent)))
|
||||
logo = logo.resize((int(bg.size[0] * (3 / 4)), hsize), Image.ANTIALIAS)
|
||||
|
@ -104,16 +103,16 @@ def download_image(game, force=False):
|
|||
# finalArt = bg.copy()
|
||||
# finalArt.paste(logo, (pasteX, pasteY), logo)
|
||||
# Write out the file
|
||||
# finalArt.save(f'{IMAGE_DIR}/' + game.app_name + '/FinalArt.png')
|
||||
# finalArt.save(f'{image_dir}/' + game.app_name + '/FinalArt.png')
|
||||
logoCopy = logo.copy()
|
||||
logoCopy.putalpha(int(256 * 3 / 4))
|
||||
logo.paste(logoCopy, logo)
|
||||
uninstalledArt = bg.copy()
|
||||
uninstalledArt.paste(logo, (pasteX, pasteY), logo)
|
||||
uninstalledArt = uninstalledArt.convert('L')
|
||||
uninstalledArt.save(f'{IMAGE_DIR}/' + game.app_name + '/UninstalledArt.png')
|
||||
uninstalledArt.save(f'{image_dir}/' + game.app_name + '/UninstalledArt.png')
|
||||
else:
|
||||
logger.warning(f"File {IMAGE_DIR}/{game.app_name}/DieselGameBoxTall.png doesn't exist")
|
||||
logger.warning(f"File {image_dir}/{game.app_name}/DieselGameBoxTall.png doesn't exist")
|
||||
|
||||
|
||||
def get_lang():
|
||||
|
@ -351,3 +350,21 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop") -
|
|||
|
||||
elif platform.system() == "Darwin":
|
||||
return False
|
||||
|
||||
|
||||
def get_pixmap(app_name: str) -> QPixmap:
|
||||
for img in ["FinalArt.png", "DieselGameBoxTall.png", "DieselGameBoxLogo.png"]:
|
||||
if os.path.exists(image := os.path.join(image_dir, app_name, img)):
|
||||
pixmap = QPixmap(image)
|
||||
break
|
||||
else:
|
||||
pixmap = QPixmap()
|
||||
return pixmap
|
||||
|
||||
|
||||
def get_uninstalled_pixmap(app_name: str) -> QPixmap:
|
||||
if os.path.exists(image := os.path.join(image_dir, app_name, "UninstalledArt.png")):
|
||||
pixmap = QPixmap(image)
|
||||
else:
|
||||
pixmap = QPixmap()
|
||||
return pixmap
|
||||
|
|
Loading…
Reference in a new issue