Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Library for easily creating text interfaces that look like Linux's top program.

Project description

Documentation Status Updates Python 3

Library for easily creating text interfaces that look like Linux’s top program.

It is built on top of urwid but requires no knowledge of urwid itself.

Quickstart

Here’s an example of how to use TopShape:

from topshape import TopShape


# The columns are a list (or tuple) of dictionaries. Each
# dictionary defines a column in the body
columns = ({'label': 'header1'},
           {'label': 'header2'},
           {'label': 'header3'})


# The body function will be passed as a callback that must
# return a 2-dimensional array everytime it's called.
def body():
    return [[str(i*j) for i in range(3)] for j in range(10)]


# The header function will be passed as a callback that must
# return a string everytime it's called.
def header():
    return 'This is the header!'


# The footer function will be passed as a callback that must
# return a string everytime it's called.
def footer():
    return 'This is the footer!'


def handle_q(app):
    app.exit()

def handle_f(app, answer):
    # do something with the answer
    # ...

# key_map maps keys pressed to callbacks
key_map = {'q': handle_q,
           'f': (handle_f, 'Enter some text here:'}

app = TopShape.create_app(columns, body, header, footer,
                          key_mapping=key_map)
app.run()

Output:

https://raw.githubusercontent.com/mchlumsky/topshape/master/docs/example1.png

Output (waiting for input from user):

https://raw.githubusercontent.com/mchlumsky/topshape/master/docs/example1-1.png

There is also a more complete example here which is a clone of the linux top program.

Screenshot:

https://raw.githubusercontent.com/mchlumsky/topshape/master/docs/example2.png

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Project details


Release history Release notifications

This version
History Node

1.0.0

History Node

0.2.0

History Node

0.1.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
topshape-1.0.0-py2.py3-none-any.whl (10.8 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Apr 10, 2017
topshape-1.0.0.tar.gz (102.1 kB) Copy SHA256 hash SHA256 Source None Apr 10, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page