Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2023-10-12 09:33:46 +0200
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2023-12-04 13:06:22 +0100
commit75ce3916f291179ed68cdc78f147e30fb7fbaf68 (patch)
treefcd2f80daf79bb3d9df50871afcbac2722b60988
parenteeda9bf8522ba49cb542398d8e01046ea62e2aa2 (diff)
Deployment: Add icon for application
- For Android deployment, by default kivy's icon is used when the application is deployed. This patch makes use of PySide icon as the default for all applications created with pyside6-android-deploy. - Icon formats accepted by Nutika windows: .ico macOS: .icns (contains a 128x128 .png file) linux: all standard image formats. We use .jpg - For Desktop deployment - change the option --linux-onefile-icon to --linux-icon. Both are the same. - Add icon options for macOS and Windows. - Adapt deployment test accordingly. - As an addition, add a default value to the --config-file option so that it picks up the one in the project directory automatically, if it exists. It aligns with the desktop deployment tool as per 6337e4a306babdb4015c248a14ad734b320ed2c1 - As another extra, remove an unused typing import from config.py Pick-to: 6.6 Task-number: PYSIDE-1612 Change-Id: Ia67ea96f94ddffe4bc65652f91c8b394c4e56a33 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--build_scripts/platforms/unix.py3
-rw-r--r--sources/pyside-tools/android_deploy.py1
-rw-r--r--sources/pyside-tools/deploy.pyproject3
-rw-r--r--sources/pyside-tools/deploy_lib/__init__.py15
-rw-r--r--sources/pyside-tools/deploy_lib/android/buildozer.py3
-rw-r--r--sources/pyside-tools/deploy_lib/config.py18
-rw-r--r--sources/pyside-tools/deploy_lib/default.spec3
-rw-r--r--sources/pyside-tools/deploy_lib/nuitka_helper.py16
-rw-r--r--sources/pyside-tools/deploy_lib/pyside_icon.icnsbin0 -> 47064 bytes
-rw-r--r--sources/pyside-tools/deploy_lib/pyside_icon.icobin0 -> 48446 bytes
-rw-r--r--sources/pyside-tools/deploy_lib/python_helper.py3
-rw-r--r--sources/pyside6/tests/tools/pyside6-deploy/test_pyside6_deploy.py20
12 files changed, 71 insertions, 14 deletions
diff --git a/build_scripts/platforms/unix.py b/build_scripts/platforms/unix.py
index 6b4a3e95d..8f8e496be 100644
--- a/build_scripts/platforms/unix.py
+++ b/build_scripts/platforms/unix.py
@@ -140,7 +140,8 @@ def prepare_packages_posix(pyside_build, _vars, cross_build=False):
src = f"{{install_dir}}/bin/{script_dir}"
target = f"{{st_build_dir}}/{{st_package_name}}/scripts/{script_dir}"
# Exclude subdirectory tests
- copydir(src, target, _filter=["*.py", "*.spec", "*.jpg"], recursive=False, _vars=_vars)
+ copydir(src, target, _filter=["*.py", "*.spec", "*.jpg", "*.icns", "*.ico"],
+ recursive=False, _vars=_vars)
# <install>/bin/* -> {st_package_name}/
executables.extend(copydir(
diff --git a/sources/pyside-tools/android_deploy.py b/sources/pyside-tools/android_deploy.py
index ef39d66b4..2d06d5819 100644
--- a/sources/pyside-tools/android_deploy.py
+++ b/sources/pyside-tools/android_deploy.py
@@ -182,6 +182,7 @@ if __name__ == "__main__":
)
parser.add_argument("-c", "--config-file", type=lambda p: Path(p).absolute(),
+ default=(Path.cwd() / "pysidedeploy.spec"),
help="Path to the .spec config file")
parser.add_argument(
diff --git a/sources/pyside-tools/deploy.pyproject b/sources/pyside-tools/deploy.pyproject
index c0085fbe1..eef1668c5 100644
--- a/sources/pyside-tools/deploy.pyproject
+++ b/sources/pyside-tools/deploy.pyproject
@@ -1,6 +1,7 @@
{
"files": ["deploy.py", "deploy_lib/__init__.py", "deploy_lib/commands.py", "deploy_lib/config.py",
- "deploy_lib/default.spec", "deploy_lib/nuitka_helper.py", "deploy_lib/pyside_icon.jpg",
+ "deploy_lib/default.spec", "deploy_lib/nuitka_helper.py", "deploy_lib/pyside_icon.ico",
+ "deploy_lib/pyside_icon.icns","deploy_lib/pyside_icon.jpg",
"deploy_lib/python_helper.py", "deploy_lib/deploy_util.py"
]
}
diff --git a/sources/pyside-tools/deploy_lib/__init__.py b/sources/pyside-tools/deploy_lib/__init__.py
index a8ac99bde..bdde7e917 100644
--- a/sources/pyside-tools/deploy_lib/__init__.py
+++ b/sources/pyside-tools/deploy_lib/__init__.py
@@ -1,9 +1,21 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
import sys
+from pathlib import Path
MAJOR_VERSION = 6
-EXE_FORMAT = ".exe" if sys.platform == "win32" else ".bin"
+
+if sys.platform == "win32":
+ IMAGE_FORMAT = ".ico"
+ EXE_FORMAT = ".exe"
+elif sys.platform == "darwin":
+ IMAGE_FORMAT = ".icns"
+ EXE_FORMAT = ".bin"
+else:
+ IMAGE_FORMAT = ".jpg"
+ EXE_FORMAT = ".bin"
+
+DEFAULT_APP_ICON = str((Path(__file__).parent / f"pyside_icon{IMAGE_FORMAT}").resolve())
from .commands import run_command
from .nuitka_helper import Nuitka
@@ -11,3 +23,4 @@ from .python_helper import PythonExecutable, find_pyside_modules
from .config import BaseConfig, Config
from .deploy_util import (cleanup, finalize, create_config_file, setup_python,
install_python_dependencies, config_option_exists)
+
diff --git a/sources/pyside-tools/deploy_lib/android/buildozer.py b/sources/pyside-tools/deploy_lib/android/buildozer.py
index f17ffd116..dcb3e5cd6 100644
--- a/sources/pyside-tools/deploy_lib/android/buildozer.py
+++ b/sources/pyside-tools/deploy_lib/android/buildozer.py
@@ -130,6 +130,9 @@ class BuildozerConfig(BaseConfig):
# change final apk/aab path
self.set_value("buildozer", "bin_dir", str(pysidedeploy_config.exe_dir.resolve()))
+ # set application icon
+ self.set_value("app", "icon.filename", pysidedeploy_config.icon)
+
self.update_config()
def __get_dependency_files(self, modules: List[str], arch: str) -> List[zipfile.Path]:
diff --git a/sources/pyside-tools/deploy_lib/config.py b/sources/pyside-tools/deploy_lib/config.py
index 57eec3d1f..81de8b2c6 100644
--- a/sources/pyside-tools/deploy_lib/config.py
+++ b/sources/pyside-tools/deploy_lib/config.py
@@ -6,11 +6,11 @@ import logging
import warnings
from configparser import ConfigParser
from pathlib import Path
-from typing import List
from project import ProjectData
from .commands import run_qmlimportscanner
+from . import DEFAULT_APP_ICON
# Some QML plugins like QtCore are excluded from this list as they don't contribute much to
# executable size. Excluding them saves the extra processing of checking for them in files
@@ -82,6 +82,13 @@ class Config(BaseConfig):
self.title = self.get_value("app", "title")
+ # set application icon
+ config_icon = self.get_value("app", "icon")
+ if config_icon:
+ self.icon = str(Path(config_icon).resolve())
+ else:
+ self.icon = DEFAULT_APP_ICON
+
self.project_dir = None
if self.get_value("app", "project_dir"):
self.project_dir = Path(self.get_value("app", "project_dir")).absolute()
@@ -167,6 +174,15 @@ class Config(BaseConfig):
self.set_value("app", "title", title)
@property
+ def icon(self):
+ return self._icon
+
+ @icon.setter
+ def icon(self, icon):
+ self._icon = icon
+ self.set_value("app", "icon", icon)
+
+ @property
def source_file(self):
return self._source_file
diff --git a/sources/pyside-tools/deploy_lib/default.spec b/sources/pyside-tools/deploy_lib/default.spec
index 473898ed2..d5f9e7c67 100644
--- a/sources/pyside-tools/deploy_lib/default.spec
+++ b/sources/pyside-tools/deploy_lib/default.spec
@@ -16,6 +16,9 @@ exec_directory =
# Path to .pyproject project file
project_file =
+# Application icon
+icon =
+
[python]
# Python path
diff --git a/sources/pyside-tools/deploy_lib/nuitka_helper.py b/sources/pyside-tools/deploy_lib/nuitka_helper.py
index ae3d2ff94..ae5834b6b 100644
--- a/sources/pyside-tools/deploy_lib/nuitka_helper.py
+++ b/sources/pyside-tools/deploy_lib/nuitka_helper.py
@@ -18,8 +18,17 @@ class Nuitka:
def __init__(self, nuitka):
self.nuitka = nuitka
+ @staticmethod
+ def icon_option():
+ if sys.platform == "linux":
+ return "--linux-icon"
+ elif sys.platform == "win32":
+ return "--windows-icon-from-ico"
+ else:
+ return "--macos-app-icon"
+
def create_executable(self, source_file: Path, extra_args: str, qml_files: List[Path],
- excluded_qml_plugins, dry_run: bool):
+ excluded_qml_plugins: List[str], icon: str, dry_run: bool):
extra_args = extra_args.split()
qml_args = []
if qml_files:
@@ -51,10 +60,7 @@ class Nuitka:
f"--output-dir={output_dir}",
]
command.extend(extra_args + qml_args)
-
- if sys.platform == "linux":
- linux_icon = str(Path(__file__).parent / "pyside_icon.jpg")
- command.append(f"--linux-onefile-icon={linux_icon}")
+ command.append(f"{self.__class__.icon_option()}={icon}")
command_str, _ = run_command(command=command, dry_run=dry_run)
return command_str
diff --git a/sources/pyside-tools/deploy_lib/pyside_icon.icns b/sources/pyside-tools/deploy_lib/pyside_icon.icns
new file mode 100644
index 000000000..a6eb02bb0
--- /dev/null
+++ b/sources/pyside-tools/deploy_lib/pyside_icon.icns
Binary files differ
diff --git a/sources/pyside-tools/deploy_lib/pyside_icon.ico b/sources/pyside-tools/deploy_lib/pyside_icon.ico
new file mode 100644
index 000000000..332a3a568
--- /dev/null
+++ b/sources/pyside-tools/deploy_lib/pyside_icon.ico
Binary files differ
diff --git a/sources/pyside-tools/deploy_lib/python_helper.py b/sources/pyside-tools/deploy_lib/python_helper.py
index 1e5f77b78..af38c274d 100644
--- a/sources/pyside-tools/deploy_lib/python_helper.py
+++ b/sources/pyside-tools/deploy_lib/python_helper.py
@@ -202,7 +202,8 @@ class PythonExecutable:
extra_args=extra_args,
qml_files=config.qml_files,
excluded_qml_plugins=config.excluded_qml_plugins,
+ icon=config.icon,
dry_run=self.dry_run,
- )
+ )
return command_str
diff --git a/sources/pyside6/tests/tools/pyside6-deploy/test_pyside6_deploy.py b/sources/pyside6/tests/tools/pyside6-deploy/test_pyside6_deploy.py
index 1277ccefe..bed4ea14f 100644
--- a/sources/pyside6/tests/tools/pyside6-deploy/test_pyside6_deploy.py
+++ b/sources/pyside6/tests/tools/pyside6-deploy/test_pyside6_deploy.py
@@ -61,7 +61,9 @@ class DeployTestBase(LongSortedOptionTest):
cls.temp_dir = tempfile.mkdtemp()
cls.current_dir = Path.cwd()
tools_path = cls.pyside_root / "sources" / "pyside-tools"
- cls.linux_onefile_icon = tools_path / "deploy_lib" / "pyside_icon.jpg"
+ cls.win_icon = tools_path / "deploy_lib" / "pyside_icon.ico"
+ cls.linux_icon = tools_path / "deploy_lib" / "pyside_icon.jpg"
+ cls.macos_icon = tools_path / "deploy_lib" / "pyside_icon.icns"
if tools_path not in sys.path:
sys.path.append(str(cls.pyside_root / "sources" / "pyside-tools"))
cls.deploy_lib = importlib.import_module("deploy_lib")
@@ -102,7 +104,12 @@ class TestPySide6DeployWidgets(DeployTestBase):
f" --noinclude-qt-translations"
)
if sys.platform.startswith("linux"):
- self.expected_run_cmd += f" --linux-onefile-icon={str(self.linux_onefile_icon)}"
+ self.expected_run_cmd += f" --linux-icon={str(self.linux_icon)}"
+ elif sys.platform == "darwin":
+ self.expected_run_cmd += f" --macos-app-icon={str(self.macos_icon)}"
+ elif sys.platform == "win32":
+ self.expected_run_cmd += f" --windows-icon-from-ico={str(self.win_icon)}"
+
if is_pyenv_python():
self.expected_run_cmd += " --static-libpython=no"
self.config_file = self.temp_example_widgets / "pysidedeploy.spec"
@@ -177,7 +184,12 @@ class TestPySide6DeployQml(DeployTestBase):
)
if sys.platform.startswith("linux"):
- self.expected_run_cmd += f" --linux-onefile-icon={str(self.linux_onefile_icon)}"
+ self.expected_run_cmd += f" --linux-icon={str(self.linux_icon)}"
+ elif sys.platform == "darwin":
+ self.expected_run_cmd += f" --macos-app-icon={str(self.macos_icon)}"
+ elif sys.platform == "win32":
+ self.expected_run_cmd += f" --windows-icon-from-ico={str(self.win_icon)}"
+
if is_pyenv_python():
self.expected_run_cmd += " --static-libpython=no"
self.config_file = self.temp_example_qml / "pysidedeploy.spec"
@@ -270,7 +282,7 @@ class TestPySide6DeployWebEngine(DeployTestBase):
)
if sys.platform.startswith("linux"):
- expected_run_cmd += f" --linux-onefile-icon={str(self.linux_onefile_icon)}"
+ expected_run_cmd += f" --linux-icon={str(self.linux_icon)}"
config_file = self.temp_example_webenginequick / "pysidedeploy.spec"