|
| 1 | +# ***************************************************************************** |
| 2 | +# |
| 3 | +# Part of the py5 library |
| 4 | +# Copyright (C) 2020-2025 Jim Schmitz |
| 5 | +# |
| 6 | +# This library is free software: you can redistribute it and/or modify it |
| 7 | +# under the terms of the GNU Lesser General Public License as published by |
| 8 | +# the Free Software Foundation, either version 2.1 of the License, or (at |
| 9 | +# your option) any later version. |
| 10 | +# |
| 11 | +# This library is distributed in the hope that it will be useful, but |
| 12 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
| 14 | +# General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 | +# |
| 19 | +# ***************************************************************************** |
| 20 | +import platform |
| 21 | +import sys |
| 22 | + |
| 23 | +import py5_tools |
| 24 | + |
| 25 | +if not py5_tools.is_jvm_running() and py5_tools.processing.check_library("JavaFX"): |
| 26 | + try: |
| 27 | + library_dir = None |
| 28 | + |
| 29 | + os_arch = platform.machine() |
| 30 | + if sys.platform == "darwin": |
| 31 | + if os_arch in ("arm64", "aarch64"): |
| 32 | + # 64-bit ARM |
| 33 | + library_dir = "macos-aarch64" |
| 34 | + elif os_arch == "x86_64": |
| 35 | + # 64-bit Intel |
| 36 | + library_dir = "macos-x86_64" |
| 37 | + # else: |
| 38 | + # raise RuntimeError(f"Unsupported architecture for MacOS: {os_arch}") |
| 39 | + elif sys.platform == "linux": |
| 40 | + if os_arch == "x86_64": |
| 41 | + # 64-bit Intel |
| 42 | + library_dir = "linux-amd64" |
| 43 | + elif os_arch.startswith("armv"): |
| 44 | + # 32-bit ARM |
| 45 | + library_dir = "linux-arm" |
| 46 | + elif os_arch == "aarch64": |
| 47 | + # 64-bit ARM |
| 48 | + library_dir = "linux-aarch64" |
| 49 | + # else: |
| 50 | + # raise RuntimeError(f"Unsupported architecture for Linux: {os_arch}") |
| 51 | + elif sys.platform in ["windows", "win32"]: |
| 52 | + if os_arch in ("AMD64", "x86_64"): |
| 53 | + # 64-bit Intel |
| 54 | + library_dir = "windows-amd64" |
| 55 | + # else: |
| 56 | + # raise RuntimeError(f"Unsupported architecture for Windows: {os_arch}") |
| 57 | + # else: |
| 58 | + # raise RuntimeError(f"Unrecognized platform: sys.platform={sys.platform}") |
| 59 | + |
| 60 | + if library_dir is not None: |
| 61 | + base_path = py5_tools.processing.library_storage_dir() |
| 62 | + py5_tools.add_options( |
| 63 | + f"-Djava.library.path={base_path}/javafx/library/{library_dir}/" |
| 64 | + ) |
| 65 | + py5_tools.add_options( |
| 66 | + f"--module-path={base_path}/javafx/library/{library_dir}/modules/" |
| 67 | + ) |
| 68 | + |
| 69 | + py5_tools.add_options( |
| 70 | + "--add-exports=javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED" |
| 71 | + ) |
| 72 | + py5_tools.add_options( |
| 73 | + "--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED" |
| 74 | + ) |
| 75 | + |
| 76 | + # add all 7 modules |
| 77 | + py5_tools.add_options( |
| 78 | + "--add-modules=javafx.base,javafx.graphics,javafx.swing,javafx.controls,javafx.media,javafx.web,javafx.fxml" |
| 79 | + ) |
| 80 | + except Exception as e: |
| 81 | + print( |
| 82 | + f"JavaFX is not properly installed. Please remove JavaFX and possibly try installing it again. Error: {e}", |
| 83 | + file=sys.stderr, |
| 84 | + ) |
| 85 | + |
| 86 | + |
| 87 | +__all__ = [] |
| 88 | + |
| 89 | + |
| 90 | +def __dir__(): |
| 91 | + return __all__ |
0 commit comments