def xbuild(config: Dict[str, Dict[str, Any]], x_out_dir: Path, info: Info) -> None: """Build `GoogleDot` cursor theme for only `X11`(UNIX) platform. :param config: `GoogleDot` configuration. :type config: ``Dict`` :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: ``pathlib.Path`` :param info: Content theme name & comment. :type info: Info """ for _, item in config.items(): with CursorAlias.from_bitmap(item["png"], item["hotspot"]) as alias: x_cfg = alias.create(item["x_sizes"], item["delay"]) print(f"Building '{x_cfg.stem}' XCursor...") XCursor.create(x_cfg, x_out_dir) add_missing_xcursor(x_out_dir / "cursors") XPackager(x_out_dir, info.name, info.comment)
def build() -> None: config = get_config() # Building for _, item in config.items(): png = item["png"] hotspot = item["hotspot"] delay = item["delay"] with CursorAlias.from_bitmap(png, hotspot) as alias: x_cfg = alias.create(X_SIZES, delay) XCursor.create(x_cfg, x_out_dir) if item.get("win_key"): win_build(item, alias) theme_name: str = "Example" comment: str = "Example theme generated from clickgen" author: str = "Kaiz Khatri" url: str = "https://github.com/ful1e5/clickgen/tree/main/examples" add_missing_xcursors(x_out_dir / "cursors", rename=True, force=True) XPackager(x_out_dir, theme_name, comment) WindowsPackager(win_out_dir, theme_name, comment, author, url)
def test_add_missing_xcursors_without_rename_and_force( data, tmpdir_factory: pytest.TempdirFactory) -> None: d = tmpdir_factory.mktemp("ffff") tmp_dir = Path(d) images = create_test_image(tmp_dir, 2, key="fffff0") with CursorAlias.from_bitmap(images, (0, 0)) as alias: config_file = alias.create((10, 10), delay=2) XCursor.create(config_file, tmp_dir) x_dir = tmp_dir / "cursors" add_missing_xcursors(x_dir, data) assert list(map(lambda x: x.name, x_dir.iterdir())) == ["fffff0"] shutil.rmtree(tmp_dir)
def test_XCursor_create_with_static_config(static_config, image_dir) -> None: """Testing XCursor `create` classmethod for generating **static** \ cursor. """ x = XCursor.create(static_config, image_dir) assert x.exists() is True assert x.__sizeof__() > 0
def build(config: Dict[str, Dict[str, Any]], x_out_dir: Path, win_out_dir: Path, info: Info) -> None: """Build `Bibata Rainbow` cursor theme for `X11` & `Windows` platforms. :param config: `Bibata` configuration. :type config: Dict[str, Dict[str, Any]] :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 :param info: Content theme name & comment :type info: Dict """ def win_build(item: Dict[str, Any], alias: CursorAlias) -> None: 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).rename(win_key) print(f"Building '{win_cfg.stem}' Windows Cursor...") WindowsCursor.create(win_cfg, win_out_dir) for _, item in config.items(): 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) print(f"Building '{x_cfg.stem}' XCursor...") XCursor.create(x_cfg, x_out_dir) if item.get("win_key"): win_build(item, alias) add_missing_xcursor(x_out_dir / "cursors") XPackager(x_out_dir, info.name, info.comment) WindowsPackager(win_out_dir, info.name, info.comment, AUTHOR, URL)
def build( config: Dict[str, Dict[str, Any]], x_out_dir: Path, win_out_dir: Path, info: Info ) -> None: """Build `macOSBigSur` cursor theme for `X11` & `Windows` platforms. :param config: `macOSBigSur` configuration. :type config: ``Dict`` :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: ``pathlib.Path`` :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: ``pathlib.Path`` :param info: Content theme name & comment. :type info: Info """ for _, item in config.items(): with CursorAlias.from_bitmap(item["png"], item["hotspot"]) as alias: x_cfg = alias.create(item["x_sizes"], item["delay"]) print(f"Building '{x_cfg.stem}' XCursor...") XCursor.create(x_cfg, x_out_dir) if item.get("win_key"): win_cfg = alias.reproduce( size=item["win_size"], canvas_size=item["canvas_size"], position=item["position"], delay=item["win_delay"], ).rename(item["win_key"]) print(f"Building '{win_cfg.stem}' Windows Cursor...") WindowsCursor.create(win_cfg, win_out_dir) add_missing_xcursor(x_out_dir / "cursors") XPackager(x_out_dir, info.name, info.comment) WindowsPackager(win_out_dir, info.name, info.comment, AUTHOR, URL)
def test_add_missing_xcursors_with_rename_and_force( data, tmpdir_factory: pytest.TempdirFactory) -> None: d = tmpdir_factory.mktemp("ffff") tmp_dir = Path(d) images = create_test_image(tmp_dir, 2, key="ffffd") with CursorAlias.from_bitmap(images, (0, 0)) as alias: config_file = alias.create((10, 10), delay=2) XCursor.create(config_file, tmp_dir) x_dir = tmp_dir / "cursors" add_missing_xcursors(x_dir, data, rename=True) with pytest.raises(FileExistsError): add_missing_xcursors(x_dir, data, rename=True) add_missing_xcursors(x_dir, data, rename=True, force=True) assert sorted(list(map(lambda x: x.name, x_dir.iterdir()))) == sorted(["ddddd", "ffffff"]) shutil.rmtree(tmp_dir)
def main() -> None: parser = argparse.ArgumentParser( prog="clickgen", description="The hassle-free cursor building toolbox", ) # Positional Args. parser.add_argument( "png", metavar="PNG", type=str, nargs="+", help= "Path to .png file. If animated, Try to mask frame-number using asterisk( * ). For Example 'wait-*.png'", ) parser.add_argument( "-o", "--out-dir", dest="out_dir", metavar="OUT", type=str, default="./", help="To change output directory. (default: %(default)s)", ) # Optional Args. parser.add_argument( "-hot", "--hotspot", dest="hotspot", metavar="cord", nargs=2, default=(0, 0), type=int, help= "To set 'x' & 'y' coordinates of cursor's hotspot. (default: %(default)s)", ) parser.add_argument( "-t", "--type", dest="type", choices=("windows", "xcursor", "all"), default="all", help= "Set cursor type, Which you want to build. (default: '%(default)s')", ) parser.add_argument( "-s", "--sizes", dest="sizes", metavar="size", nargs="+", default=[22], type=int, help="Set pixel-size for cursor. (default: %(default)s)", ) parser.add_argument( "-d", "--delay", dest="delay", metavar="ms", default=50, type=int, help= "Set animated cursor's frames delay in 'micro-second'. (default: %(default)s)", ) args = parser.parse_args() hotspot = (args.hotspot[0], args.hotspot[1]) sizes = [(s, s) for s in args.sizes] out_dir = Path(args.out_dir) if not out_dir.exists(): out_dir.mkdir(parents=True, exist_ok=True) with CursorAlias.from_bitmap(args.png, hotspot) as alias: cfg = alias.create(sizes) if args.type == "windows": WindowsCursor.create(cfg, out_dir) elif args.type == "xcursor": # Using Temporary directory, Because 'XCursor' create inside 'cursors' directory. tmp_dir = Path(tempfile.mkdtemp()) try: xcursor = XCursor.create(cfg, tmp_dir) shutil.move(str(xcursor.absolute()), str(out_dir.absolute())) finally: shutil.rmtree(tmp_dir) else: tmp_dir = Path(tempfile.mkdtemp()) try: xcursor = XCursor.create(cfg, tmp_dir) win_cursor = WindowsCursor.create(cfg, tmp_dir) shutil.move(str(xcursor.absolute()), str(out_dir.absolute())) shutil.move(str(win_cursor.absolute()), str(out_dir.absolute())) finally: shutil.rmtree(tmp_dir)