Skip to content

Commit 3102446

Browse files
Merge pull request #14 from EGJ-Moorington/12-update-the-documentation-to-version-300
Updated the documentation to version 3.0.0
2 parents a17c58a + c117630 commit 3102446

File tree

1 file changed

+69
-32
lines changed

1 file changed

+69
-32
lines changed

button_handler.py

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ def __init__(
7373
) -> None:
7474
"""
7575
:param bool enable_multi_press: Sets :attr:`.enable_multi_press`
76-
(whether to track multi presses).
76+
(whether to track multi-presses).
7777
:param float multi_press_interval: Sets :attr:`.multi_press_interval`
78-
(the time frame within which two presses should occur to count as a multi press).
78+
(the time frame within which two presses should occur to count as a multi-press).
7979
:param float long_press_threshold: Sets :attr:`.long_press_threshold`
8080
(the minimum length of a press to count as a long press).
8181
:param int max_multi_press: Sets :attr:`.max_multi_press`
82-
(the maximum amount of presses a multi press can have).
82+
(the maximum amount of presses a multi-press can have).
8383
8484
.. attribute:: enable_multi_press
8585
:type: bool
8686
:value: enable_multi_press = True
8787
8888
Whether to account for the possibility of another short press
89-
following a short press and counting as a multi press.
89+
following a short press and counting as a multi-press.
9090
If set to false, :meth:`ButtonHandler.update`
91-
returns ``SHORT_PRESS`` immediately after a short press.
91+
returns a short press :class:`ButtonInput` object immediately after a short press.
9292
9393
.. attribute:: long_press_threshold
9494
:type: float
@@ -101,16 +101,16 @@ def __init__(
101101
:type: int
102102
:value: max_multi_press = 2
103103
104-
The maximum amount of button presses that a multi press can be.
105-
:meth:`ButtonHandler.update` returns the appropiate ``_MULTI_PRESS`` immediaetly after
106-
the button has been pressed this many times.
104+
The maximum amount of button presses that a multi-press can be.
105+
:meth:`ButtonHandler.update` returns the appropiate multi-press :class:`ButtonInput`
106+
object immediaetly after the button has been pressed this many times.
107107
108108
.. attribute:: multi_press_interval
109109
:type: float
110110
:value: multi_press_interval = 175
111111
112112
The time frame from a button release within which
113-
another release should occur to count as a multi press.
113+
another release should occur to count as a multi-press.
114114
"""
115115
self.enable_multi_press = enable_multi_press
116116
self.long_press_threshold = long_press_threshold
@@ -137,8 +137,9 @@ def __init__(
137137
:value: config.enable_multi_press = True
138138
139139
Whether to account for the possibility of another short press
140-
following a short press and counting that as a multi press. If set to false,
141-
:meth:`ButtonHandler.update` returns ``SHORT_PRESS`` immediately after a short press.
140+
following a short press and counting that as a multi-press. If set to false,
141+
:meth:`ButtonHandler.update` returns a short press :class:`ButtonInput`
142+
object immediately after a short press.
142143
143144
.. attribute:: long_press_threshold
144145
:type: float
@@ -151,16 +152,16 @@ def __init__(
151152
:type: int
152153
:value: config.max_multi_press = 2
153154
154-
The maximum amount of button presses that a multi press can be.
155-
:meth:`ButtonHandler.update` returns the appropiate ``_MULTI_PRESS`` immediaetly after
156-
the button has been pressed this many times.
155+
The maximum amount of button presses that a multi-press can be.
156+
:meth:`ButtonHandler.update` returns the appropiate multi-press :class:`ButtonInput`
157+
object immediaetly after the button has been pressed this many times.
157158
158159
.. attribute:: multi_press_interval
159160
:type: float
160161
:value: config.multi_press_interval = 175
161162
162163
The time frame from a button release within which
163-
another release should occur to count as a multi press.
164+
another release should occur to count as a multi-press.
164165
165166
.. caution:: Attributes with a *leading underscore (_)* are meant for **internal use only**,
166167
and accessing them may cause **unexpected behaviour**. Please consider accessing
@@ -192,15 +193,15 @@ def __init__(
192193
:value: None
193194
194195
The time (in miliseconds, tracked by :meth:`supervisor.ticks_ms`) that has passed since
195-
the start of the previous press of a multi press. It is set to :type:`None`
196+
the start of the previous press of a multi-press. It is set to :type:`None`
196197
after the time specified by :attr:`.multi_press_interval` has passed.
197198
198199
.. attribute:: _press_count
199200
:type: int
200201
:value: 0
201202
202203
The amount of times the button has been pressed since the last
203-
multi press ended. It is set to 0 if the time set
204+
multi-press ended. It is set to 0 if the time set
204205
by :attr:`.multi_press_interval` passes after a short press.
205206
206207
.. attribute:: _press_start_time
@@ -257,12 +258,12 @@ def _check_multi_press_timeout(self, current_time: int) -> Union[int, None]:
257258
.. caution:: Methods with a *leading underscore (_)* are meant for **internal use only**,
258259
and calling them may cause **unexpected behaviour**. Please refrain from using them.
259260
260-
Check whether a multi press has ended.
261-
If it has, return the amount of times the button was pressed in that multi press.
261+
Check whether a multi-press has ended.
262+
If it has, return the amount of times the button was pressed in that multi-press.
262263
263264
:param int current_time: The current time, provided by :meth:`supervisor.ticks_ms`.
264-
:return: The amount of times the button was pressed in a multi press,
265-
if a multi press has ended.
265+
:return: The amount of times the button was pressed in a multi-press,
266+
if a multi-press has ended.
266267
:rtype: int or None
267268
"""
268269
if (
@@ -303,8 +304,8 @@ class ButtonInput:
303304

304305
SHORT_PRESS = 1
305306
DOUBLE_PRESS = 2
306-
LONG_PRESS = "L"
307307
HOLD = "H"
308+
LONG_PRESS = "L"
308309

309310
def __init__(
310311
self,
@@ -322,7 +323,13 @@ def __init__(
322323
:param int timestamp: Sets :attr:`timestamp` (the time at which the input was performed).
323324
324325
.. type:: InputAction
325-
:canonical: Literal["SHORT_PRESS", "LONG_PRESS", "HOLD", "DOUBLE_PRESS"] | str
326+
:canonical: int | str
327+
328+
Represents the action the :class:`ButtonInput` object represents.
329+
Using a constant defined by :class:`ButtonInput` when available is recommended.
330+
To represent a multi-press, use the number of presses in that multi-press.
331+
Available constants are :const:`SHORT_PRESS`, :const:`DOUBLE_PRESS`,
332+
:const:`HOLD` and :const:`LONG_PRESS`.
326333
327334
.. attribute:: button_number
328335
:type: int
@@ -344,6 +351,37 @@ def __init__(
344351
The timestamp (in milliseconds, provided by :meth:`supervisor.ticks_ms`)
345352
at which the input was performed.
346353
354+
.. warning:: Variables written in *upper case with underscores* are constants and
355+
should not be modified. Doing so may cause **unexpected behaviour**.
356+
357+
.. data:: SHORT_PRESS
358+
:type: int
359+
:value: 1
360+
361+
Represents a short press to pass as an argument to
362+
parameter `action` in :class:`ButtonInput`.
363+
364+
.. data:: DOUBLE_PRESS
365+
:type: int
366+
:value: 2
367+
368+
Represents a double press to pass as an argument to
369+
parameter `action` in :class:`ButtonInput`.
370+
371+
.. data:: HOLD
372+
:type: str
373+
:value: "H"
374+
375+
Represents a hold action to pass as an argument to
376+
parameter `action` in :class:`ButtonInput`.
377+
378+
.. data:: LONG_PRESS
379+
:type: str
380+
:value: "L"
381+
382+
Represents a long press to pass as an argument to
383+
parameter `action` in :class:`ButtonInput`.
384+
347385
.. caution:: Attributes with a *leading underscore (_)* are meant for
348386
**internal use only**, and accessing them may cause **unexpected behaviour**.
349387
Please consider accessing a *property* (if available) instead.
@@ -366,10 +404,9 @@ def action(self):
366404
367405
:type: InputAction
368406
:param InputAction action: The action associated with the input.
369-
:raise ValueError: if action is not a valid action. Valid actions are ``LONG_PRESS``,
370-
``HOLD``, ``SHORT_PRESS`` (exactly the same as ``1_MULTI_PRESS``),
371-
``DOUBLE_PRESS`` (exactly the same as ``2_MULTI_PRESS``) and
372-
``x_MULTI_PRESS`` where x is an :type:`int` bigger than 0.
407+
:raise ValueError: if *action* is not a valid action. Valid actions are
408+
:const:`SHORT_PRESS`, :const:`DOUBLE_PRESS`, :const:`HOLD`, :const:`LONG_PRESS`
409+
and any :type:`int` bigger than 0.
373410
374411
"""
375412
return self._action
@@ -444,15 +481,15 @@ def __init__(
444481
:param keypad.EventQueue event_queue: Sets :attr:`_event_queue`
445482
(the :class:`keypad.EventQueue` object the handler should read events from).
446483
:param set[ButtonInput] callable_inputs: Sets :attr:`callable_inputs`
447-
(the :class:`ButtonInitConfig` objects used to define the callback functions).
484+
(the :class:`ButtonInput` objects used to define the callback functions).
448485
:param int button_amount: The amount of buttons scanned by the :mod:`keypad` scanner
449-
that created the event_queue parameter's argument :class:`keypad.EventQueue` object.
486+
that created the *event_queue* parameter's argument :class:`keypad.EventQueue` object.
450487
:param dict[int, ButtonInitConfig] config: A dictionary containing
451488
:class:`ButtonInitConfig` objects used to initialise :class:`Button` objects.
452489
The dictionary's keys should be the index numbers of the target buttons.
453490
For each button that doesn't have a :class:`ButtonInitConfig` attached to it, an object
454491
containing the default values is created.
455-
:raise ValueError: if *button_amount* is smaller than 1, or if it is not an :type:`int`..
492+
:raise ValueError: if *button_amount* is smaller than 1, or if it is not an :type:`int`.
456493
457494
.. attribute:: callable_inputs
458495
:type: set[ButtonInput]
@@ -505,7 +542,7 @@ def buttons(self) -> list[Button]:
505542

506543
def update(self) -> set[ButtonInput]:
507544
"""
508-
Check if any button ended a multi press since the last time this method was called,
545+
Check if any button ended a multi-press since the last time this method was called,
509546
process the next :class:`keypad.Event` in :attr:`_event_queue`, call all the relevant
510547
callback functions and return a set of the detected :class:`ButtonInput`\\ s.
511548
@@ -551,7 +588,7 @@ def _handle_buttons(self) -> set[ButtonInput]:
551588
and calling them may cause **unexpected behaviour**. Please refrain from using them.
552589
553590
Check if any button began being held down since the last time this mehod was called
554-
and if any multi press ended, and return every detected :class:`ButtonInput`.
591+
and if any multi-press ended, and return every detected :class:`ButtonInput`.
555592
556593
:return: A set containing every detected :class:`ButtonInput`.
557594
:rtype: set[ButtonInput]

0 commit comments

Comments
 (0)