use izzylib.color
This commit is contained in:
parent
0e3eeec994
commit
55844397a7
|
@ -22,7 +22,6 @@ except:
|
|||
pass
|
||||
|
||||
try:
|
||||
from .color import Color
|
||||
from .template import Template
|
||||
except: pass
|
||||
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
from colour import Color as Colour
|
||||
|
||||
|
||||
class Color(Colour):
|
||||
def __init__(self, color):
|
||||
if isinstance(color, str):
|
||||
super().__init__(f'#{str(color)}' if not color.startswith('#') else color)
|
||||
|
||||
elif isinstance(color, Colour):
|
||||
super().__init__(str(color))
|
||||
|
||||
else:
|
||||
raise TypeError(f'Color has to be a string or Color class, not {type(color)}')
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return self.__str__()
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.hex_l
|
||||
|
||||
|
||||
def lighten(self, multiplier):
|
||||
return self.alter('lighten', multiplier)
|
||||
|
||||
|
||||
def darken(self, multiplier):
|
||||
return self.alter('darken', multiplier)
|
||||
|
||||
|
||||
def saturate(self, multiplier):
|
||||
return self.alter('saturate', multiplier)
|
||||
|
||||
|
||||
def desaturate(self, multiplier):
|
||||
return self.alter('desaturate', multiplier)
|
||||
|
||||
|
||||
def rgba(self, multiplier):
|
||||
return self.alter('rgba', multiplier)
|
||||
|
||||
|
||||
def multi(self, multiplier):
|
||||
if multiplier >= 100:
|
||||
return 100
|
||||
|
||||
elif multiplier <= 0:
|
||||
return 0
|
||||
|
||||
return multiplier / 100
|
||||
|
||||
|
||||
def alter(self, action, multiplier):
|
||||
new_color = Color(self)
|
||||
|
||||
if action == 'lighten':
|
||||
new_color.luminance += ((1 - self.luminance) * self.multi(multiplier))
|
||||
|
||||
elif action == 'darken':
|
||||
new_color.luminance -= (self.luminance * self.multi(multiplier))
|
||||
|
||||
elif action == 'saturate':
|
||||
new_color.saturation += ((1 - self.saturation) * self.multi(multiplier))
|
||||
|
||||
elif action == 'desaturate':
|
||||
new_color.saturation -= (self.saturation * self.multi(multiplier))
|
||||
|
||||
elif action == 'rgba':
|
||||
red = self.red*255
|
||||
green = self.green*255
|
||||
blue = self.blue*255
|
||||
trans = self.multi(multiplier)
|
||||
return f'rgba({red:0.2f}, {green:0.2f}, {blue:0.2f}, {trans})'
|
||||
|
||||
return new_color
|
||||
|
||||
|
||||
def color_func(action, color, multi):
|
||||
return Color(color).alter(action, multi)
|
|
@ -155,11 +155,8 @@ class ApplicationBase:
|
|||
elif isinstance(handler_response, ServerResponse):
|
||||
response = handler_response
|
||||
|
||||
elif not handler_response:
|
||||
pass
|
||||
|
||||
else:
|
||||
raise error.InternalServerError()
|
||||
elif handler_response:
|
||||
raise error.InternalServerError(f'Invalid server response type: {type(handler_response).__name__}')
|
||||
|
||||
await self.handle_middleware(request, response)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import mimetypes
|
||||
|
||||
from izzylib import DotDict, Path
|
||||
from izzylib import Color, DotDict, Path
|
||||
|
||||
from . import http_methods, error
|
||||
|
||||
|
@ -12,22 +12,17 @@ from ..exceptions import (
|
|||
try: import magic
|
||||
except ImportError: magic = None
|
||||
|
||||
try:
|
||||
from ..template import Color
|
||||
|
||||
default_theme = DotDict(
|
||||
primary = Color('#e7a'),
|
||||
secondary = Color('#a7e'),
|
||||
background = Color('#191919'),
|
||||
positive = Color('#aea'),
|
||||
negative = Color('#e99'),
|
||||
white = Color('#eee'),
|
||||
black = Color('#111'),
|
||||
speed = 250
|
||||
)
|
||||
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
default_theme = DotDict(
|
||||
primary = Color('#e7a'),
|
||||
secondary = Color('#a7e'),
|
||||
background = Color('#191919'),
|
||||
positive = Color('#aea'),
|
||||
negative = Color('#e99'),
|
||||
white = Color('#eee'),
|
||||
black = Color('#111'),
|
||||
speed = 250
|
||||
)
|
||||
|
||||
|
||||
class View:
|
||||
|
|
|
@ -2,14 +2,12 @@ import codecs, traceback, os, json, xml
|
|||
|
||||
from functools import partial
|
||||
from hamlish_jinja import HamlishExtension
|
||||
from izzylib import DotDict, Path, izzylog
|
||||
from izzylib import DotDict, Path, color, izzylog
|
||||
from jinja2 import Environment, FileSystemLoader, ChoiceLoader, select_autoescape
|
||||
from os import listdir, makedirs
|
||||
from os.path import isfile, isdir, getmtime, abspath
|
||||
from xml.dom import minidom
|
||||
|
||||
from .color import Color, color_func
|
||||
|
||||
try:
|
||||
from sanic import response as Response
|
||||
|
||||
|
@ -31,7 +29,7 @@ class Template(Environment):
|
|||
self.autoescape = autoescape
|
||||
self.func_context = context
|
||||
|
||||
self.hamlish_file_extensions=('.haml',)
|
||||
self.hamlish_file_extensions=('.haml', '.jhaml')
|
||||
self.hamlish_enable_div_shortcut=True
|
||||
self.hamlish_mode = 'indented'
|
||||
|
||||
|
@ -40,12 +38,12 @@ class Template(Environment):
|
|||
|
||||
self.globals.update({
|
||||
'cleanhtml': lambda text: ''.join(xml.etree.ElementTree.fromstring(text).itertext()),
|
||||
'color': Color,
|
||||
'lighten': partial(color_func, 'lighten'),
|
||||
'darken': partial(color_func, 'darken'),
|
||||
'saturate': partial(color_func, 'saturate'),
|
||||
'desaturate': partial(color_func, 'desaturate'),
|
||||
'rgba': partial(color_func, 'rgba')
|
||||
'Color': color.Color,
|
||||
'lighten': color.lighten,
|
||||
'darken': color.darken,
|
||||
'saturate': color.saturate,
|
||||
'desaturate': color.desaturate,
|
||||
'rgba': color.rgba
|
||||
})
|
||||
|
||||
self.globals.update(global_vars)
|
||||
|
|
Loading…
Reference in a new issue