Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom icons to build #737

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion ursina/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
build_folder = Path(project_folder / f'build_{platform.system()}')
build_folder.mkdir(exist_ok=True)

rcedit = os.path.abspath(os.path.dirname(__file__)) + "/scripts/rcedit.exe"
print("Rcedit at: ", rcedit)

ignore_folders = []
ignore_filetypes = []

Expand Down Expand Up @@ -55,6 +58,7 @@ def copytree(src, dst, symlinks=False, ignore_patterns=[], ignore_filetypes=[]):
src_dest = Path(build_folder / 'src')
build_engine = True
build_game = True
icon = False
compile_to_pyc = True
entry_point = 'main.py'

Expand All @@ -71,6 +75,7 @@ def copytree(src, dst, symlinks=False, ignore_patterns=[], ignore_filetypes=[]):
--ignore_filetypes=* # filetype to ignore, for example: --ignore_filetypes=.blend,.psd
--name='' # change project name
--include_modules=* # include extra modules like this: --include_modules=module_one,module_two,module_tree
--icon='' # Add an icon to the game, has to be .ico format, for example: --icon=new.ico
--overwrite # don't ask to overwrite existing build, just overwrite
--skip_engine
--skip_game
Expand All @@ -97,6 +102,9 @@ def copytree(src, dst, symlinks=False, ignore_patterns=[], ignore_filetypes=[]):
elif arg.startswith('--include_modules='):
include_modules = arg.split('=')[1].split(',')

elif arg.startswith("--icon="):
icon = Path(project_folder / arg.split('=')[1])

elif arg == '--skip_engine':
build_engine = False
elif arg == '--skip_game':
Expand All @@ -114,7 +122,7 @@ def copytree(src, dst, symlinks=False, ignore_patterns=[], ignore_filetypes=[]):
if '--overwrite' not in sys.argv:
for e in (python_dest, src_dest):
msg = f'Folder {e} already exists. \nProceed to delete and overwrite?'
overwrite = input("%s (y/N) " % msg).lower() == 'y'
overwrite = input("%s (y/n) " % msg).lower() == 'y'
# if not overwrite:
# print('stopped building')
# exit()
Expand Down Expand Up @@ -209,6 +217,9 @@ def copytree(src, dst, symlinks=False, ignore_patterns=[], ignore_filetypes=[]):

# def copy_ursina():
print('copying ursina')
#if sys.version_info[1] >= 12:
#import importlib.util #Have to change to import importlib.util in python 3.12?
#else:
import importlib
spec = importlib.util.find_spec('ursina')
ursina_path = Path(spec.origin).parent
Expand Down Expand Up @@ -302,6 +313,27 @@ def copytree(src, dst, symlinks=False, ignore_patterns=[], ignore_filetypes=[]):
call "python\python.exe" "src\{entry_point}{c}" > "log.txt" 2>&1'''
))

if icon:
import subprocess
from pathlib import Path

print("Changing icon to custom icon")

python_exe = Path(build_folder / "python/python.exe")

try:
update_icon_command = [
str(rcedit),
str(python_exe),
"--set-icon", str(icon)
]

subprocess.run(update_icon_command, check=True, capture_output=True, text=True)
print("Icon updated successfully.")
except subprocess.CalledProcessError as e:
print("Error updating icon:", e.stderr)


# make exe
# import subprocess
# import importlib
Expand Down
Binary file added ursina/scripts/rcedit.exe
Binary file not shown.