diff --git a/builder/applbuild/configure.py b/builder/applbuild/configure.py index 89514ad..e53d135 100644 --- a/builder/applbuild/configure.py +++ b/builder/applbuild/configure.py @@ -2,12 +2,10 @@ # -*- coding: utf-8 -*- from pathlib import Path -from typing import Any, Dict, List, Tuple, TypeVar, Union - -from clickgen.util import LikePath, PNGProvider +from typing import Any, Dict, Tuple, TypeVar, Union from applbuild.constants import WIN_CURSORS_CFG, WIN_DELAY, X_CURSORS_CFG, X_DELAY - +from clickgen.util import PNGProvider X = TypeVar("X") @@ -16,51 +14,56 @@ def to_tuple(x: X) -> Tuple[X, X]: return (x, x) -def get_config(bitmaps_dir: LikePath, **kwargs) -> Dict[str, Any]: +def get_config(bitmaps_dir: Union[str, Path], **kwargs) -> Dict[str, Any]: """Return configuration of `macOSBigSur` pointers. - Args: + :param bitmaps_dir: Path to .png file's directory. + :type bitmaps_dir: Union[str, Path] - :bitmaps_dir: (str | Path) Path to .png file's directory. + :param x_sizes: List of pixel-sizes for xcursors. + :type x_sizes: List[int] + :param win_canvas_size: Windows cursor's canvas pixel-size. + :type win_canvas_size: int - Keywords Args: - - :x_sizes: (List[int]) List of pixel-sizes for xcursors. - - :win_canvas_size: (int) Windows cursor's canvas pixel-size. - - :win_size: (int) Pixel-size for Windows cursor. - + :param win_size: Pixel-size for Windows cursor. + :type win_size: int Example: ```python - get_config("./bitmaps", x_sizes=[(24, 24), (32, 32)], win_canvas_size=(32, 32), win_size=(24, 24)) + get_config( + "./bitmaps", + x_sizes=[(24, 24), (32, 32)], + win_canvas_size=(32, 32), + win_size=(24, 24), + ) ``` """ w_size = to_tuple(kwargs.pop("win_size")) w_canvas_size = to_tuple(kwargs.pop("win_canvas_size")) - x = kwargs.pop("x_sizes") + raw_x_sizes = kwargs.pop("x_sizes") x_sizes = [] - for s in x: - x_sizes.append(to_tuple(s)) + for size in raw_x_sizes: + x_sizes.append(to_tuple(size)) - png = PNGProvider(bitmaps_dir) config: Dict[str, Any] = {} for key, item in X_CURSORS_CFG.items(): - x_hot: int = item.get("xhot", 0) - y_hot: int = item.get("yhot", 0) + x_hot: int = int(item.get("xhot", 0)) + y_hot: int = int(item.get("yhot", 0)) hotspot: Tuple[int, int] = (x_hot, y_hot) - delay: int = item.get("delay", X_DELAY) - p: Union[List[Path], Path] = png.get(key) + delay: int = int(item.get("delay", X_DELAY)) + pngs = PNGProvider(bitmaps_dir).get(key) + + if not pngs: + raise FileNotFoundError(f"{key} not found in {bitmaps_dir}") data = { - "png": p, + "png": pngs, "x_sizes": x_sizes, "hotspot": hotspot, "delay": delay, @@ -69,17 +72,18 @@ def get_config(bitmaps_dir: LikePath, **kwargs) -> Dict[str, Any]: win_data = WIN_CURSORS_CFG.get(key) if win_data: - win_key = win_data.get("to") + win_key: str = str(win_data.get("to")) - position = win_data.get("position", "center") - win_delay: int = win_data.get("delay", WIN_DELAY) + position: str = str(win_data.get("position", "center")) + win_delay: int = int(win_data.get("delay", WIN_DELAY)) - canvas_size: Tuple[int, int] = win_data.get("canvas_size", w_canvas_size) - win_size: Tuple[int, int] = win_data.get("size", w_size) + canvas_size = win_data.get("canvas_size", w_canvas_size) + win_size = win_data.get("size", w_size) # Because provided cursor size is bigger than cursor's canvas. - # Also, "position" settings will not effect on cursor because the cursor's canvas and cursor sizes are equals. - if (win_size[0] > canvas_size[0]) or (win_size[1] > canvas_size[1]): + # Also, "position" settings will not effect on cursor because the + # cursor's canvas and cursor sizes are equals. + if (win_size[0] > canvas_size[0]) | (win_size[1] > canvas_size[1]): canvas_size = win_size config[key] = { @@ -90,6 +94,7 @@ def get_config(bitmaps_dir: LikePath, **kwargs) -> Dict[str, Any]: "win_size": win_size, "win_delay": win_delay, } + else: config[key] = data diff --git a/builder/applbuild/constants.py b/builder/applbuild/constants.py index 08c26d1..47f6d6d 100644 --- a/builder/applbuild/constants.py +++ b/builder/applbuild/constants.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from typing import Dict, List, Tuple +from typing import Dict # Info THEME_NAME = "macOSBigSur" @@ -12,7 +12,6 @@ URL = "https://github.com/ful1e5/apple_cursor" # XCursor X_DELAY: int = 10 - # Windows Cursor WIN_DELAY = 1 diff --git a/builder/applbuild/generator.py b/builder/applbuild/generator.py index 6e28d4d..3a72545 100644 --- a/builder/applbuild/generator.py +++ b/builder/applbuild/generator.py @@ -4,13 +4,12 @@ from pathlib import Path from typing import Any, Dict +from applbuild.constants import AUTHOR, COMMENT, THEME_NAME, URL +from applbuild.symlinks import add_missing_xcursor from clickgen.builders import WindowsCursor, XCursor from clickgen.core import CursorAlias from clickgen.packagers import WindowsPackager, XPackager -from applbuild.constants import AUTHOR, COMMENT, THEME_NAME, URL -from applbuild.symlinks import add_missing_xcursor - def xbuild( config: Dict[str, Dict[str, Any]], @@ -18,16 +17,20 @@ def xbuild( ) -> None: """Build `macOSBigSur` cursor theme for only `X11`(UNIX) platform. - :config: (Dict) `macOSBigSur` configuration. + :param config: `macOSBigSur` configuration. + :type config: Dict[str, Dict[str, Any]] - :x_out_dir: (Path) Path to the output directory, Where the `X11` cursor theme package will generate. It also creates a directory if not exists. + :param x_out_dir: Path to the output directory, \ + Where the `X11` cursor theme package will\ + generate. It also creates a directory if not exists. + :type x_out_dir: Path """ for _, item in config.items(): - png = item.get("png") - hotspot = item.get("hotspot") - x_sizes = item.get("x_sizes") - delay = item.get("delay") + png = item["png"] + hotspot = item["hotspot"] + x_sizes = item["x_sizes"] + delay = item["delay"] with CursorAlias.from_bitmap(png, hotspot) as alias: x_cfg = alias.create(x_sizes, delay) @@ -41,26 +44,30 @@ def xbuild( def wbuild(config: Dict[str, Dict[str, Any]], win_out_dir: Path) -> None: """Build `macOSBigSur` cursor theme for only `Windows` platforms. - :config: (Dict) `macOSBigSur` configuration. + :param config: `macOSBigSur` configuration. + :type config: Dict[str, Dict[str, Any]] - :win_out_dir: (Path) Path to the output directory, Where the `Windows` cursor theme package will generate. It also creates a directory if not exists. + :param win_out_dir: Path to the output directory, \ + Where the `Windows` cursor theme package will\ + generate. It also creates a directory if not exists. + :type win_out_dir: Path """ for _, item in config.items(): - png = item.get("png") - hotspot = item.get("hotspot") - x_sizes = item.get("x_sizes") - delay = item.get("delay") + png = item["png"] + hotspot = item["hotspot"] + x_sizes = item["x_sizes"] + delay = item["delay"] with CursorAlias.from_bitmap(png, hotspot) as alias: alias.create(x_sizes, delay) if item.get("win_key"): - position = item.get("position") - win_size = item.get("win_size") - win_key = item.get("win_key") - canvas_size = item.get("canvas_size") - win_delay = item.get("win_delay") + position = item["position"] + win_size = item["win_size"] + win_key = item["win_key"] + canvas_size = item["canvas_size"] + win_delay = item["win_delay"] win_cfg = alias.reproduce( win_size, canvas_size, position, delay=win_delay @@ -76,19 +83,26 @@ def build( ) -> None: """Build `macOSBigSur` cursor theme for `X11` & `Windows` platforms. - :config: (Dict) `macOSBigSur` configuration. + :param config: `macOSBigSur` configuration. + :type config: Dict[str, Dict[str, Any]] - :x_out_dir: (Path) Path to the output directory, Where the `X11` cursor theme package will generate. It also creates a directory if not exists. + :param x_out_dir: Path to the output directory, \ + Where the `X11` cursor theme package will\ + generate. It also creates a directory if not exists. + :type x_out_dir: Path - :win_out_dir: (Path) Path to the output directory, Where the `Windows` cursor theme package will generate. It also creates a directory if not exists. + :param win_out_dir: Path to the output directory, \ + Where the `Windows` cursor theme package will\ + generate. It also creates a directory if not exists. + :type win_out_dir: Path """ def win_build(item: Dict[str, Any], alias: CursorAlias) -> None: - position = item.get("position") - win_size = item.get("win_size") - win_key = item.get("win_key") - canvas_size = item.get("canvas_size") - win_delay = item.get("win_delay") + position = item["position"] + win_size = item["win_size"] + win_key = item["win_key"] + canvas_size = item["canvas_size"] + win_delay = item["win_delay"] win_cfg = alias.reproduce( win_size, canvas_size, position, delay=win_delay @@ -97,10 +111,10 @@ def build( WindowsCursor.create(win_cfg, win_out_dir) for _, item in config.items(): - png = item.get("png") - hotspot = item.get("hotspot") - x_sizes = item.get("x_sizes") - delay = item.get("delay") + png = item["png"] + hotspot = item["hotspot"] + x_sizes = item["x_sizes"] + delay = item["delay"] with CursorAlias.from_bitmap(png, hotspot) as alias: x_cfg = alias.create(x_sizes, delay) diff --git a/builder/applbuild/symlinks.py b/builder/applbuild/symlinks.py index 82a265d..ab981a8 100644 --- a/builder/applbuild/symlinks.py +++ b/builder/applbuild/symlinks.py @@ -2,15 +2,17 @@ # -*- coding: utf-8 -*- import os +from pathlib import Path from typing import Dict, List, Union -from clickgen.util import LikePath, chdir +from clickgen.util import chdir -def add_missing_xcursor(directory: LikePath) -> None: +def add_missing_xcursor(directory: Union[str, Path]) -> None: """Add missing `XCursor` to the Unix cursor package. - :directory: (Path|str) directory where XCursors are available. + :param directory: directory where XCursors are available. + :type directory: Union[str, Path] """ symlinks: List[Dict[str, Union[str, List[str]]]] = [ @@ -160,7 +162,7 @@ def add_missing_xcursor(directory: LikePath) -> None: with chdir(directory): for item in symlinks: - src = item.get("src") + src: str = str(item["src"]) for link in item.get("links"): print(f"Creating symlink {src} -> {link}") os.symlink(src, link)