Skip to content

Pylint update #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
Expand Down
32 changes: 18 additions & 14 deletions adafruit_display_notification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,35 @@

# pylint: disable=too-few-public-methods


class NotificationFree(displayio.Group):
"""Widget to show when no notifications are active."""

def __init__(self, width, height, *, dark_mode=True):
# pylint: disable=unused-argument
super().__init__()

if dark_mode:
text_color = 0xffffff
text_color = 0xFFFFFF
else:
text_color = 0x000000

# Create the text label
self.title = label.Label(TEXT_FONT, text="None!", y=height//2, color=text_color)
self.title = label.Label(
TEXT_FONT, text="None!", y=height // 2, color=text_color
)
self.append(self.title)


class PlainNotification(displayio.Group):
"""Plain text widget with a title and message."""

def __init__(self, title, message, width, height, *, dark_mode=True):
super().__init__()

# Set text, font, and color
if dark_mode:
text_color = 0xffffff
text_color = 0xFFFFFF
else:
text_color = 0x000000

Expand All @@ -76,11 +82,9 @@ def __init__(self, title, message, width, height, *, dark_mode=True):
max_lines = height // 20
message = "\n".join(lines[:max_lines])

self.message = label.Label(terminalio.FONT,
text=message,
color=text_color,
x=2,
y=height // 2 + 8)
self.message = label.Label(
terminalio.FONT, text=message, color=text_color, x=2, y=height // 2 + 8
)
self.append(self.message)

# cribbed from pyportal
Expand All @@ -90,17 +94,17 @@ def _wrap_nicely(string, max_chars):
:param str string: The text to be wrapped.
:param int max_chars: The maximum number of characters on a line before wrapping.
"""
string = string.replace('\n', '').replace('\r', '') # strip confusing newlines
words = string.split(' ')
string = string.replace("\n", "").replace("\r", "") # strip confusing newlines
words = string.split(" ")
the_lines = []
the_line = ""
for w in words:
if len(the_line+' '+w) <= max_chars:
the_line += ' '+w
if len(the_line + " " + w) <= max_chars:
the_line += " " + w
else:
the_lines.append(the_line)
the_line = ''+w
if the_line: # last line remaining
the_line = "" + w
if the_line: # last line remaining
the_lines.append(the_line)
# remove first space from first line:
the_lines[0] = the_lines[0][1:]
Expand Down
9 changes: 7 additions & 2 deletions adafruit_display_notification/apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Notification.git"

def create_notification_widget(notification, max_width, max_height, *, color_count=2**16):

def create_notification_widget(
notification, max_width, max_height, *, color_count=2 ** 16
):
"""Creates a notification widget for the given Apple notification."""
# pylint: disable=unused-argument
return PlainNotification(notification.title, notification.message, max_width, max_height)
return PlainNotification(
notification.title, notification.message, max_width, max_height
)
119 changes: 71 additions & 48 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,59 @@

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))

# -- General configuration ------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# 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!
# 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", "adafruit_bitmap_font", "adafruit_display_text", "terminalio"]
autodoc_mock_imports = [
"displayio",
"adafruit_bitmap_font",
"adafruit_display_text",
"terminalio",
]


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 Display_Notification Library'
copyright = u'2019 Scott Shawcroft'
author = u'Scott Shawcroft'
project = "Adafruit Display_Notification Library"
copyright = "2019 Scott Shawcroft"
author = "Scott Shawcroft"

# 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.
Expand All @@ -57,7 +66,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.
Expand All @@ -69,7 +78,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
Expand All @@ -84,68 +93,76 @@
# 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 = 'AdafruitDisplay_notificationLibrarydoc'
htmlhelp_basename = "AdafruitDisplay_notificationLibrarydoc"

# -- 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, 'AdafruitDisplay_NotificationLibrary.tex', u'AdafruitDisplay_Notification Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitDisplay_NotificationLibrary.tex",
"AdafruitDisplay_Notification Library Documentation",
author,
"manual",
),
]

# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'AdafruitDisplay_Notificationlibrary', u'Adafruit Display_Notification Library Documentation',
[author], 1)
(
master_doc,
"AdafruitDisplay_Notificationlibrary",
"Adafruit Display_Notification Library Documentation",
[author],
1,
)
]

# -- Options for Texinfo output -------------------------------------------
Expand All @@ -154,7 +171,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitDisplay_NotificationLibrary', u'Adafruit Display_Notification Library Documentation',
author, 'AdafruitDisplay_NotificationLibrary', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitDisplay_NotificationLibrary",
"Adafruit Display_Notification Library Documentation",
author,
"AdafruitDisplay_NotificationLibrary",
"One line description of project.",
"Miscellaneous",
),
]
19 changes: 14 additions & 5 deletions examples/display_notification_eink_gizmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# This is a whitelist of apps to show notifications from.
APPS = ["com.tinyspeck.chatlyio", "com.atebits.Tweetie2"]


def find_connection():
for connection in radio.connections:
if AppleNotificationCenterService not in connection:
Expand All @@ -20,6 +21,7 @@ def find_connection():
return connection, connection[AppleNotificationCenterService]
return None, None


# Start advertising before messing with the display so that we can connect immediately.
radio = adafruit_ble.BLERadio()
a = SolicitServicesAdvertisement()
Expand Down Expand Up @@ -51,14 +53,19 @@ def find_connection():
if not screen_updated:
remaining_time = display.time_to_refresh
new_notification = None
for notification in notification_service.wait_for_new_notifications(remaining_time):
for notification in notification_service.wait_for_new_notifications(
remaining_time
):
# Filter notifications we don't care about.
if APPS and notification.app_id not in APPS:
continue
# For now, use _raw_date even though we should use a parsed version of the date.
# pylint: disable=protected-access
# Ignore notifications older than the currently shown one.
if latest_notification and notification._raw_date < latest_notification._raw_date:
if (
latest_notification
and notification._raw_date < latest_notification._raw_date
):
continue
new_notification = notification
break
Expand All @@ -67,9 +74,11 @@ def find_connection():
print(new_notification)
latest_notification = new_notification
screen_updated = False
display.show(apple.create_notification_widget(latest_notification,
display.width,
display.height))
display.show(
apple.create_notification_widget(
latest_notification, display.width, display.height
)
)
elif latest_notification and latest_notification.removed:
# Stop showing the latest and show that there are no new notifications.
latest_notification = None
Expand Down
Loading