Merge pull request #5954 from kmatch98/repl_wrangler

Expose display’s root_group, add function to resize REPL terminal
This commit is contained in:
Dan Halbert 2022-02-02 15:36:22 -05:00 committed by GitHub
commit 4dc9b00221
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 7 deletions

View File

@ -444,6 +444,23 @@ const mp_obj_property_t displayio_display_bus_obj = {
MP_ROM_NONE}, MP_ROM_NONE},
}; };
//| root_group: Group
//| """The root group on the display."""
//|
//|
STATIC mp_obj_t displayio_display_obj_get_root_group(mp_obj_t self_in) {
displayio_display_obj_t *self = native_display(self_in);
return common_hal_displayio_display_get_root_group(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_root_group_obj, displayio_display_obj_get_root_group);
const mp_obj_property_t displayio_display_root_group_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_display_get_root_group_obj,
MP_ROM_NONE,
MP_ROM_NONE},
};
//| def fill_row(self, y: int, buffer: WriteableBuffer) -> WriteableBuffer: //| def fill_row(self, y: int, buffer: WriteableBuffer) -> WriteableBuffer:
//| """Extract the pixels from a single row //| """Extract the pixels from a single row
@ -517,6 +534,7 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) }, { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) },
{ MP_ROM_QSTR(MP_QSTR_rotation), MP_ROM_PTR(&displayio_display_rotation_obj) }, { MP_ROM_QSTR(MP_QSTR_rotation), MP_ROM_PTR(&displayio_display_rotation_obj) },
{ MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_display_bus_obj) }, { MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_display_bus_obj) },
{ MP_ROM_QSTR(MP_QSTR_root_group), MP_ROM_PTR(&displayio_display_root_group_obj) },
}; };
STATIC MP_DEFINE_CONST_DICT(displayio_display_locals_dict, displayio_display_locals_dict_table); STATIC MP_DEFINE_CONST_DICT(displayio_display_locals_dict, displayio_display_locals_dict_table);

View File

@ -69,6 +69,6 @@ mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t *
bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self, mp_float_t brightness); bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self, mp_float_t brightness);
mp_obj_t common_hal_displayio_display_get_bus(displayio_display_obj_t *self); mp_obj_t common_hal_displayio_display_get_bus(displayio_display_obj_t *self);
mp_obj_t common_hal_displayio_display_get_root_group(displayio_display_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_DISPLAY_H #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_DISPLAY_H

View File

@ -33,6 +33,7 @@
#include "shared/runtime/interrupt_char.h" #include "shared/runtime/interrupt_char.h"
#include "supervisor/shared/autoreload.h" #include "supervisor/shared/autoreload.h"
#include "supervisor/shared/bluetooth/bluetooth.h" #include "supervisor/shared/bluetooth/bluetooth.h"
#include "supervisor/shared/display.h"
#include "supervisor/shared/status_leds.h" #include "supervisor/shared/status_leds.h"
#include "supervisor/shared/stack.h" #include "supervisor/shared/stack.h"
#include "supervisor/shared/traceback.h" #include "supervisor/shared/traceback.h"
@ -299,6 +300,21 @@ STATIC mp_obj_t supervisor_disable_ble_workflow(void) {
} }
MP_DEFINE_CONST_FUN_OBJ_0(supervisor_disable_ble_workflow_obj, supervisor_disable_ble_workflow); MP_DEFINE_CONST_FUN_OBJ_0(supervisor_disable_ble_workflow_obj, supervisor_disable_ble_workflow);
//| def reset_terminal(x_pixels: int, y_pixels: int) -> None:
//| """Reset the CircuitPython serial terminal with new dimensions."""
//| ...
//|
STATIC mp_obj_t supervisor_reset_terminal(mp_obj_t x_pixels, mp_obj_t y_pixels) {
#if CIRCUITPY_DISPLAYIO
supervisor_stop_terminal();
supervisor_start_terminal(mp_obj_get_int(x_pixels), mp_obj_get_int(y_pixels));
#else
mp_raise_NotImplementedError(NULL);
#endif
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(supervisor_reset_terminal_obj, supervisor_reset_terminal);
STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = { STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_supervisor) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_supervisor) },
{ MP_ROM_QSTR(MP_QSTR_enable_autoreload), MP_ROM_PTR(&supervisor_enable_autoreload_obj) }, { MP_ROM_QSTR(MP_QSTR_enable_autoreload), MP_ROM_PTR(&supervisor_enable_autoreload_obj) },
@ -312,6 +328,7 @@ STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&supervisor_ticks_ms_obj) }, { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&supervisor_ticks_ms_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_previous_traceback), MP_ROM_PTR(&supervisor_get_previous_traceback_obj) }, { MP_ROM_QSTR(MP_QSTR_get_previous_traceback), MP_ROM_PTR(&supervisor_get_previous_traceback_obj) },
{ MP_ROM_QSTR(MP_QSTR_disable_ble_workflow), MP_ROM_PTR(&supervisor_disable_ble_workflow_obj) }, { MP_ROM_QSTR(MP_QSTR_disable_ble_workflow), MP_ROM_PTR(&supervisor_disable_ble_workflow_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset_terminal), MP_ROM_PTR(&supervisor_reset_terminal_obj) },
}; };
STATIC MP_DEFINE_CONST_DICT(supervisor_module_globals, supervisor_module_globals_table); STATIC MP_DEFINE_CONST_DICT(supervisor_module_globals, supervisor_module_globals_table);

View File

@ -220,6 +220,10 @@ mp_obj_t common_hal_displayio_display_get_bus(displayio_display_obj_t *self) {
return self->core.bus; return self->core.bus;
} }
mp_obj_t common_hal_displayio_display_get_root_group(displayio_display_obj_t *self) {
return self->core.current_group;
}
STATIC const displayio_area_t *_get_refresh_areas(displayio_display_obj_t *self) { STATIC const displayio_area_t *_get_refresh_areas(displayio_display_obj_t *self) {
if (self->core.full_refresh) { if (self->core.full_refresh) {
self->core.area.next = NULL; self->core.area.next = NULL;

View File

@ -163,12 +163,15 @@ void displayio_display_core_set_rotation(displayio_display_core_t *self,
} }
bool displayio_display_core_show(displayio_display_core_t *self, displayio_group_t *root_group) { bool displayio_display_core_show(displayio_display_core_t *self, displayio_group_t *root_group) {
if (root_group == NULL) {
if (!circuitpython_splash.in_group) { if (root_group == NULL) { // set the display to the REPL, reset REPL position and size
root_group = &circuitpython_splash; circuitpython_splash.in_group = false;
} else if (self->current_group == &circuitpython_splash) { // force the circuit_python_splash out of any group (Note: could cause problems with the parent group)
return true; circuitpython_splash.x = 0; // reset position in case someone moved it.
} circuitpython_splash.y = 0;
supervisor_stop_terminal();
supervisor_start_terminal(self->width, self->height);
root_group = &circuitpython_splash;
} }
if (root_group == self->current_group) { if (root_group == self->current_group) {
return true; return true;