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
6 changes: 3 additions & 3 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.13
- name: Set up Python 3.14
uses: actions/setup-python@v4
with:
python-version: 3.13
python-version: 3.14
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install coverage setuptools
pip install coverage setuptools pytest pytest-asyncio
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run Coverage
run: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pip
python -m pip install pytest pytest-asyncio
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run Unittests
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,4 @@ cython_debug/
marimo/_static/
marimo/_lsp/
__marimo__/
.aider*
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ description = "A thin slider control widget for the Textual UI platform"
authors = [
{ name = "Robert Abram", email = "rabram991@gmail.com" },
]
dependencies = ["textual", ]
dependencies = [
"textual",
]
readme = "README.md"
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down Expand Up @@ -39,6 +41,14 @@ keywords = [
"control"
]

[project.optional-dependencies]
dev = [
"build",
"pytest",
"pytest-asyncio",
"coverage",
]

[project.urls]
Homepage = "https://github.com/robabram/textual-thin-slider"
Repository = "https://github.com/robabram/textual-thin-slider"
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
textual

# Development, build or testing libraries
build
pytest
pytest-asyncio
coverage
# build
# pytest
# pytest-asyncio
# coverage
29 changes: 21 additions & 8 deletions src/textual_thin_slider/thinslider.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,23 @@ class ThinSliderRender:
SOLID_GLYPH: ClassVar[str] = "█"
BLANK_GLYPH: ClassVar[str] = " "

range_min: int = 0
range_max: int = 0
value: int = 0
display_type: ThinSliderDisplayOptions = ThinSliderDisplayOptions.none

def __init__(self, range_min: int = 0, range_max: int = 100, value: int = 0,
display_type: ThinSliderDisplayOptions = ThinSliderDisplayOptions.none) -> None:
self.range_min = range_min
self.range_max = range_max
self.value = value
self.display_type = display_type

def update(self, value: int = None):
""" Update the slider position value and return self """
self.value = value or self.value
return self

@classmethod
def render_bar(cls, range_min: int, range_max: int, size: int, value: int,
display_type: ThinSliderDisplayOptions) -> str:
Expand Down Expand Up @@ -105,7 +115,8 @@ class ThinSlider(Widget, can_focus=True):
"""
A Textual thin slider control widget.
"""
renderer: ClassVar[Type[ThinSliderRender]] = ThinSliderRender
renderer_cls: ClassVar[Type[ThinSliderRender]] = ThinSliderRender
renderer: ThinSliderRender
# Prevent user from selecting text within the widget
ALLOW_SELECT = False

Expand All @@ -121,7 +132,7 @@ class ThinSlider(Widget, can_focus=True):
background: $surface;
padding: 0 0;

color: $foreground 90%;
color: $foreground 80%;

&:focus {
# border: tall $border;
Expand Down Expand Up @@ -183,6 +194,13 @@ def __init__(self, range_min: int, range_max: int,

self._virtual_pos = ((self.value - self.min) / (self.total_steps / 100)) / self.step

self.renderer = self.renderer_cls(
range_min=self.min,
range_max=self.max,
value=self.value,
display_type=self.display_type
)

@property
def total_steps(self) -> int:
return int((self.max - self.min) / self.step) + 1
Expand All @@ -204,12 +222,7 @@ def watch_value(self) -> None:

def render(self) -> RenderableType:
""" Render the slider bar """
return self.renderer(
range_min=self.min,
range_max=self.max,
value=self.value,
display_type=self.display_type
)
return self.renderer.update(self.value)

def _calc_bar_min_max_positions(self, display_left: int, width: int) -> tuple[int, int]:
"""
Expand Down
Loading