diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..21c125c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +.py text eol=lf +.rst text eol=lf +.txt text eol=lf +.yaml text eol=lf +.toml text eol=lf +.license text eol=lf +.md text eol=lf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 374676d..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,42 +1,21 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries # # SPDX-License-Identifier: Unlicense repos: - - repo: https://github.com/python/black - rev: 23.3.0 - hooks: - - id: black - - repo: https://github.com/fsfe/reuse-tool - rev: v1.1.2 - hooks: - - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pycqa/pylint - rev: v3.3.1 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: pylint - name: pylint (library code) - types: [python] - args: - - --disable=consider-using-f-string - exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint - name: pylint (example code) - description: Run pylint rules on "examples/*.py" files - types: [python] - files: "^examples/" - args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint - name: pylint (test code) - description: Run pylint rules on "tests/*.py" files - types: [python] - files: "^tests/" - args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - id: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 + hooks: + - id: reuse diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index fe3f21d..0000000 --- a/.pylintrc +++ /dev/null @@ -1,399 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist= - -# Add files or directories to the ignore-list. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. The -# regex matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. -jobs=1 - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins=pylint.extensions.no_self_use - -# Pickle collected data for later comparisons. -persistent=yes - -# Specify a configuration file. -#rcfile= - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call -disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable= - - -[REPORTS] - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio).You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -# notes=FIXME,XXX,TODO -notes=FIXME,XXX - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules=board - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,future.builtins - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -# expected-line-ending-format= -expected-line-ending-format=LF - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=yes - -# Minimum lines number of a similarity. -min-similarity-lines=12 - - -[BASIC] - -# Regular expression matching correct argument names -argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct attribute names -attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -# class-rgx=[A-Z_][a-zA-Z0-9]+$ -class-rgx=[A-Z_][a-zA-Z0-9_]+$ - -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Regular expression matching correct function names -function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Good variable names which should always be accepted, separated by a comma -# good-names=i,j,k,ex,Run,_ -good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -property-classes=abc.abstractproperty - -# Regular expression matching correct variable names -variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - - -[IMPORTS] - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=18 - -# Maximum number of attributes for a class (see R0902). -# max-attributes=7 -max-attributes=11 - -# Maximum number of boolean expressions in a if statement -max-bool-expr=5 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of locals for function / method body -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of statements in function / method body -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=1 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=builtins.Exception diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 33c2a61..88bca9f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,9 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: os: ubuntu-20.04 tools: diff --git a/README.rst b/README.rst index 7828bef..f88b195 100644 --- a/README.rst +++ b/README.rst @@ -13,9 +13,9 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_Display_Button/actions :alt: Build Status -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code Style: Black +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json + :target: https://github.com/astral-sh/ruff + :alt: Code Style: Ruff UI Buttons for displayio diff --git a/adafruit_button/__init__.py b/adafruit_button/__init__.py index 2fa5ba8..f521f2e 100644 --- a/adafruit_button/__init__.py +++ b/adafruit_button/__init__.py @@ -20,4 +20,5 @@ https://github.com/adafruit/circuitpython/releases """ + from adafruit_button.button import Button diff --git a/adafruit_button/button.py b/adafruit_button/button.py index 45c87f7..d81e994 100644 --- a/adafruit_button/button.py +++ b/adafruit_button/button.py @@ -1,4 +1,5 @@ # SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries +# SPDX-FileCopyrightText: 2024 Channing Ramos # # SPDX-License-Identifier: MIT @@ -9,7 +10,7 @@ UI Buttons for displayio -* Author(s): Limor Fried +* Author(s): Limor Fried, Channing Ramos Implementation Notes -------------------- @@ -21,41 +22,64 @@ """ -from micropython import const from adafruit_display_shapes.rect import Rect from adafruit_display_shapes.roundrect import RoundRect +from micropython import const + from adafruit_button.button_base import ButtonBase, _check_color +try: + from typing import Optional, Tuple, Union + + from displayio import Group + from fontio import FontProtocol +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Button.git" class Button(ButtonBase): - # pylint: disable=too-many-instance-attributes, too-many-locals - """Helper class for creating UI buttons for ``displayio``. - - :param x: The x position of the button. - :param y: The y position of the button. - :param width: The width of the button in pixels. - :param height: The height of the button in pixels. - :param name: The name of the button. + """Helper class for creating UI buttons for ``displayio``. Provides the following + buttons: + RECT: A rectangular button. SHAWDOWRECT adds a drop shadow. + ROUNDRECT: A rectangular button with rounded corners. SHADOWROUNDRECT adds + a drop shadow. + + :param int x: The x position of the button. + :param int y: The y position of the button. + :param int width: The width of the button in pixels. + :param int height: The height of the button in pixels. + :param Optional[str] name: The name of the button. :param style: The style of the button. Can be RECT, ROUNDRECT, SHADOWRECT, SHADOWROUNDRECT. Defaults to RECT. - :param fill_color: The color to fill the button. Defaults to 0xFFFFFF. - :param outline_color: The color of the outline of the button. - :param label: The text that appears inside the button. Defaults to not displaying the label. - :param label_font: The button label font. - :param label_color: The color of the button label text. Defaults to 0x0. - :param selected_fill: Inverts the fill color. - :param selected_outline: Inverts the outline color. - :param selected_label: Inverts the label color. + :param Optional[Union[int, Tuple[int, int, int]]] fill_color: The color to fill the button. + Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0xFFFFFF. + :param Optional[Union[int, Tuple[int, int, int]]] outline_color: The color of the outline of + the button. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. + :param Optional[str] label: The text that appears inside the button. + :param Optional[FontProtocol] label_font: The button label font. Defaults to + ''terminalio.FONT'' + :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the button label + text. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0. + :param Optional[Union[int, Tuple[int, int, int]]] selected_fill: The fill color when the + button is selected. Accepts an int or a tuple of 3 integers representing RGB values. + Defaults to the inverse of the fill_color. + :param Optional[Union[int, Tuple[int, int, int]]] selected_outline: The outline color when the + button is selected. Accepts an int or a tuple of 3 integers representing RGB values. + Defaults to the inverse of outline_color. + :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The label color when the + button is selected. Accepts an int or a tuple of 3 integers representing RGB values. + Defaults to inverting the label_color. + :param Optional[int] label_scale: The scale factor used for the label. Defaults to 1. """ - def _empty_self_group(self): + def _empty_self_group(self) -> None: while len(self) > 0: self.pop() - def _create_body(self): + def _create_body(self) -> None: if (self.outline_color is not None) or (self.fill_color is not None): if self.style == Button.RECT: self.body = Rect( @@ -77,9 +101,7 @@ def _create_body(self): outline=self._outline_color, ) elif self.style == Button.SHADOWRECT: - self.shadow = Rect( - 2, 2, self.width - 2, self.height - 2, fill=self.outline_color - ) + self.shadow = Rect(2, 2, self.width - 2, self.height - 2, fill=self.outline_color) self.body = Rect( 0, 0, @@ -114,24 +136,24 @@ def _create_body(self): SHADOWRECT = const(2) SHADOWROUNDRECT = const(3) - def __init__( + def __init__( # noqa: PLR0913 Too many arguments self, *, - x, - y, - width, - height, - name=None, + x: int, + y: int, + width: int, + height: int, + name: Optional[str] = None, style=RECT, - fill_color=0xFFFFFF, - outline_color=0x0, - label=None, - label_font=None, - label_color=0x0, - selected_fill=None, - selected_outline=None, - selected_label=None, - label_scale=None + fill_color: Optional[Union[int, Tuple[int, int, int]]] = 0xFFFFFF, + outline_color: Optional[Union[int, Tuple[int, int, int]]] = 0x0, + label: Optional[str] = None, + label_font: Optional[FontProtocol] = None, + label_color: Optional[Union[int, Tuple[int, int, int]]] = 0x0, + selected_fill: Optional[Union[int, Tuple[int, int, int]]] = None, + selected_outline: Optional[Union[int, Tuple[int, int, int]]] = None, + selected_label: Optional[Union[int, Tuple[int, int, int]]] = None, + label_scale: Optional[int] = 1, ): super().__init__( x=x, @@ -157,9 +179,9 @@ def __init__( self._selected_outline = _check_color(selected_outline) if self.selected_fill is None and fill_color is not None: - self.selected_fill = (~self._fill_color) & 0xFFFFFF + self.selected_fill = (~_check_color(self._fill_color)) & 0xFFFFFF if self.selected_outline is None and outline_color is not None: - self.selected_outline = (~self._outline_color) & 0xFFFFFF + self.selected_outline = (~_check_color(self._outline_color)) & 0xFFFFFF self._create_body() if self.body: @@ -167,7 +189,7 @@ def __init__( self.label = label - def _subclass_selected_behavior(self, value): + def _subclass_selected_behavior(self, value: bool) -> None: if self._selected: new_fill = self.selected_fill new_out = self.selected_outline @@ -180,7 +202,7 @@ def _subclass_selected_behavior(self, value): self.body.outline = new_out @property - def group(self): + def group(self) -> Group: """Return self for compatibility with old API.""" print( "Warning: The group property is being deprecated. " @@ -189,66 +211,57 @@ def group(self): ) return self - def contains(self, point): - """Used to determine if a point is contained within a button. For example, - ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for - determining that a button has been touched. - """ - return (self.x <= point[0] <= self.x + self.width) and ( - self.y <= point[1] <= self.y + self.height - ) - @property - def fill_color(self): + def fill_color(self) -> Optional[int]: """The fill color of the button body""" return self._fill_color @fill_color.setter - def fill_color(self, new_color): + def fill_color(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._fill_color = _check_color(new_color) if not self.selected: self.body.fill = self._fill_color @property - def outline_color(self): + def outline_color(self) -> Optional[int]: """The outline color of the button body""" return self._outline_color @outline_color.setter - def outline_color(self, new_color): + def outline_color(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._outline_color = _check_color(new_color) if not self.selected: self.body.outline = self._outline_color @property - def selected_fill(self): + def selected_fill(self) -> Optional[int]: """The fill color of the button body when selected""" return self._selected_fill @selected_fill.setter - def selected_fill(self, new_color): + def selected_fill(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._selected_fill = _check_color(new_color) if self.selected: self.body.fill = self._selected_fill @property - def selected_outline(self): + def selected_outline(self) -> Optional[int]: """The outline color of the button body when selected""" return self._selected_outline @selected_outline.setter - def selected_outline(self, new_color): + def selected_outline(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._selected_outline = _check_color(new_color) if self.selected: self.body.outline = self._selected_outline @property - def width(self): + def width(self) -> int: """The width of the button""" return self._width @width.setter - def width(self, new_width): + def width(self, new_width: int) -> None: self._width = new_width self._empty_self_group() self._create_body() @@ -257,12 +270,12 @@ def width(self, new_width): self.label = self.label @property - def height(self): + def height(self) -> int: """The height of the button""" return self._height @height.setter - def height(self, new_height): + def height(self, new_height: int) -> None: self._height = new_height self._empty_self_group() self._create_body() @@ -270,10 +283,10 @@ def height(self, new_height): self.append(self.body) self.label = self.label - def resize(self, new_width, new_height): + def resize(self, new_width: int, new_height: int) -> None: """Resize the button to the new width and height given - :param new_width int the desired width - :param new_height int the desired height + :param int new_width: The desired width in pixels. + :param int new_height: he desired height in pixels. """ self._width = new_width self._height = new_height diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 8a7709c..7e430b6 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -1,4 +1,5 @@ # SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries +# SPDX-FileCopyrightText: 2024 Channing Ramos # # SPDX-License-Identifier: MIT @@ -9,7 +10,7 @@ UI Buttons for displayio -* Author(s): Limor Fried +* Author(s): Limor Fried, Channing Ramos Implementation Notes -------------------- @@ -20,11 +21,20 @@ https://github.com/adafruit/circuitpython/releases """ + +import terminalio from adafruit_display_text.bitmap_label import Label from displayio import Group +try: + from typing import Dict, List, Optional, Tuple, Union + + from fontio import FontProtocol +except ImportError: + pass + -def _check_color(color): +def _check_color(color: Optional[Union[int, tuple[int, int, int]]]) -> int: # if a tuple is supplied, convert it to a RGB number if isinstance(color, tuple): r, g, b = color @@ -33,34 +43,38 @@ def _check_color(color): class ButtonBase(Group): - # pylint: disable=too-many-instance-attributes """Superclass for creating UI buttons for ``displayio``. - :param x: The x position of the button. - :param y: The y position of the button. - :param width: The width of the button in tiles. - :param height: The height of the button in tiles. - :param name: A name, or miscellaneous string that is stored on the button. - :param label: The text that appears inside the button. Defaults to not displaying the label. - :param label_font: The button label font. - :param label_color: The color of the button label text. Defaults to 0x0. - :param selected_label: Text that appears when selected + :param int x: The x position of the button. + :param int y: The y position of the button. + :param int width: The width of the button in tiles. + :param int height: The height of the button in tiles. + :param Optional[str] name: A name, or miscellaneous string that is stored on the button. + :param Optional[str] label: The text that appears inside the button. + :param Optional[FontProtocol] label_font: The button label font. + Defaults to ''terminalio.FONT'' + :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the label text. + Defaults to 0x0. Accepts an int or a tuple of 3 integers representing RGB values. + :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The color of the label text + when the button is selected. Accepts an int or a tuple of 3 integers representing RGB values. + Defaults to an inverse of label_color. + :param Optional[int] label_scale: The scale factor used for the label. Defaults to 1. """ - def __init__( + def __init__( # noqa: PLR0913 Too many arguments self, *, - x, - y, - width, - height, - name=None, - label=None, - label_font=None, - label_color=0x0, - selected_label=None, - label_scale=None - ): + x: int, + y: int, + width: int, + height: int, + name: Optional[str] = None, + label: Optional[str] = None, + label_font: Optional[FontProtocol] = None, + label_color: Optional[Union[int, Tuple[int, int, int]]] = 0x0, + selected_label: Optional[Union[int, Tuple[int, int, int]]] = None, + label_scale: Optional[int] = 1, + ) -> None: super().__init__(x=x, y=y) self.x = x self.y = y @@ -68,20 +82,20 @@ def __init__( self._height = height self._font = label_font self._selected = False - self.name = name + self._name = name self._label = label - self._label_color = label_color + self._label_color = _check_color(label_color) self._label_font = label_font self._selected_label = _check_color(selected_label) - self._label_scale = label_scale or 1 + self._label_scale = label_scale @property - def label(self): + def label(self) -> Optional[str]: """The text label of the button""" return getattr(self._label, "text", None) @label.setter - def label(self, newtext): + def label(self, newtext: str) -> None: if self._label and self and (self[-1] == self._label): self.pop() @@ -90,16 +104,14 @@ def label(self, newtext): return # nothing to do! if not self._label_font: - raise RuntimeError("Please provide label font") + self._label_font = terminalio.FONT self._label = Label(self._label_font, text=newtext, scale=self._label_scale) dims = list(self._label.bounding_box) dims[2] *= self._label.scale dims[3] *= self._label.scale if dims[2] >= self.width or dims[3] >= self.height: - while len(self._label.text) > 1 and ( - dims[2] >= self.width or dims[3] >= self.height - ): - self._label.text = "{}.".format(self._label.text[:-2]) + while len(self._label.text) > 1 and (dims[2] >= self.width or dims[3] >= self.height): + self._label.text = f"{self._label.text[:-2]}." dims = list(self._label.bounding_box) dims[2] *= self._label.scale dims[3] *= self._label.scale @@ -107,25 +119,23 @@ def label(self, newtext): raise RuntimeError("Button not large enough for label") self._label.x = (self.width - dims[2]) // 2 self._label.y = self.height // 2 - self._label.color = ( - self._label_color if not self.selected else self._selected_label - ) + self._label.color = self._label_color if not self.selected else self._selected_label self.append(self._label) if (self.selected_label is None) and (self._label_color is not None): - self.selected_label = (~self._label_color) & 0xFFFFFF + self.selected_label = (~_check_color(self._label_color)) & 0xFFFFFF - def _subclass_selected_behavior(self, value): - # Subclasses should overide this! + def _subclass_selected_behavior(self, value: bool): + # Subclasses should override this! pass @property - def selected(self): - """Selected inverts the colors.""" + def selected(self) -> bool: + """Returns whether the button is selected.""" return self._selected @selected.setter - def selected(self, value): + def selected(self, value: bool) -> None: if value == self._selected: return # bail now, nothing more to do self._selected = value @@ -140,20 +150,54 @@ def selected(self, value): self._subclass_selected_behavior(value) @property - def selected_label(self): - """The font color of the button when selected""" + def selected_label(self) -> int: + """The font color of the button when selected. + If no color is specified it defaults to the inverse of the label_color""" return self._selected_label @selected_label.setter - def selected_label(self, new_color): + def selected_label(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._selected_label = _check_color(new_color) @property - def label_color(self): + def label_color(self) -> int: """The font color of the button""" return self._label_color @label_color.setter - def label_color(self, new_color): + def label_color(self, new_color: Union[int, Tuple[int, int, int]]) -> None: self._label_color = _check_color(new_color) self._label.color = self._label_color + + @property + def name(self) -> str: + """The name of the button""" + return self._name + + @name.setter + def name(self, new_name: str) -> None: + self._name = new_name + + def contains(self, point: Union[tuple[int, int], List[int], List[Dict[str, int]]]) -> bool: + """Used to determine if a point is contained within a button. For example, + ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for + determining that a button has been touched. + """ + if isinstance(point, tuple) or (isinstance(point, list) and isinstance(point[0], int)): + return (self.x <= point[0] <= self.x + self.width) and ( + self.y <= point[1] <= self.y + self.height + ) + elif isinstance(point, list): + touch_points = point + if len(touch_points) == 0: + return False + for touch_point in touch_points: + if ( + isinstance(touch_point, dict) + and "x" in touch_point.keys() + and "y" in touch_point.keys() + ): + if self.contains((touch_point["x"], touch_point["y"])): + return True + + return False diff --git a/adafruit_button/sprite_button.py b/adafruit_button/sprite_button.py index 67fd9ee..e8f2f44 100644 --- a/adafruit_button/sprite_button.py +++ b/adafruit_button/sprite_button.py @@ -1,4 +1,5 @@ # SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries +# SPDX-FileCopyrightText: 2024 Channing Ramos # # SPDX-License-Identifier: MIT @@ -9,7 +10,7 @@ Bitmap 3x3 Spritesheet based UI Button for displayio -* Author(s): Tim Cocks +* Author(s): Tim Cocks, Channing Ramos Implementation Notes -------------------- @@ -20,44 +21,60 @@ https://github.com/adafruit/circuitpython/releases """ -from adafruit_imageload.tilegrid_inflator import inflate_tilegrid + from adafruit_imageload import load +from adafruit_imageload.tilegrid_inflator import inflate_tilegrid + from adafruit_button.button_base import ButtonBase +try: + from typing import Optional, Tuple, Union + + from fontio import FontProtocol +except ImportError: + pass + class SpriteButton(ButtonBase): """Helper class for creating 3x3 Bitmap Spritesheet UI buttons for ``displayio``. - - :param x: The x position of the button. - :param y: The y position of the button. - :param width: The width of the button in tiles. - :param height: The height of the button in tiles. - :param name: A name, or miscellaneous string that is stored on the button. - :param label: The text that appears inside the button. Defaults to not displaying the label. - :param label_font: The button label font. - :param label_color: The color of the button label text. Defaults to 0x0. - :param selected_label: Text that appears when selected - :param string bmp_path: The path of the 3x3 spritesheet Bitmap file - :param string selected_bmp_path: The path of the 3x3 spritesheet Bitmap file to use when pressed - :param int or tuple transparent_index: Index(s) that will be made transparent on the Palette + Compatible with any format supported by ''adafruit_imageload''. + + :param int x: The x position of the button. + :param int y: The y position of the button. + :param int width: The width of the button in tiles. + :param int height: The height of the button in tiles. + :param Optional[str] name: A name, or miscellaneous string that is stored on the button. + :param Optional[str] label: The text that appears inside the button. + :param Optional[FontProtocol] label_font: The button label font. + :param Optional[Union[int, Tuple[int, int, int]]] label_color: The color of the label text. + Accepts either an integer or a tuple of 3 integers representing RGB values. Defaults to 0x0. + :param Optional[Union[int, Tuple[int, int, int]]] selected_label: The color of the button label + text when the button is selected. Accepts either an integer or a tuple of 3 integers + representing RGB values. Defaults to the inverse of label_color. + :param str bmp_path: The path of the 3x3 spritesheet mage file + :param Optional[str] selected_bmp_path: The path of the 3x3 spritesheet image file to use when + pressed + :param Optional[Union[int, Tuple]] transparent_index: Palette index(s) that will be set to + transparent. PNG files have these index(s) set automatically. Not compatible with JPG files. + :param Optional[int] label_scale: The scale multiplier of the button label. Defaults to 1. """ - def __init__( + def __init__( # noqa: PLR0913 Too many arguments self, *, - x, - y, - width, - height, - name=None, - label=None, - label_font=None, - label_color=0x0, - selected_label=None, - bmp_path=None, - selected_bmp_path=None, - transparent_index=None, - label_scale=None + x: int, + y: int, + width: int, + height: int, + name: Optional[str] = None, + label: Optional[str] = None, + label_font: Optional[FontProtocol] = None, + label_color: Optional[Union[int, Tuple[int, int, int]]] = 0x0, + selected_label: Optional[Union[int, Tuple[int, int, int]]] = None, + bmp_path: str = None, + selected_bmp_path: Optional[str] = None, + transparent_index: Optional[Union[int, Tuple]] = None, + label_scale: Optional[int] = 1, ): if bmp_path is None: raise ValueError("Please supply bmp_path. It cannot be None.") @@ -88,7 +105,7 @@ def __init__( for _index in transparent_index: self._selected_bmp_palette.make_transparent(_index) elif isinstance(transparent_index, int): - self._selected_bmp_palette.make_transparent(0) + self._selected_bmp_palette.make_transparent(transparent_index) self._btn_tilegrid = inflate_tilegrid( bmp_obj=self._bmp, @@ -104,25 +121,16 @@ def __init__( self.label = label @property - def width(self): - """The width of the button""" + def width(self) -> int: + """The width of the button. Read-Only""" return self._width @property - def height(self): - """The height of the button""" + def height(self) -> int: + """The height of the button. Read-Only""" return self._height - def contains(self, point): - """Used to determine if a point is contained within a button. For example, - ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for - determining that a button has been touched. - """ - return (self.x <= point[0] <= self.x + self.width) and ( - self.y <= point[1] <= self.y + self.height - ) - - def _subclass_selected_behavior(self, value): + def _subclass_selected_behavior(self, value: bool) -> None: if self._selected: if self._selected_bmp is not None: self._btn_tilegrid.bitmap = self._selected_bmp diff --git a/docs/conf.py b/docs/conf.py index 8e24264..d657c39 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,12 +1,10 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) @@ -27,7 +25,7 @@ # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -autodoc_mock_imports = ["displayio", "bitmaptools"] +autodoc_mock_imports = ["displayio", "bitmaptools", "terminalio", "fontio"] intersphinx_mapping = { @@ -48,9 +46,7 @@ creation_year = "2019" current_year = str(datetime.datetime.now().year) year_duration = ( - current_year - if current_year == creation_year - else creation_year + " - " + current_year + current_year if current_year == creation_year else creation_year + " - " + current_year ) copyright = year_duration + " Limor Fried" author = "Limor Fried" diff --git a/examples/display_button_color_properties.py b/examples/display_button_color_properties.py index d8bf92f..9ad73a0 100644 --- a/examples/display_button_color_properties.py +++ b/examples/display_button_color_properties.py @@ -6,10 +6,11 @@ properties after the button has been initialized. """ +import adafruit_touchscreen import board import displayio import terminalio -import adafruit_touchscreen + from adafruit_button import Button # use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.) diff --git a/examples/display_button_customfont.py b/examples/display_button_customfont.py index 189af96..eb6a3ae 100644 --- a/examples/display_button_customfont.py +++ b/examples/display_button_customfont.py @@ -5,10 +5,12 @@ """ import os + +import adafruit_touchscreen import board import displayio from adafruit_bitmap_font import bitmap_font -import adafruit_touchscreen + from adafruit_button import Button # use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.) diff --git a/examples/display_button_debounced.py b/examples/display_button_debounced.py new file mode 100644 index 0000000..8a0471b --- /dev/null +++ b/examples/display_button_debounced.py @@ -0,0 +1,73 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# SPDX-License-Identifier: MIT +""" +Basic debounced button example. +""" + +import adafruit_touchscreen +import board +import displayio +import terminalio + +from adafruit_button import Button + +# use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.) +# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.) +# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus +display = board.DISPLAY + +# --| Button Config |------------------------------------------------- +BUTTON_X = 110 +BUTTON_Y = 95 +BUTTON_WIDTH = 100 +BUTTON_HEIGHT = 50 +BUTTON_STYLE = Button.ROUNDRECT +BUTTON_FILL_COLOR = 0x00FFFF +BUTTON_OUTLINE_COLOR = 0xFF00FF +BUTTON_LABEL = "HELLO WORLD" +BUTTON_LABEL_COLOR = 0x000000 +# --| Button Config |------------------------------------------------- + +# Setup touchscreen (PyPortal) +ts = adafruit_touchscreen.Touchscreen( + board.TOUCH_XL, + board.TOUCH_XR, + board.TOUCH_YD, + board.TOUCH_YU, + calibration=((5200, 59000), (5800, 57000)), + size=(display.width, display.height), +) + +# Make the display context +splash = displayio.Group() +display.root_group = splash + +# Make the button +button = Button( + x=BUTTON_X, + y=BUTTON_Y, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + style=BUTTON_STYLE, + fill_color=BUTTON_FILL_COLOR, + outline_color=BUTTON_OUTLINE_COLOR, + label=BUTTON_LABEL, + label_font=terminalio.FONT, + label_color=BUTTON_LABEL_COLOR, +) + +# Add button to the display context +splash.append(button) + +# Loop and look for touches +while True: + p = ts.touch_point + if p: + if button.contains(p): + if not button.selected: + button.selected = True + print("pressed") + else: + button.selected = False # if touch is dragged outside of button + else: + button.selected = False # if touch is released diff --git a/examples/display_button_simpletest.py b/examples/display_button_simpletest.py index fa388f3..f8d8546 100644 --- a/examples/display_button_simpletest.py +++ b/examples/display_button_simpletest.py @@ -4,10 +4,11 @@ Simple button example. """ +import adafruit_touchscreen import board import displayio import terminalio -import adafruit_touchscreen + from adafruit_button import Button # use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.) diff --git a/examples/display_button_soundboard.py b/examples/display_button_soundboard.py index 2fd0bad..ef52c8a 100644 --- a/examples/display_button_soundboard.py +++ b/examples/display_button_soundboard.py @@ -5,7 +5,9 @@ """ import time + from adafruit_pyportal import PyPortal + from adafruit_button import Button SHOW_BUTTONS = False diff --git a/examples/display_button_spritebutton_debounced.py b/examples/display_button_spritebutton_debounced.py new file mode 100644 index 0000000..6d6f65f --- /dev/null +++ b/examples/display_button_spritebutton_debounced.py @@ -0,0 +1,74 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# SPDX-License-Identifier: MIT +import time + +import adafruit_touchscreen +import board +import displayio +import terminalio + +from adafruit_button.sprite_button import SpriteButton + +""" +Sprite button debounced example +""" + +# These pins are used as both analog and digital! XL, XR and YU must be analog +# and digital capable. YD just need to be digital +ts = adafruit_touchscreen.Touchscreen( + board.TOUCH_XL, + board.TOUCH_XR, + board.TOUCH_YD, + board.TOUCH_YU, + calibration=((5200, 59000), (5800, 57000)), + size=(board.DISPLAY.width, board.DISPLAY.height), +) + +# Make the display context +main_group = displayio.Group() +board.DISPLAY.root_group = main_group + +BUTTON_WIDTH = 10 * 16 +BUTTON_HEIGHT = 3 * 16 +BUTTON_MARGIN = 20 + +font = terminalio.FONT + +buttons = [] + + +button_0 = SpriteButton( + x=BUTTON_MARGIN, + y=BUTTON_MARGIN, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="button0", + label_font=font, + bmp_path="bmps/gradient_button_0.bmp", + selected_bmp_path="bmps/gradient_button_1.bmp", + transparent_index=0, +) + +buttons.append(button_0) + +for b in buttons: + main_group.append(b) +while True: + p = ts.touch_point + if p: + for i, b in enumerate(buttons): + if b.contains(p): + if not b.selected: + print("Button %d pressed" % i) + b.selected = True + b.label = "pressed" + else: + b.selected = False + b.label = f"button{i}" + + else: + for i, b in enumerate(buttons): + if b.selected: + b.selected = False + b.label = f"button{i}" + time.sleep(0.01) diff --git a/examples/display_button_spritebutton_simpletest.py b/examples/display_button_spritebutton_simpletest.py index 838ed30..1836d67 100644 --- a/examples/display_button_spritebutton_simpletest.py +++ b/examples/display_button_spritebutton_simpletest.py @@ -1,10 +1,12 @@ # SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries # SPDX-License-Identifier: MIT import time + +import adafruit_touchscreen import board import displayio -import adafruit_touchscreen import terminalio + from adafruit_button.sprite_button import SpriteButton # These pins are used as both analog and digital! XL, XR and YU must be analog diff --git a/examples/display_button_spritebutton_tft_featherwing_simpletest.py b/examples/display_button_spritebutton_tft_featherwing_simpletest.py index bac2cf7..3c6ffd9 100644 --- a/examples/display_button_spritebutton_tft_featherwing_simpletest.py +++ b/examples/display_button_spritebutton_tft_featherwing_simpletest.py @@ -1,12 +1,15 @@ # SPDX-FileCopyrightText: 2024 DJDevon3 # SPDX-License-Identifier: MIT import time -import displayio -import terminalio + +import adafruit_stmpe610 # TFT Featherwing V1 touch driver import board import digitalio +import displayio +import fourwire +import terminalio from adafruit_hx8357 import HX8357 # TFT Featherwing display driver -import adafruit_stmpe610 # TFT Featherwing V1 touch driver + from adafruit_button.sprite_button import SpriteButton # 3.5" TFT Featherwing is 480x320 @@ -18,7 +21,7 @@ spi = board.SPI() tft_cs = board.D9 tft_dc = board.D10 -display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) +display_bus = fourwire.FourWire(spi, command=tft_dc, chip_select=tft_cs) display = HX8357(display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT) display.rotation = 0 _touch_flip = (False, True) diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..73e9efc --- /dev/null +++ b/ruff.toml @@ -0,0 +1,108 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +target-version = "py38" +line-length = 100 + +[lint] +preview = true +select = ["I", "PL", "UP"] + +extend-select = [ + "D419", # empty-docstring + "E501", # line-too-long + "W291", # trailing-whitespace + "PLC0414", # useless-import-alias + "PLC2401", # non-ascii-name + "PLC2801", # unnecessary-dunder-call + "PLC3002", # unnecessary-direct-lambda-call + "E999", # syntax-error + "PLE0101", # return-in-init + "F706", # return-outside-function + "F704", # yield-outside-function + "PLE0116", # continue-in-finally + "PLE0117", # nonlocal-without-binding + "PLE0241", # duplicate-bases + "PLE0302", # unexpected-special-method-signature + "PLE0604", # invalid-all-object + "PLE0605", # invalid-all-format + "PLE0643", # potential-index-error + "PLE0704", # misplaced-bare-raise + "PLE1141", # dict-iter-missing-items + "PLE1142", # await-outside-async + "PLE1205", # logging-too-many-args + "PLE1206", # logging-too-few-args + "PLE1307", # bad-string-format-type + "PLE1310", # bad-str-strip-call + "PLE1507", # invalid-envvar-value + "PLE2502", # bidirectional-unicode + "PLE2510", # invalid-character-backspace + "PLE2512", # invalid-character-sub + "PLE2513", # invalid-character-esc + "PLE2514", # invalid-character-nul + "PLE2515", # invalid-character-zero-width-space + "PLR0124", # comparison-with-itself + "PLR0202", # no-classmethod-decorator + "PLR0203", # no-staticmethod-decorator + "UP004", # useless-object-inheritance + "PLR0206", # property-with-parameters + "PLR0904", # too-many-public-methods + "PLR0911", # too-many-return-statements + "PLR0912", # too-many-branches + "PLR0913", # too-many-arguments + "PLR0914", # too-many-locals + "PLR0915", # too-many-statements + "PLR0916", # too-many-boolean-expressions + "PLR1702", # too-many-nested-blocks + "PLR1704", # redefined-argument-from-local + "PLR1711", # useless-return + "C416", # unnecessary-comprehension + "PLR1733", # unnecessary-dict-index-lookup + "PLR1736", # unnecessary-list-index-lookup + + # ruff reports this rule is unstable + #"PLR6301", # no-self-use + + "PLW0108", # unnecessary-lambda + "PLW0120", # useless-else-on-loop + "PLW0127", # self-assigning-variable + "PLW0129", # assert-on-string-literal + "B033", # duplicate-value + "PLW0131", # named-expr-without-context + "PLW0245", # super-without-brackets + "PLW0406", # import-self + "PLW0602", # global-variable-not-assigned + "PLW0603", # global-statement + "PLW0604", # global-at-module-level + + # fails on the try: import typing used by libraries + #"F401", # unused-import + + "F841", # unused-variable + "E722", # bare-except + "PLW0711", # binary-op-exception + "PLW1501", # bad-open-mode + "PLW1508", # invalid-envvar-default + "PLW1509", # subprocess-popen-preexec-fn + "PLW2101", # useless-with-lock + "PLW3301", # nested-min-max +] + +ignore = [ + "PLR2004", # magic-value-comparison + "UP030", # format literals + "PLW1514", # unspecified-encoding + "PLR0913", # too-many-arguments + "PLR0915", # too-many-statements + "PLR0917", # too-many-positional-arguments + "PLR0904", # too-many-public-methods + "PLR0912", # too-many-branches + "PLR0916", # too-many-boolean-expressions + "PLR6301", # could-be-static no-self-use + "PLC0415", # import outside toplevel + "PLC2701", # private import +] + +[format] +line-ending = "lf"