Skip to main content

urw-scroll-table

A scrollable and editable table widget for urwid terminal applications.

Features

  • Scrollable: Both horizontal and vertical scrolling support
  • Editable: In-place editing of table cells
  • Multiple Cell Types: Support for text, editable, and dropdown cell types
  • Keyboard Navigation: Full keyboard navigation with arrow keys
  • Customizable Styling: Customizable colors and appearance
  • Compact Display: Efficient use of terminal space

Installation

This package uses Poetry for dependency management. To install:

pip install urw-scroll-table

or manually:

# Clone the repository
git clone https://github.com/zhum/urw-scroll-table.git
cd urw-scroll-table

# Install dependencies
poetry install

# Activate the virtual environment
poetry shell

Quick Start

import urwid
from urw_scroll_table import UrwScrollTable

# Define your data
headers = ['Name', 'Age', 'City', 'Status']
data = [
    ['Alice', 25, 'New York', 'Active'],
    ['Bob', 30, 'Los Angeles', 'Active'],
    ['Charlie', 35, 'Chicago', 'Inactive'],
]

# Define column types
column_types = {
    0: 'editable',    # Name - editable text
    1: 'editable',    # Age - editable text
    2: 'editable',    # City - editable text
    3: 'dropdown',    # Status - dropdown
}

# Create the table widget
table = UrwScrollTable(
    headers=headers,
    data=data,
    column_types=column_types
)

# Create and run the application
frame = urwid.Frame(body=table)
loop = urwid.MainLoop(frame)
loop.run()

Usage

Basic Table Creation

from urw_scroll_table import UrwScrollTable

table = UrwScrollTable(
    headers=['Name', 'Age', 'City'],
    data=[
        ['Alice', 25, 'New York'],
        ['Bob', 30, 'Los Angeles'],
    ]
)

Column Types

The table supports three column types:

  • 'text': Read-only text display (default)
  • 'editable': Editable text cells
  • 'dropdown': Dropdown selection cells
column_types = {
    0: 'editable',    # Column 0 is editable
    1: 'dropdown',    # Column 1 is a dropdown
    2: 'text',        # Column 2 is read-only
}

Customization

Colors

You can customize the appearance using the colors parameter. Available options are: 'header', 'active_cell', 'editing_cell', and 'status'. colors parameter accepts a dictionary with options as keys, and tuples for foreground color and background color. Available colors are:

  • for background: 'black', 'dark red', 'dark green', 'brown', 'dark blue', 'dark magenta', 'dark cyan', 'light gray'.
  • for foreground: as above, and 'dark gray', 'light red', 'light green', 'yellow', 'light blue', 'light magenta', 'light cyan', 'white'.
  • you may use 'default' to use default terminal colors.
colors = {
    'header': ('white', 'dark blue'),
    'active_cell': ('black', 'white'),
    'editing_cell': ('black', 'yellow'),
}

table = UrwScrollTable(
    headers=headers,
    data=data,
    colors=colors
)

You may use 24-bit colors like below. 4-th and 5-th fields are foreground and background colors. If terminal does not support 24 bit color, 1-st and 2-nd fields are used.

custom_colors = {
    'header': ('dark blue', 'light red', 'default', '#00f', '#ff0'),
    'active_cell': ('white', 'light green', 'default', '#999', '#12f'),
    'editing_cell': ('dark blue', 'dark green', 'default', '#005', '#0f0'),
}

Size Constraints

table = UrwScrollTable(
    headers=headers,
    data=data,
    max_width=100,    # Maximum width
    max_height=20,    # Maximum height
)

Keyboard Controls

  • Arrow Keys: Navigate between cells
  • Enter: Start editing the current cell (opens popup for dropdowns)
  • Esc: Cancel editing
  • Up/Down (in dropdown popup): Navigate dropdown options
  • Enter (in dropdown popup): Select option and close popup
  • Esc (in dropdown popup): Cancel selection and close popup
  • q: Quit the application

Examples

Complete Example

See examples/demo.py for a complete working example:

cd examples
python demo.py

Custom Dropdown Options

You can customize dropdown options by modifying the _get_dropdown_options method in the UrwScrollTable class:

def _get_dropdown_options(self, col_idx):
    """Get dropdown options for a specific column."""
    if col_idx == 0:  # Status column
        return ['Active', 'Inactive', 'Pending', 'Suspended']
    elif col_idx == 1:  # Priority column
        return ['Low', 'Medium', 'High', 'Critical']
    else:
        return []

API Reference

UrwScrollTable

The main table widget class.

Constructor Parameters

  • headers (list): List of header strings
  • data (list): List of lists containing row data
  • max_width (int, optional): Maximum width of the widget (default: 80)
  • max_height (int, optional): Maximum height of the widget (default: 20)
  • edit_color (str, optional): Background color for editing cells (default: 'yellow')
  • column_types (dict/list, optional): Column type definitions
  • colors (dict, optional): Custom color definitions

Methods

  • keypress(size, key): Handle keyboard input
  • render(size, focus): Render the widget
  • _on_cell_change(row, col, new_value): Handle cell value changes

Widget Classes

  • SafeText: Text widget with safe size parameter handling
  • EditableCell: Editable text cell widget
  • DropdownCell: Dropdown selection cell widget

Supplimental classes

  • SingleLineText: Single-line text widget
  • HeightEnforcer: Widget wrapper that enforces single-row height

Reading Table Data

The UrwScrollTable class provides several methods to read current table values:

# Get all table data
all_data = table.get_all_data()

# Get specific row data
row_data = table.get_row_data(row_index)

# Get specific cell value
cell_value = table.get_cell_value(row_index, col_index)

# Get table headers
headers = table.get_headers()

# Get comprehensive table information
info = table.get_table_info()

All methods return copies of the data to prevent external modification of the table's internal state.

Development

Running Tests

poetry run pytest

Code Formatting

poetry run black src/ examples/

Type Checking

poetry run mypy src/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

Requirements

  • Python 3.8+
  • urwid 3.0.0+

Metadata

Release files for urw-scroll-table 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for urw-scroll-table 0.1.2
File Size Uploaded Provenance Actions
urw_scroll_table-0.1.2.tar.gz 16.5 kB Without provenance Details for urw_scroll_table-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for urw-scroll-table 0.1.2
File Interpreter ABI Platform Actions
urw_scroll_table-0.1.2-py3-none-any.whl Python 3 none any Details for urw_scroll_table-0.1.2-py3-none-any.whl

Total release size: 32.1 kB

Release files / urw_scroll_table-0.1.2.tar.gz

Download URL urw_scroll_table-0.1.2.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0218b2dd58fc2ed46bb16c358bb58033cc6a15d100381841739299edd96d3615
BLAKE2b-256 checksum
How to use checksums
ef80f5edbd001b29287a719cd3b6b2fbc1c45ac2fdfcb6f57c2237d5318cff72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.12 Linux/6.8.0-79-generic

Release files / urw_scroll_table-0.1.2-py3-none-any.whl

Download URL urw_scroll_table-0.1.2-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d31b49699589893063aa7cf95da712cde30ccabbbde21f94b7d94b7dfe808e1
BLAKE2b-256 checksum
How to use checksums
94fe9a77150d4ddd8a11a989c5dcdb6a8c97673dd3e15b918fcfdf7cb99c4dc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.12 Linux/6.8.0-79-generic

Security for urw-scroll-table 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page