Package entropy :: Module output :: Class TextInterface

Class TextInterface

source code


TextInterface is a base class for handling the communication between user and Entropy-based applications.

This class works for text-based applications, it must be inherited from subclasses and its methods reimplemented to make Entropy working on situations where a terminal is not used as UI (Graphical applications, web-based interfaces, remote interfaces, etc).

Every part of Entropy is using the methods in this class to communicate with the user, channel is bi-directional.

Instance Methods

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods
None
ask_question(cls, question, importance=0, responses=None)
Questions asking function.
source code
bool
edit_file(cls, file_path)
Open a file editor on given file path (file_path).
source code
 
input_box(cls, title, input_parameters, cancel_button=True)
Generic input box (form) creator and data collector.
source code
None
output(cls, text, header='', footer='', back=False, importance=0, level='info', count=None, percent=False)
Text output print function.
source code
 
set_title(cls, title)
Set application title.
source code
Class Variables
  OUTPUT_LOCK = <_RLock owner=None count=0>
Properties

Inherited from object: __class__

Method Details

ask_question(cls, question, importance=0, responses=None)
Class Method

source code 

Questions asking function. It asks the user to answer the question given by choosing between a preset list of answers given by the "reposonses" argument.

Parameters:
  • question (string) - question text
  • importance (int) - question importance (no default valid values)
  • responses (tuple or list) - list of valid answers which user has to choose from
Returns: None
None

edit_file(cls, file_path)
Class Method

source code 

Open a file editor on given file path (file_path).

Parameters:
  • file_path (string) - path to a writeable file
Returns: bool
True for successful edit, False otherwise

input_box(cls, title, input_parameters, cancel_button=True)
Class Method

source code 
Generic input box (form) creator and data collector.

@param title: input box title
@type title: string
@param input_parameters: list of properly formatted tuple items.
@type input_parameters: list
@keyword cancel_button: make possible to "cancel" the input request.
@type cancel_button: bool
@return: dict containing input box answers
@rtype: dict

input_parameters supported items:

[input id], [input text title], [input verification callback], [
    no text echo?]
('identifier 1', 'input text 1', input_verification_callback, False)

('item_3', ('checkbox', 'Checkbox option (boolean request) - please choose',),
    input_verification_callback, True)

('item_4', ('combo', ('Select your favorite option', ['option 1', 'option 2', 'option 3']),),
    input_verification_callback, True)

('item_4',('list',('Setup your list',['default list item 1', 'default list item 2']),),
    input_verification_callback, True)

output(cls, text, header='', footer='', back=False, importance=0, level='info', count=None, percent=False)
Class Method

source code 

Text output print function. By default text is written to stdout.

Parameters:
  • text (string) - text to write to stdout
  • header (string) - text header (decoration?)
  • footer (string) - text footer (decoration?)
  • back (bool) - push back cursor to the beginning of the line
  • importance (int) - message importance (default valid values: 0, 1, 2, 3
  • level (string) - message type (default valid values: "info", "warning", "error", "generic")
  • count (tuple) - tuple of lengh 2, containing count information to make function print something like "(10/100) doing stuff". In this case tuple would be: (10, 100,)
  • percent - determine whether "count" argument should be printed as percentual value (for values like (10, 100,), "(10%) doing stuff" will be printed.
  • percent - bool
Returns: None
None

set_title(cls, title)
Class Method

source code 

Set application title.

Parameters:
  • title (string) - new application title