summaryrefslogtreecommitdiff
path: root/pywal/util.py
diff options
context:
space:
mode:
authordylan <dylan.araps@gmail.com>2020-01-23 10:38:33 +0200
committerGitHub <noreply@github.com>2020-01-23 10:38:33 +0200
commitc1d90676f9074cf4131f8cb94aeb2344d6fc8ecc (patch)
tree63e7fe384b10449fd893b5a2da3e90199df21dae /pywal/util.py
parent7ecc2ffd39d1c01639da666dd4dbe0aa4789f85c (diff)
parent3537e8cc8f2af2051dd695ef1ca7247e76e0f74f (diff)
Merge branch 'master' into add-vs-code-support
Diffstat (limited to 'pywal/util.py')
-rw-r--r--pywal/util.py50
1 files changed, 45 insertions, 5 deletions
diff --git a/pywal/util.py b/pywal/util.py
index 4495dbe..cd6628a 100644
--- a/pywal/util.py
+++ b/pywal/util.py
@@ -5,6 +5,9 @@ import colorsys
import json
import logging
import os
+import platform
+import re
+import shutil
import subprocess
import sys
@@ -30,6 +33,12 @@ class Color:
return hex_to_xrgba(self.hex_color)
@property
+ def rgba(self):
+ """Convert a hex color to rgba."""
+ return "rgba(%s,%s,%s,%s)" % (*hex_to_rgb(self.hex_color),
+ int(self.alpha_num) / 100)
+
+ @property
def alpha(self):
"""Add URxvt alpha value to color."""
return "[%s]%s" % (self.alpha_num, self.hex_color)
@@ -49,6 +58,21 @@ class Color:
"""Strip '#' from color."""
return self.hex_color[1:]
+ def lighten(self, percent):
+ """Lighten color by percent"""
+ percent = float(re.sub(r'[\D\.]', '', str(percent)))
+ return Color(lighten_color(self.hex_color, percent / 100))
+
+ def darken(self, percent):
+ """Darken color by percent"""
+ percent = float(re.sub(r'[\D\.]', '', str(percent)))
+ return Color(darken_color(self.hex_color, percent / 100))
+
+ def saturate(self, percent):
+ """Saturate a color"""
+ percent = float(re.sub(r'[\D\.]', '', str(percent)))
+ return Color(saturate_color(self.hex_color, percent / 100))
+
def read_file(input_file):
"""Read data from a file and trim newlines."""
@@ -148,12 +172,11 @@ def blend_color(color, color2):
def saturate_color(color, amount):
"""Saturate a hex color."""
r, g, b = hex_to_rgb(color)
- r, g, b = [x/255.0 for x in (r, g, b)]
- h, s, v = colorsys.rgb_to_hsv(r, g, b)
+ r, g, b = [x / 255.0 for x in (r, g, b)]
+ h, l, s = colorsys.rgb_to_hls(r, g, b)
s = amount
- v = 0.2
- r, g, b = colorsys.hls_to_rgb(h, s, v)
- r, g, b = [x*255.0 for x in (r, g, b)]
+ r, g, b = colorsys.hls_to_rgb(h, l, s)
+ r, g, b = [x * 255.0 for x in (r, g, b)]
return rgb_to_hex((int(r), int(g), int(b)))
@@ -169,3 +192,20 @@ def disown(cmd):
subprocess.Popen(cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
+
+
+def get_pid(name):
+ """Check if process is running by name."""
+ if not shutil.which("pidof"):
+ return False
+
+ try:
+ if platform.system() != 'Darwin':
+ subprocess.check_output(["pidof", "-s", name])
+ else:
+ subprocess.check_output(["pidof", name])
+
+ except subprocess.CalledProcessError:
+ return False
+
+ return True