Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Coverage

on: [push]

jobs:
coverage:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.14
uses: actions/setup-python@v4
with:
python-version: 3.14
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install coverage pytest pytest-asyncio
if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi
- name: Run Coverage
run: |
export PYTHONPATH=./src
coverage run -m pytest tests
- name: Generate Coverage Report
run: |
coverage report -m
coverage xml
- name: Creating coverage folder
run: |
mkdir -p coverage
pip install -U genbadge defusedxml
genbadge coverage -i coverage.xml -o coverage/coverage.svg
- name: Publish coverage report to coverage-badge branch
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: coverage-badge
folder: coverage
27 changes: 27 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Tests

on: [push]

jobs:
unittests:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest pytest-asyncio
if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi
- name: Run Unittests
run: |
export PYTHONPATH=./src
pytest -v tests
Binary file added examples/images/color-gradient-example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/images/simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dev = [
"pytest",
"pytest-asyncio",
"coverage",
"textual-thin-slider",
]

[project.urls]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ textual
# pytest
# pytest-asyncio
# coverage
# textual-thin-slider
9 changes: 4 additions & 5 deletions src/textual_color_gradient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#
from .color_gradient import ColorGradient, ColorGradientRenderer, GRADIENT_RANGE_MAX, GRADIENT_RANGE_MIN


__all__ = [
ColorGradient,
ColorGradientRenderer,
GRADIENT_RANGE_MAX,
GRADIENT_RANGE_MIN,
"ColorGradient",
"ColorGradientRenderer",
"GRADIENT_RANGE_MAX",
"GRADIENT_RANGE_MIN",
]
18 changes: 9 additions & 9 deletions src/textual_color_gradient/color_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
import colorsys
from math import ceil
from typing import ClassVar, Any, Type
from typing import ClassVar, Any, Type, Union, List

from rich.color import Color as RichColor
from rich.segment import Segment
Expand Down Expand Up @@ -42,7 +42,7 @@ def _hsv_to_rgb(cls, hue: int, sat: int, val: int) -> tuple:
))

@classmethod
def _gradient_gen(cls, y: int, hue: int, sat: int, val: int, width: int, height: int, target: bool) -> list[Any]:
def _gradient_gen(cls, y: int, hue: int, sat: int, val: int, width: int, height: int, target: bool) -> List[Any]:
""" Calculate the H, S and V values for each cell of the gradient square """
horz_step = GRADIENT_RANGE_MAX / width
vert_step = GRADIENT_RANGE_MAX / height
Expand Down Expand Up @@ -72,7 +72,7 @@ def _gradient_gen(cls, y: int, hue: int, sat: int, val: int, width: int, height:
)
return segments

def render_line_segment(self, hsv: HSV, y: int, width: int, height: int, target: bool = True) -> list[Segment]:
def render_line_segment(self, hsv: HSV, y: int, width: int, height: int, target: bool = True) -> List[Segment]:
return self._gradient_gen(
y,
round(hsv.h * GRADIENT_RANGE_MAX),
Expand Down Expand Up @@ -108,26 +108,26 @@ def watch_value(self) -> None:
self.post_message(self.Changed(self, self.value))

def to_color(self) -> Color:
return Color.from_hsv(self.value)
return Color.from_hsv(*self.value)

class Changed(Message):
"""
Posted when the value of the gradient changes.
This message can be handled using an `on_gradient_changed` method.
"""
def __init__(self, color_manager: ColorGradient, hsv: HSV) -> None:
def __init__(self, color_manager: "ColorGradient", hsv: HSV) -> None:
super().__init__()
self.hsv = hsv
self.__control__: ColorGradient = color_manager
self.__control__: "ColorGradient" = color_manager

@property
def control(self) -> ColorGradient:
def control(self) -> "ColorGradient":
return self.__control__

# -- ------------------------------------------------------------

def __init__(self, value: HSV | None = None, name: str | None = None, id: str | None = None,
classes: str | None = None, disabled: bool = False) -> None:
def __init__(self, value: Union[HSV, None] = None, name: Union[str, None] = None, id: Union[str, None] = None,
classes: Union[str, None] = None, disabled: bool = False) -> None:
super().__init__(name=name, id=id, classes=classes, disabled=disabled, markup=False)
self.value = value if value is not None else HSV(*_INITIAL_HSV)
self.renderer = ColorGradientRenderer()
Expand Down
6 changes: 2 additions & 4 deletions tests/test_gradient_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
# This file is subject to the terms and conditions defined in the
# file 'LICENSE', which is part of this source code package.
#
import colorsys
from textual.color import HSV, Color
from src.textual_color_gradient.color_gradient import (ColorGradient, ColorGradientRenderer, GRADIENT_RANGE_MIN,
GRADIENT_RANGE_MAX)
from textual.color import HSV
from src.textual_color_gradient.color_gradient import ColorGradientRenderer, GRADIENT_RANGE_MIN, GRADIENT_RANGE_MAX


TEST_HSV = (0.0, 121 / GRADIENT_RANGE_MAX, 131 / GRADIENT_RANGE_MAX)
Expand Down
Loading