Skip to content

Commit

Permalink
Merge pull request #148 from Victor-IX/soft-resource-warning
Browse files Browse the repository at this point in the history
Replace Resources ImportError with Graphical Warning
  • Loading branch information
Victor-IX authored Oct 30, 2024
2 parents 51cf594 + 61bd859 commit a469476
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions source/modules/_resources_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@

try:
import resources_rc

# Upon importing resources_rc, the :resources QIODevice should be open,
# and the contained styles should be available for use.
RESOURCES_AVAILABLE = True
except ImportError:
RESOURCES_AVAILABLE = False
if is_frozen():
print("Failed to import cached resources! Blender-Launcher-V2 was built without resources.")
elif (Path.cwd() / "build_style.py").exists():
# TODO: Attempt to build the style and check if it fails
print("Resources were not built! Run python build_style.py to build the style.")

else:
raise
print("Resources were not built! build the style so the launcher looks right.")

sys.exit()
raise
9 changes: 9 additions & 0 deletions source/modules/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

import contextlib
import os
import shutil
Expand Down Expand Up @@ -126,6 +127,14 @@ def set_favorite_path(path):
get_settings().setValue("Internal/favorite_path", path)


def get_dont_show_resource_warning():
return get_settings().value("Internal/dont_show_resource_err_again", type=bool, defaultValue=False)


def set_dont_show_resource_warning(b: bool = True):
get_settings().setValue("Internal/dont_show_resource_err_again", b)


def get_last_time_checked_utc():
v = get_settings().value("Internal/last_time_checked_utc", defaultValue=ISO_EPOCH)
return datetime.fromisoformat(v)
Expand Down
19 changes: 19 additions & 0 deletions source/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
get_default_downloads_page,
get_default_library_page,
get_default_tab,
get_dont_show_resource_warning,
get_enable_download_notifications,
get_enable_new_builds_notifications,
get_enable_quick_launch_key_seq,
Expand All @@ -44,6 +45,7 @@
get_use_system_titlebar,
get_worker_thread_count,
is_library_folder_valid,
set_dont_show_resource_warning,
set_last_time_checked_utc,
set_library_folder,
set_tray_icon_notified,
Expand All @@ -64,6 +66,7 @@
QWidget,
)
from semver import Version
from modules._resources_rc import RESOURCES_AVAILABLE
from threads.library_drawer import DrawLibraryTask
from threads.remover import RemovalTask
from threads.scraper import Scraper
Expand Down Expand Up @@ -176,6 +179,17 @@ def __init__(self, app: QApplication, version: Version, offline: bool = False):
# Vesrion Update
self.pre_release_build = get_use_pre_release_builds

if not RESOURCES_AVAILABLE and not get_dont_show_resource_warning():
dlg = DialogWindow(
parent=self,
title="Error",
text="Resources failed to load! The launcher will still work,<br> \
but the style will be broken.",
accept_text="OK",
cancel_text="Don't Show Again",
)
dlg.cancelled.connect(self.__dont_show_resources_warning_again)

# Check library folder
if is_library_folder_valid() is False:
self.dlg = DialogWindow(
Expand All @@ -191,6 +205,11 @@ def __init__(self, app: QApplication, version: Version, offline: bool = False):
create_library_folders(get_library_folder())
self.draw()

def __dont_show_resources_warning_again(self):
set_dont_show_resource_warning(True)



def prompt_library_folder(self):
library_folder = get_cwd().as_posix()
new_library_folder = FileDialogWindow().get_directory(self, "Select Library Folder", library_folder)
Expand Down

0 comments on commit a469476

Please sign in to comment.