Skip to content
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

Make Flake8 line limit consistent with Black and shorten lines to comply #2993

Merged
merged 10 commits into from
Nov 28, 2024
10 changes: 6 additions & 4 deletions android/src/toga_android/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def onActivityResult(self, requestCode, resultCode, resultData):

def onRequestPermissionsResult(self, requestCode, permissions, grantResults):
print(
f"Toga app: onRequestPermissionsResult {requestCode=} {permissions=} {grantResults=}"
f"Toga app: onRequestPermissionsResult "
f"{requestCode=} {permissions=} {grantResults=}"
)
try:
# Retrieve the completion callback and invoke it.
Expand Down Expand Up @@ -227,11 +228,12 @@ def exit(self):
pass # pragma: no cover

def main_loop(self):
# In order to support user asyncio code, start the Python/Android cooperative event loop.
# In order to support user asyncio code, start the Python/Android cooperative
# event loop.
self.loop.run_forever_cooperatively()

# On Android, Toga UI integrates automatically into the main Android event loop by virtue
# of the Android Activity system.
# On Android, Toga UI integrates automatically into the main Android event loop
# by virtue of the Android Activity system.
self.create()

def set_icon(self, icon):
Expand Down
12 changes: 8 additions & 4 deletions android/src/toga_android/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
KeyEvent.KEYCODE_F10: Key.F10,
KeyEvent.KEYCODE_F11: Key.F11,
KeyEvent.KEYCODE_F12: Key.F12,
# KeyEvent.KEY_quoteleft: Key.BACK_QUOTE, TODO Find matching key
# TODO Find matching key
# KeyEvent.KEY_quoteleft: Key.BACK_QUOTE,
KeyEvent.KEYCODE_1: Key._1,
KeyEvent.KEYCODE_2: Key._2,
KeyEvent.KEYCODE_3: Key._3,
Expand All @@ -27,7 +28,8 @@
KeyEvent.KEYCODE_8: Key._8,
KeyEvent.KEYCODE_9: Key._9,
KeyEvent.KEYCODE_0: Key._0,
# KeyEvent.KEYCODE_MINUS: Key.MINUS, TODO Create handling for num row special keys
# TODO Create handling for num row special keys
# KeyEvent.KEYCODE_MINUS: Key.MINUS,
# KeyEvent.KEYCODE_EQUALS: Key.EQUAL,
# KeyEvent.KEYCODE_DEL: Key.BACKSPACE,
# KeyEvent.KEY_asciitilde: Key.TILDE,
Expand Down Expand Up @@ -70,7 +72,8 @@
KeyEvent.KEYCODE_Y: Key.Y,
KeyEvent.KEYCODE_Z: Key.Z,
KeyEvent.KEYCODE_TAB: Key.TAB,
# KeyEvent.KEYCODE_LEFT_BRACKET: Key.OPEN_BRACKET,TODO Create handling for num row special keys
# TODO Create handling for num row special keys
# KeyEvent.KEYCODE_LEFT_BRACKET: Key.OPEN_BRACKET,
# KeyEvent.KEYCODE_RIGHT_BRACKET: Key.CLOSE_BRACKET,
# KeyEvent.KEYCODE_BACKSLASH: Key.BACKSLASH,
# KeyEvent.KEY_braceleft: Key.OPEN_BRACE,
Expand All @@ -79,7 +82,8 @@
# KeyEvent.KEY_semicolon: Key.SEMICOLON,
# KeyEvent.KEY_apostrophe: Key.QUOTE,
KeyEvent.KEYCODE_ENTER: Key.ENTER,
# KeyEvent.KEY_colon: Key.COLON, TODO Create handling for num row special keys
# TODO Create handling for num row special keys
# KeyEvent.KEY_colon: Key.COLON,
# KeyEvent.KEY_quotedbl: Key.DOUBLE_QUOTE,
# KeyEvent.KEY_comma: Key.COMMA,
# KeyEvent.KEY_period: Key.FULL_STOP,
Expand Down
212 changes: 105 additions & 107 deletions android/src/toga_android/libs/events.py

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions android/src/toga_android/widgets/detailedlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ class DetailedList(Widget):
def create(self):
if SwipeRefreshLayout is None: # pragma: no cover
raise RuntimeError(
"Unable to import SwipeRefreshLayout. Ensure that the AndroidX Swipe Refresh Layout "
"widget package (androidx.swiperefreshlayout:swiperefreshlayout:1.1.0) "
"is listed in your app's dependencies."
"Unable to import SwipeRefreshLayout. Ensure that the AndroidX Swipe "
"Refresh Layout widget package "
"(androidx.swiperefreshlayout:swiperefreshlayout:1.1.0) is listed in "
"your app's dependencies."
)
# get the selection color from the current theme
attrs = [R.attr.colorBackground, R.attr.colorControlHighlight]
Expand Down
3 changes: 2 additions & 1 deletion android/src/toga_android/widgets/imageview.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def rehint(self):
# we need to convert all sizes into physical pixels.
dpi = self.native.getContext().getResources().getDisplayMetrics().densityDpi
# Toga needs to know how the current DPI compares to the platform default,
# which is 160: https://developer.android.com/training/multiscreen/screendensities
# which is 160:
# https://developer.android.com/training/multiscreen/screendensities
scale = float(dpi) / 160

