diff --git a/desktop_client/file.py b/desktop_client/file.py index 7d599ba..a727d20 100644 --- a/desktop_client/file.py +++ b/desktop_client/file.py @@ -11,6 +11,7 @@ import pydantic from PyQt6.QtGui import QIcon from PyQt6.QtWidgets import QFileDialog, QLabel, QMessageBox, QWidget from request_client import RequestClient +from utils import resource_path class File(pydantic.BaseModel): @@ -54,7 +55,7 @@ class File(pydantic.BaseModel): return size, power_labels[n] + "bytes" def icon(self) -> QIcon: - return QIcon("assets/file.png") + return QIcon(resource_path("assets/file.png")) def double_click(self, list: file_widgets.FileListWidget) -> None: location = QFileDialog.getExistingDirectory( diff --git a/desktop_client/file_widgets.py b/desktop_client/file_widgets.py index c198dc8..f9b7df0 100644 --- a/desktop_client/file_widgets.py +++ b/desktop_client/file_widgets.py @@ -5,9 +5,9 @@ import uuid from typing import Protocol, Self import create_folder_widget -import sync import pydantic import state +import sync import user from file import File from folder import Folder diff --git a/desktop_client/folder.py b/desktop_client/folder.py index b5f649c..f11941b 100644 --- a/desktop_client/folder.py +++ b/desktop_client/folder.py @@ -1,8 +1,8 @@ from __future__ import annotations import datetime -import uuid import typing +import uuid if typing.TYPE_CHECKING: import file_widgets @@ -11,6 +11,7 @@ import pydantic from PyQt6.QtGui import QIcon from PyQt6.QtWidgets import QMessageBox, QWidget from request_client import RequestClient +from utils import resource_path class Folder(pydantic.BaseModel): @@ -38,7 +39,7 @@ class Folder(pydantic.BaseModel): return folder_info.FolderInfoWidget(self) def icon(self) -> QIcon: - return QIcon("assets/folder.png") + return QIcon(resource_path("assets/folder.png")) def double_click(self, list: file_widgets.FileListWidget) -> None: import file_widgets diff --git a/desktop_client/state.py b/desktop_client/state.py index 6dfbd9b..5621bb3 100644 --- a/desktop_client/state.py +++ b/desktop_client/state.py @@ -3,7 +3,7 @@ import file_widgets import keyring import request_client import sync -from PyQt6.QtWidgets import QMainWindow, QStackedWidget, QMessageBox +from PyQt6.QtWidgets import QMainWindow, QMessageBox, QStackedWidget class State(QMainWindow): diff --git a/desktop_client/utils.py b/desktop_client/utils.py new file mode 100644 index 0000000..2023306 --- /dev/null +++ b/desktop_client/utils.py @@ -0,0 +1,12 @@ +import os +import sys +from functools import cache + +_DEFAULT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +@cache +def resource_path(relative_path: str) -> str: + """Get absolute path to resource, works for dev and for PyInstaller""" + base_path = getattr(sys, "_MEIPASS", _DEFAULT) + return os.path.join(base_path, relative_path)