feat: use ctp python lib instead of hardcoded colors (#55)

This commit is contained in:
Pranav Santhosh
2022-12-08 21:06:51 +05:30
committed by GitHub
parent 34ac795d4e
commit 17aaa5b36c
9 changed files with 88 additions and 244 deletions

View File

@@ -65,6 +65,9 @@ With your favourite AUR helper, install them:
Clone the repository using
```bash
git clone --recurse-submodules git@github.com:npv12/gtk.git
virtualenv -p python3 venv # to be created only once and only if you need a virtual env
source venv/bin/activate
pip install -r requirements.txt
```
To check out the install script, run
```bash
@@ -83,7 +86,6 @@ python build.py
A few important notes to keep in mind
* `recolor.py` handles all changes that needs to be done to colloid to ensure it generated catppuccin colors. If vinceliuice changes anything in his theme in future, that is where you must change
* `ctp_colors.py` includes all catppuccin colors and accent. If any colors beside accent is included, ensure it is changed in `get_accent` as well.
* `var.py` includes all different variables that you can tinker around as per your personal requirements.
* `create_theme.py` consists of a wrapper that will recolor the colloid theme, install it as per the args provided and rename it accordingly.

View File

@@ -1,8 +1,8 @@
from scripts.create_theme import create_theme
from scripts.ctp_colors import ctp_colors
from scripts.ctp_colors import ctp_colors, get_all_accent
for theme, value in ctp_colors.items():
for accent, _ in value.get_accent().items():
for accent, _ in get_all_accent(value).items():
print("\n\n\nCreating theme for", theme, "with accent", accent)
create_theme(theme, accent)

Submodule colloid updated: 34cfc98fa9...5b08fdbf1c

View File

@@ -43,7 +43,7 @@ parser.add_argument('--accent', '-a',
parser.add_argument("--size", "-s",
metavar='Size of the theme',
type=str,
default="compact",
default="standard",
dest="size",
choices=['standard', 'compact'],
help='Size variant of the theme. Can be standard or compact')
@@ -51,7 +51,7 @@ parser.add_argument("--size", "-s",
parser.add_argument('--tweaks',
metavar='Colloid specific tweaks',
type=str,
default=["rimless"],
default=[],
nargs='+',
dest="tweaks",
choices=['black', 'rimless', 'normal'],

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
catppuccin>=1.1.1

View File

@@ -7,7 +7,7 @@ from scripts.recolor import recolor
from scripts.var import def_color_map, theme_name, tmp_dir, work_dir
def create_theme(type: str, accent: str, dest: str = tmp_dir, link: bool = False, name: str = theme_name, size: str = "compact", tweaks=['rimless']) -> str:
def create_theme(type: str, accent: str, dest: str = tmp_dir, link: bool = False, name: str = theme_name, size: str = "standard", tweaks=[]) -> str:
try:
os.makedirs(tmp_dir) # Create our temporary directory

View File

@@ -1,178 +1,16 @@
class Color:
def __init__(self, rosewater, flamingo, pink, mauve, red, maroon, peach,
yellow, green, teal, sky, sapphire, blue, lavender,
text, subtext0, subtext1, overlay0, overlay1, overlay2,
surface0, surface1, surface2, base, mantle, crust):
from catppuccin import Flavour
self.rosewater = rosewater # All accent colours
self.flamingo = flamingo
self.pink = pink
self.mauve = mauve
self.red = red
self.maroon = maroon
self.peach = peach
self.yellow = yellow
self.green = green
self.teal = teal
self.sky = sky
self.sapphire = sapphire
self.blue = blue
self.lavender = lavender
self.white = text
self.black = base
ctp_colors = {
"latte": Flavour.latte(),
"mocha": Flavour.mocha(),
"frappe": Flavour.frappe(),
"macchiato": Flavour.macchiato()
}
self.text = text # All remaining colors
self.subtext0 = subtext0
self.subtext1 = subtext1
self.overlay0 = overlay0
self.overlay1 = overlay1
self.overlay2 = overlay2
self.surface0 = surface0
self.surface1 = surface1
self.surface2 = surface2
self.base = base
self.mantle = mantle
self.crust = crust
self.color_map = {}
self.__create_color_map__()
# Function to create a map of colors to their names
def __create_color_map__(self):
for key, value in self.__dict__.items():
if key != "color_map":
self.color_map[key] = value
def get_accent(self):
def get_all_accent(color):
accent = {}
for key, value in self.color_map.items():
for key, value in color.__dict__.items():
if key not in ['white', 'black', 'text', 'subtext0', 'subtext1', 'overlay0', 'overlay1', 'overlay2', 'surface0', 'surface1', 'surface2', 'base', 'mantle', 'crust']:
accent[key] = value
return accent
# Light =
latte = Color(
rosewater="#dc8a78",
flamingo="#dd7878",
pink="#ea76cb",
mauve="#8839ef",
red="#d20f39",
maroon="#e64553",
peach="#fe640b",
yellow="#df8e1d",
green="#40a02b",
teal="#179299",
sky="#04a5e5",
sapphire="#209fb5",
blue="#1e66f5",
lavender="#7287fd",
text="#4c4f69",
subtext0="#6c6f85",
subtext1="#5c5f77",
overlay0="#9ca0b0",
overlay1="#8c8fa1",
overlay2="#7c7f93",
surface0="#ccd0da",
surface1="#bcc0cc",
surface2="#acb0be",
base="#eff1f5",
mantle="#e6e9ef",
crust="#dce0e8",
)
# Dark
mocha = Color(
rosewater="#f5e0dc",
flamingo="#f2cdcd",
pink="#f5c2e7",
mauve="#cba6f7",
red="#f38ba8",
maroon="#eba0ac",
peach="#fab387",
yellow="#f9e2af",
green="#a6e3a1",
teal="#94e2d5",
sky="#89dceb",
sapphire="#74c7ec",
blue="#89b4fa",
lavender="#b4befe",
text="#cdd6f4",
subtext0="#a6adc8",
subtext1="#bac2de",
overlay0="#6c7086",
overlay1="#7f849c",
overlay2="#9399b2",
surface0="#313244",
surface1="#45475a",
surface2="#585b70",
base="#1e1e2e",
mantle="#181825",
crust="#11111b",
)
frappe = Color(
rosewater="#f2d5cf",
flamingo="#eebebe",
pink="#f4b8e4",
mauve="#ca9ee6",
red="#e78284",
maroon="#ea999c",
peach="#ef9f76",
yellow="#e5c890",
green="#a6d189",
teal="#81c8be",
sky="#99d1db",
sapphire="#85c1dc",
blue="#8caaee",
lavender="#babbf1",
text="#c6d0f5",
subtext0="#a5adce",
subtext1="#b5bfe2",
overlay0="#a5adce",
overlay1="#838ba7",
overlay2="#949cbb",
surface0="#414559",
surface1="#51576d",
surface2="#626880",
base="#303446",
mantle="#292c3c",
crust="#232634"
)
macchiato = Color(
rosewater="#f4dbd6",
flamingo="#f0c6c6",
pink="#f5bde6",
mauve="#c6a0f6",
red="#ed8796",
maroon="#ee99a0",
peach="#f5a97f",
yellow="#eed49f",
green="#a6da95",
teal="#8bd5ca",
sky="#91d7e3",
sapphire="#7dc4e4",
blue="#8aadf4",
lavender="#b7bdf8",
text="#cad3f5",
subtext0="#a5adcb",
subtext1="#b8c0e0",
overlay0="#6e738d",
overlay1="#8087a2",
overlay2="#939ab7",
surface0="#363a4f",
surface1="#494d64",
surface2="#5b6078",
base="#24273a",
mantle="#1e2030",
crust="#181926"
)
ctp_colors = {
"latte": latte,
"mocha": mocha,
"frappe": frappe,
"macchiato": macchiato
}

View File

@@ -1,9 +1,11 @@
from .ctp_colors import Color, latte, mocha
from catppuccin import Flavour
from .utils import replacetext
from .var import src_dir, theme_name, work_dir, def_accent_dark, def_accent_light, def_color_map
from .var import (def_accent_dark, def_accent_light, def_color_map, src_dir,
theme_name, work_dir)
def recolor_accent(color: Color, file: str, accent: str = "blue"):
def recolor_accent(color, file: str, accent: str = "blue"):
"""
Recolors the accent color in a file.
color:
@@ -14,19 +16,23 @@ def recolor_accent(color: Color, file: str, accent: str = "blue"):
The accent color to replace. Defaults to Blue
"""
print(f"Recoloring accent for {file}...")
# Recolor as per accent for light. Hard code it as latte
replacetext(file, def_accent_light[def_color_map[accent]], latte.color_map[accent])
for key, value in Flavour.latte().__dict__.items():
if key == accent:
replacetext(
file, def_accent_light[def_color_map[accent]], value.hex)
# Recolor as per base for dark theme.
replacetext(file, def_accent_dark[def_color_map[accent]], color.color_map[accent])
for key, value in color.__dict__.items():
if key == accent:
replacetext(
file, def_accent_dark[def_color_map[accent]], value.hex)
def recolor(color: Color, accent: str):
def recolor(color, accent: str):
"""
Recolor the theme. currently hard code it frappe
"""
global latte
print("Recoloring to suit catppuccin theme")
replacetext(f"{work_dir}/install.sh", "Colloid", theme_name)
@@ -35,94 +41,91 @@ def recolor(color: Color, accent: str):
recolor_accent(color, f"{work_dir}/gtkrc.sh", accent)
replacetext(f"{work_dir}/gtkrc.sh", "background_light='#FFFFFF'",
f"background_light='{latte.base}'") # use latte_base for background_light
f"background_light='#{Flavour.latte().base.hex}'") # use latte_base for background_light
replacetext(f"{work_dir}/gtkrc.sh", "background_dark='#0F0F0F'",
f"background_dark='{color.base}'")
f"background_dark='#{color.base.hex}'")
replacetext(f"{work_dir}/gtkrc.sh", "background_darker='#121212'",
f"background_darker='{color.mantle}'")
f"background_darker='#{color.mantle.hex}'")
replacetext(f"{work_dir}/gtkrc.sh",
"background_alt='#212121'", f"background_alt='{color.crust}'")
"background_alt='#212121'", f"background_alt='#{color.crust.hex}'")
replacetext(f"{work_dir}/gtkrc.sh", "titlebar_light='#F2F2F2'",
f"titlebar_light='{latte.crust}'") # use latte_crust for titlebar_light
f"titlebar_light='#{Flavour.latte().crust.hex}'") # use latte_crust for titlebar_light
replacetext(f"{work_dir}/gtkrc.sh", "titlebar_dark='#030303'",
f"titlebar_dark='{color.crust}'")
f"titlebar_dark='#{color.crust.hex}'")
replacetext(f"{work_dir}/gtkrc.sh", "background_dark='#2C2C2C'",
f"background_dark='{color.base}'")
f"background_dark='#{color.base.hex}'")
replacetext(f"{work_dir}/gtkrc.sh", "background_darker='#3C3C3C'",
f"background_darker='{color.mantle}'")
f"background_darker='#{color.mantle.hex}'")
replacetext(f"{work_dir}/gtkrc.sh",
"background_alt='#464646'", f"background_alt='{color.crust}'")
"background_alt='#464646'", f"background_alt='#{color.crust.hex}'")
replacetext(f"{work_dir}/gtkrc.sh",
"titlebar_light='#F2F2F2'", f"titlebar_light='{latte.crust}'")
"titlebar_light='#F2F2F2'", f"titlebar_light='#{Flavour.latte().crust.hex}'")
replacetext(f"{work_dir}/gtkrc.sh",
"titlebar_dark='#242424'", f"titlebar_dark='{color.crust}'")
"titlebar_dark='#242424'", f"titlebar_dark='#{color.crust.hex}'")
print("Mod SASS Color_Palette_default")
recolor_accent(
color, f"{src_dir}/sass/_color-palette-default.scss", accent)
# Greys
if color == latte: # Hardcode till someone smarter than me comes along
if color == Flavour.latte(): # Hardcode till someone smarter than me comes along
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-050: #FAFAFA", f"grey-050: {color.crust}")
"grey-050: #FAFAFA", f"grey-050: #{color.crust.hex}")
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-100: #F2F2F2", f"grey-100: {color.mantle}")
"grey-100: #F2F2F2", f"grey-100: #{color.mantle.hex}")
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-150: #EEEEEE", f"grey-150: {color.base}")
"grey-150: #EEEEEE", f"grey-150: #{color.base.hex}")
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-200: #DDDDDD", f"grey-200: {color.surface0}") # Surface 0 Late
"grey-200: #DDDDDD", f"grey-200: #{color.surface0.hex}") # Surface 0 Late
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-250: #CCCCCC", f"grey-250: {color.surface1}") # D = Surface 1 Late
"grey-250: #CCCCCC", f"grey-250: #{color.surface1.hex}") # D = Surface 1 Late
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-650: #3C3C3C", f"grey-650: {mocha.surface0}") # H $surface $tooltip
"grey-650: #3C3C3C", f"grey-650: #{Flavour.mocha().surface0.hex}") # H $surface $tooltip
replacetext(f"{src_dir}/sass/_color-palette-default.scss", "grey-700: #2C2C2C",
f"grey-700: {mocha.base}") # G $background; $base; titlebar-backdrop; $popover
f"grey-700: #{Flavour.mocha().base.hex}") # G $background; $base; titlebar-backdrop; $popover
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-750: #242424", f"grey-750: {mocha.crust}") # F $base-alt
"grey-750: #242424", f"grey-750: #{Flavour.mocha().crust.hex}") # F $base-alt
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-800: #212121", f"grey-800: {mocha.crust}") # E $panel-solid;p
"grey-800: #212121", f"grey-800: #{Flavour.mocha().crust.hex}") # E $panel-solid;p
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-850: #121212", f"grey-850: {mocha.surface1}") # H Darknes
"grey-850: #121212", f"grey-850: #{Flavour.mocha().surface1.hex}") # H Darknes
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-900: #0F0F0F", f"grey-900: {mocha.base}") # G Darknes
"grey-900: #0F0F0F", f"grey-900: #{Flavour.mocha().base.hex}") # G Darknes
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-950: #030303", f"grey-950: {mocha.crust}") # F Darknes
"grey-950: #030303", f"grey-950: #{Flavour.mocha().crust.hex}") # F Darknes
else:
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-050: #FAFAFA", f"grey-050: {color.overlay2}")
"grey-050: #FAFAFA", f"grey-050: #{color.overlay2.hex}")
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-100: #F2F2F2", f"grey-100: {color.overlay1}")
"grey-100: #F2F2F2", f"grey-100: #{color.overlay1.hex}")
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-150: #EEEEEE", f"grey-150: {color.overlay0}")
"grey-150: #EEEEEE", f"grey-150: #{color.overlay0.hex}")
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-200: #DDDDDD", f"grey-200: {color.surface2}") # Surface 0 Late
"grey-200: #DDDDDD", f"grey-200: #{color.surface2.hex}") # Surface 0 Late
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-250: #CCCCCC", f"grey-250: {color.surface1}") # D = Surface 1 Late
"grey-250: #CCCCCC", f"grey-250: #{color.surface1.hex}") # D = Surface 1 Late
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-650: #3C3C3C", f"grey-650: {color.surface0}") # H $surface $tooltip
"grey-650: #3C3C3C", f"grey-650: #{color.surface0.hex}") # H $surface $tooltip
replacetext(f"{src_dir}/sass/_color-palette-default.scss", "grey-700: #2C2C2C",
f"grey-700: {color.base}") # G $background; $base; titlebar-backdrop; $popover
f"grey-700: #{color.base.hex}") # G $background; $base; titlebar-backdrop; $popover
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-750: #242424", f"grey-750: {color.crust}") # F $base-alt
"grey-750: #242424", f"grey-750: #{color.crust.hex}") # F $base-alt
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-800: #212121", f"grey-800: {color.crust}") # E $panel-solid;p
"grey-800: #212121", f"grey-800: #{color.crust.hex}") # E $panel-solid;p
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-850: #121212", f"grey-850: {color.surface1}") # H Darknes
"grey-850: #121212", f"grey-850: #{color.surface1.hex}") # H Darknes
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-900: #0F0F0F", f"grey-900: {color.base}") # G Darknes
"grey-900: #0F0F0F", f"grey-900: #{color.base.hex}") # G Darknes
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"grey-950: #030303", f"grey-950: {color.crust}") # F Darknes
# I personally do not like this but this seems more accurate
replacetext(f"{src_dir}/sass/_color-palette-default.scss", "white: #FFFFFF", f"white: {color.white}")
replacetext(f"{src_dir}/sass/_color-palette-default.scss", "black: #FFFFFF", f"black: {color.black}")
"grey-950: #030303", f"grey-950: #{color.crust.hex}") # F Darknes
# Buttons
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"button-close: #fd5f51", f"button-close: {color.red}")
"button-close: #fd5f51", f"button-close: #{color.red.hex}")
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"button-max: #38c76a", f"button-max: {color.green}")
"button-max: #38c76a", f"button-max: #{color.green.hex}")
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
"button-min: #fdbe04", f"button-min: {color.yellow}")
"button-min: #fdbe04", f"button-min: #{color.yellow.hex}")
print("Mod Accent Cinnamon")
recolor_accent(color, f"{src_dir}/assets/cinnamon/make-assets.sh", accent)

View File

@@ -28,23 +28,23 @@ def_color_map = {
'lavender': 'default'}
def_accent_light = {
'default': '#3c84f7',
'purple': '#AB47BC',
'pink': '#EC407A',
'red': '#E53935',
'orange': '#F57C00',
'yellow': '#FBC02D',
'green': '#4CAF50',
'teal': '#009688'
'default': '3c84f7',
'purple': 'AB47BC',
'pink': 'EC407A',
'red': 'E53935',
'orange': 'F57C00',
'yellow': 'FBC02D',
'green': '4CAF50',
'teal': '009688'
}
def_accent_dark = {
'default': '#5b9bf8',
'purple': '#BA68C8',
'pink': '#F06292',
'red': '#F44336',
'orange': '#FB8C00',
'yellow': '#FFD600',
'green': '#66BB6A',
'teal': '#4DB6AC'
'default': '5b9bf8',
'purple': 'BA68C8',
'pink': 'F06292',
'red': 'F44336',
'orange': 'FB8C00',
'yellow': 'FFD600',
'green': '66BB6A',
'teal': '4DB6AC'
}