width, height, aspect_ratio = rehint_imageview(
Expand Down
6 changes: 3 additions & 3 deletions android/src/toga_android/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def set_font(self, font):
)

def set_background_color(self, value):
# In the case of EditText, this causes any custom color to hide the bottom border
# line, but it's better than set_background_filter, which affects *only* the
# bottom border line.
# In the case of EditText, this causes any custom color to hide the bottom
# border line, but it's better than set_background_filter, which affects *only*
# the bottom border line.
self.set_background_simple(value)

def set_color(self, value):
Expand Down
3 changes: 2 additions & 1 deletion android/tests_backend/widgets/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ def position(self):
return self.native.getProgress() / self.native.getMax()

async def wait_for_animation(self):
# Android ProgressBar has internal animation handling; no special handling required.
# Android ProgressBar has internal animation handling;
# no special handling required.
pass
3 changes: 2 additions & 1 deletion android/tests_backend/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def readonly(self):
# TYPE_TEXT_FLAG_NO_SUGGESTIONS is not set
if not focusable:
raise ValueError(
"TYPE_TEXT_FLAG_NO_SUGGESTIONS has been set when the input is readonly."
"TYPE_TEXT_FLAG_NO_SUGGESTIONS "
"has been set when the input is readonly."
)

return not focusable
Expand Down
1 change: 1 addition & 0 deletions changes/2975.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The flake8 line limit was adjusted to 88 to match limit for Black.
4 changes: 2 additions & 2 deletions cocoa/src/toga_cocoa/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ def enter_full_screen(self, windows):
)

for window, screen in zip(windows, NSScreen.screens):
# The widgets are actually added to window._impl.container.native, instead of
# window.content._impl.native. And window._impl.native.contentView is
# The widgets are actually added to window._impl.container.native, instead
# of window.content._impl.native. And window._impl.native.contentView is
# window._impl.container.native. Hence, we need to go fullscreen on
# window._impl.container.native instead.
window._impl.container.native.enterFullScreenMode(screen, withOptions=opts)
Expand Down
14 changes: 10 additions & 4 deletions cocoa/src/toga_cocoa/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ def container(self):

@container.setter
def container(self, value):
# This will *always* remove and then add constraints. It relies on the base widget to
# *not* invoke this setter unless the container is actually changing.
# This will *always* remove and then add constraints. It relies on the base
# widget to *not* invoke this setter unless the container is actually changing.

self._remove_constraints()
self._container = value
if value is not None:
# print(f"Add constraints for {self.widget} in {self.container} {self.widget.interface.layout})
# print(
# f"Add constraints for {self.widget} in {self.container} "
# f"{self.widget.interface.layout}"
# )
self.left_constraint = NSLayoutConstraint.constraintWithItem(
self.widget.native,
attribute__1=NSLayoutAttributeLeft,
Expand Down Expand Up @@ -107,7 +110,10 @@ def container(self, value):
self.container.native.addConstraint(self.height_constraint)

def update(self, x, y, width, height):
# print(f"UPDATE CONSTRAINTS {self.widget} in {self.container} {width}x{height}@{x},{y}")
# print(
# f"UPDATE CONSTRAINTS {self.widget} in {self.container} "
# f"{width}x{height}@{x},{y}"
# )
self.left_constraint.constant = x
self.top_constraint.constant = y

Expand Down
21 changes: 12 additions & 9 deletions cocoa/src/toga_cocoa/hardware/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def create_preview_window(self):
style=Pack(width=200),
)

