adafruit / adafruit_circuitpython_displayio_layout Goto Github PK
View Code? Open in Web Editor NEWA Circuitpython helper library for display element layout using displayio.
License: MIT License
A Circuitpython helper library for display element layout using displayio.
License: MIT License
log from RTD:
Running Sphinx v4.5.0
loading translations [en]... done
making output directory... done
loading intersphinx inventory from https://docs.python.org/3/objects.inv...
loading intersphinx inventory from https://docs.circuitpython.org/en/latest/objects.inv...
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 3 source files that are out of date
updating environment: [new config] 3 added, 0 changed, 0 removed
reading sources... [ 33%] api
WARNING: autodoc: failed to import module 'icon_widget' from module 'adafruit_displayio_layout.widgets'; the following exception was raised:
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/ext/autodoc/importer.py", line 62, in import_module
return importlib.import_module(modname)
File "/home/docs/.asdf/installs/python/3.10.0/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/checkouts/latest/adafruit_displayio_layout/widgets/icon_widget.py", line 26, in <module>
import terminalio
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/terminalio.py", line 26, in <module>
FONT = fontio.BuiltinFont()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/fontio.py", line 31, in __init__
self._font = ImageFont.load_default()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py", line 361, in load_default
f._load_pilfont_data(
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py", line 107, in _load_pilfont_data
image.load()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFile.py", line 241, in load
n, err_code = decoder.decode(b)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
WARNING: autodoc: failed to import module 'icon_animated' from module 'adafruit_displayio_layout.widgets'; the following exception was raised:
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/ext/autodoc/importer.py", line 62, in import_module
return importlib.import_module(modname)
File "/home/docs/.asdf/installs/python/3.10.0/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/checkouts/latest/adafruit_displayio_layout/widgets/icon_animated.py", line 30, in <module>
from adafruit_displayio_layout.widgets.icon_widget import IconWidget
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/checkouts/latest/adafruit_displayio_layout/widgets/icon_widget.py", line 26, in <module>
import terminalio
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/terminalio.py", line 26, in <module>
FONT = fontio.BuiltinFont()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/fontio.py", line 31, in __init__
self._font = ImageFont.load_default()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py", line 361, in load_default
f._load_pilfont_data(
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py", line 107, in _load_pilfont_data
image.load()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFile.py", line 241, in load
n, err_code = decoder.decode(b)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
WARNING: autodoc: failed to import module 'flip_input' from module 'adafruit_displayio_layout.widgets'; the following exception was raised:
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/ext/autodoc/importer.py", line 62, in import_module
return importlib.import_module(modname)
File "/home/docs/.asdf/installs/python/3.10.0/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/checkouts/latest/adafruit_displayio_layout/widgets/flip_input.py", line 27, in <module>
from terminalio import FONT
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/terminalio.py", line 26, in <module>
FONT = fontio.BuiltinFont()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/fontio.py", line 31, in __init__
self._font = ImageFont.load_default()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py", line 361, in load_default
f._load_pilfont_data(
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py", line 107, in _load_pilfont_data
image.load()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFile.py", line 241, in load
n, err_code = decoder.decode(b)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
WARNING: autodoc: failed to import module 'cartesian' from module 'adafruit_displayio_layout.widgets'; the following exception was raised:
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/ext/autodoc/importer.py", line 62, in import_module
return importlib.import_module(modname)
File "/home/docs/.asdf/installs/python/3.10.0/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/checkouts/latest/adafruit_displayio_layout/widgets/cartesian.py", line 28, in <module>
import terminalio
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/terminalio.py", line 26, in <module>
FONT = fontio.BuiltinFont()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/fontio.py", line 31, in __init__
self._font = ImageFont.load_default()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py", line 361, in load_default
f._load_pilfont_data(
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py", line 107, in _load_pilfont_data
image.load()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFile.py", line 241, in load
n, err_code = decoder.decode(b)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/cmd/build.py", line 276, in build_main
app.build(args.force_all, filenames)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/application.py", line 330, in build
self.builder.build_update()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 286, in build_update
self.build(to_build,
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 300, in build
updated_docnames = set(self.read())
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 407, in read
self._read_serial(docnames)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 428, in _read_serial
self.read_doc(docname)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 468, in read_doc
doctree = read_doc(self.app, self.env, self.env.doc2path(docname))
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/io.py", line 181, in read_doc
pub.publish()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/core.py", line 217, in publish
self.document = self.reader.read(self.source, self.parser,
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/io.py", line 101, in read
self.parse()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/readers/__init__.py", line 78, in parse
self.parser.parse(self.input, document)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/parsers.py", line 89, in parse
self.statemachine.run(inputlines, document, inliner=self.inliner)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/parsers/rst/states.py", line 170, in run
results = StateMachineWS.run(self, input_lines, input_offset,
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/statemachine.py", line 239, in run
context, next_state, result = self.check_line(
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/statemachine.py", line 451, in check_line
return method(match, context, next_state)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/parsers/rst/states.py", line 2344, in explicit_markup
self.explicit_list(blank_finish)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/parsers/rst/states.py", line 2369, in explicit_list
newline_offset, blank_finish = self.nested_list_parse(
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/parsers/rst/states.py", line 318, in nested_list_parse
state_machine.run(block, input_offset, memo=self.memo,
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/parsers/rst/states.py", line 196, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/statemachine.py", line 239, in run
context, next_state, result = self.check_line(
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/statemachine.py", line 451, in check_line
return method(match, context, next_state)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/parsers/rst/states.py", line 2647, in explicit_markup
nodelist, blank_finish = self.explicit_construct(match)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/parsers/rst/states.py", line 2354, in explicit_construct
return method(self, expmatch)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/parsers/rst/states.py", line 2096, in directive
return self.run_directive(
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/docutils/parsers/rst/states.py", line 2146, in run_directive
result = directive_instance.run()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/ext/inheritance_diagram.py", line 351, in run
graph = InheritanceGraph(
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/ext/inheritance_diagram.py", line 142, in __init__
classes = self._import_classes(class_names, currmodule)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/ext/inheritance_diagram.py", line 153, in _import_classes
classes.extend(import_classes(name, currmodule))
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/ext/inheritance_diagram.py", line 102, in import_classes
target = try_import(name)
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/sphinx/ext/inheritance_diagram.py", line 71, in try_import
return import_module(objname)
File "/home/docs/.asdf/installs/python/3.10.0/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/checkouts/latest/adafruit_displayio_layout/widgets/cartesian.py", line 28, in <module>
import terminalio
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/terminalio.py", line 26, in <module>
FONT = fontio.BuiltinFont()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/fontio.py", line 31, in __init__
self._font = ImageFont.load_default()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py", line 361, in load_default
f._load_pilfont_data(
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py", line 107, in _load_pilfont_data
image.load()
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFile.py", line 241, in load
n, err_code = decoder.decode(b)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Exception occurred:
File "/home/docs/checkouts/readthedocs.org/user_builds/adafruit-circuitpython-displayio-layout/envs/latest/lib/python3.10/site-packages/PIL/ImageFile.py", line 241, in load
n, err_code = decoder.decode(b)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
The full traceback has been saved in /tmp/sphinx-err-rmrc8_xt.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
WARNING: GENERIC_X86 is not fully supported. Some features may not work.
When you install the library via pip it's missing many of the library code files.
I think we need to include more entries in the list in setup.py like this:
packages=[
"adafruit_displayio_layout",
"adafruit_displayio_layout.layouts",
"adafruit_displayio_layout.widgets",
],
I tested this approach locally by using pip install .
and it does seem to allow the library to install correctly.
With the advent of new widgets such as icon_widget
, a clear need has arisen for common function naming schemes for the Control
class. The objective is so that the main event handler can use a common approach for calling multiple widgets to respond to various input events.
Of course, widgets aren't required to conform to any pre-defined response functions, but it will likely make it easier to write a Main loop event handler if widgets have the same function naming and a common expected effect.
Here's one example. Looking at the PyGUI, it defines responses to four mouse events:
This issue is raised to gather suggestions for the basic response functions to use in the Control
class.
Let's discuss a few basic functions that make sense in a touch environment on small microcontroller screens. The objective is not to collect 100% of cases, but to capture the few things that would be most used, and then grow from there.
On my path of creating a touch keyboard for the TFT Featherwing after laying out the keyboard saw there's no .contains param like there are for widgets and buttons. Requesting contains add to grid layout or some advice on completing this with touch capability.
forkawesome_font = bitmap_font.load_font("/fonts/forkawesome-12.pcf")
# Quick Colors for Labels
TEXT_BLACK = 0x000000
TEXT_BLUE = 0x0000FF
TEXT_CYAN = 0x00FFFF
TEXT_GRAY = 0x8B8B8B
TEXT_GREEN = 0x00FF00
TEXT_LIGHTBLUE = 0x90C7FF
TEXT_MAGENTA = 0xFF00FF
TEXT_ORANGE = 0xFFA500
TEXT_PURPLE = 0x800080
TEXT_RED = 0xFF0000
TEXT_WHITE = 0xFFFFFF
TEXT_YELLOW = 0xFFFF00
def make_my_label(font, anchor_point, anchored_position, scale, color):
func_label = label.Label(font)
func_label.anchor_point = anchor_point
func_label.anchored_position = anchored_position
func_label.scale = scale
func_label.color = color
return func_label
hello_label_change_wifi = make_my_label(
terminalio.FONT, (0.5, 1.0), (DISPLAY_WIDTH / 2, 15), 1, TEXT_WHITE)
input_change_wifi = make_my_label(
terminalio.FONT, (0.0, 0.0), (5, 50), 1, TEXT_WHITE)
input_new_cred = make_my_label(
terminalio.FONT, (0.0, 0.0), (100, 50), 1, TEXT_WHITE)
# Grid Layout Labels. Cell invisible with no text label
_labels = []
keyboard_input =[]
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="`"))
layout.add_content(_labels[0], grid_position=(0, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="1"))
layout.add_content(_labels[1], grid_position=(1, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="2"))
layout.add_content(_labels[2], grid_position=(2, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="3"))
layout.add_content(_labels[3], grid_position=(3, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="4"))
layout.add_content(_labels[4], grid_position=(4, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="5"))
layout.add_content(_labels[5], grid_position=(5, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="6"))
layout.add_content(_labels[6], grid_position=(6, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="7"))
layout.add_content(_labels[7], grid_position=(7, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="8"))
layout.add_content(_labels[8], grid_position=(8, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="9"))
layout.add_content(_labels[9], grid_position=(9, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="0"))
layout.add_content(_labels[10], grid_position=(10, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="-"))
layout.add_content(_labels[11], grid_position=(11, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="="))
layout.add_content(_labels[12], grid_position=(12, 0), cell_size=(1, 1))
_labels.append(label.Label(forkawesome_font, scale=1, x=0, y=0, text="\uf0e2"))
layout.add_content(_labels[13], grid_position=(13, 0), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Q"))
layout.add_content(_labels[14], grid_position=(0, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="W"))
layout.add_content(_labels[15], grid_position=(1, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="E"))
layout.add_content(_labels[16], grid_position=(2, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="R"))
layout.add_content(_labels[17], grid_position=(3, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="T"))
layout.add_content(_labels[18], grid_position=(4, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Y"))
layout.add_content(_labels[19], grid_position=(5, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="U"))
layout.add_content(_labels[20], grid_position=(6, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="I"))
layout.add_content(_labels[21], grid_position=(7, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="O"))
layout.add_content(_labels[22], grid_position=(8, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="P"))
layout.add_content(_labels[23], grid_position=(9, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="["))
layout.add_content(_labels[24], grid_position=(10, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="]"))
layout.add_content(_labels[25], grid_position=(11, 1), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="\\"))
layout.add_content(_labels[26], grid_position=(12, 1), cell_size=(2, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="A"))
layout.add_content(_labels[27], grid_position=(0, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="S"))
layout.add_content(_labels[28], grid_position=(1, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="D"))
layout.add_content(_labels[29], grid_position=(2, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="F"))
layout.add_content(_labels[30], grid_position=(3, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="G"))
layout.add_content(_labels[31], grid_position=(4, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="H"))
layout.add_content(_labels[32], grid_position=(5, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="J"))
layout.add_content(_labels[33], grid_position=(6, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="K"))
layout.add_content(_labels[34], grid_position=(7, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="L"))
layout.add_content(_labels[35], grid_position=(8, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text=";"))
layout.add_content(_labels[36], grid_position=(9, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="'"))
layout.add_content(_labels[37], grid_position=(10, 2), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="ENTER"))
layout.add_content(_labels[38], grid_position=(11, 2), cell_size=(3, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Z"))
layout.add_content(_labels[39], grid_position=(0, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="X"))
layout.add_content(_labels[40], grid_position=(1, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="C"))
layout.add_content(_labels[41], grid_position=(2, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="V"))
layout.add_content(_labels[42], grid_position=(3, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="B"))
layout.add_content(_labels[43], grid_position=(4, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="N"))
layout.add_content(_labels[44], grid_position=(5, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="M"))
layout.add_content(_labels[45], grid_position=(6, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text=","))
layout.add_content(_labels[46], grid_position=(7, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text=","))
layout.add_content(_labels[47], grid_position=(8, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="."))
layout.add_content(_labels[48], grid_position=(9, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="/"))
layout.add_content(_labels[49], grid_position=(10, 3), cell_size=(1, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="SHIFT"))
layout.add_content(_labels[50], grid_position=(11, 3), cell_size=(3, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="CTRL"))
layout.add_content(_labels[51], grid_position=(0, 4), cell_size=(2, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="ALT"))
layout.add_content(_labels[52], grid_position=(2, 4), cell_size=(2, 1))
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="SPACE"))
layout.add_content(_labels[53], grid_position=(4, 4), cell_size=(6, 1))
_labels.append(label.Label(forkawesome_font, scale=1, x=0, y=0, text="\uf060"))
layout.add_content(_labels[54], grid_position=(10, 4), cell_size=(1, 1))
_labels.append(label.Label(forkawesome_font, scale=1, x=0, y=0, text="\uf061"))
layout.add_content(_labels[55], grid_position=(11, 4), cell_size=(1, 1))
_labels.append(label.Label(forkawesome_font, scale=1, x=0, y=0, text="\uf062"))
layout.add_content(_labels[56], grid_position=(12, 4), cell_size=(1, 1))
_labels.append(label.Label(forkawesome_font, scale=1, x=0, y=0, text="\uf063"))
layout.add_content(_labels[57], grid_position=(13, 4), cell_size=(1, 1))
# bunch of stuff and while True:
while display.root_group is wifi_change_group:
label_list1 = []
New_Label_list =[]
hello_label_change_wifi.text = "Wifi Change Credentials"
input_change_wifi.text = "New Password: "
for label in _labels:
label_list1.append(label)
for label in label_list1:
sorted_labels = {'text':label.text}
New_Label_list.append([sorted_labels])
jsonLabelList = json.dumps(New_Label_list)
jsonlabel_list = json.loads(jsonLabelList)
while (time.monotonic() - last) <= sleep_time and display.root_group is wifi_change_group:
p = touchscreen.touch_point
if p:
print(f"Touch Point: {p}")
print(f"Get Grid Cell H: {layout.get_cell((5,2)).text}")
print(f"Get Grid Cell E: {layout.get_cell((2,1)).text}")
print(f"Get Grid Cell L: {layout.get_cell((8,2)).text}")
print(f"Get Grid Cell L: {layout.get_cell((8,2)).text}")
print(f"Get Grid Cell O: {layout.get_cell((8,1)).text}")
print("Key Pressed")
label_list = json.dumps(_labels)
#print(f"Label List: {label_list}")
#print(f"jsonList: {jsonlabel_list}")
print(f"Labels: {jsonlabel_list[0]}")
print(f"Object Type: {type(_labels)}")
input_new_cred.text = f"{jsonlabel_list[0][0]['text']}"
menu_switching(wifi_change_group, main_group2, main_group, preferences_group, wifi_settings_group, rssi_group, sys_info_group, wifi_change_group)
else:
# Default state always running
group_cleanup()
last = time.monotonic()
Key Pressed
Labels: [{'text': '`'}]
Object Type: <class 'list'>
Touch Point: (461, 194, 71)
Get Grid Cell: H
Get Grid Cell: E
Get Grid Cell: L
Get Grid Cell: L
Get Grid Cell: O
Key Pressed
Labels: [{'text': '`'}]
Object Type: <class 'list'>
I have it drilled down to being able to work with the individual cells to print out the keyboard letters needed with hardcoded statements but not touch yet.
That's the gist of it. Full code can be viewed on my Github which I've been working on daily.
Having grid layout the capability for touch contains would have made this much easier. I'm all ears for ideas if there's a better way.
I noticed that the detailed documentation from the docstrings is no longer being generated into the ReadTheDocs.
It's missing the graphics and all the long-form description of how these widgets are made.
Widget
class definition that had a lot of details about how to use it.Dial
widget where the graphics are missing.Q. Is it worth resolving this now or wait until these find their new home in the CircuitPython github pages?
i think it would make a nice addition to be able to plot multiple lines in the same Cartesian.
what i think needs to be done for this:
add point
functiondraw
or update
function (what is the better naming here?)please let me know what you think!
It would be nice to provide a way within GridLayout to let the user enable some functionality that can draw lines between the cells in the GridLayout.
The most basic implementation might be simply on or off for lines between all cells.
A more advanced implementation could allow the user to specify that they'd like lines between only certain cells that they are able to specify with parameters. This would allow them to visually group cells together that contain things logically grouped within their application / use case.
Ideally this should be done in a way that doesn't require any further library dependencies (so no adafruit_display_shapes) perhaps using vectorio
or displayio.Shape
Currently the sub-elements within a GridLayout can be accessed by index of the order that they were added:
my_grid_layout[0]
Will return the first element that was added to the grid so that you can access it's properties i.e.
my_grid_layout[0].color = 0xFFFFFF
would change the font color of a Label that was the first item added.
It would be great to provide an alternate way to lookup the elements in the grid based on their x,y cell location so that you could do something like:
my_grid_layout.get_element(0,0).color = 0xFFFFFF
and it would give you back the element in the first row / column without needing to worry about the order that the elements were added in.
The docs claim that it's possible to set animation_time
to zero:
animation: Set
animation_time
to the duration (in seconds) it will take to transition the switch, set zero if you want it to snap into position immediately
However, the code doesn't actually handle that case, thus leading to a ZeroDivisionError
here:
Traceback:
Traceback (most recent call last):
[...]
File "adafruit_displayio_layout/widgets/switch_round.py", line 830, in value
File "adafruit_displayio_layout/widgets/switch_round.py", line 792, in selected
File "adafruit_displayio_layout/widgets/switch_round.py", line 767, in _animate_switch
The DisplayIO_Layout library will rely on having several standard parameters for any "widgets" so this function can place them in the desired layout. Additionally, for any touch-related objects, it is useful to have standard response functions.
The starting point for this proposal was the Adafruit_CircuitPython_Display_Text library with the label item along with the Adafruit_CircuitPython_Display_Button library with the button item.
I'd especially like proposals on the standardized "Response functions" for widgets.
x
, y
: upper left corner of the widget, in display pixel coordinates (see diagram)anchor_point
: (a, b) two values between 0 and 1. Widget placement using anchor_point
and anchored_position
should operate the same as display_text.Label (see candy hearts example: https://learn.adafruit.com/circuit-python-tft-gizmo-candy-hearts/how-it-works)anchored_position
: (C,D) in pixels (see anchor_point
description above)width
: in pixelsheight
: in pixelsbounding_box
: (x, y, width, height), *getter onlytouch_padding
: in pixels, additional space around the bounding_box
that accept touch input (alternately, modify touch_boundary
directly)touch_boundary
: (x, y, width, height) region that will accept touch inputcontains(touch_point)
: responds True if touch-point is within the widget’s touch_boundary
selected(touch_point)
: widget was just touched, reaction to selection will depend upon the widget’s needsstill_touched(touch_point)
: widget remains touched (***?)released(touch_point)
: widget is released (***?)value
: type will depend upon the widget (getter/setter required)label
: text label to describe the buttondisplay_label
: Boolean, set True
to display the name of the widgetlabel_font
: fontlabel_anchor_point_on_widget
: proposed (*need to add description and diagram)label_anchor_point_on_label
: proposed (*need to add description and diagram)_color
: use as many parameters as needed for fill and outline colors for the widget structures, prefer to include _color
somewhere in the parameter name. Should accommodate hex 0xFFFFFF 8-bit RGB color codes, but prefer to also support tuples (R, G, B)._stroke
: this is the width in pixels of outline features. Use as many as needed, prefer to include _stroke
in the parameter name.animation_time
: in seconds, the time required for the widget’s animation. For example, for a switch, the time allotted for switching from off to on and vise versa. Preferably, the widget will check the elapsed animation time and redraw accordingly, so that the response time is the approximately the same even when run on different processors and systems. (see example in switch_round_horizontal.py, see selected
function)orientation
: horizontal
or vertical
flip
: Boolean, default is False. Set True if mirror image is desired.Here is a graphic with a proposal of some of the naming of the pixel coordinate schemes:
Here is a code snippet of the __init__
function for a draft of a switch widget that runs on the Adafruit PyPortal:
class SwitchRoundHorizontal(displayio.Group):
def __init__(
self,
*,
x=0, # Placement of upper left corner pixel position on the display
y=0,
width=None, # defaults to the 4*radius
height=30,
name="",
value=False,
touch_padding=0,
anchor_point=None,
anchored_position=None,
fill_color_off=(66, 44, 66),
fill_color_on=(0,100,0),
outline_color_off=(30,30,30),
outline_color_on=(0,60,0),
background_color_off=(255,255,255),
background_color_on=(0,60,0),
background_outline_color_off=None, # default to background_color_off
background_outline_color_on=None, # default to background_color_on
switch_stroke=2,
text_stroke=None, # default to switch_stroke
display_button_text=True,
animation_time=0.2, # animation duration (in seconds)
):
super().__init__(x=x, y=y, max_size=3)
As described above, the widget position on the screen can be defined directly by widget.x
and widget.y
or by the combination of widget.anchor_point
and widget.anchored_position
.
Here is a reference image for the usage of anchor_point
and anchored_position
as snipped from the Adafruit Learn guide's Candy Hearts Example:
@kmatch98 This guide page covers the process if you'd like to add it to the Adafruit CircuitPython Bundle.
Currently the import here:
makes vectorio
a hard requirement for anything inside of the widgets
module within this library.
If I understand correctly the vecotorio import is only used if something calls rectangle_helper()
which is also in this file. Wrapping this import with try/except would allow the module to be used in contexts where vectorio
is not present i.e. using objects that extend widget.Widget
with Blinka_Displayio (as long as those widgets don't need rectangle_helper()
or anything else from vectorio
specifically.
There are missing type annotations for some functions in this library.
The typing
module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:
try:
from typing import List, Tuple
except ImportError:
pass
Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:
def wrap_text_to_pixels(
string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:
If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github
There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs
and Check your code with pre-commit
contain the tools to install and commands to run locally to run the checks.
If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev
channel.
The following locations are reported by mypy to be missing type annotations:
I was looking into a question someone in #help-with-circuitpython had about centering text, and noticed in this conditional, if the content has anchor_point
, it's then reset to (0,0)
.
Currently the dial gauge value
can be set outside the range that is displayed. This causes the needle to go outside the range of motion defined by the sweep_angle
Recommend that the needle position be limited to the specified range. But also recommend to allow the value
to be anything in case the user needs the dial to retain this set value, even if outside the min and max values.
So, only clip the needle position but allow value to be anything.
(Possible subclass extension: adding a “clip” indicator to a gauge, like in a VU meter, to show that the value is over range)
Hi,
I tried to add a Cartesian to a ST7735 display.
All the elements (axis, tick, labels...) appear, but when I tried to add some points, I've got a 'TypeError' message.
I post this on Adafruit forum but someone told me to post an issue here.
This is my code
import time
import board
import displayio
import pwmio
import analogio
import busio
import adafruit_st7735r
import terminalio
from adafruit_display_text import label
from adafruit_progressbar.verticalprogressbar import (VerticalProgressBar,VerticalFillDirection,)
import adafruit_simplemath
from adafruit_displayio_layout.widgets.cartesian import Cartesian
luminosite_led = pwmio.PWMOut(board.LED)
potentiometre = analogio.AnalogIn(board.A0)
displayio.release_displays()
# Création des objets nécessaires au pilotage de l'écran
bus_spi = busio.SPI(clock=board.GP10, MOSI=board.GP11, MISO=board.GP12)
bus_affichage = displayio.FourWire(bus_spi, command=board.GP15, chip_select=board.GP13, reset=board.GP14)
ecran = adafruit_st7735r.ST7735R(bus_affichage, width=160, height=128, colstart=2, rowstart=1, rotation=90, bgr=True)
# Création du groupe pour les éléments graphiques sur l'écran
groupe_elements = displayio.Group()
# Création d'un label de texte
Valeur_volt = label.Label(terminalio.FONT, text="V = +x.xx V", color=0xFFFFFF, x=55, y=5)
groupe_elements.append(Valeur_volt)
# Création d'une barre de progression verticale
niveau_tension = VerticalProgressBar((10, 18), (15, 100), direction=VerticalFillDirection.BOTTOM_TO_TOP)
groupe_elements.append(niveau_tension)
# Création d'un graphique cartésien
graphique = Cartesian(
x=50, # coordonnée x du coin supérieur gauche du graphique
y=18, # coordonnée y du coin supérieur gauche du graphique
width=100, # largeur du graphique
height=100, # hauteur du graphique
axes_color=0xFFFFFF, # couleur des axes
axes_stroke=2, # épaisseur des axes en pixels
tick_color=0xFFFFFF, # couleur des graduations
major_tick_stroke=1, # largeur des graduations en pixels
major_tick_length=5, # longueur des graduations en pixels
tick_label_font=terminalio.FONT, # police pour les graduations
font_color=0xFFFFFF, # couleur de la police
pointer_radius = 1,
)
groupe_elements.append(graphique)
# Affichage du groupe sur l'écran
ecran.show(groupe_elements)
point_x = 0
point_y = 0
while True :
# variation de la luminosité de la LED avec le potentiomètre
luminosite_led.duty_cycle = potentiometre.value
# Affichage de la tension sur l'écran
tension = round(((potentiometre.value*3.3)/65535),2)
Valeur_volt.text = f"V = +{tension} V"
# Affichage du niveau de tension
valeur_pourcentage = int(adafruit_simplemath.map_range(potentiometre.value, 0, 65535, 0, 100))
niveau_tension.value = valeur_pourcentage
# Affichage d'un point sur le graphique
point_y = valeur_pourcentage
graphique.update_pointer(10, 10)
#graphique._draw_pointers(point_x, point_y)
point_x = point_x + 1
if point_x == 100 :
pointx = 0
# Pause entre deux points de mesure
time.sleep(0.05)
Hope you can find what's wrong.
Mike
Updated 2021-04-08: Please come back for news and developments regarding this
After the discussion in the CircuitPython meeting on 2021-04-05, it was discussed that individual widgets will be moved to individual libraries. This will help users find the widgets more easily. The DisplayIO library will keep the layouts configuration and the general helpers.
This change will have two types of consequences, in the widget itself, and in the library.
work will start with widgets not in PR as they are easier to move. After that alphabetical order will be used.
@kmatch98 @FoamyGuy if for any reason you don't want your widget to be moved let me know, or if you want to move the module yourself, please let me know also.
This wil probably raise a new library version as folks would need to rewrite their scripts
Re this thread:
https://forums.adafruit.com/viewtopic.php?f=47&t=186239
Added a dump of the values just before this line:
print(self._anchored_position[0], self._anchor_point[0], self._bounding_box[2], self._bounding_box[0])
and get:
6.0 0.0 93 0
So some of the values are float making the result also float. displayio.Group.x
requires int
.
there is a update_line
function in the Cartesian
class.
but i have not found any documentation about it -
i would expect to be able to draw some kind of linegraph with multiple points.
but looking at the code and testing that does not happen..
it seems that the first time the function is called it setups self.plot_line_point
and adds the given point.
and after this it draws a line from this first point to the given point.
resulting in a star-like graph.
i tested and the only thing missing is a self.plot_line_point.append((local_x, local_y))
after the call to bitmaptools.draw_line(
my minimal testcode:
# SPDX-FileCopyrightText: 2021 Stefan Krüger
#
# SPDX-License-Identifier: MIT
#############################
"""
Simple Test for line-ploting with the Cartesian widget.
"""
import time
import board
import displayio
from adafruit_displayio_layout.widgets.cartesian import Cartesian
# create the display on the PyPortal or Clue or PyBadge (for example)
display = board.DISPLAY
# pybadge display: 160x128
# Create a Cartesian widget
# https://circuitpython.readthedocs.io/projects/displayio-layout/en/latest/api.html#module-adafruit_displayio_layout.widgets.cartesian
my_plane = Cartesian(
x=30, # x position for the plane
y=2, # y plane position
width=128, # display width
height=105, # display height
xrange=(0, 90),
yrange=(0, 90),
)
my_group = displayio.Group()
my_group.append(my_plane)
display.show(my_group) # add high level Group to the display
positions = [
(0, 0),
(10, 10),
(20, 50),
(30, 60),
(40, 40),
(50, 80),
(60, 20),
(70, 60),
(80, 30),
(90, 90),
]
print("displayIO__layout_widget_cartesian_lineplot.py")
for x, y in positions:
my_plane.update_line(x, y)
time.sleep(1)
while True:
pass
I would like to request an additional Layout: BoxLayout.
Here is a use case from a project I am working on: I am using a GridLayout to simplify laying out the information on the screen. I have defined 4 rows and 1 column in the grid. I want each row to contain multiple Labels and a TileGrid bitmap. The allows me to position these objects without having to manually calculate all of the horizontal positions.
I created a primitive horizontal boxlayout that works with Label and TileGrid to create a Group that can be placed in the GridLayout.
Here is the code I used this works for my limited use case:
class HBoxLayout(Group):
@property
def width(self):
_width = 0
for w in self:
if isinstance(w, TileGrid):
_width += w.width * w.tile_width
else:
_width += w.width * w.scale
#_width = sum([w.width * w.scale for w in self]) #TileGrid does not have a scale attribute
return _width
@property
def height(self):
return max([w.height for w in self]) # also needs scale - but not needed for my use case.
def append(self, layer):
if not len(self):
layer.x = 0 # the first widget starts at zero
else:
layer.x = self.width
super().append(layer)
As you can see in the code above, the HBoxLayout adds height and width properties to Group, and overrides the append method to automatically position "widgets".
Here is a simple example of the class in use:
layout = GridLayout(
x=128,
y=0,
width=168,
height=128,
grid_size=(1, 4),
cell_padding=0,
divider_lines=False,
divider_line_color=0x000000,
cell_anchor_point=(0, 1))
for row in range(4):
group = HBoxLayout()
weather_icon = TileGrid(
icons_small_bmp,
pixel_shader=icons_small_pal,
x=0,
y=-8,
width=1,
height=1,
tile_width=20,
tile_height=20,
)
weather_icon[0] = row
group.append(label.Label(terminalio.FONT, text=f'{DAYS[row]} ', color=0x000000, scale=2))
group.append(weather_icon)
group.append(label.Label(terminalio.FONT, text=' 88/106', color=0x000000, scale=2))
group.append(label.Label(terminalio.FONT, text='o', y=-6, color=0x000000, scale=1))
layout.add_content(cell_content=group, grid_position=(0, row), cell_size=(1,1))
magtag.splash.append(layout)
magtag.refresh()
magtag.exit_and_deep_sleep(15)
A more robust solution would include a more general BoxLayout that supports vertical and horizontal orientations.
Although the extension is included in the doc conf.py
As far as I can tell there's no parameter for changing the line color with cartesian. Would like to change it depending on y-axis value.
Here's my current code for the fitbit api project.
my_plane = Cartesian(
x=30, # x position for the plane
y=60, # y plane position
width=DISPLAY_WIDTH-20, # display width
height=DISPLAY_HEIGHT-80, # display height
xrange=(0, 14), # x range
yrange=(lowest_y[0], highest_y[0]), # y range
axes_color=bar_color(highest_y[0]),
pointer_color=TEXT_PINK,
axes_stroke=4,
major_tick_stroke=2,
subticks=True,
)
Only thing I can currently colorize is the axes depending on value.
ref: #5087
The vectorio
API will be getting changed with regards to it's usage of palette. The Dial wiget that is currently in this library (although slated to move to it's own in circuitpython org) will need updated to reflect those changes in order to work properly.
@FoamyGuy @kmatch98 Thank you so much for writing this! It made my project much simpler. Here are a few thoughts!
For context, I am currently working with this file.
The project I am using it in can be found here.
In terms of add_sub_view
:
add_sub_view
doesn't make it clear to me what it's doing - the example did that. I do not know, however, from where the name was derived, so it could be a displayio
thing, in which case proceed as is. Really, I am unclear on what the concept of a view
is - this may be a concept I'm simply unfamiliar with in which case education will resolve the issue. Otherwise, consider a naming change to make things more clear.view
could be clearer. That or we supplement with excellent documentation. :)view_grid_size
should default to (1, 1)
as that seems like a sane default. It would significantly shorten up a basic constructor.In the GridLayout
constructor:
child_padding
could be more clearly named, I had to mess with it to figure out what it did, and I'm still not sure I really know.max_children
could default to the grid size x
* y
.child_padding
does versus what setting x
and y
do?Feature requests:
These are the things that occurred to me while using the version linked above in a project. I'm sure I'll come up with more as we work through it!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.