Skip to content

Commit

Permalink
Reformat existing files so all lines are under 88 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbradshaw committed Nov 26, 2024
1 parent 8a6187c commit b100ab0
Show file tree
Hide file tree
Showing 135 changed files with 644 additions and 414 deletions.
9 changes: 6 additions & 3 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,10 +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
# On Android, Toga UI integrates automatically into the main Android event
# loop by virtue
# of the Android Activity system.
self.create()

Expand Down
3 changes: 2 additions & 1 deletion android/src/toga_android/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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
# KeyEvent.KEYCODE_LEFT_BRACKET: Key.OPEN_BRACKET,
# TODO Create handling for num row special keys
# KeyEvent.KEYCODE_RIGHT_BRACKET: Key.CLOSE_BRACKET,
# KeyEvent.KEYCODE_BACKSLASH: Key.BACKSLASH,
# KeyEvent.KEY_braceleft: Key.OPEN_BRACE,
Expand Down
138 changes: 82 additions & 56 deletions android/src/toga_android/libs/events.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion android/src/toga_android/widgets/detailedlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ 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 "
"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."
)
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
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
10 changes: 6 additions & 4 deletions cocoa/src/toga_cocoa/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ 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}
# {self.widget.interface.layout})
self.left_constraint = NSLayoutConstraint.constraintWithItem(
self.widget.native,
attribute__1=NSLayoutAttributeLeft,
Expand Down Expand Up @@ -107,7 +108,8 @@ 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}
# {width}x{height}@{x},{y}")
self.left_constraint.constant = x
self.top_constraint.constant = y

Expand Down
17 changes: 11 additions & 6 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,8 @@ 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"
)
if self.interface.app.is_bundled:
raise RuntimeError(msg)
Expand All @@ -278,9 +280,12 @@ def has_permission(self, allow_unknown=False):
# 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
# 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

