Beispiel #1
0
def test_XCursor_from_bitmap_with_animated_png_exceptions(
        animated_png, hotspot, image_dir) -> None:
    """Testing XCursor `form_bitmap` classmethod exceptions for generating **animated** \
    cursor.
    """
    with pytest.raises(KeyError) as excinfo1:
        XCursor.from_bitmap()
    assert str(excinfo1.value) == "\"argument 'png' required\""

    with pytest.raises(KeyError) as excinfo2:
        XCursor.from_bitmap(png=animated_png)
    assert str(excinfo2.value) == "\"argument 'hotspot' required\""

    with pytest.raises(KeyError) as excinfo3:
        XCursor.from_bitmap(png=animated_png, hotspot=hotspot)
    assert str(excinfo3.value) == "\"argument 'x_sizes' required\""

    with pytest.raises(KeyError) as excinfo4:
        XCursor.from_bitmap(png=animated_png,
                            hotspot=hotspot,
                            x_sizes=(10, 10))
    assert str(excinfo4.value) == "\"argument 'out_dir' required\""

    with pytest.raises(KeyError) as excinfo5:
        XCursor.from_bitmap(png=animated_png,
                            hotspot=hotspot,
                            x_sizes=(10, 10),
                            out_dir=image_dir)
    assert str(excinfo5.value) == "\"argument 'delay' required\""
Beispiel #2
0
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)
Beispiel #3
0
def test_XCursor_from_bitmap_with_static_png(static_png, hotspot,
                                             image_dir) -> None:
    """Testing XCursor `form_bitmap` classmethod for generating **static** \
    cursor.
    """
    x = XCursor.from_bitmap(png=static_png,
                            hotspot=hotspot,
                            x_sizes=(10, 10),
                            out_dir=image_dir)
    assert x.exists() is True
    assert x.__sizeof__() > 0

    x1 = XCursor.from_bitmap(png=static_png,
                             hotspot=hotspot,
                             x_sizes=[(10, 10)],
                             out_dir=image_dir)
    assert x1.exists() is True
    assert x1.__sizeof__() > 0

    x2 = XCursor.from_bitmap(png=static_png,
                             hotspot=hotspot,
                             x_sizes=[(10, 10), (20, 20)],
                             out_dir=image_dir)
    assert x2.exists() is True
    assert x2.__sizeof__() > 0
Beispiel #4
0
def test_XCursor_generate_with_static_config(static_config, image_dir) -> None:
    """Testing XCursor generate **static** cursors."""
    x = XCursor(static_config, image_dir)
    x.generate()

    assert x.out.exists() is True
    assert x.out.__sizeof__() > 0
Beispiel #5
0
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)
Beispiel #6
0
def test_XCursor_from_bitmap_with_animated_png(animated_png, hotspot,
                                               image_dir) -> None:
    """Testing XCursor `form_bitmap` classmethod for generating **animated** \
    cursor.
    """
    # testing with single size
    x = XCursor.from_bitmap(
        png=animated_png,
        hotspot=hotspot,
        x_sizes=[(10, 10)],
        out_dir=image_dir,
        delay=1,
    )
    assert x.exists() is True
    assert x.__sizeof__() > 0

    x1 = XCursor.from_bitmap(png=animated_png,
                             hotspot=hotspot,
                             x_sizes=(10, 10),
                             out_dir=image_dir,
                             delay=1)
    assert x1.exists() is True
    assert x1.__sizeof__() > 0

    # testing with multiple sizes
    x2 = XCursor.from_bitmap(
        png=animated_png,
        hotspot=hotspot,
        x_sizes=[(10, 10), (20, 20)],
        out_dir=image_dir,
        delay=1,
    )
    assert x2.exists() is True
    assert x2.__sizeof__() > 0
Beispiel #7
0
def test_XCursor_generate_exception(image_dir) -> None:
    """Testing XCursor generate **RuntimeError** exception."""
    cfg: Path = image_dir / "test.alias"
    cfg.write_text("10 10 10 test/test.png")
    x = XCursor(cfg, image_dir)
    with pytest.raises(RuntimeError) as excinfo:
        x.generate()

    assert (str(excinfo.value) ==
            "'xcursorgen' failed to generate XCursor from 'test.alias'")
Beispiel #8
0
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)
Beispiel #9
0
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)
Beispiel #11
0
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)
Beispiel #12
0
def test_XCursor(static_config, image_dir) -> None:
    """Testing XCursor members value."""

    x = XCursor(static_config, image_dir)
    assert x.config_file == static_config

    # We know 'out_dir' is not exists
    assert x.out_dir.exists() is True
    assert x.out_dir == image_dir / "cursors"
Beispiel #13
0
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)
Beispiel #14
0
def test_XCursor_config_file_not_found_exception(image_dir) -> None:
    """Testing XCursor raises **FileNotFoundError** for config_file or not."""
    with pytest.raises(FileNotFoundError) as excinfo:
        XCursor(image_dir, image_dir)
    assert str(excinfo.value
               ) == f"'{image_dir.name}' is not found or not a config file"
Beispiel #15
0
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)