feat: add coloryou custom python script and some packages

This commit is contained in:
matt1432 2023-08-16 23:28:58 -04:00
parent 1f36e97b05
commit 330dfa896f
10 changed files with 123 additions and 3 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.egg-info

View file

@ -14,6 +14,7 @@ in
(builtins.getFlake "github:hyprwm/Hyprland").packages.x86_64-linux.default
(builtins.getFlake "path:/home/matt/git/hyprland-touch-gestures").packages.x86_64-linux.default
pkgs.kora-icon-theme
pkgs.coloryou
];
imports = [

View file

@ -13,8 +13,7 @@
waybar = {
enable = true;
# https://discourse.nixos.org/t/how-to-use-waybar-hyprland/27638/6
package = (builtins.getFlake "github:hyprwm/Hyprland").packages.x86_64-linux.waybar-hyprland;
package = pkgs.waybar-hyprland;
};
};
@ -75,6 +74,7 @@
libayatana-appindicator
libnotify
libinput
playerctl
dracula-theme
dracula-icon-theme
steam-run

View file

@ -18,6 +18,10 @@
dracula-plymouth = final.callPackage ./pkgs/dracula-plymouth.nix {};
})
(final: prev: {
coloryou = final.callPackage ./pkgs/coloryou/default.nix {};
})
(import (builtins.fetchTarball {
url = "https://github.com/nix-community/neovim-nightly-overlay/archive/master.tar.gz";
}))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,48 @@
#!/usr/bin/env python
"""
The original script:
https://github.com/dharmx/vile/blob/7d486c128c7e553912673755f97b118aaab0193d/src/shell/playerctl.py#L2
"""
import argparse
import utils
from material_color_utilities_python import *
parser = argparse.ArgumentParser(
prog='coloryou',
description='Extract Material You colors from an image',
epilog='coucou')
parser.add_argument("image_path", help="A full path to your image", type=str)
args = parser.parse_args()
def get_material_you_colors(image_path: str) -> dict:
"""Get the material you pallete colors from an image and save them to a
JSON file if it isn't already. Then return the path to that JSON file.
Arguments:
image_path: The location of the image.
Returns:
A dict of image accent color, button accent color and button text color eg: {'image_accent': '#292929', 'button_accent': '#BEBFC1', 'button_text': '#292929'}
"""
"""if image_path == default_cover:
return {'image_accent': '#292929', 'button_accent': '#BEBFC1', 'button_text': '#292929'}"""
img = Image.open(image_path)
basewidth = 64
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize),Image.Resampling.LANCZOS)
theme = themeFromImage(img)
themePalette = theme.get("palettes")
themePalettePrimary = themePalette.get("primary")
parsed_colors = {"image_accent": hexFromArgb(themePalettePrimary.tone(40)), "button_accent": hexFromArgb(themePalettePrimary.tone(90)), "button_text": hexFromArgb(themePalettePrimary.tone(10))}
# parsed_colors = {"bright": colors[3], "dark": colors[9]}
return parsed_colors
print(get_material_you_colors(args.image_path))

View file

@ -0,0 +1,48 @@
# https://blog.hackeriet.no/packaging-python-script-for-nixos/
# Below, we can supply defaults for the function arguments to make the script
# runnable with `nix-build` without having to supply arguments manually.
# Also, this lets me build with Python 3.11 by default, but makes it easy
# to change the python version for customised builds (e.g. testing).
{ nixpkgs ? import <nixpkgs> {}, pythonPkgs ? nixpkgs.pkgs.python311Packages }:
let
# This takes all Nix packages into this scope
inherit (nixpkgs) pkgs;
# This takes all Python packages from the selected version into this scope.
inherit pythonPkgs;
# Inject dependencies into the build function
f = { buildPythonPackage, utils, material-color-utilities }:
buildPythonPackage rec {
pname = "coloryou";
version = "0.0.1";
# If you have your sources locally, you can specify a path
src = ./.;
# Pull source from a Git server.
#src = builtins.fetchGit {
#url = "git://github.com/stigok/ruterstop.git";
#ref = "master";
#rev = "a9a4cd60e609ed3471b4b8fac8958d009053260d";
#};
# Specify runtime dependencies for the package
propagatedBuildInputs = [ utils material-color-utilities ];
postInstall = ''
mv -v $out/bin/coloryou.py $out/bin/coloryou
'';
meta = {
description = ''
Get Material You colors from an image.
'';
};
};
drv = pythonPkgs.callPackage f {};
in
if pkgs.lib.inNixShell then drv.env else drv

View file

@ -0,0 +1,2 @@
material-color-utilities
utils

View file

@ -0,0 +1,7 @@
from distutils.core import setup
setup(
name='coloryou',
version='0.0.1',
scripts=['coloryou.py',],
)

View file

@ -0,0 +1,8 @@
with import <nixpkgs> {};
with pkgs.python311Packages;
buildPythonPackage rec {
name = "coloryou";
src = ./.;
propagatedBuildInputs = [ material-color-utilities utils ];
}