Skip to main content

Graphic library based on curses

Project description

CursedUI

License: LGPL v3 PEP8 Typing PyPI PyPI - Status

This is a python graphic library based on the curses library.

It hides the complexity of the basic library and offers a class-first approach to UI.

Index

Examples

You can run the example files simply by running python [filename].py

Available tiles

Split

Equally vertically splits the available space between its child tiles.

from cursedui import Split

splitTile = Split(tile1, tile2, ...)

Text

Shows the string subject in the available canvas. offsetX and offsetY attributes allow to move the pane of the visible text.

Invalid offset values will be reset either to 0 (if offset < 0) or to the calculated maximum offset (if offset > maximum offset).

from cursedui import Text

textSubject = Subject('myText')
splitTile = Text(title='My title', bordered=True, subject=textSubject)

splitTile.offsetY = 27 # might default to the maximum possible offset
splitTile.offsetX = -1 # defaults to 0

Log

Derived from Text. The key difference is the auto-scroll feature, which disables itself whenever the vertical offset (offsetY) is not aligned with the last line of the subject (i.e. when manual offset control is used).

from cursedui import Log

logSubject = Subject('Log line 0')
splitTile = Log(title='My scrolling log', bordered=True, subject=logSubject)

for i in range(100):
  logSubject(f'{logSubject.value}\nLog line {i}')

Extending (creating new tiles)

The library is made to be easily enhanced with new tiles.

To create a new tile, you need to extend the cursedui.Tile class and implement its abstract render method.

See the tile.py file to see the rest of the overrideable methods.

See tiles folder for a list of tiles available out-of-the-box.

Other than the render method, you might want to override the following methods:

  • Tile.onBeforeWindowRefresh - used to access the curses' window (it should be used for particular cases only). See the Split tile for an example.
  • Tile.shouldRender - which should be overwritten returning the super's result and the new tile's particular logic. See the Text tile for an example.
from typing import List

from cursedui import Tile, Subject


class Dumb(Tile[str]):
    def render(self, canvas: Canvas) -> None:
        lines = [self.subject * canvas.width for _ in range(canvas.height)]
        canvas.lines = lines

        return canvas

Tile decorators

Tile decorators allow to extend their graphical representation without adding complexity to the normal usage. All the available decorators are written in the tile_decorators.py file.

fixed_height

Allows to define a fixed height tile, rather than following the mainstram logic to split the view equally between tiles.

It will attempt to get the required vertical space, but it will be limited to the main UI's available space. Also notice that this might preclude other views to show (for example if the remaining available space is not sufficient to show the remaining tiles).

Currently only the main UI class (CursedUI) supports this decorator.

from cursedui import Text
from cursedui.tile_decorators import fixed_height

myTile = fixed_height(maxHeight=20)(Text(...))

fixed_width

Allows to define a fixed width tile (absolute, percentage), rather than following the mainstream logic (CursedUI: full width; Split: equally divided).

It wil lattempt to get the required horizontal space, but it will be limited to the available width. Also notice that if misused, this might prevent other tiles to be shown.

Allowable parents:

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

cursedui-0.0.1.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file cursedui-0.0.1.tar.gz.

File metadata

  • Download URL: cursedui-0.0.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for cursedui-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1d0f82b80bce632ae89e4d750cf95f94c2f39c563f4bd0a18cc406fd2c46f58c
MD5 43288f0b5d527114ed66bc4ce3b64c81
BLAKE2b-256 820803b0b558feb7ebadd65f3beecd67c51eb38068cd4f1c1f6ebb74ad938819

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