Cleaned up the code, fixed the hanging thread

This commit is contained in:
Joseff 2023-03-08 17:18:54 +01:00 committed by Ondřej Samohel
parent c58778194f
commit 57faf21309
4 changed files with 34 additions and 26 deletions

View file

@ -5,7 +5,10 @@ import copy
from pathlib import Path
from openpype.widgets.splash_screen import SplashScreen
from qtpy import QtCore
from openpype.hosts.unreal.ue_workers import UEProjectGenerationWorker, UEPluginInstallWorker
from openpype.hosts.unreal.ue_workers import (
UEProjectGenerationWorker,
UEPluginInstallWorker
)
from openpype import resources
from openpype.lib import (
@ -73,8 +76,10 @@ class UnrealPrelaunchHook(PreLaunchHook):
ue_plugin_worker.setup(engine_path, env)
ue_plugin_worker.moveToThread(q_thread)
splash_screen = SplashScreen("Installing plugin",
resources.get_resource("app_icons", "ue4.png"))
splash_screen = SplashScreen(
"Installing plugin",
resources.get_resource("app_icons", "ue4.png")
)
# set up the splash screen with necessary triggers
ue_plugin_worker.installing.connect(splash_screen.update_top_label_text)
@ -111,10 +116,14 @@ class UnrealPrelaunchHook(PreLaunchHook):
ue_project_worker.moveToThread(q_thread)
q_thread.started.connect(ue_project_worker.run)
splash_screen = SplashScreen("Initializing UE project",
resources.get_resource("app_icons", "ue4.png"))
splash_screen = SplashScreen(
"Initializing UE project",
resources.get_resource("app_icons", "ue4.png")
)
ue_project_worker.stage_begin.connect(splash_screen.update_top_label_text)
ue_project_worker.stage_begin.connect(
splash_screen.update_top_label_text
)
ue_project_worker.progress.connect(splash_screen.update_progress)
ue_project_worker.log.connect(splash_screen.append_log)
ue_project_worker.finished.connect(splash_screen.quit_and_close)

View file

@ -252,7 +252,7 @@ def create_unreal_project(project_name: str,
with open(project_file.as_posix(), mode="r+") as pf:
pf_json = json.load(pf)
pf_json["EngineAssociation"] = _get_build_id(engine_path, ue_version)
pf_json["EngineAssociation"] = get_build_id(engine_path, ue_version)
pf.seek(0)
json.dump(pf_json, pf, indent=4)
pf.truncate()
@ -338,7 +338,7 @@ def get_path_to_ubt(engine_path: Path, ue_version: str) -> Path:
return Path(u_build_tool_path)
def _get_build_id(engine_path: Path, ue_version: str) -> str:
def get_build_id(engine_path: Path, ue_version: str) -> str:
ue_modules = Path()
if platform.system().lower() == "windows":
ue_modules_path = engine_path / "Engine/Binaries/Win64"

View file

@ -64,19 +64,6 @@ class UEProjectGenerationWorker(QtCore.QObject):
self.engine_path = engine_path
def run(self):
ue_id = ".".join(self.ue_version.split(".")[:2])
# get unreal engine identifier
# -------------------------------------------------------------------------
# FIXME (antirotor): As of 4.26 this is problem with UE4 built from
# sources. In that case Engine ID is calculated per machine/user and not
# from Engine files as this code then reads. This then prevents UE4
# to directly open project as it will complain about project being
# created in different UE4 version. When user convert such project
# to his UE4 version, Engine ID is replaced in uproject file. If some
# other user tries to open it, it will present him with similar error.
# engine_path should be the location of UE_X.X folder
ue_editor_exe = ue_lib.get_editor_exe_path(self.engine_path,
@ -122,10 +109,17 @@ class UEProjectGenerationWorker(QtCore.QObject):
self.stage_begin.emit(f'Writing the Engine ID of the build UE ... 1 out'
f' of {stage_count}')
if not project_file.is_file():
msg = "Failed to write the Engine ID into .uproject file! Can " \
"not read!"
self.failed.emit(msg)
raise RuntimeError(msg)
with open(project_file.as_posix(), mode="r+") as pf:
pf_json = json.load(pf)
pf_json["EngineAssociation"] = ue_lib.get_build_id(self.engine_path,
self.ue_version)
print(pf_json["EngineAssociation"])
pf.seek(0)
json.dump(pf_json, pf, indent=4)
pf.truncate()

View file

@ -64,7 +64,8 @@ class SplashScreen(QtWidgets.QDialog):
None
"""
if not q_thread:
raise RuntimeError("Failed to run a worker thread! The thread is null!")
raise RuntimeError("Failed to run a worker thread! "
"The thread is null!")
self.q_thread = q_thread
self.q_thread.start()
@ -147,8 +148,12 @@ class SplashScreen(QtWidgets.QDialog):
self.scroll_area.hide()
log_widget = QtWidgets.QWidget(self.scroll_area)
self.scroll_area.setWidgetResizable(True)
self.scroll_area.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.scroll_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.scroll_area.setHorizontalScrollBarPolicy(
QtCore.Qt.ScrollBarAlwaysOn
)
self.scroll_area.setVerticalScrollBarPolicy(
QtCore.Qt.ScrollBarAlwaysOn
)
self.scroll_area.setWidget(log_widget)
self.scroll_bar = self.scroll_area.verticalScrollBar()
@ -203,8 +208,8 @@ class SplashScreen(QtWidgets.QDialog):
"""A slot used for receiving log info and appending it to scroll area's
content.
Args:
text (str): A log text that will append to the current one in the scroll
area.
text (str): A log text that will append to the current one in the
scroll area.
end (str): end string which can be appended to the end of the given
line (for ex. a line break).