spend.display package

Submodules

spend.display.Message module

class spend.display.Message.Message(content=None, level=30, duration=None, template=2, is_last_one=False)

Bases: object

Displayed message representation. Comparable, Hashable, Human-readable

LEVEL_CRITICAL = 0
LEVEL_DEBUG = 40
LEVEL_ERROR = 10
LEVEL_INFO = 30
LEVEL_WARNING = 20
TEMPLATE_TYPES = [1, 2, 3]
TEMPLATE_TYPE_ERROR = 3
TEMPLATE_TYPE_NORMAL = 2
TEMPLATE_TYPE_SPLASH = 1
can_overtake(message)

Check if message in argument can overtake A message can overtake others with lower level, or with same level and no duration

Parameters:message (Message)
Returns:
Return type:boolean can_overtake

spend.display.MessageHandler module

spend.display.QueueManager module

class spend.display.QueueManager.PreviousItemsList

Bases: list

Old thing ? List that can have only one Message without duration On insert, previous elem is discarded

class spend.display.QueueManager.QueueManager(queue, message_handler)

Bases: threading.Thread

This module handles Message bus management. It allows Message prioritization and Temporary messages.

CHECK_FREQUENCY = 1
current_item = None
display(message: spend.display.Message.Message)

Store argument as currently displayed message and pass it to the Handler

Parameters:message (Message)
external_queue = None
kill()

kills instance without waiting

message_handler = None
next(message: spend.display.Message.Message)

function called by a Timer when it wakes up. Trigger update

Parameters:message (Message)
poll()

Get a new item from the Queue and process it

previous_items = []
process_message(raw_message: Union[spend.display.Message.Message, logging.LogRecord])

Check if message can be displayed considering current item. Start Timer if needed and ask for display

Parameters:raw_message (Union[Message, LogRecord])
Raises:StopListeningException – Used to stop the Manager. Triggered when receiving Message(is_last_one=True)
process_previous_items(new_item=Message: [Lvl.40] )

Check if previous messages can be displayed considering new Message. If last previous item can overtake new one and nothing is displayed, of if it can overtake both ; it can be used

run()

Loop until StopListeningException is received

stop()

Wait for Messages with duration to complete and stop instance

timers = {}
exception spend.display.QueueManager.StopListeningException

Bases: BaseException

spend.display.init module

Functions managing global oled communication environment : PriorityQueue joining QueueManager and a logging.Logger

spend.display.init.kill_display_management(display_props)

Stop display management with kill flag

Parameters:display_props
spend.display.init.start_display_management()
  • Create PriorityQueue
  • Create logging Handler
  • Create QueueManager thread reading from the PriorityQueue
Returns:{‘queue_manager’
Return type:QueueManager, ‘message_queue’: PriorityQueue, ‘handler’: logging.Handler}
spend.display.init.teardown_display_management(display_props, kill=False)

Stops disaplys management. Join threads.

Parameters:
  • display_props ({‘queue_manager’: QueueManager, ‘message_queue’: PriorityQueue, ‘handler’: logging.Handler})
  • kill (bool)

spend.display.logging module

This file hold classes for a custom logger, preparing LogRecord containing a Message to be push in a PriorityQueue Overrides in order to

  • filter log record not meant to be displayed
  • Put only Message instances in the queue
class spend.display.logging.DisplayFilter(name='')

Bases: logging.Filter

filter(r)

Filter non-Message LogRecords

class spend.display.logging.DisplayFormatter(fmt=None, datefmt=None, style='%')

Bases: logging.Formatter

format(record)

Does nothing

class spend.display.logging.DisplayQueueHandler(queue)

Bases: logging.handlers.QueueHandler

prepare(record)

Return actual content

spend.display.logging.create_display_handler(queue: queue.PriorityQueue)

Bootstrap handler and registers it

Parameters:queue (PriorityQueue)

Module contents

This module abstracts communication from one or many scripts to an OLED screen connected via GPIO It receive Message from a PriorityQueue and display them using a MessageHandler It can be plugged to the logging module for convenient use