6
6
# SPDX - License - Identifier: GPL - 3.0 +
7
7
# This file is part of the mantid workbench.
8
8
import os
9
+ from pathlib import Path
10
+ import shutil
9
11
import subprocess
10
12
import sys
11
13
12
14
from workbench .app .main import main
13
15
14
16
17
+ def _patch_qtwebengine_files (prefix : str ):
18
+ """
19
+ Copy Qt WebEngine executable, resources, locales, and ICU data into the environment
20
+ root so Qt can find them when launching from a conda environment on Windows.
21
+ """
22
+ env_root = Path (prefix ) # Python executable directory
23
+ library = env_root / "Library"
24
+
25
+ # Copy QtWebEngineProcess.exe
26
+ src_exe = library / "bin" / "QtWebEngineProcess.exe"
27
+ dst_exe = env_root / "QtWebEngineProcess.exe"
28
+ if src_exe .exists () and not dst_exe .exists ():
29
+ shutil .copy2 (src_exe , dst_exe )
30
+
31
+ # Copy the contents of the resources directory
32
+ src_resources = library / "resources"
33
+ for f in src_resources .glob ("*" ):
34
+ dst = env_root / f .name
35
+ if not dst .exists ():
36
+ shutil .copy2 (f , dst )
37
+
38
+ # Copy locales directory
39
+ src_locales = library / "translations" / "qtwebengine_locales"
40
+ dst_locales = env_root / "qtwebengine_locales"
41
+ if src_locales .exists () and not dst_locales .exists ():
42
+ shutil .copytree (src_locales , dst_locales )
43
+
44
+
15
45
def launch (args = None ):
16
46
if args is None :
17
47
args = sys .argv
@@ -20,9 +50,12 @@ def launch(args=None):
20
50
subprocess .run (command )
21
51
else :
22
52
if sys .platform .startswith ("win" ):
23
- # Windows conda installs require us to set the QT_PLUGIN_PATH variable.
53
+ # Windows conda installs require us to set the QT_PLUGIN_PATH variable and copy QtWebEngine files
54
+ # to the root directory of the conda environment.
24
55
if "CONDA_PREFIX" in os .environ :
25
- os .environ ["QT_PLUGIN_PATH" ] = f"{ os .environ .get ('CONDA_PREFIX' )} \\ Library\\ plugins"
56
+ prefix = os .environ .get ("CONDA_PREFIX" )
57
+ os .environ ["QT_PLUGIN_PATH" ] = f"{ prefix } \\ Library\\ plugins"
58
+ _patch_qtwebengine_files (prefix )
26
59
main (args [1 :])
27
60
28
61
0 commit comments