Reference (PiFace CAD Tools)

pifacecad.tools.question

class pifacecad.tools.question.LCDQuestion(question, answers, selector='>', cad=None)

Asks a question on the LCD”

Parameters:
  • question (string) – The question to be asked.
  • answers (list) – The answers to choose from.
  • selector (string) – The selector displayed in front of each answer.
  • cad (PiFaceCAD) – An already initialised PiFaceCAD object.
ask()

Asks the question using the LCD screen.

Returns:int – index of the answer selected.

pifacecad.tools.scanf

class pifacecad.tools.scanf.LCDScanf(format, custom_values=None, cad=None)

Allows the user to input text using the LCD.

To change mode from moving and editing press switch 5 (navigation switch in). Move the navigation switch side to side (switches 6 and 7) to change character.

The available character set is specified using a format string similar to printf. Supported character specifiers are:

c: Characters
C: Capital Characters
i: Integers
d: Integers
x: Hexadecimal
X: Capital Hexadecimal
.: Punctuation
m: Custom (specifed by ``custom_values`` in init args)
r: Return (switch 5 to submit string)

You must prefix them with a % symbol and you can also specify a number argument. Each specifier is returned as an element in a list.

For example:

>>> scanner = pifacecad.tools.LCDScanf("Text: %c%2i%.%r")
>>> print(scanner.scan())  # user enters things on PiFaceCAD
['a', '13', '!']

You can also specify custom values:

>>> scanner = pifacecad.tools.LCDScanf(
...     "Animal: %m%r",
...     custom_values=('cat', 'dog', 'fish')
... )
>>> print(scanner.scan())
['fish']
move_cursor_left()

move cursor left, roll around string, scroll screen. Only place cursor on ValueSelect, ignore plain text.

move_cursor_right()

move cursor right, roll around string, scroll screen. Only place cursor on ValueSelect, ignore plain text.

class pifacecad.tools.scanf.MultiValueSelect(multiplier, value_select, custom_values=None)

A list of ValueSelects representing a single value.

class pifacecad.tools.scanf.ValueSelect(values=, []value_index=0)

A character in a specified range

longest_len

Return the length of the longest value in this list. Example:

ValueSelect(["one", "two", "three"]).longest_len() == 5
class pifacecad.tools.scanf.ValueSelectString(format, custom_values=None)

A list of ValueSelect’s and characters, representing a string.

instanceindex(instance_type)

Returns the first index of an instance of instance_type

selected_values

Returns a list of currently selected values.

value_at(string_index)

Returns the ValueSelect or character at the string index. The string index is the index of this ValueSelectString as if it is being treated as a string.

Example:

cs0 == CustomValueSelect == ["bb", "cc"]
cs1 == CustomValueSelect == ["dd", "ee"]
vss == ValueSelectString == ["a", cs0, cs1, "f"]
vss == ["a", ["bb", "cc"], ["dd", "ee"], "f"]
str(vss) == "abbddf"
vss.value_at(0) == "a"
vss.value_at(1) == cs0
vss.value_at(2) == cs0
vss.value_at(3) == cs1
vss.value_at(5) == "f"
str(vss.value_at(2)) == "bb"
pifacecad.tools.scanf.char_range(c1, c2)

Generates the characters from c1 to c2, inclusive.

pifacecad.tools.scanf.is_number(character)

Returns True if given character is a number, False otherwise.

pifacecad.tools.scanf.is_selectable_character(display_string, col)

Returns True if the character can be selected