Skip to content

Feature TextBlockApplication

Valentin Valls requested to merge textblockapp into master

This PR provides a TextBlockApplication to handle properly a block of text which have to be refreshed time to time.

This is already used by @berruyer with BLISS 1.11, and i would expect to use it to handle umv or scan progress in the future. But this can be discussed in a second time.

A user function (render) have to be defined to render the block content. It have to return the height of the block and the text content. The height can change dynalically, and the text can be one of str or prompt toolkit formatting classes HTML, ANSI, FormattedText.

A process function can be defined, to process in a background stuffs, like moving motors. It can be one of a callable or a greenlet. If this function is defined, the application will terminated just after the termination of this processing function.

The application can be aborted by the user with CTRL-C. If a process function was defined, it is first killed, then the application terminate by raising a KeyboardInterrupt exception.

The base code is the following one.

def render():
    """User function which returns height and content"""
    import time 
    return 1, f"time.time()"

app = TextBlockApplication(
    render=render,
    refresh_interval=0.3,
)
app.exec()

A code with a background processing can be:

def background():
    # do some stuffs
    gevent.sleep(10.0)

def render():
    import time 
    return 1, f"{time.time()}"

app = TextBlockApplication(
    render=render,
    refresh_interval=0.3,
)
app.exec(process=background)

Merge request reports