iotile.core.utilities.linebuffer_ui

A simple console UI that displays a list of objects with a title.

The use case for this object is that you want to create a UI that shows a list of information where individual lines could be changing and you want to update them in place like this:

<TITLE> Item 1 Value 1 Item 2 Value 2 …

You could just write a new line to the console with every changing item but that quickly gets unusable because things change too fast and unrelated lines stomp on each other.

LinebufferUI provides a nice way to do this. It has the following prerequisites:

  1. There must be a polling function that will return a new line. This is treated as an opaque object so it may have whatever format you want. This function will be called in a loop to check for changes to the items that are being displayed. If you return a list from this function, it will be treated as multiple results. This means that your object type cannot be anything such that isinstance(object, list) is True otherwise it will be misinterpreted as multiple objects.
  2. You must be able to calculate a single hashable value that determines for a result from your polling function, what line it corresponds to. If you wish to exclude some results from your polling function, simply return None from this function and that specific result will be dropped.
  3. You must be be able to implement a function that draws each line given your object.
  4. You can optionally define a function that sorts your objects, which is called to get the final sorted list before these are rendered to the screen.

These 3 (optionally 4) functions are called for you in order to create a nice UI that doesn’t flicker or scroll.

Module Contents

LineEntry
class LinebufferUI(poll_func, id_func, draw_func, sortkey_func=None, title=None)

A simple console UI that displays a list of items and updates them in place.

run(self, refresh_interval=0.05)

Set up the loop, check that the tool is installed

_update_items(self, screen)
_run_loop(self, screen, refresh_interval)
_parse_and_format(self, item)