def add_widget(self, name, class_, *args, **kwargs): tab = self.add_tab(name) group = lv.group_create() lv.group_remove_all_objs(group) widget = class_(tab, *args, **kwargs) if hasattr(widget, 'input_children'): for c in widget.input_children(): lv.group_add_obj(group, c) lv.group_set_refocus_policy(group, lv.GROUP_REFOCUS_POLICY.NEXT) lv.group_set_focus_cb(group, ft.partial(group_focus_cb, tab)) self._groups.append(group) self._widgets.append(widget) self.on_tab_selected(self, lv.EVENT.VALUE_CHANGED)
def __init__(self, manifest: DandelionAppManifest): super().__init__(manifest) self.container = super().get_container() self.container.set_style_local_bg_color(lv.cont.PART.MAIN, lv.STATE.DEFAULT, lv.color_hex(0x000000)) self.manifests = Dandelion.discoverApplicationManifests() # Count apps self.numberOfApps = 0 for m in self.manifests: if m.visibleInLauncher: self.numberOfApps += 1 self.numberOfColumns = self.container.get_width() // 100 # Scrollview self.scrollview = lv.page(self.container) self.scrollview.set_size(self.container.get_width(), self.container.get_height()) self.scrollview.align(self.container, lv.ALIGN.IN_TOP_LEFT, 0, 0) self.scrollview.set_style_local_bg_opa(lv.page.PART.BG, lv.STATE.DEFAULT, lv.OPA._0) # Group self.scrollgroup = lv.group_create() # Populate pages index = 0 for m in filter(lambda x: (x.visibleInLauncher), self.manifests): i = SpringboardIcon(self.scrollview, m) self.scrollgroup.add_obj(i) index += 1 super().start()
def __init__(self, name, display, buttons, timer, **kwargs): self.disp = display self.buttons = buttons self.tim = timer # self.theme = th self.group = lv.group_create() # lv.theme_set_current(self.theme) self.scr = lv.obj() self.name = name self.items = {} self.item_ids = {} self.cont = w.Container(self.scr) self.set_buttons(kwargs.get("btn_left", lambda x: print("undefined left")), kwargs.get("btn_right", lambda x: print( "undefined right")), kwargs.get("btn_up", lambda x: print("undefined up")), kwargs.get("btn_down", lambda x: print( "undefined down")), kwargs.get("btn_a", lambda x: print("undefined a")), kwargs.get("btn_b", lambda x: print("undefined b")), kwargs.get("btn_x", lambda x: print("undefined x")), kwargs.get("btn_y", lambda x: print("undefined y")), )
lb3.set_text("3") btn3.set_size(60, 40) btn3.align(btn2, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) # btn4 = lv.btn(scr) lb4 = lv.label(btn4) lb4.set_text("4") btn4.set_size(60, 40) btn4.align(btn3, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) lv.scr_load(scr) # ButtonEncoder # step set at 5. Try with 7-10 to see how long one has to press (loooooonger) enc = M5ButtonEncoder(step=5, debug=True) # register the device driver: enc.registerDriver() # Create a group group = lv.group_create() lv.group_add_obj(group, btn1) lv.group_add_obj(group, btn2) lv.group_add_obj(group, btn3) lv.group_add_obj(group, btn4) # add it: only possible after registering the driver... enc.group = group print("Setup finished...")
chart.set_next(dl2, 10) chart.set_next(dl2, 25) chart.set_next(dl2, 45) chart.set_next(dl2, 80) chart.set_next(dl2, 75) chart.set_next(dl2, 505) """ CREATE ENCODER Emulate an encoder using the 3 buttons on the front of the m5stack. The first button moves left, the second button moves right, and the third button selects/deselects. """ button_encoder = ButtonsInputEncoder() button_driver = EncoderInputDriver(button_encoder) """ ADD WIDGETS TO A GROUP AND ASSOCIATE WITH DRIVER Add the "selectable" widgets to a group and associate this group with the button encoder driver. """ group = lv.group_create() # Create a group lv.group_add_obj(group, btn1) lv.group_add_obj(group, btn2) lv.group_add_obj(group, slider) lv.group_add_obj(group, ddlist) button_driver.group = group