From 6aa9836a06ce10b95d9f2eaa6d59f602afb80072 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 26 Nov 2021 12:52:10 -0600 Subject: [PATCH 1/3] allow missing vectorio --- adafruit_displayio_layout/widgets/__init__.py | 5 +- ...ut_gridlayout_pygame_display_simpletest.py | 6 +- ...ayio_layout_pygame_display_switch_round.py | 83 +++++++++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 examples/displayio_layout_pygame_display_switch_round.py diff --git a/adafruit_displayio_layout/widgets/__init__.py b/adafruit_displayio_layout/widgets/__init__.py index e1e8282..cbc4f01 100644 --- a/adafruit_displayio_layout/widgets/__init__.py +++ b/adafruit_displayio_layout/widgets/__init__.py @@ -7,7 +7,10 @@ ======================= """ -import vectorio +try: + import vectorio +except ImportError: + pass try: import bitmaptools diff --git a/examples/displayio_layout_gridlayout_pygame_display_simpletest.py b/examples/displayio_layout_gridlayout_pygame_display_simpletest.py index 447d75a..207faf8 100644 --- a/examples/displayio_layout_gridlayout_pygame_display_simpletest.py +++ b/examples/displayio_layout_gridlayout_pygame_display_simpletest.py @@ -2,8 +2,10 @@ # # SPDX-License-Identifier: MIT """ -Make green and purple rectangles and a -"Hello World" label. Displayed with Blinka_Displayio_PyGameDisplay +Make a GridLayout with some Labels in it's cells. +Displayed with Blinka_Displayio_PyGameDisplay + +Requires: https://github.com/FoamyGuy/Blinka_Displayio_PyGameDisplay """ import displayio import terminalio diff --git a/examples/displayio_layout_pygame_display_switch_round.py b/examples/displayio_layout_pygame_display_switch_round.py new file mode 100644 index 0000000..e6f4cd6 --- /dev/null +++ b/examples/displayio_layout_pygame_display_switch_round.py @@ -0,0 +1,83 @@ +# SPDX-FileCopyrightText: 2021 Tim C +# +# SPDX-License-Identifier: MIT +""" +Make a GridLayout with some Labels in it's cells. +Displayed with Blinka_Displayio_PyGameDisplay + +Requires: https://github.com/FoamyGuy/Blinka_Displayio_PyGameDisplay +""" +import displayio +import pygame +from blinka_displayio_pygamedisplay import PyGameDisplay +from adafruit_displayio_layout.widgets.switch_round import SwitchRound as Switch + + +# Make the display context. Change size if you want +display = PyGameDisplay(width=320, height=240) + +# Make the display context +main_group = displayio.Group(max_size=10) +display.show(main_group) + +switch_x = 30 +switch_y = 30 +switch_radius = 20 + +switch_fill_color_off = (200, 44, 200) +switch_fill_color_on = (0, 100, 0) + +switch_outline_color_off = (30, 30, 30) +switch_outline_color_on = (0, 60, 0) + +background_color_off = (255, 255, 255) +background_color_on = (90, 255, 90) + +background_outline_color_off = background_color_off +background_outline_color_on = background_color_on + +switch_width = 4 * switch_radius # This is a good aspect ratio to start with + +switch_stroke = 2 # Width of the outlines (in pixels) +text_stroke = switch_stroke # width of text lines +touch_padding = 0 # Additional boundary around widget that will accept touch input + +animation_time = 0.2 # time for switch to display change (in seconds). + # animation_time=0.15 is a good starting point +display_text = True # show the text (0/1) + +# initialize state variables +switch_value = False +switch_value = True + +my_switch = Switch( + x=switch_x, + y=switch_y, + height=switch_radius * 2, + fill_color_off=switch_fill_color_off, + fill_color_on=switch_fill_color_on, + outline_color_off=switch_outline_color_off, + outline_color_on=switch_outline_color_on, + background_color_off=background_color_off, + background_color_on=background_color_on, + background_outline_color_off=background_outline_color_off, + background_outline_color_on=background_outline_color_on, + switch_stroke=switch_stroke, + display_button_text=display_text, + touch_padding=10, + animation_time=animation_time, + value=False, +) + + +main_group.append(my_switch) +while display.running: + + # get mouse up events + ev = pygame.event.get(eventtype=pygame.MOUSEBUTTONUP) + # proceed events + for event in ev: + pos = pygame.mouse.get_pos() + print(pos) + if my_switch.contains(pos): + my_switch.selected(pos) From bbf600251895a0227c340c2325f82062399d3871 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 26 Nov 2021 12:55:55 -0600 Subject: [PATCH 2/3] code format --- examples/displayio_layout_pygame_display_switch_round.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/displayio_layout_pygame_display_switch_round.py b/examples/displayio_layout_pygame_display_switch_round.py index e6f4cd6..f0e0d7a 100644 --- a/examples/displayio_layout_pygame_display_switch_round.py +++ b/examples/displayio_layout_pygame_display_switch_round.py @@ -43,7 +43,7 @@ touch_padding = 0 # Additional boundary around widget that will accept touch input animation_time = 0.2 # time for switch to display change (in seconds). - # animation_time=0.15 is a good starting point +# animation_time=0.15 is a good starting point display_text = True # show the text (0/1) # initialize state variables From f2142a23b64b4e096552ac1b0fd1c8d296f48a91 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 28 Nov 2021 14:06:31 -0600 Subject: [PATCH 3/3] remove max_size usage from switch_round example --- examples/displayio_layout_pygame_display_switch_round.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/displayio_layout_pygame_display_switch_round.py b/examples/displayio_layout_pygame_display_switch_round.py index f0e0d7a..63eb69c 100644 --- a/examples/displayio_layout_pygame_display_switch_round.py +++ b/examples/displayio_layout_pygame_display_switch_round.py @@ -17,7 +17,7 @@ display = PyGameDisplay(width=320, height=240) # Make the display context -main_group = displayio.Group(max_size=10) +main_group = displayio.Group() display.show(main_group) switch_x = 30