diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..97fe64d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/adafruit_cursorcontrol/cursorcontrol.py b/adafruit_cursorcontrol/cursorcontrol.py index 12516f4..e2f2ee9 100644 --- a/adafruit_cursorcontrol/cursorcontrol.py +++ b/adafruit_cursorcontrol/cursorcontrol.py @@ -65,8 +65,17 @@ class Cursor(): # initialize the mouse cursor object mouse_cursor = Cursor(display, display_group=splash) """ + # pylint: disable=too-many-arguments,line-too-long - def __init__(self, display=None, display_group=None, bmp=None, is_hidden=False, cursor_speed=5, scale=1): + def __init__( + self, + display=None, + display_group=None, + bmp=None, + is_hidden=False, + cursor_speed=5, + scale=1, + ): self._display = display self._scale = scale self._speed = cursor_speed @@ -79,6 +88,7 @@ def __init__(self, display=None, display_group=None, bmp=None, is_hidden=False, else: self._cursor_bitmap = bmp self.generate_cursor(self._cursor_bitmap) + # pylint: enable=too-many-arguments,line-too-long def __enter__(self): @@ -96,8 +106,10 @@ def deinit(self): def _is_deinited(self): """checks cursor deinitialization""" if self._scale is None: - raise ValueError("Cursor object has been deinitialized and can no longer " - "be used. Create a new cursor object.") + raise ValueError( + "Cursor object has been deinitialized and can no longer " + "be used. Create a new cursor object." + ) @property def scale(self): @@ -187,7 +199,7 @@ def show(self): """Show the cursor.""" self.hidden = False - #pylint:disable=no-self-use + # pylint:disable=no-self-use def _default_cursor_bitmap(self): bmp = displayio.Bitmap(20, 20, 3) # left edge, outline @@ -196,20 +208,21 @@ def _default_cursor_bitmap(self): # right diag outline, inside fill for j in range(1, 15): bmp[j, j] = 2 - for i in range(j+1, bmp.height - j): + for i in range(j + 1, bmp.height - j): bmp[j, i] = 1 # bottom diag., outline for i in range(1, 5): - bmp[i, bmp.height-i] = 2 + bmp[i, bmp.height - i] = 2 # bottom flat line, right side fill for i in range(5, 15): bmp[i, 15] = 2 - bmp[i-1, 14] = 1 - bmp[i-2, 13] = 1 - bmp[i-3, 12] = 1 - bmp[i-4, 11] = 1 + bmp[i - 1, 14] = 1 + bmp[i - 2, 13] = 1 + bmp[i - 3, 12] = 1 + bmp[i - 4, 11] = 1 return bmp - #pylint:enable=no-self-use + + # pylint:enable=no-self-use @property def cursor_bitmap(self): @@ -224,8 +237,7 @@ def cursor_bitmap(self, bmp): """ self._cursor_bitmap = bmp self._cursor_grp.remove(self._cur_sprite) - self._cur_sprite = displayio.TileGrid(bmp, - pixel_shader=self._cur_palette) + self._cur_sprite = displayio.TileGrid(bmp, pixel_shader=self._cur_palette) self._cursor_grp.append(self._cur_sprite) def generate_cursor(self, bmp): @@ -236,7 +248,6 @@ def generate_cursor(self, bmp): self._cur_palette.make_transparent(0) self._cur_palette[1] = 0xFFFFFF self._cur_palette[2] = 0x0000 - self._cur_sprite = displayio.TileGrid(bmp, - pixel_shader=self._cur_palette) + self._cur_sprite = displayio.TileGrid(bmp, pixel_shader=self._cur_palette) self._cursor_grp.append(self._cur_sprite) self._display_grp.append(self._cursor_grp) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 5510f77..8f0e4ec 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -41,7 +41,8 @@ # PyBadge & PyGamer PYBADGE_BUTTON_A = const(2) -class CursorManager(): + +class CursorManager: """Simple interaction user interface interaction for Adafruit_CursorControl. :param adafruit_cursorcontrol cursor: The cursor object we are using. diff --git a/docs/conf.py b/docs/conf.py index 18b11b8..2361b8c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,10 +11,10 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.napoleon', - 'sphinx.ext.todo', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.todo", ] # TODO: Please Read! @@ -23,29 +24,32 @@ autodoc_mock_imports = ["displayio"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit CursorControl Library' -copyright = u'2019 Brent Rubell' -author = u'Brent Rubell' +project = "Adafruit CursorControl Library" +copyright = "2019 Brent Rubell" +author = "Brent Rubell" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = "1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = "1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -57,7 +61,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -69,7 +73,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -84,59 +88,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitCursorcontrolLibrarydoc' +htmlhelp_basename = "AdafruitCursorcontrolLibrarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitCursorControlLibrary.tex', u'AdafruitCursorControl Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitCursorControlLibrary.tex", + "AdafruitCursorControl Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -144,8 +151,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitCursorControllibrary', u'Adafruit CursorControl Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitCursorControllibrary", + "Adafruit CursorControl Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -154,7 +166,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitCursorControlLibrary', u'Adafruit CursorControl Library Documentation', - author, 'AdafruitCursorControlLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitCursorControlLibrary", + "Adafruit CursorControl Library Documentation", + author, + "AdafruitCursorControlLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/cursorcontrol_buttons_text.py b/examples/cursorcontrol_buttons_text.py index 95d8314..22dac28 100644 --- a/examples/cursorcontrol_buttons_text.py +++ b/examples/cursorcontrol_buttons_text.py @@ -22,9 +22,7 @@ color_bitmap = displayio.Bitmap(display.width, display.height, 1) color_palette = displayio.Palette(1) color_palette[0] = 0x404040 -bg_sprite = displayio.TileGrid(color_bitmap, - pixel_shader=color_palette, - x=0, y=0) +bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) splash.append(bg_sprite) ########################################################################## @@ -49,24 +47,46 @@ # Create the buttons buttons = [] -button_speed_inc = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN+BUTTON_HEIGHT, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="Speed+", label_font=font) +button_speed_inc = Button( + x=BUTTON_MARGIN, + y=BUTTON_MARGIN + BUTTON_HEIGHT, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="Speed+", + label_font=font, +) buttons.append(button_speed_inc) -button_speed_dec = Button(x=BUTTON_MARGIN, y=BUTTON_MARGIN*4+BUTTON_HEIGHT, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="Speed-", label_font=font) +button_speed_dec = Button( + x=BUTTON_MARGIN, + y=BUTTON_MARGIN * 4 + BUTTON_HEIGHT, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="Speed-", + label_font=font, +) buttons.append(button_speed_dec) -button_scale_pos = Button(x=BUTTON_MARGIN*3+2*BUTTON_WIDTH, y=BUTTON_MARGIN+BUTTON_HEIGHT, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="Scale+", label_font=font, style=Button.SHADOWRECT) +button_scale_pos = Button( + x=BUTTON_MARGIN * 3 + 2 * BUTTON_WIDTH, + y=BUTTON_MARGIN + BUTTON_HEIGHT, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="Scale+", + label_font=font, + style=Button.SHADOWRECT, +) buttons.append(button_scale_pos) -button_scale_neg = Button(x=BUTTON_MARGIN*3+2*BUTTON_WIDTH, y=BUTTON_MARGIN*4+BUTTON_HEIGHT, - width=BUTTON_WIDTH, height=BUTTON_HEIGHT, - label="Scale-", label_font=font, style=Button.SHADOWRECT) +button_scale_neg = Button( + x=BUTTON_MARGIN * 3 + 2 * BUTTON_WIDTH, + y=BUTTON_MARGIN * 4 + BUTTON_HEIGHT, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="Scale-", + label_font=font, + style=Button.SHADOWRECT, +) buttons.append(button_scale_neg) # Show the button @@ -74,16 +94,19 @@ splash.append(b.group) # Create a text label -text_label = label.Label(font, text="CircuitPython Cursor!", color=0x00FF00, - x = LBL_HEADER[0], y = LBL_HEADER[1]) +text_label = label.Label( + font, text="CircuitPython Cursor!", color=0x00FF00, x=LBL_HEADER[0], y=LBL_HEADER[1] +) splash.append(text_label) -text_speed = label.Label(font, max_glyphs = 15, color=0x00FF00, - x = LBL_TEXT[0], y = LBL_TEXT[1]) +text_speed = label.Label( + font, max_glyphs=15, color=0x00FF00, x=LBL_TEXT[0], y=LBL_TEXT[1] +) splash.append(text_speed) -text_scale = label.Label(font, max_glyphs = 15, color=0x00FF00, - x = LBL_TEXT[0], y = LBL_TEXT[1]+20) +text_scale = label.Label( + font, max_glyphs=15, color=0x00FF00, x=LBL_TEXT[0], y=LBL_TEXT[1] + 20 +) splash.append(text_scale) # initialize the mouse cursor object @@ -101,19 +124,19 @@ if cursor.is_clicked is True: for i, b in enumerate(buttons): if b.contains((mouse_cursor.x, mouse_cursor.y)): - b.selected=True - print("Button %d pressed"%i) - if i == 0: # Increase the cursor speed + b.selected = True + print("Button %d pressed" % i) + if i == 0: # Increase the cursor speed mouse_cursor.speed += 1 - elif i == 1: # Decrease the cursor speed + elif i == 1: # Decrease the cursor speed mouse_cursor.speed -= 1 - if i == 2: # Increase the cursor scale + if i == 2: # Increase the cursor scale mouse_cursor.scale += 1 - elif i == 3: # Decrease the cursor scale + elif i == 3: # Decrease the cursor scale mouse_cursor.scale -= 1 prev_btn = b elif prev_btn is not None: prev_btn.selected = False - text_speed.text = 'Speed: {0}px'.format(mouse_cursor.speed) - text_scale.text = 'Scale: {0}px'.format(mouse_cursor.scale) + text_speed.text = "Speed: {0}px".format(mouse_cursor.speed) + text_scale.text = "Scale: {0}px".format(mouse_cursor.scale) time.sleep(0.1) diff --git a/setup.py b/setup.py index d013aeb..63aa20f 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ """ from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -13,52 +14,40 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-cursorcontrol', - + name="adafruit-circuitpython-cursorcontrol", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='Mouse cursor for interaction with CircuitPython UI elements.', + setup_requires=["setuptools_scm"], + description="Mouse cursor for interaction with CircuitPython UI elements.", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_CursorControl', - + url="https://github.com/adafruit/Adafruit_CircuitPython_CursorControl", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=[ - 'Adafruit-Blinka', - 'no' - ], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka", "no"], # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit blinka circuitpython micropython cursorcontrol mouse, cursor, ui', - + keywords="adafruit blinka circuitpython micropython cursorcontrol mouse, cursor, ui", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=['adafruit_cursorcontrol'], + py_modules=["adafruit_cursorcontrol"], )