-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Preston
committed
Oct 30, 2013
1 parent
86485ef
commit d31ed0f
Showing
8 changed files
with
139 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
Tools | ||
===== | ||
|
||
There are some tools provided with PiFace Control and Display which simplify | ||
getting input from a user. | ||
|
||
Question | ||
-------- | ||
:class:`pifacecad.tools.question.LCDQuestion` will display a question on the | ||
top row and an answer on the bottom. The user can cycle through answers by | ||
moving the navigation switch left and right and select an answer by pressing | ||
the navigation switch in. | ||
|
||
It can be used like this:: | ||
|
||
>>> import pifacecad | ||
>>> from pifacecad.tools.question import LCDQuestion | ||
|
||
>>> question = LCDQuestion(question="What is 5 x 2?", answers=["1", "10", "12"]) | ||
>>> answer_index = question.ask() | ||
|
||
You can pass in an already initialised Control and Display object and also | ||
specify a custom selector:: | ||
|
||
>>> import pifacecad | ||
>>> from pifacecad.tools.question import LCDQuestion | ||
|
||
>>> customcad = pifacecad.PiFaceCAD() | ||
>>> customcad.lcd.cursor_off() | ||
>>> customcad.lcd.blink_off() | ||
|
||
>>> question = LCDQuestion(question="What is 5 x 2?", | ||
... answers=["1", "10", "12"], | ||
... selector="#", | ||
... cad=customcad) | ||
>>> answer_index = question.ask() | ||
|
||
Scanf | ||
----- | ||
:class:`pifacecad.tools.scanf.LCDScanf` will display a custom string that | ||
can be modified using the navigation switch. In 'select' mode, moving the | ||
navigation switch left or right (switches 6 and 7) selects a character. | ||
Change to 'edit' mode by pressing the navigation switch in (switch 5). | ||
In edit mode, moving the navigation switch left or right changes the character. | ||
|
||
To return the input, move the cursor under the 'enter' arrow and press the | ||
navigation switch in. | ||
|
||
The `LCDScanf` class can be used like this:: | ||
|
||
>>> import pifacecad | ||
>>> from pifacecad.tools.scanf import LCDScanf | ||
|
||
>>> scanner = LCDScanf("Text: %c%2i%.%r") | ||
>>> print(scanner.scan()) # user enters things on PiFace C&D | ||
['a', '13', '!'] | ||
|
||
The format string defines editable variables using a `%` symbol. The | ||
format specification is:: | ||
|
||
c: Characters | ||
C: Capital Characters | ||
i: Integers | ||
d: Intergers | ||
x: Hexadecimal | ||
X: Capital Hexadecimal | ||
.: Punctuation | ||
m: Custom (specifed by ``custom_values`` in init args) | ||
r: Return (switch 5 to submit string) | ||
|
||
To add multiple characters in the same variable you can specify a number | ||
after the `%` symbol. For example, to request that the user enter a two | ||
digit integer:: | ||
|
||
>>> print(LCDScanf("%2i%r").scan()) | ||
['42'] | ||
|
||
You can use the `m` specifier to enter custom variable values:: | ||
|
||
>>> scanner = LCDScanf("Animal: %m%r", custom_values=('cat', 'dog', 'fish')) | ||
>>> print(scanner.scan()) | ||
['fish'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '2.0.2' | ||
__version__ = '2.0.3' |