60
60
import audiomp3
61
61
import usb_hid
62
62
from adafruit_hid .keyboard import Keyboard
63
- from adafruit_hid .keycode import Keycode
63
+ from adafruit_hid .keyboard_layout_base import KeyboardLayoutBase
64
64
from adafruit_hid .keyboard_layout_us import KeyboardLayoutUS
65
+ from adafruit_hid .keycode import Keycode
65
66
from adafruit_hid .consumer_control import ConsumerControl
66
67
from adafruit_hid .consumer_control_code import ConsumerControlCode
67
68
from adafruit_hid .mouse import Mouse
80
81
from typing import Tuple , Optional , Union , Iterator
81
82
from neopixel import NeoPixel
82
83
from keypad import Keys
83
- import adafruit_hid
84
+ import adafruit_hid # pylint:disable=ungrouped-imports
84
85
except ImportError :
85
86
pass
86
87
93
94
ROTATED_KEYMAP_270 = (9 , 6 , 3 , 0 , 10 , 7 , 4 , 1 , 11 , 8 , 5 , 2 )
94
95
95
96
97
+ keycodes = Keycode
98
+ """Module level Keycode class, to be changed when initing Macropad with a different language"""
99
+
100
+
96
101
class _PixelMapLite :
97
102
"""Generate a pixel map based on a specified order. Designed to work with a set of 12 pixels,
98
103
e.g. the MacroPad keypad LEDs.
@@ -163,7 +168,7 @@ def brightness(self, value: float) -> None:
163
168
self ._pixels .brightness = value
164
169
165
170
166
- # pylint: disable=too-many-lines
171
+ # pylint: disable=too-many-lines, disable=invalid-name, too-many-instance-attributes, too-many-public-methods, too-many-arguments
167
172
class MacroPad :
168
173
"""
169
174
Class representing a single MacroPad.
@@ -182,6 +187,14 @@ class MacroPad:
182
187
channels. Defaults to 1.
183
188
:param int midi_out_channel: The MIDI output channel. Defaults to 1.
184
189
190
+ :param type[KeyboardLayoutBase] layout_class: Class for the keyboard layout, to setup an
191
+ international or alternative keyboard. Defaults
192
+ to KeyboardLayoutUS from adafruit_hid.
193
+ :param type[Keycode] keycode_class: Class used for the keycode names provided by
194
+ adafruit_macropad.Keycode. Defaults to the standard Keycode
195
+ from adafruit_hid.
196
+
197
+
185
198
The following shows how to initialise the MacroPad library with the board rotated 90 degrees,
186
199
and the MIDI channels both set to 1.
187
200
@@ -192,9 +205,43 @@ class MacroPad:
192
205
macropad = MacroPad(rotation=90, midi_in_channel=1, midi_out_channel=1)
193
206
"""
194
207
195
- # pylint: disable=invalid-name, too-many-instance-attributes, too-many-public-methods
208
+ Keycode = Keycode
209
+ """
210
+ The contents of the Keycode module are available as a property of MacroPad. This includes all
211
+ keycode constants available within the Keycode module, which includes all the keys on a
212
+ regular PC or Mac keyboard.
213
+
214
+ Remember that keycodes are the names for key _positions_ on a US keyboard, and may not
215
+ correspond to the character that you mean to send if you want to emulate non-US keyboard.
216
+
217
+ For usage example, see the ``keyboard`` documentation in this library.
218
+ """
219
+
220
+ ConsumerControlCode = ConsumerControlCode
221
+ """
222
+ The contents of the ConsumerControlCode module are available as a property of MacroPad.
223
+ This includes the available USB HID Consumer Control Device constants. This list is not
224
+ exhaustive.
225
+
226
+ For usage example, see the ``consumer_control`` documentation in this library.
227
+ """
228
+
229
+ Mouse = Mouse
230
+ """
231
+ The contents of the Mouse module are available as a property of MacroPad. This includes the
232
+ ``LEFT_BUTTON``, ``MIDDLE_BUTTON``, and ``RIGHT_BUTTON`` constants. The rest of the
233
+ functionality of the ``Mouse`` module should be used through ``macropad.mouse``.
234
+
235
+ For usage example, see the ``mouse`` documentation in this library.
236
+ """
237
+
196
238
def __init__ (
197
- self , rotation : int = 0 , midi_in_channel : int = 1 , midi_out_channel : int = 1
239
+ self ,
240
+ rotation : int = 0 ,
241
+ midi_in_channel : int = 1 ,
242
+ midi_out_channel : int = 1 ,
243
+ layout_class : type [KeyboardLayoutBase ] = KeyboardLayoutUS ,
244
+ keycode_class : type [Keycode ] = Keycode ,
198
245
):
199
246
200
247
if rotation not in (0 , 90 , 180 , 270 ):
@@ -257,6 +304,12 @@ def _keys_and_pixels(
257
304
self ._keyboard_layout = None
258
305
self ._consumer_control = None
259
306
self ._mouse = None
307
+ self ._layout_class = layout_class
308
+ self .Keycode = keycode_class
309
+ # pylint:disable=global-statement
310
+ global keycodes
311
+ keycodes = keycode_class
312
+ # pylint:enable=global-statement
260
313
261
314
# Define MIDI:
262
315
try :
@@ -271,36 +324,6 @@ def _keys_and_pixels(
271
324
# No MIDI ports available.
272
325
self ._midi = None
273
326
274
- Keycode = Keycode
275
- """
276
- The contents of the Keycode module are available as a property of MacroPad. This includes all
277
- keycode constants available within the Keycode module, which includes all the keys on a
278
- regular PC or Mac keyboard.
279
-
280
- Remember that keycodes are the names for key _positions_ on a US keyboard, and may not
281
- correspond to the character that you mean to send if you want to emulate non-US keyboard.
282
-
283
- For usage example, see the ``keyboard`` documentation in this library.
284
- """
285
-
286
- ConsumerControlCode = ConsumerControlCode
287
- """
288
- The contents of the ConsumerControlCode module are available as a property of MacroPad.
289
- This includes the available USB HID Consumer Control Device constants. This list is not
290
- exhaustive.
291
-
292
- For usage example, see the ``consumer_control`` documentation in this library.
293
- """
294
-
295
- Mouse = Mouse
296
- """
297
- The contents of the Mouse module are available as a property of MacroPad. This includes the
298
- ``LEFT_BUTTON``, ``MIDDLE_BUTTON``, and ``RIGHT_BUTTON`` constants. The rest of the
299
- functionality of the ``Mouse`` module should be used through ``macropad.mouse``.
300
-
301
- For usage example, see the ``mouse`` documentation in this library.
302
- """
303
-
304
327
@property
305
328
def pixels (self ) -> Optional [_PixelMapLite ]:
306
329
"""Sequence-like object representing the twelve NeoPixel LEDs in a 3 x 4 grid on the
@@ -501,7 +524,7 @@ def keyboard_layout(self) -> adafruit_hid.keyboard_layout_base.KeyboardLayoutBas
501
524
"""
502
525
if self ._keyboard_layout is None :
503
526
# This will need to be updated if we add more layouts. Currently there is only US.
504
- self ._keyboard_layout = KeyboardLayoutUS (self .keyboard )
527
+ self ._keyboard_layout = self . _layout_class (self .keyboard )
505
528
return self ._keyboard_layout
506
529
507
530
@property
0 commit comments