# The shutter button. Initially disabled until we know we have a camera available
# The shutter button. Initially disabled until we know we have a camera
# available
self.shutter_button = toga.Button(
icon=toga.Icon("camera", system=True),
on_press=self.take_photo,
Expand Down Expand Up @@ -214,7 +215,7 @@ def change_camera(self, widget=None, **kwargs):
self._update_flash_mode()

def close_window(self, widget, **kwargs):
# If the user actually takes a photo, the window will be programmatically closed.
# If the user actually takes a photo the window will be programmatically closed.
# This handler is only triggered if the user manually closes the window.
# Stop the camera session
self.camera_session.stopRunning()
Expand Down Expand Up @@ -261,7 +262,7 @@ def __init__(self, interface):
msg = (
"Application metadata does not declare that the app will use "
"the camera. See "
"https://toga.readthedocs.io/en/stable/reference/api/hardware/camera.html"
"https://toga.readthedocs.io/en/stable/reference/api/hardware/camera.html" # noqa: E501
)
if self.interface.app.is_bundled:
raise RuntimeError(msg)
Expand All @@ -272,15 +273,17 @@ def __init__(self, interface):

def has_permission(self, allow_unknown=False):
# To reset permissions to "factory" status, run:
# tccutil reset Camera
# tccutil reset Camera
#
# To reset a single app:
# tccutil reset Camera <bundleID>
# tccutil reset Camera <bundleID>
#
# e.g.
# tccutil reset Camera org.beeware.appname # for a bundled app
# tccutil reset Camera com.microsoft.VSCode # for code running in Visual Studio
# tccutil reset Camera com.apple.Terminal # for code running in the Apple terminal
# e.g. For a bundled app:
# tccutil reset Camera org.beeware.appname
# For code running in Visual Studio:
# tccutil reset Camera com.microsoft.VSCode
# For code running in the Apple terminal:
# tccutil reset Camera com.apple.Terminal

if allow_unknown:
valid_values = {
Expand Down
10 changes: 5 additions & 5 deletions cocoa/src/toga_cocoa/widgets/internal/refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
NSView,
)

#########################################################################################
########################################################################################
# This is broadly derived from Alex Zielenski's ScrollToRefresh implementation:
# https://github.com/alexzielenski/ScrollToRefresh/blob/master/ScrollToRefresh/src/EQSTRScrollView.m
# =======================================================================================
# https://github.com/alexzielenski/ScrollToRefresh/blob/master/ScrollToRefresh/src/EQSTRScrollView.m # noqa: E501
# ======================================================================================
# ScrollToRefresh
#
# Copyright (C) 2011 by Alex Zielenski.
Expand All @@ -54,7 +54,7 @@
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# =======================================================================================
# ======================================================================================
#
# HOW THIS WORKS
#
Expand All @@ -78,7 +78,7 @@
#
# All of this is also gated by the refreshEnabled flag; when refresh is disabled, it
# also makes the refresh widget invisible so that it can't be seen in a bounce scroll.
#########################################################################################
########################################################################################

# The height of the refresh header; also the minimum pull height to trigger a refresh.
HEADER_HEIGHT = 45.0
Expand Down
10 changes: 5 additions & 5 deletions cocoa/src/toga_cocoa/widgets/mapview.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ def get_zoom(self):

def set_zoom(self, zoom):
if self.backlog is None:
# The zoom level indicates how many degrees of longitude will be displayed in a
# 256 pixel horizontal range. Determine how many degrees of longitude that is,
# and scale to the size of the visible horizontal space.
# The zoom level indicates how many degrees of longitude will be displayed
# in a 256 pixel horizontal range. Determine how many degrees of longitude
# that is, and scale to the size of the visible horizontal space.

# The horizontal axis can't show more than 360 degrees of longitude, so clip
# the range to that value. The OSM zoom level is based on 360 degrees of
Expand All @@ -144,8 +144,8 @@ def set_zoom(self, zoom):
)

# If we're currently panning to a new location, use the desired *future*
# location as the center of the zoom region. Otherwise use the current center
# coordinate.
# location as the center of the zoom region. Otherwise use the current
# center coordinate.
center = (
self.future_location
if self.future_location is not None
Expand Down
Loading