textblock: Allow to use textblock as a context
This PR provides an helper to the TextBlock in order to use it as a python context and stack multiple text together.
This provides some interesting features
- Reduce the verbosity
- Simplify the integration with code written as context (like in !5928 (merged))
- Do not interleave the main process with asyncio (asyncio is used on the side for the display only)
from bliss.shell.pt.text_block_app import TextBlockApplication
import gevent
## Simple example
app = TextBlockApplication()
with app.exec_context():
tb = app.first_text_block()
tb.set_text("Processing: Step 1", height=1)
gevent.sleep(1) # do some real stuffs
tb.set_text("Processing: Step 2", height=1)
gevent.sleep(1) # do some real stuffs
tb.set_text("Processing: Step 3", height=1)
gevent.sleep(1) # do some real stuffs
tb.set_text("Processing was done", height=1)
## Interruption
app = TextBlockApplication()
with app.exec_context():
tb = app.first_text_block()
tb.set_text("Init", height=1)
try:
tb.set_text("Processing...", height=1)
gevent.sleep(5)
except:
tb.set_text("Processing aborted: Restore...", height=1)
try:
gevent.sleep(3)
except:
tb.set_text("Processing and restoration aborted", height=1)
raise
tb.set_text("Processing aborted", height=1)
raise
gevent.sleep(1)
tb.set_text("Terminated", height=1)
Edited by Valentin Valls