Update to new QResource system
This commit is contained in:
parent
e370841532
commit
c425775f28
|
@ -1,5 +1,2 @@
|
|||
include README.md
|
||||
include rare/languages/*.qm
|
||||
include rare/resources/images/*
|
||||
recursive-include rare/resources/stylesheets/* *
|
||||
include rare/resources/colors/*
|
||||
|
|
8
misc/qrc2py.sh
Executable file
8
misc/qrc2py.sh
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
cwd="$(pwd)"
|
||||
cd "$(dirname "$0")"/../ || exit
|
||||
|
||||
pyrcc5 rare/resources/resources.qrc -o rare/resources/resources.py
|
||||
|
||||
cd "$cwd" || exit
|
|
@ -1,5 +1,5 @@
|
|||
import os
|
||||
|
||||
for f in os.listdir("../rare/languages/"):
|
||||
for f in os.listdir("../rare/resources/languages/"):
|
||||
if f.endswith(".ts") and f != "placeholder.ts":
|
||||
os.system("lrelease ../rare/languages/" + f)
|
||||
|
|
|
@ -5,7 +5,6 @@ __version__ = "1.7.0"
|
|||
import platform
|
||||
|
||||
resources_path = os.path.join(os.path.dirname(__file__), "resources")
|
||||
languages_path = os.path.join(os.path.dirname(__file__), "languages")
|
||||
data_dir = ""
|
||||
|
||||
# Cache Directory: Store images
|
||||
|
|
17
rare/app.py
17
rare/app.py
|
@ -5,13 +5,15 @@ import sys
|
|||
import time
|
||||
import traceback
|
||||
|
||||
from PyQt5.QtCore import QThreadPool, QSettings, QTranslator
|
||||
from PyQt5.QtCore import QThreadPool, QSettings, QTranslator, QFile
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMessageBox
|
||||
from requests import HTTPError
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
import rare.resources.resources
|
||||
import rare.shared as shared
|
||||
from rare import languages_path, resources_path, cache_dir
|
||||
from rare import cache_dir
|
||||
from rare.components.dialogs.launch_dialog import LaunchDialog
|
||||
from rare.components.main_window import MainWindow
|
||||
from rare.components.tray_icon import TrayIcon
|
||||
|
@ -97,17 +99,18 @@ class App(QApplication):
|
|||
# Translator
|
||||
self.translator = QTranslator()
|
||||
lang = self.settings.value("language", self.core.language_code, type=str)
|
||||
if os.path.exists(p := os.path.join(languages_path, lang + ".qm")):
|
||||
self.translator.load(p)
|
||||
|
||||
if QFile(f":/languages/{lang}.qm").exists():
|
||||
self.translator.load(f":/languages/{lang}.qm")
|
||||
logger.info("Your language is supported: " + lang)
|
||||
elif not lang == "en":
|
||||
logger.info("Your language is not supported")
|
||||
self.installTranslator(self.translator)
|
||||
|
||||
# translator for qt stuff
|
||||
if os.path.exists(p := os.path.join(languages_path, f"qt_{lang}.qm")):
|
||||
if QFile(f":/languages/{lang}.qm").exists():
|
||||
self.qt_translator = QTranslator()
|
||||
self.qt_translator.load(p)
|
||||
self.qt_translator.load(f":/languages/qt_{lang}.qm")
|
||||
self.installTranslator(self.qt_translator)
|
||||
|
||||
# Style
|
||||
|
@ -125,7 +128,7 @@ class App(QApplication):
|
|||
elif style_sheet := self.settings.value("style_sheet", False):
|
||||
self.settings.setValue("color_scheme", "")
|
||||
set_style_sheet(style_sheet)
|
||||
self.setWindowIcon(QIcon(os.path.join(resources_path, "images", "Rare.png")))
|
||||
self.setWindowIcon(QIcon(":/images/Rare.png"))
|
||||
|
||||
# launch app
|
||||
self.launch_dialog = LaunchDialog()
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
import os
|
||||
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import QSystemTrayIcon, QMenu, QAction
|
||||
|
||||
from rare import resources_path
|
||||
|
||||
|
||||
class TrayIcon(QSystemTrayIcon):
|
||||
def __init__(self, parent):
|
||||
super(TrayIcon, self).__init__(parent)
|
||||
self.setIcon(QIcon(os.path.join(resources_path, "images", "Rare.png")))
|
||||
self.setIcon(QIcon(":/images/Rare.png"))
|
||||
self.setVisible(True)
|
||||
self.setToolTip("Rare")
|
||||
|
||||
|
|
0
rare/resources/__init__.py
Normal file
0
rare/resources/__init__.py
Normal file
BIN
rare/resources/resources.py
Normal file
BIN
rare/resources/resources.py
Normal file
Binary file not shown.
36
rare/resources/resources.qrc
Normal file
36
rare/resources/resources.qrc
Normal file
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE RCC>
|
||||
<RCC version="1.0">
|
||||
<qresource prefix="schemes">
|
||||
<file alias="Adapta-Nokto">colors/Adapta-Nokto.scheme</file>
|
||||
<file alias="Airy">colors/Airy.scheme</file>
|
||||
<file alias="Arc-Dark">colors/Arc-Dark.scheme</file>
|
||||
<file alias="Arc-Darker">colors/Arc-Darker.scheme</file>
|
||||
<file alias="Darker">colors/Darker.scheme</file>
|
||||
<file alias="Dusk">colors/Dusk.scheme</file>
|
||||
<file alias="Numix-Dark">colors/Numix-Dark.scheme</file>
|
||||
<file alias="Rare">colors/Rare.scheme</file>
|
||||
<file alias="Zukitre">colors/Zukitre.scheme</file>
|
||||
</qresource>
|
||||
<qresource prefix="stylesheets">
|
||||
<file alias="RareStyle">stylesheets/RareStyle/stylesheet.qss</file>
|
||||
</qresource>
|
||||
<qresource prefix="icons">
|
||||
<file alias="circle.svg">stylesheets/RareStyle/circle.svg</file>
|
||||
<file alias="circle-disabled.svg">stylesheets/RareStyle/circle-disabled.svg</file>
|
||||
<file alias="drop-down.svg">stylesheets/RareStyle/drop-down.svg</file>
|
||||
<file alias="half-square.svg">stylesheets/RareStyle/half-square.svg</file>
|
||||
<file alias="half-square-disabled.svg">stylesheets/RareStyle/half-square-disabled.svg</file>
|
||||
<file alias="sort-down.svg">stylesheets/RareStyle/sort-down.svg</file>
|
||||
<file alias="sort-up.svg">stylesheets/RareStyle/sort-up.svg</file>
|
||||
<file alias="square.svg">stylesheets/RareStyle/square.svg</file>
|
||||
<file alias="square-disabled.svg">stylesheets/RareStyle/square-disabled.svg</file>
|
||||
</qresource>
|
||||
<qresource prefix="languages">
|
||||
<file alias="de.qm">languages/de.qm</file>
|
||||
<file alias="qt_de.qm">languages/qt_de.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="images">
|
||||
<file alias="Rare.png">images/Rare.png</file>
|
||||
<file alias="loader.gif">images/loader.gif</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -140,7 +140,7 @@ QComboBox QAbstractItemView {
|
|||
*::drop-down,
|
||||
*::drop-down:editable {
|
||||
width: 14px;
|
||||
image: url("@path@drop-down.svg");
|
||||
image: url(":/icons/drop-down.svg");
|
||||
}
|
||||
*::up-button,
|
||||
*::down-button {
|
||||
|
@ -149,12 +149,12 @@ QComboBox QAbstractItemView {
|
|||
*::up-button {
|
||||
subcontrol-position: top right; /* position at the top right corner */
|
||||
border-bottom-width: 1;
|
||||
image: url("@path@sort-up.svg");
|
||||
image: url(":/icons/sort-up.svg");
|
||||
}
|
||||
*::down-button {
|
||||
subcontrol-position: bottom right; /* position at bottom right corner */
|
||||
border-top-width: 1;
|
||||
image: url("@path@sort-down.svg");
|
||||
image: url(":/icons/sort-down.svg");
|
||||
}
|
||||
QProgressBar {
|
||||
text-align: center;
|
||||
|
@ -379,7 +379,7 @@ QListView::indicator:checked,
|
|||
QTreeView::indicator:checked,
|
||||
QTableView::indicator:checked {
|
||||
border-radius: 2px;
|
||||
image: url("@path@square.svg");
|
||||
image: url(":/icons/square.svg");
|
||||
}
|
||||
QGroupBox::indicator:indeterminate,
|
||||
QCheckBox::indicator:indeterminate,
|
||||
|
@ -387,28 +387,28 @@ QListView::indicator:indeterminate,
|
|||
QTreeView::indicator:indeterminate,
|
||||
QTableView::indicator:indeterminate {
|
||||
border-radius: 2px;
|
||||
image: url("@path@half-square.svg");
|
||||
image: url(":/icons/half-square.svg");
|
||||
}
|
||||
QRadioButton::indicator:checked {
|
||||
border-radius: 5%;
|
||||
image: url("@path@circle.svg");
|
||||
image: url(":/icons/circle.svg");
|
||||
}
|
||||
QGroupBox::indicator:checked:disabled,
|
||||
QCheckBox::indicator:checked:disabled,
|
||||
QListView::indicator:checked:disabled,
|
||||
QTreeView::indicator:checked:disabled,
|
||||
QTableView::indicator:checked:disabled {
|
||||
image: url("@path@square-disabled.svg");
|
||||
image: url(":/icons/square-disabled.svg");
|
||||
}
|
||||
QGroupBox::indicator:indeterminate:disabled,
|
||||
QCheckBox::indicator:indeterminate:disabled,
|
||||
QListView::indicator:indeterminate:disabled,
|
||||
QTreeView::indicator:indeterminate:disabled,
|
||||
QTableView::indicator:indeterminate:disabled {
|
||||
image: url("@path@half-square-disabled.svg");
|
||||
image: url(":/icons/half-square-disabled.svg");
|
||||
}
|
||||
QRadioButton::indicator:checked:disabled {
|
||||
image: url("@path@circle-disabled.svg");
|
||||
image: url(":/icons/circle-disabled.svg");
|
||||
}
|
||||
|
||||
QGroupBox,
|
||||
|
|
|
@ -9,7 +9,7 @@ from PyQt5.QtWidgets import QLayout, QStyle, QSizePolicy, QLabel, QFileDialog, Q
|
|||
QStyledItemDelegate, QFileIconProvider
|
||||
from qtawesome import icon as qta_icon
|
||||
|
||||
from rare import resources_path, cache_dir
|
||||
from rare import cache_dir
|
||||
from rare.utils.qt_requests import QtRequestManager
|
||||
|
||||
logger = getLogger("ExtraWidgets")
|
||||
|
@ -357,7 +357,7 @@ class WaitingSpinner(QLabel):
|
|||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
""")
|
||||
self.movie = QMovie(os.path.join(resources_path, "images", "loader.gif"))
|
||||
self.movie = QMovie(":/images/loader.gif")
|
||||
self.setMovie(self.movie)
|
||||
self.movie.start()
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ from typing import Tuple, List
|
|||
|
||||
import qtawesome
|
||||
import requests
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QRunnable, QSettings, Qt
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QRunnable, QSettings, Qt, QFile, QDir
|
||||
from PyQt5.QtGui import QPalette, QColor, QPixmap, QImage
|
||||
from PyQt5.QtWidgets import QApplication, QStyleFactory
|
||||
from requests.exceptions import HTTPError
|
||||
|
@ -24,7 +24,7 @@ if platform.system() == "Windows":
|
|||
# noinspection PyUnresolvedReferences
|
||||
from win32com.client import Dispatch # pylint: disable=E0401
|
||||
|
||||
from rare import languages_path, resources_path, image_dir, shared
|
||||
from rare import image_dir, shared, resources_path
|
||||
# Mac not supported
|
||||
|
||||
from legendary.core import LegendaryCore
|
||||
|
@ -150,7 +150,7 @@ def set_color_pallete(color_scheme: str):
|
|||
QApplication.instance().setPalette(QApplication.instance().style().standardPalette())
|
||||
return
|
||||
QApplication.instance().setStyle(QStyleFactory.create("Fusion"))
|
||||
custom_palette = load_color_scheme(os.path.join(resources_path, "colors", color_scheme + ".scheme"))
|
||||
custom_palette = load_color_scheme(f":/schemes/{color_scheme}")
|
||||
if custom_palette is not None:
|
||||
QApplication.instance().setPalette(custom_palette)
|
||||
qtawesome.set_defaults(color=custom_palette.color(QPalette.Text))
|
||||
|
@ -158,8 +158,8 @@ def set_color_pallete(color_scheme: str):
|
|||
|
||||
def get_color_schemes() -> List[str]:
|
||||
colors = []
|
||||
for file in os.listdir(os.path.join(resources_path, "colors")):
|
||||
if file.endswith(".scheme") and os.path.isfile(os.path.join(resources_path, "colors", file)):
|
||||
for file in QDir(":/schemes"):
|
||||
if file.endswith(".scheme"):
|
||||
colors.append(file.replace(".scheme", ""))
|
||||
return colors
|
||||
|
||||
|
@ -170,25 +170,24 @@ def set_style_sheet(style_sheet: str):
|
|||
QApplication.instance().setStyleSheet("")
|
||||
return
|
||||
QApplication.instance().setStyle(QStyleFactory.create("Fusion"))
|
||||
stylesheet = open(os.path.join(resources_path, "stylesheets", style_sheet, "stylesheet.qss")).read()
|
||||
style_resource_path = os.path.join(resources_path, "stylesheets", style_sheet, "")
|
||||
if platform.system() == "Windows":
|
||||
style_resource_path = style_resource_path.replace('\\', '/')
|
||||
QApplication.instance().setStyleSheet(stylesheet.replace("@path@", style_resource_path))
|
||||
file = QFile(f":/stylesheets/{style_sheet}")
|
||||
file.open(QFile.ReadOnly)
|
||||
stylesheet = file.readAll().data().decode("utf-8")
|
||||
|
||||
QApplication.instance().setStyleSheet(stylesheet)
|
||||
qtawesome.set_defaults(color="white")
|
||||
|
||||
|
||||
def get_style_sheets() -> List[str]:
|
||||
styles = []
|
||||
for folder in os.listdir(os.path.join(resources_path, "stylesheets")):
|
||||
if os.path.isfile(os.path.join(resources_path, "stylesheets", folder, "stylesheet.qss")):
|
||||
styles.append(folder)
|
||||
for file in QDir(":/stylesheets/"):
|
||||
styles.append(file)
|
||||
return styles
|
||||
|
||||
|
||||
def get_translations():
|
||||
langs = ["en"]
|
||||
for i in os.listdir(languages_path):
|
||||
for i in QDir(":/languages"):
|
||||
if i.endswith(".qm"):
|
||||
langs.append(i.split(".")[0])
|
||||
return langs
|
||||
|
@ -481,4 +480,4 @@ def get_default_platform(app_name):
|
|||
return "Windows"
|
||||
|
||||
else:
|
||||
return "Mac"
|
||||
return "Mac"
|
||||
|
|
4
setup.py
4
setup.py
|
@ -29,12 +29,10 @@ setuptools.setup(
|
|||
description="A gui for Legendary",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
include_package_data=True,
|
||||
url="https://github.com/Dummerle/Rare",
|
||||
packages=setuptools.find_packages() + [
|
||||
"rare.legendary." + i for i in setuptools.find_packages(where="rare/legendary")
|
||||
],
|
||||
# package_dir={'rare': 'rare'},
|
||||
] + ["rare.resources"],
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
|
|
Loading…
Reference in a new issue