Skip to main content

A Sliding Container widget for Textual

Project description

textual-slidecontainer

textual-slidecontainer

This is a library that provides a custom container (widget) called the SlideContainer.

It is designed to make it extremely simple to implement a sliding menu bar in yor Textual apps.

Features

  • Usage is a single line of code with the default settings. Everything is handled automatically.
  • Set the direction - Containers can slide to the left, right, top, or bottom, independently of where they are on the screen.
  • Enable or disable Floating mode - With a simple boolean, containers can switch between floating on top of your app, or being a part of it and affecting the layout.
  • Set the default state - Containers can be set to start in closed mode.
  • Fade in/out - Containers can be set to fade while they slide
  • Set the container to dock as an initialization argument.
  • Floating containers automatically dock to the edge they move towards (this can be changed).
  • Change how the animation looks with the duration and easing_function arguments.
  • Included demo application which has comments in the code.

Installation

Install with:

pip install textual-slidecontainer

or for uv users:

uv add textual-slidecontainer

Import into your project with:

from textual_slidecontainer import SlideContainer

Demo app

You can instantly try out the demo app using uv or pipx:

uvx textual-slidecontainer
pipx textual-slidecontainer

Or if you have it downloaded into your python environment, run it using the entry script:

textual-slidecontainer

For uv users:

uv run textual-slidecontainer

Usage

Most basic usage.:

from textual_slidecontainer import SlideContainer

def compose(self):
    with SlideContainer(id = "my_slidecontainer", slide_direction = "up"):
        yield Static("Your widgets here")

Set the container's width and height in CSS as you usually would. Note that the above example will dock to the top of your screen automatically because it is in floating mode (floating is the default).

If you'd like the container to start closed/hidden, simply set start_open to False:

def compose(self):
    with SlideContainer(
        id = "my_slidecontainer", slide_direction = "left", start_open = False      
    ):
        yield Static("Your widgets here")

You can set the slide direction and dock direction to be different:

def compose(self):
    with SlideContainer(
        id = "my_slidecontainer", slide_direction = "right", dock_direction = "top"       
    ):
        yield Static("Your widgets here")

Here's an example using all the arguments:

with SlideContainer(
    classes = "my_container_classes",
    id = "my_slidecontainer",
    start_open = False         
    slide_direction = "left",
    dock_direction = "top",      # dock to the top but slide left
    floating = False,            # default is True
    fade = True,
    duration = 0.6,                   # the default is 0.8     
    easing_function = "out_bounce",   # default is "out_cubic".                           
):
    yield Static("Your widgets here")

Here's a demonstration of it being used in a full app:

from textual.app import App
from textual import on
from textual.widgets import Static, Footer, Button
from textual.containers import Container

from textual_slidecontainer import SlideContainer

class TextualApp(App):

    DEFAULT_CSS = """
    #my_container {
        width: 1fr; height: 1fr; border: solid red;
        align: center middle; content-align: center middle;
    }
    Static { border: solid blue; width: 1fr;}
    SlideContainer {
        width: 25; height: 1fr;
        background: $panel; align: center middle;
    }
    """
    def compose(self):

        # The container will start closed / hidden:
        with SlideContainer(slide_direction="left", start_open=False):
            yield Static("This is content in the slide container.")
        with Container(id="my_container"):
            yield Button("Show/Hide slide container", id="toggle_slide")
        yield Footer()

    @on(Button.Pressed, "#toggle_slide")
    def toggle_slide(self) -> None:
        self.query_one(SlideContainer).toggle()

TextualApp().run()

Questions, issues, suggestions?

Feel free to post an issue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textual_slidecontainer-0.2.4.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

textual_slidecontainer-0.2.4-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file textual_slidecontainer-0.2.4.tar.gz.

File metadata

File hashes

Hashes for textual_slidecontainer-0.2.4.tar.gz
Algorithm Hash digest
SHA256 c14c7cab3596f88268f0a5084e1c1ba6eb0683e1777d394841459febd304dd41
MD5 8903b58489dcbf0e8a2008c47a1cafa4
BLAKE2b-256 004bdda0a18276005714a2492eaaeebfc53588639fc8284984cbebe00ea89acb

See more details on using hashes here.

File details

Details for the file textual_slidecontainer-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for textual_slidecontainer-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 95f12371617c21df767a09e6ab0497750e7aa5d7b5f87602425994141ddfde5b
MD5 7a761709139a164599be2721f2723f78
BLAKE2b-256 1b26c2bab79f532eff02aa481c2db7a5ef17e280b6647ec65aaf94893324be92

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page