Skip to content

Commit ad31b57

Browse files
brentrubrentru
brentru
authored and
brentru
committed
pylint!
1 parent 41fc404 commit ad31b57

File tree

1 file changed

+30
-40
lines changed

1 file changed

+30
-40
lines changed

adafruit_cursor.py

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
`adafruit_cursor`
2424
================================================================================
2525
26-
Simulated mouse cursor for display interaction
26+
Simulated mouse cursor for interaction using displayio Groups.
2727
2828
* Author(s): Brent Rubell
2929
@@ -51,15 +51,14 @@ class Cursor:
5151
;param int scale: Scale amount for the cursor in both directions.
5252
:param bool is_hidden: Cursor is hidden on init.
5353
"""
54+
# pylint: disable=too-many-arguments
5455
def __init__(self, display=None, display_group=None, is_hidden=False, cursor_speed=5, scale=1):
5556
self._display = display
5657
self._scale = scale
57-
self._display_grp = display_group
58-
self._disp_x = display.height
59-
self._disp_y = display.width
60-
self._disp_sz = self._disp_x - 1, self._disp_y - 1
6158
self._speed = cursor_speed
6259
self._is_hidden = is_hidden
60+
self._display_grp = display_group
61+
self._disp_sz = display.height - 1, display.width - 1
6362
self.generate_cursor()
6463

6564
@property
@@ -96,7 +95,7 @@ def x(self):
9695
@x.setter
9796
def x(self, x_val):
9897
"""Sets the x-value of the cursor.
99-
:param int x_val: x position, in pixels.
98+
:param int x_val: cursor x-position, in pixels.
10099
"""
101100
if x_val < 0 and not self._is_hidden:
102101
self._cursor_grp.x = self._cursor_grp.x
@@ -113,7 +112,7 @@ def y(self):
113112
@y.setter
114113
def y(self, y_val):
115114
"""Sets the y-value of the cursor.
116-
:param int y_val: y position, in pixels.
115+
:param int y_val: cursor y-position, in pixels.
117116
"""
118117
if y_val < 0 and not self._is_hidden:
119118
self._cursor_grp.y = self._cursor_grp.y
@@ -122,16 +121,11 @@ def y(self, y_val):
122121
elif not self._is_hidden:
123122
self._cursor_grp.y = y_val
124123

125-
@property
126-
def is_hidden(self):
127-
"""Returns if the cursor is hidden or visible on the display."""
128-
return self._is_hidden
129-
130124
@property
131125
def hide(self):
132-
"""Returns if the cursor is hidden or visible on the display."""
126+
"""Returns True if the cursor is hidden or visible on the display."""
133127
return self._is_hidden
134-
128+
135129
@hide.setter
136130
def hide(self, is_hidden):
137131
if is_hidden:
@@ -142,36 +136,32 @@ def hide(self, is_hidden):
142136
self._display_grp.append(self._cursor_grp)
143137

144138
def generate_cursor(self):
145-
"""Generates a cursor icon bitmap"""
139+
"""Generates a cursor icon"""
146140
self._cursor_grp = displayio.Group(max_size=1, scale=self._scale)
147-
self._pointer_bitmap = displayio.Bitmap(20, 20, 3)
148-
self._pointer_palette = displayio.Palette(3)
149-
self._pointer_palette.make_transparent(0)
150-
self._pointer_palette[1] = 0xFFFFFF
151-
self._pointer_palette[2] = 0x0000
141+
self._cur_bmp = displayio.Bitmap(20, 20, 3)
142+
self._cur_palette = displayio.Palette(3)
143+
self._cur_palette.make_transparent(0)
144+
self._cur_palette[1] = 0xFFFFFF
145+
self._cur_palette[2] = 0x0000
152146
# left edge, outline
153-
for i in range(0, self._pointer_bitmap.height):
154-
self._pointer_bitmap[0, i] = 2
155-
# inside fill
147+
for i in range(0, self._cur_bmp.height):
148+
self._cur_bmp[0, i] = 2
149+
# right diag outline, inside fill
156150
for j in range(1, 15):
157-
for i in range(j+1, self._pointer_bitmap.height - j):
158-
self._pointer_bitmap[j, i] = 1
159-
# right diag., outline
160-
for i in range(1, 15):
161-
self._pointer_bitmap[i, i] = 2
151+
self._cur_bmp[j, j] = 2
152+
for i in range(j+1, self._cur_bmp.height - j):
153+
self._cur_bmp[j, i] = 1
162154
# bottom diag., outline
163155
for i in range(1, 5):
164-
self._pointer_bitmap[i, self._pointer_bitmap.height-i] = 2
165-
# bottom flat line, outline
166-
for i in range(5, 15):
167-
self._pointer_bitmap[i, 15] = 2
168-
# right side fill
156+
self._cur_bmp[i, self._cur_bmp.height-i] = 2
157+
# bottom flat line, right side fill
169158
for i in range(5, 15):
170-
self._pointer_bitmap[i-1, 14] = 1
171-
self._pointer_bitmap[i-2, 13] = 1
172-
self._pointer_bitmap[i-3, 12] = 1
173-
self._pointer_bitmap[i-4, 11] = 1
174-
# create a tilegrid out of the bitmap and palette
175-
self._pointer_sprite = displayio.TileGrid(self._pointer_bitmap, pixel_shader=self._pointer_palette)
176-
self._cursor_grp.append(self._pointer_sprite)
159+
self._cur_bmp[i, 15] = 2
160+
self._cur_bmp[i-1, 14] = 1
161+
self._cur_bmp[i-2, 13] = 1
162+
self._cur_bmp[i-3, 12] = 1
163+
self._cur_bmp[i-4, 11] = 1
164+
self._cur_sprite = displayio.TileGrid(self._cur_bmp,
165+
pixel_shader=self._cur_palette)
166+
self._cursor_grp.append(self._cur_sprite)
177167
self._display_grp.append(self._cursor_grp)

0 commit comments

Comments
 (0)