👷 Bibata cursors builder

This commit is contained in:
ful1e5 2020-10-08 17:45:11 +05:30
parent f1fbce7510
commit 24e5506fdd
4 changed files with 93 additions and 26 deletions

View file

@ -2,6 +2,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from .cursor import CursorBuilder from .cursor import CursorBuilder
from .provider import ConfigsProvider from .config import ConfigProvider
__version__: str = "1.0.1" __version__: str = "1.0.1"

View file

@ -6,21 +6,22 @@ import log
import sys import sys
import json import json
import builder import builder
import tempfile
from os import path, listdir from os import path, listdir
import shutil import shutil
class ConfigsProvider(): class ConfigProvider():
""" """
Configure `Bibata` building process. Configure `Bibata` building process.
""" """
# Build Config # Build Config
__delay = 35 delay = 35
__sizes = [22, 24, 28, 32, 40, 48, 56, 64, 72, 80, 88, 96] sizes = [22, 24, 28, 32, 40, 48, 56, 64, 72, 80, 88, 96]
# Windows Cursors Config # Windows Cursors Config
__windows_cursors = { windows_cursors = {
"left_ptr_watch.ani": "AppStarting.ani", "left_ptr_watch.ani": "AppStarting.ani",
"left_ptr.cur": "Arrow.cur", "left_ptr.cur": "Arrow.cur",
"crosshair.cur": "Cross.cur", "crosshair.cur": "Cross.cur",
@ -52,8 +53,9 @@ class ConfigsProvider():
os.mkdir(out_dir) os.mkdir(out_dir)
self.__bitmaps_dir: str = bitmaps_dir self.bitmaps_dir: str = bitmaps_dir
self.__out_dir: str = out_dir self.temp_out_dir: str = tempfile.mkdtemp()
self.out_dir: str = out_dir
# read hotspots file # read hotspots file
with open(path.join(builder.__path__[0], "hotspots.json")) as hotspot_file: with open(path.join(builder.__path__[0], "hotspots.json")) as hotspot_file:

View file

@ -1,16 +1,94 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import builder import tempfile
from .provider import ConfigsProvider import shutil
from os import path, listdir, rename, remove, makedirs
from .config import ConfigProvider
from clickgen import build_x11_cursor_theme, build_cursor_theme, build_win_cursor_theme
class CursorBuilder(): class CursorBuilder():
""" """
docstring Bibata cursors builder 🚀
""" """
def __init__(self, configs: ConfigsProvider): def __init__(self, name: str, config: ConfigProvider):
self.__config = config
self.__name = name
self.__x11_out = name
self.__windows_out = name + "-" + "Windows"
self.__temp_out_dir = tempfile.mkdtemp()
print("⚡ Bibata Builder Version %s" % builder.__version__) def __window_bundle(self, win_out_dir: str):
self.__configs = configs # Remove & Rename cursors
# If Key found => Rename else Remove
for cursor in listdir(win_out_dir):
old_path = path.join(win_out_dir, cursor)
try:
new_path = path.join(
win_out_dir, self.__config.windows_cursors[cursor])
rename(old_path, new_path)
except KeyError:
remove(old_path)
# creating install.inf file
install_inf_path = path.join(win_out_dir, "install.inf")
with open(install_inf_path, "w") as file:
file.write(self.__config.get_windows_script(
theme_name=self.__name, author="Kaiz Khatri"))
def __pack_win(self):
win_out_dir = path.join(self.__config.out_dir, self.__windows_out)
shutil.move(path.join(self.__temp_out_dir,
self.__name, "win"), win_out_dir)
# create install.inf file in Windows Theme
self.__window_bundle(win_out_dir)
def __pack_x11(self):
x11_out_dir = path.join(self.__config.out_dir, self.__x11_out)
shutil.move(path.join(self.__temp_out_dir,
self.__name, "x11"), x11_out_dir)
def build_x11_cursors(self):
print('🌈 Building %s Theme ...' % self.__name)
build_x11_cursor_theme(
name=self.__name,
image_dir=self.__config.bitmaps_dir,
cursor_sizes=self.__config.sizes,
hotspots=self.__config.hotspots,
out_path=self.__temp_out_dir,
archive=False,
delay=self.__config.delay
)
self.__pack_x11()
def build_win_cursors(self):
print('🌈 Building %s Theme ...' % self.__name)
build_win_cursor_theme(
name=self.__name,
image_dir=self.__config.bitmaps_dir,
cursor_sizes=self.__config.sizes,
hotspots=self.__config.hotspots,
out_path=self.__temp_out_dir,
archive=False,
delay=self.__config.delay
)
self.__pack_win()
def build_cursors(self):
print('🌈 Building %s Theme ...' % self.__name)
build_cursor_theme(
name=self.__name,
image_dir=self.__config.bitmaps_dir,
cursor_sizes=self.__config.sizes,
hotspots=self.__config.hotspots,
out_path=self.__temp_out_dir,
archive=False,
delay=self.__config.delay
)
self.__pack_x11()
self.__pack_win()

View file

@ -1,13 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .provider import ConfigsProvider
class Packager():
"""
Create Crisp 📦 Packages for Windows & X11 Cursor Theme.
"""
def __init__(self, configs: ConfigsProvider):
self.__configs = configs