-
Notifications
You must be signed in to change notification settings - Fork 15
Add FlipInput selector #28
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
Conversation
@kmatch98 these look awesome! I will dive in and take a closer look at this one after a few of the prior PRs. Should get to it within the next few days. Thanks again for churning out so many great widgets! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this @kmatch98
I have a few suggestions.
This branch also needs main merged into it to catch up a few of the rst files.
Thanks for the positive feedback and the detailed notes. I’ll work on adopting your suggested defaults. Also I think I should add a couple drawings to clarify some of the parameters. A couple of things where I’d like your feedback that are more philosophical or strategic about widgets in general.
This seems like a question that could raise its head in many different widgets. Generalized, the question is how much “smarts” are in the main event loop and how much resides down in the widgets. Of course there is no right answer since each way can work just fine. I think the question is “how will beginning users best be served” to use these? Do we want a consistent expectation and strategy on how these things will behave. Or do we provide a menu of options? Also if folks accidentally have denounce on the main loop and in the defaults of the Widget it might cause unexpected behavior if folks don’t realize it. A related note, I struggle sometimes how much details and structural options to put into a widget since it can feel overwhelming. The question is extended for your suggestion on response behavior, do we want options of debounce behavior to have a home inside the widget. The second issues you raise is related to font scaling. Now we have one tool to do this with rotozoom. Do you think I’m eager to hear your thoughts, and of course we can’t predict everything but we can always try something and see where it leads us. |
I resolve all issues except for the request for debouncing. Your inputs are welcome. |
I don't know exactly how the modules for different devices are chosen but I would think it's fairly safe to assume any device that has It's an interesting question about how much logic to put into the object vs. the main loop. I'm not sure that I have the definite answer. One thing to consider is the adafruit_debouncer library. it could likely be used in the main loop to provide the logic for debouncing. To the extent that it does exist within the object I think it should be easy to configure or disable if user want to take more direct control of the behavior. I think offering a |
… accidental touches
I updated per your suggestions on I didn't change the # SPDX-FileCopyrightText: 2021 Kevin Matocha
#
# SPDX-License-Identifier: MIT
#############################
"""
This is a basic demonstration of a FlipInput widget.
"""
# pylint: disable=invalid-name
import time
import board
import displayio
import adafruit_touchscreen
from adafruit_bitmap_font import bitmap_font
from adafruit_displayio_layout.widgets.flip_input import FlipInput
display = board.DISPLAY # create the display on the PyPortal,
# otherwise change this to setup the display
# for display chip driver and pinout you have (e.g. ILI9341)
# setup the touchscreen
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),
)
# Select the font file for use
font_file = "fonts/DSEG14Classic-Regular-64-ModS.pcf"
my_font = bitmap_font.load_font(font_file)
my_flip1 = FlipInput(
display,
anchor_point=[0.0, 0.0],
anchored_position=[50, 40],
color=0xFF2222, # reddish orange color
value_list=[ # list of month strings, using three characters
"JAN",
"FEB",
"MAR",
"APR",
"MAY",
"JUN",
"JUL",
"AUG",
"SEP",
"OCT",
"NOV",
"DEC",
],
font_scale=5,
horizontal=False, # use vertical arrows
animation_time=0.0,
cool_down=0.25, # add a little time before responding to the next touch
)
my_flip2 = FlipInput(
display,
anchor_point=[0.0, 0.0],
anchored_position=[220, 40],
color=0xFF2222, # reddish orange color
value_list=["{0:02d}".format(x) for x in range(1, 31 + 1)],
# use a list of strings from 01 through 31
# use the {0:02d} format string to always use two digits (e.g. '03')
font_scale=5,
horizontal=False, # use vertical arrows
animation_time=0.0,
cool_down=-1.0, # requires button to be released prior to next activation
)
my_flip3 = FlipInput(
display,
anchor_point=[0.5, 1.0],
anchored_position=[320 // 2, 240 - 10],
color=0xFF2222, # reddish orange color
value_list=["{}".format(x) for x in range(1985, 2022, 1)],
# use a list with values of stringsfrom 1985 to 2022
font=my_font,
horizontal=True, # use horizontal arrows
animation_time=0.8, # add more time since the animation covers a longer distance
)
# Pick an interesting date to start
#
# You can set the value by direct integer indexes of the list or by a string
# Here are three ways to set the values:
my_flip1.value = 9 # use direct integer indexing to set the value to the 10th month
my_flip2.value = my_flip2.value_list.index("21") # find the index yourself by
# searching the value_list
my_flip3.value = "2015" # or set the value based on a string that is in the value_list
# Create the group to display and append the FlipInput widgets
my_group = displayio.Group(max_size=3)
my_group.append(my_flip1)
my_group.append(my_flip2)
my_group.append(my_flip3)
display.show(my_group) # add high level Group to the display
display.auto_refresh = True
while True:
p = ts.touch_point
# print("touch_point p: {}".format(p)) # print the touch point
if p: # if touched, check if any of the widgets was triggered
if my_flip1.contains(p):
my_flip1.selected(p)
else:
my_flip1.released()
if my_flip2.contains(p):
my_flip2.selected(p)
else:
my_flip2.released()
if my_flip3.contains(p):
my_flip3.selected(p)
else:
my_flip3.released()
else:
my_flip1.released()
my_flip2.released()
my_flip3.released()
time.sleep(0.05) # small delay seems to improve touch response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
I tested the latest version successfully with:
Adafruit CircuitPython 6.2.0-beta.4 on 2021-03-18; Adafruit PyPortal with samd51j20
Thanks for another awesome new widget @kmatch98 !
@kmatch98 Thanks kmatch :) |
Updating https://github.com/adafruit/Adafruit_CircuitPython_EPD to 2.9.3 from 2.9.2: > Merge pull request adafruit/Adafruit_CircuitPython_EPD#50 from lyusupov/master Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.18.2 from 2.18.1: > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#148 from jposada202020/solving_kwargs Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout to 1.8.0 from 1.7.0: > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_Layout#28 from kmatch98/flip_input_init
Adds a flip-style input selector widget.