Button Module
This module help you to manage integrated button.
Examples:
>>> from pybox.button import SIMPLEBUTTON
>>> but = SIMPLEBUTTON()
>>> but.value
0
>>> # press and hold the button
>>> but.value
1
The module consists basically in two classes
SIMPLEBUTTON
: to get the value of the buttonBUTTON
: to bind custom functions to button behavior
Classes
SIMPLEBUTTON
SimpleButton class.
Examples:
>>> but = SIMPLEBUTTON()
>>> but.value
0 # if button is not pressed
Source code in pybox/button.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
Attributes
value: int
property
Raw button value.
It contains the value of the button based on its status: 1 if pressed, 0 otherwise.
Examples:
>>> but.value
0
Functions
deinit()
Turn off the button.
Source code in pybox/button.py
42 43 44 45 |
|
BUTTON
Button class.
Examples:
>>> but = BUTTON()
>>> def press_callback():
... print("PRESSED")
>>> def release_callback():
... print("RELEASED")
>>> but.press_handler(press_callback)
>>> but.release_handler(release_callback)
>>> while True:
... but.update()
Source code in pybox/button.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
Attributes
press_time: float
property
Time of pressure.
Functions
update() -> None
Update button state on main loop.
Examples:
>>> but = BUTTON()
>>> while True:
... but.update()
Source code in pybox/button.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
press_handler(callback: callable = None) -> None
Bind a function to call when button is pressed.
Parameters:
-
callback
(callable
, default:None
) –a function to be executed when button is pressed.
Examples:
>>> def press_callback():
... print("PRESSED")
>>> push = BUTTON()
>>> push.press_handler(press_callback)
>>> while True:
... # print PRESSED on press button
... push.update()
Todo
- Add possibility to add arguments to callback
Source code in pybox/button.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
release_handler(callback: callable = None) -> None
Bind a function to call when button is released.
Parameters:
-
callback
(callable
, default:None
) –a function to be executed when button is released.
Examples:
>>> def release_callback():
... print("RELEASED")
>>> push = BUTTON()
>>> push.release_handler(release_callback)
>>> while True:
... # print RELEASED on release button
... push.update()
Todo
- Add possibility to add arguments to callback
Source code in pybox/button.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
deinit()
Turn off the button.
Source code in pybox/button.py
149 150 151 152 |
|