if allow_unknown:
valid_values = {
Expand Down
11 changes: 6 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,11 @@
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
# ======================================================================================
# ScrollToRefresh
#
# Copyright (C) 2011 by Alex Zielenski.
Expand All @@ -54,7 +55,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 +79,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
15 changes: 8 additions & 7 deletions cocoa/src/toga_cocoa/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def create(self):
# Add constraints to lay out the input and stepper.
# Stepper is always top right corner.
self.native.addConstraint(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self.native,
NSLayoutAttributeTop,
NSLayoutRelationEqual,
Expand All @@ -104,7 +104,7 @@ def create(self):
)
)
self.native.addConstraint(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self.native,
NSLayoutAttributeRight,
NSLayoutRelationEqual,
Expand All @@ -117,7 +117,7 @@ def create(self):

# Stepper height matches container box height
self.native.addConstraint(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self.native,
NSLayoutAttributeBottom,
NSLayoutRelationEqual,
Expand All @@ -130,7 +130,7 @@ def create(self):

# Input is always left, centred vertically on the stepper
self.native.addConstraint(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self.native_stepper,
NSLayoutAttributeCenterY,
NSLayoutRelationEqual,
Expand All @@ -141,7 +141,7 @@ def create(self):
)
)
self.native.addConstraint(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self.native,
NSLayoutAttributeLeft,
NSLayoutRelationEqual,
Expand All @@ -154,7 +154,7 @@ def create(self):

# Stepper and input meet in the middle with a small gap
self.native.addConstraint(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self.native_stepper,
NSLayoutAttributeLeft,
NSLayoutRelationEqual,
Expand Down Expand Up @@ -183,7 +183,8 @@ def set_background_color(self, color):

def has_focus(self):
# When the NSTextField gets focus, a field editor is created, and that editor
# has the original widget as the delegate. The first responder is the Field Editor.
# has the original widget as the delegate. The first responder is the
# Field Editor.
return isinstance(self.native.window.firstResponder, NSTextView) and (
self.native.window.firstResponder.delegate == self.native_input
)
Expand Down
3 changes: 2 additions & 1 deletion cocoa/src/toga_cocoa/widgets/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def tableViewSelectionDidChange_(self, notification) -> None:
# value = getattr(data_row, col_identifier, None)
# if isinstance(value, toga.Widget):
# # if the cell value is a widget, use its height
# heights.append(value._impl.native.intrinsicContentSize().height + margin)
# heights.append(value._impl.native.intrinsicContentSize().height
# + margin)
#
# return max(heights)

Expand Down
6 changes: 4 additions & 2 deletions cocoa/src/toga_cocoa/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def add_error_label(self):
@property
def has_focus(self):
# When the NSTextField gets focus, a field editor is created, and that editor
# has the original widget as the delegate. The first responder is the Field Editor.
# has the original widget as the delegate. The first responder is
# the Field Editor.
return (
self.native.window is not None
and isinstance(self.native.window.firstResponder, NSTextView)
Expand Down Expand Up @@ -219,7 +220,8 @@ def rehint(self):
# Height of a text input is known and fixed.
# Width must be > 100
# print("REHINT TextInput", self,
# self._impl.intrinsicContentSize().width, self._impl.intrinsicContentSize().height
# self._impl.intrinsicContentSize().width,
# self._impl.intrinsicContentSize().height
# )
self.interface.intrinsic.width = at_least(self.interface._MIN_WIDTH)
self.interface.intrinsic.height = self.native.intrinsicContentSize().height
Expand Down
9 changes: 6 additions & 3 deletions cocoa/src/toga_cocoa/widgets/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def outlineView_viewForTableColumn_item_(self, tree, column, item):
tcv = self.makeViewWithIdentifier(identifier, owner=self)

if not tcv: # there is no existing view to reuse so create a new one
# tcv = TogaIconView.alloc().initWithFrame(CGRectMake(0, 0, column.width, 16))
# tcv = TogaIconView.alloc().initWithFrame(CGRectMake(
# 0, 0, column.width, 16))
tcv = TogaIconView.alloc().init()
tcv.identifier = identifier

Expand Down Expand Up @@ -127,7 +128,8 @@ def outlineView_viewForTableColumn_item_(self, tree, column, item):

# for column in self.tableColumns:
# value = getattr(
# item.attrs["node"], str(column.identifier), self.interface.missing_value
# item.attrs["node"], str(column.identifier),
# self.interface.missing_value
# )

# if isinstance(value, toga.Widget):
Expand All @@ -144,7 +146,8 @@ def outlineView_pasteboardWriterForItem_(
return None

# @objc_method
# def outlineView_sortDescriptorsDidChange_(self, tableView, oldDescriptors) -> None:
# def outlineView_sortDescriptorsDidChange_(self,
# tableView, oldDescriptors) -> None:
#
# for descriptor in self.sortDescriptors[::-1]:
# accessor = descriptor.key
Expand Down
3 changes: 2 additions & 1 deletion cocoa/src/toga_cocoa/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def __init__(self, interface, title, position, size):
self.container = Container(on_refresh=self.content_refreshed)
self.native.contentView = self.container.native

# Ensure that the container renders it's background in the same color as the window.
# Ensure that the container renders it's background in the
# same color as the window.
self.native.wantsLayer = True
self.container.native.backgroundColor = self.native.backgroundColor

Expand Down
4 changes: 2 additions & 2 deletions cocoa/tests_backend/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ async def post_event(self, event, delay=None):
# this prevents
await asyncio.sleep(delay)
else:
# Add another event to the queue behind the original event, to notify us once
# it's been processed.
# Add another event to the queue behind the original event, to notify us
# once it's been processed.
NSRunLoop.currentRunLoop.performSelector(
SEL("onEvent"),
target=self.event_listener,
Expand Down
3 changes: 2 additions & 1 deletion cocoa/tests_backend/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ async def type_character(self, char, modifierFlags=0):
if modifierFlags:
char = None

# This posts a single keyDown followed by a keyUp, matching "normal" keyboard operation.
# This posts a single keyDown followed by a keyUp, matching "normal"
# keyboard operation.
await self.post_event(
NSEvent.keyEventWithType(
NSEventType.KeyDown,
Expand Down
Loading

0 comments on commit b100ab0

Please sign in to comment.