mirror of
https://github.com/ful1e5/apple_cursor.git
synced 2025-05-27 21:44:23 -04:00
🔧 Dynamic Cursors sizes
This commit is contained in:
parent
3f09a14176
commit
d6f9ad8750
4 changed files with 109 additions and 85 deletions
|
@ -6,15 +6,47 @@ from typing import Any, Dict, List, Tuple, Union
|
|||
|
||||
from clickgen.util import LikePath, PNGProvider
|
||||
|
||||
from applbuild.constants import *
|
||||
from applbuild.constants import (
|
||||
WIN_CANVAS_SIZE,
|
||||
WIN_CURSORS_CFG,
|
||||
WIN_DELAY,
|
||||
WIN_SIZE,
|
||||
X_CURSORS_CFG,
|
||||
X_DELAY,
|
||||
X_SIZES,
|
||||
)
|
||||
|
||||
|
||||
def get_config(bitmaps_dir: LikePath) -> Dict[str, Any]:
|
||||
def get_config(bitmaps_dir: LikePath, **kwargs) -> Dict[str, Any]:
|
||||
"""Return configuration of `macOSBigSur` pointers.
|
||||
|
||||
Args:
|
||||
|
||||
:bitmaps_dir: (str | Path) Path to .png file's directory.
|
||||
|
||||
Keywords Args:
|
||||
|
||||
:x_sizes: (List[Tuple[int, int]] | Tuple[int, int]) List or Tuple of xcursor sizes.
|
||||
|
||||
:win_size: (Tuple[int, int]) Single size for Windows cursor.
|
||||
|
||||
Example:
|
||||
|
||||
```python
|
||||
get_config("./bitmaps", x_sizes=[(24, 24), (32, 32)], win_size=(32, 32))
|
||||
```
|
||||
"""
|
||||
|
||||
if kwargs.get("x_sizes"):
|
||||
x_sizes = kwargs.pop("x_sizes")
|
||||
else:
|
||||
x_sizes = X_SIZES
|
||||
|
||||
if kwargs.get("win_size"):
|
||||
w_size = kwargs.pop("win_size")
|
||||
else:
|
||||
w_size = WIN_SIZE
|
||||
|
||||
png = PNGProvider(bitmaps_dir)
|
||||
config: Dict[str, Any] = {}
|
||||
|
||||
|
@ -28,6 +60,7 @@ def get_config(bitmaps_dir: LikePath) -> Dict[str, Any]:
|
|||
|
||||
data = {
|
||||
"png": p,
|
||||
"x_sizes": x_sizes,
|
||||
"hotspot": hotspot,
|
||||
"delay": delay,
|
||||
}
|
||||
|
@ -38,16 +71,22 @@ def get_config(bitmaps_dir: LikePath) -> Dict[str, Any]:
|
|||
win_key = win_data.get("to")
|
||||
|
||||
position = win_data.get("position", "center")
|
||||
canvas_size: Tuple[int, int] = win_data.get("canvas_size", CANVAS_SIZE)
|
||||
size: Tuple[int, int] = win_data.get("size", SIZE)
|
||||
win_delay: int = win_data.get("delay", WIN_DELAY)
|
||||
|
||||
canvas_size: Tuple[int, int] = win_data.get("canvas_size", WIN_CANVAS_SIZE)
|
||||
win_size: Tuple[int, int] = 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]):
|
||||
canvas_size = win_size
|
||||
|
||||
config[key] = {
|
||||
**data,
|
||||
"win_key": win_key,
|
||||
"position": position,
|
||||
"canvas_size": canvas_size,
|
||||
"size": size,
|
||||
"win_size": win_size,
|
||||
"win_delay": win_delay,
|
||||
}
|
||||
else:
|
||||
|
|
|
@ -29,13 +29,13 @@ X_SIZES: List[Tuple[int, int]] = [
|
|||
|
||||
# Windows Cursor
|
||||
WIN_DELAY = 1
|
||||
CANVAS_SIZE = (32, 32)
|
||||
SIZE = (24, 24)
|
||||
WIN_CANVAS_SIZE = (32, 32)
|
||||
WIN_SIZE = (24, 24)
|
||||
|
||||
X_CURSORS_CFG: Dict[str, Dict[str, int]] = {
|
||||
#
|
||||
# Static
|
||||
#
|
||||
##########
|
||||
# Static #
|
||||
##########
|
||||
"all-scroll.png": {"xhot": 100, "yhot": 100},
|
||||
"bottom_left_corner.png": {"xhot": 100, "yhot": 100},
|
||||
"bottom_right_corner.png": {"xhot": 100, "yhot": 100},
|
||||
|
@ -78,20 +78,20 @@ X_CURSORS_CFG: Dict[str, Dict[str, int]] = {
|
|||
"xterm.png": {"xhot": 100, "yhot": 104},
|
||||
"zoom-in.png": {"xhot": 100, "yhot": 100},
|
||||
"zoom-out.png": {"xhot": 100, "yhot": 100},
|
||||
#
|
||||
# Animated
|
||||
#
|
||||
# Note: Animated cursors not need any extension & frames number
|
||||
"wait": {"xhot": 100, "yhot": 100},
|
||||
############
|
||||
# Animated #
|
||||
############
|
||||
# Note: Animated cursors don't need an extension and frame numbers.
|
||||
"left_ptr_watch": {"xhot": 67, "yhot": 46},
|
||||
"wait": {"xhot": 100, "yhot": 100},
|
||||
}
|
||||
|
||||
WIN_CURSORS_CFG: Dict[str, Dict[str, str]] = {
|
||||
#
|
||||
# Static
|
||||
#
|
||||
"right_ptr.png": {"to": "Alternate", "position": "top_left"},
|
||||
"cross.png": {"to": "Cross", "size": (32, 32)},
|
||||
##########
|
||||
# Static #
|
||||
##########
|
||||
"right_ptr.png": {"to": "Alternate", "position": "top_right"},
|
||||
"cross.png": {"to": "Cross"},
|
||||
"left_ptr.png": {"to": "Default", "position": "top_left"},
|
||||
"bottom_left_corner.png": {"to": "Diagonal_1"},
|
||||
"bottom_right_corner.png": {"to": "Diagonal_2"},
|
||||
|
@ -101,16 +101,12 @@ WIN_CURSORS_CFG: Dict[str, Dict[str, str]] = {
|
|||
"xterm.png": {"to": "IBeam", "position": "top_left"},
|
||||
"hand2.png": {"to": "Link", "position": "top_left"},
|
||||
"hand1.png": {"to": "Move"},
|
||||
"crossed_circle.png": {
|
||||
"to": "Unavailiable",
|
||||
"position": "top_left",
|
||||
"size": (32, 32),
|
||||
},
|
||||
"crossed_circle.png": {"to": "Unavailiable", "position": "top_left"},
|
||||
"sb_v_double_arrow.png": {"to": "Vertical"},
|
||||
#
|
||||
# Animated
|
||||
#
|
||||
# Note: Animated cursors not need any extension & frames number
|
||||
"wait": {"to": "Busy", "size": (28, 28)},
|
||||
"left_ptr_watch": {"to": "Work", "position": "top_left", "size": (28, 28)},
|
||||
############
|
||||
# Animated #
|
||||
############
|
||||
# Note: Animated cursors don't need frame numbers.
|
||||
"left_ptr_watch": {"to": "Work", "position": "top_left"},
|
||||
"wait": {"to": "Busy", "size": WIN_CANVAS_SIZE},
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, Dict
|
||||
|
||||
from clickgen.builders import WindowsCursor, XCursor
|
||||
from clickgen.core import CursorAlias
|
||||
|
@ -10,32 +10,32 @@ from clickgen.packagers import WindowsPackager, XPackager
|
|||
from clickgen.util import LikePath
|
||||
|
||||
from applbuild.configure import get_config
|
||||
from applbuild.constants import *
|
||||
from applbuild.constants import AUTHOR, COMMENT, THEME_NAME, URL
|
||||
from applbuild.symlinks import add_missing_xcursor
|
||||
|
||||
#
|
||||
# 📝 Note: All CONSTANT variables are imported from `applbuild.constants` module.
|
||||
#
|
||||
|
||||
|
||||
def xbuild(bitmaps_dir: LikePath, x_out_dir: Path) -> None:
|
||||
def xbuild(
|
||||
bitmaps_dir: LikePath,
|
||||
x_out_dir: Path,
|
||||
) -> None:
|
||||
"""Build `macOSBigSur` cursor theme for only `X11`(UNIX) platform.
|
||||
|
||||
:bitmaps_dir: (str | Path) Path to .png file's directory.
|
||||
|
||||
:x_out_dir: (Path) Path to output directory, Where X11 cursor theme package store. Created automatically if not exists.
|
||||
: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.
|
||||
"""
|
||||
|
||||
config = get_config(bitmaps_dir)
|
||||
config: Dict[str, Dict[str, Any]] = get_config(bitmaps_dir)
|
||||
|
||||
# Building
|
||||
for _, item in config.items():
|
||||
png = item["png"]
|
||||
hotspot = item["hotspot"]
|
||||
delay = item["delay"]
|
||||
png = item.get("png")
|
||||
hotspot = item.get("hotspot")
|
||||
x_sizes = item.get("x_sizes")
|
||||
delay = item.get("delay")
|
||||
|
||||
with CursorAlias.from_bitmap(png, hotspot) as alias:
|
||||
x_cfg = alias.create(X_SIZES, delay)
|
||||
x_cfg = alias.create(x_sizes, delay)
|
||||
print(f"Building '{x_cfg.stem}' XCursor...")
|
||||
XCursor.create(x_cfg, x_out_dir)
|
||||
|
||||
|
@ -48,29 +48,30 @@ def wbuild(bitmaps_dir: LikePath, win_out_dir: Path) -> None:
|
|||
|
||||
:bitmaps_dir: (str | Path) Path to .png file's directory.
|
||||
|
||||
:win_out_dir: (Path) Path to output directory, Where Windows Cursor theme package store. Created automatically if not exists.
|
||||
: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.
|
||||
"""
|
||||
|
||||
config = get_config(bitmaps_dir)
|
||||
config: Dict[str, Dict[str, Any]] = get_config(bitmaps_dir)
|
||||
|
||||
# Building
|
||||
for _, item in config.items():
|
||||
png = item["png"]
|
||||
hotspot = item["hotspot"]
|
||||
delay = item["delay"]
|
||||
png = item.get("png")
|
||||
hotspot = item.get("hotspot")
|
||||
x_sizes = item.get("x_sizes")
|
||||
delay = item.get("delay")
|
||||
|
||||
with CursorAlias.from_bitmap(png, hotspot) as alias:
|
||||
alias.create(X_SIZES, delay)
|
||||
alias.create(x_sizes, delay)
|
||||
|
||||
if item.get("win_key"):
|
||||
position = item["position"]
|
||||
size = item["size"]
|
||||
win_key = item["win_key"]
|
||||
canvas_size = item["canvas_size"]
|
||||
win_delay = item["win_delay"]
|
||||
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")
|
||||
|
||||
win_cfg = alias.reproduce(
|
||||
size, canvas_size, position, delay=win_delay
|
||||
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)
|
||||
|
@ -83,34 +84,35 @@ def build(bitmaps_dir: LikePath, x_out_dir: Path, win_out_dir: Path) -> None:
|
|||
|
||||
:bitmaps_dir: (str | Path) Path to .png file's directory.
|
||||
|
||||
:x_out_dir: (Path) Path to output directory, Where X11 cursor theme package store. Created automatically if not exists.
|
||||
: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.
|
||||
|
||||
:win_out_dir: (Path) Path to output directory, Where Windows Cursor theme package store. Created automatically if not exists.
|
||||
: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.
|
||||
"""
|
||||
|
||||
def win_build(item: Any, alias: CursorAlias) -> None:
|
||||
position = item["position"]
|
||||
size = item["size"]
|
||||
win_key = item["win_key"]
|
||||
canvas_size = item["canvas_size"]
|
||||
win_delay = item["win_delay"]
|
||||
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")
|
||||
|
||||
win_cfg = alias.reproduce(size, canvas_size, position, delay=win_delay).rename(
|
||||
win_key
|
||||
)
|
||||
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)
|
||||
|
||||
config = get_config(bitmaps_dir)
|
||||
config: Dict[str, Dict[str, Any]] = get_config(bitmaps_dir)
|
||||
|
||||
# Building
|
||||
for _, item in config.items():
|
||||
png = item["png"]
|
||||
hotspot = item["hotspot"]
|
||||
delay = item["delay"]
|
||||
png = item.get("png")
|
||||
hotspot = item.get("hotspot")
|
||||
x_sizes = item.get("x_sizes")
|
||||
delay = item.get("delay")
|
||||
|
||||
with CursorAlias.from_bitmap(png, hotspot) as alias:
|
||||
x_cfg = alias.create(X_SIZES, delay)
|
||||
x_cfg = alias.create(x_sizes, delay)
|
||||
print(f"Building '{x_cfg.stem}' XCursor...")
|
||||
XCursor.create(x_cfg, x_out_dir)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue