Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement urwid image widget #73

Merged
merged 46 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
bffef06
feat: Add `term_image.widget` subpackage
AnonymouX47 Feb 4, 2023
98dc135
feat: Add urwid image widget and canvas
AnonymouX47 Feb 4, 2023
2997d8f
docs: Add `term_image.widget` to the docs
AnonymouX47 Feb 4, 2023
b65823d
fix: Add `urwid` to docs build requirements
AnonymouX47 Feb 4, 2023
bcfb04a
fix: Correct typos in `.widget.urwid`
AnonymouX47 Feb 5, 2023
53bd90e
fix: Handle packed widget render for `UrwidImage`
AnonymouX47 Feb 5, 2023
e8f89b2
fix: Add workaround for urwid images on last row
AnonymouX47 Feb 5, 2023
6a21592
docs: Update docstrings of urwid image classes
AnonymouX47 Feb 5, 2023
fad1257
test: Add tests for urwid image widget and canvas
AnonymouX47 Feb 5, 2023
7ee6fa1
chore: Add make targets for urwid and widget tests
AnonymouX47 Feb 5, 2023
5f7a832
docs: Remove "urwid widgets" from planned features
AnonymouX47 Feb 5, 2023
fe5a8c4
Merge branch 'main'
AnonymouX47 Feb 11, 2023
d061a30
refactor: Update `urwid` last row workaround
AnonymouX47 Feb 11, 2023
13e690e
feat: Add support for `urwid` horizontal trimming
AnonymouX47 Feb 11, 2023
3a26d93
test: Update `urwid` image widget and canvas tests
AnonymouX47 Feb 11, 2023
bebce96
refactor: Deconjest `UrwidImageCanvas.content()`
AnonymouX47 Feb 11, 2023
dd1ecb7
fix: Fix error when the image is fully trimmed
AnonymouX47 Feb 11, 2023
e821347
refactor: Modify `UrwidImageCanvas` constructor
AnonymouX47 Feb 15, 2023
765ef8a
fix: Fix urwid canvas horizontally trimmed output
AnonymouX47 Feb 18, 2023
8b1a5e0
test: Add tests for urwid canvas trim calculation
AnonymouX47 Feb 18, 2023
7edcea8
test: Add tests for urwid canvas trim output
AnonymouX47 Feb 18, 2023
5677ee7
docs: Update docstring for canvas trim calculation
AnonymouX47 Feb 18, 2023
5dc92cc
Merge branch 'main'
AnonymouX47 Feb 18, 2023
47fbbf3
Merge branch 'main'
AnonymouX47 Feb 20, 2023
8a41b08
feat: Add exception class specific to `UrwidImage`
AnonymouX47 Feb 20, 2023
1815149
feat: Add per-widget clear for kitty urwid images
AnonymouX47 Feb 20, 2023
f9cdfdf
feat: Disallow image blend for urwid kitty images
AnonymouX47 Feb 20, 2023
d725c9c
docs: Update documentation within `UrwidImage`
AnonymouX47 Feb 20, 2023
96c3a92
feat: Add `UrwidImageJanitor`
AnonymouX47 Feb 20, 2023
7c29212
fix: Handle error at GC of `UrwidImage` objects
AnonymouX47 Feb 20, 2023
0d19a10
fix: Validate argument for `UrwidImageJanitor`
AnonymouX47 Feb 21, 2023
8caf332
feat: Add `UrwidImageJanitor.widget` property
AnonymouX47 Feb 21, 2023
74a70a1
refactor: Optimize `UrwidImageJanitor`
AnonymouX47 Feb 21, 2023
fad6833
refactor: Rename `UrwidImageJanitor._ti_images`
AnonymouX47 Feb 21, 2023
c217837
feat: Add the *now* param to `UrwidImage.clear*()`
AnonymouX47 Feb 22, 2023
99b0a19
Merge branch 'main'
AnonymouX47 Feb 22, 2023
c1af6af
docs: Update `UrwidImageJanitor` docstring
AnonymouX47 Feb 22, 2023
f0cb34b
feat: Add `.widget.UrwidImageScreen`
AnonymouX47 Feb 22, 2023
b3eb6fb
docs: Update `UrwidImage.clear*()` docstrings
AnonymouX47 Feb 22, 2023
a8574e7
test: Add tests for `UrwidImageScreen`
AnonymouX47 Feb 22, 2023
1e6e8a3
test: Add tests for `UrwidImageJanitor`
AnonymouX47 Feb 22, 2023
fd7e533
refactor: Make `UrwidImage` unselectable
AnonymouX47 Feb 23, 2023
c2ddb72
test: Update tests for `UrwidImage`
AnonymouX47 Feb 23, 2023
5440f8f
test: Update tests for `UrwidImageCanvas` disguise
AnonymouX47 Feb 23, 2023
cfe9808
test: Update tests for `UrwidImageJanitor`
AnonymouX47 Feb 23, 2023
48b9b08
Update CHANGELOG for #73
AnonymouX47 Feb 23, 2023
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `write_tty()`
- Support for clearing *kitty* images by z-index ([97eceab]).
- Support for clearing *iterm2* images on konsole by intersection with cursor position ([807a9ec]).
- Widgets and related classes to display images with [urwid](https://urwid.org) ([#73]).
- `term_image.widget` subpackage
- `term_image.widget.UrwidImage`
- `term_image.widget.UrwidImageCanvas`
- `term_image.widget.UrwidImageJanitor`
- `term_image.widget.UrwidImageScreen`

### Changed
- **(BREAKING!)** Redefined `KittyImage.clear()` ([97eceab]).
Expand All @@ -36,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[#70]: https://github.com/AnonymouX47/term-image/pull/70
[#72]: https://github.com/AnonymouX47/term-image/pull/72
[#73]: https://github.com/AnonymouX47/term-image/pull/73
[#74]: https://github.com/AnonymouX47/term-image/pull/74
[b4533d5]: https://github.com/AnonymouX47/term-image/commit/b4533d5697d41fe0742c2ac895077da3b8d889dc
[97eceab]: https://github.com/AnonymouX47/term-image/commit/97eceab77e7448a18281aa6edb3fa8ec9e6564c5
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ uninstall:
# Tests

test-all: test test-url
test: test-base test-iterator test-others test-graphics test-text
test: test-base test-iterator test-others test-graphics test-text test-widget
test-graphics: test-kitty test-iterm2
test-text: test-block
test-widget: test-urwid

# Executing using `python -m` adds CWD to `sys.path`.

Expand All @@ -88,3 +89,6 @@ test-block:

test-url:
python -m pytest -v tests/test_url.py

test-urwid:
python -m pytest -v tests/test_widget/test_urwid.py
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
sphinx==6.1.2
furo==2022.12.7
urwid==2.1.2
1 change: 0 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ In no particular order:
* Use ``termpile`` for URL-sourced images
* Source images from raw pixel data
* IPython Extension
* Addition of urwid widgets for displaying images
* etc...


Expand Down
1 change: 1 addition & 0 deletions docs/source/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Reference
:caption: Sub-sections:

image
widget
exceptions
utils

Expand Down
8 changes: 8 additions & 0 deletions docs/source/reference/widget.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TUI Widgets
===========

.. automodule:: term_image.widget
:members:
:show-inheritance:

The ``term_image.widget`` module defines the following:
7 changes: 7 additions & 0 deletions src/term_image/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class KittyImageError(GraphicsImageError):
"""


# Widgets


class UrwidImageError(TermImageError):
"""Raised for errors specific to :py:class:`~term_image.widget.UrwidImage`."""


__all__ = ["TermImageWarning"] + [
name
for name, obj in vars().items()
Expand Down
20 changes: 20 additions & 0 deletions src/term_image/widget/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
""".. Image widgets for TUI frameworks"""

from __future__ import annotations

__all__ = []

try:
import urwid
except ImportError:
pass
else:
from .urwid import UrwidImage, UrwidImageCanvas, UrwidImageJanitor, UrwidImageScreen

del urwid
__all__ += [
"UrwidImage",
"UrwidImageCanvas",
"UrwidImageJanitor",
"UrwidImageScreen",
]
Loading