예제 #1
0
    def on_app_btn(self, obj, event):
        def on_close(obj, evt):
            lv.win.close_event_cb(lv.win.__cast__(obj), evt)

        if event == lv.EVENT.CLICKED:
            name = lv.list.__cast__(obj).get_btn_text()[:-3]

            # load code
            try:
                f = open("apps/" + name + ".py")
                code = f.read()
                f.close()
            except:
                # TODO: handle load error
                return

            # create window to run the app in
            self.win = lv.win(lv.scr_act())
            self.win.set_title(name)

            # add close button to the header
            self.close_btn = self.win.add_btn_right(lv.SYMBOL.CLOSE)
            self.close_btn.set_event_cb(on_close)

            self.run_in_console(name, code)
예제 #2
0
        disp_drv = lv.disp_drv_t()
        disp_drv.init()
        disp_drv.buffer = disp_buf1
        disp_drv.flush_cb = SDL.monitor_flush
        disp_drv.hor_res = 240
        disp_drv.ver_res = 320
        disp_drv.register()

        # Register SDL mouse driver
        indev_drv = lv.indev_drv_t()
        indev_drv.init() 
        indev_drv.type = lv.INDEV_TYPE.POINTER
        indev_drv.read_cb = SDL.mouse_read
        indev_drv.register();
    
        # create window to run the app in
        win = lv.win(lv.scr_act())

        # add close button to the header
        close_btn = win.add_btn_right(lv.SYMBOL.CLOSE)
        close_btn.set_event_cb(on_close)
        
        # make windows availabel to all llvgl instances
        import llvgl
        sys.modules['llvgl'].config = { "win": win, "close_btn": close_btn, "objects": [ ] }
        
        exec('import ' + name, {} )

        while running:
            pass
예제 #3
0
    def execute(self, is_sd=None, name=None):
        def on_close(obj, evt):
            lv.win.close_event_cb(lv.win.__cast__(obj), evt)
            if evt == lv.EVENT.CLICKED:
                if 'llvgl' in sys.modules:
                    sys.modules['llvgl'].close()
                    del sys.modules['llvgl']

                if self.app_page:
                    if hasattr(self.app_page, "close"):
                        self.app_page.close()
                    del self.app_page
                    self.app_page = None

                # may not be there anymore if page creation failed
                if "apps." + name in sys.modules:
                    del sys.modules["apps." + name]
            self.win = None

        # check of there is already an open app
        if self.win:
            if self.close_btn.get_state(0) & lv.STATE.DISABLED:
                # we cannot close the window if the thread is still
                # running. And we cannot stop threads ... so we don't
                # do anything and hope for the thread to end sometime ...
                return
            else:
                # send released event to the close button so this in turn
                # closes the windows which is currently open
                self.close_btn.set_event_cb(None)  # prevent buttons own events
                on_close(self.close_btn, lv.EVENT.PRESSED)
                on_close(self.close_btn, lv.EVENT.CLICKED)
                # needed to call close()
                on_close(self.close_btn, lv.EVENT.RELEASED)

        # assume app has no own page
        self.app_page = None

        # if no name was supplied then the window was just to be closed
        # and we are done at this point
        if not name: return

        # if the machine has an sd card, then change
        # into the appropriate dir
        if hasattr(machine, "SDCard") and is_sd:
            uos.chdir("/sd")

        # load code
        try:
            f = open("apps/" + name + ".py")
            code = f.read()
            f.close()
        except Exception as e:
            code = None
            # TODO: handle load error
            print("Load error:", e)
            return

        if code:
            # create window to run the app in
            self.win = lv.win(lv.scr_act())

            self.win.set_title(name)

            # add close button to the header
            self.close_btn = self.win.add_btn_right(lv.SYMBOL.CLOSE)
            self.close_btn.set_event_cb(on_close)

            # try to figure out if this a simple script or
            # if it implements its own lvgl ui
            if self.check_for_page_class(code):
                self.run_with_own_page(name)
            elif self.check_for_llvgl_import(code):
                self.run_with_llvgl(name)
            else:
                self.run_in_console(name, code)

        # return to default path
        if hasattr(machine, "SDCard"):
            uos.chdir("/")
예제 #4
0
#!/opt/bin/lv_micropython -i
import time
import lvgl as lv
import display_driver


def event_handler(e):
    code = e.get_code()
    obj = lv.obj.__cast__(e.get_target())
    if code == lv.EVENT.CLICKED:
        print("Button {:d} clicked".format(obj.get_child_id()))


win = lv.win(lv.scr_act(), 60)
btn1 = win.add_btn(lv.SYMBOL.LEFT, 40)
btn1.add_event_cb(event_handler, lv.EVENT.ALL, None)
win.add_title("A title")
btn2 = win.add_btn(lv.SYMBOL.RIGHT, 40)
btn2.add_event_cb(event_handler, lv.EVENT.ALL, None)
btn3 = win.add_btn(lv.SYMBOL.CLOSE, 60)
btn3.add_event_cb(event_handler, lv.EVENT.ALL, None)

cont = win.get_content()  #Content can be aded here
label = lv.label(cont)
label.set_text("""This is
a pretty
long text
to see how
the window
becomes
scrollable.
예제 #5
0
#!/opt/bin/lv_micropython -i
import time
import lvgl as lv
import display_driver
            
# create a window
win = lv.win(lv.scr_act(),None)
win.set_title("Window title")                   # Set the title

win_style = lv.style_t()
win_style.init()
win_style.set_margin_right(lv.STATE.DEFAULT, 50)
win.add_style(lv.win.PART.CONTENT_SCROLLABLE,win_style)

# Add control button to the header
close_btn = win.add_btn_right(lv.SYMBOL.CLOSE)
close_btn.set_event_cb(lambda obj,e:  lv.win.close_event_cb(lv.win.__cast__(obj), e))


win.add_btn_right(lv.SYMBOL.SETTINGS)           # Add a setup button

# Add some dummy content
txt = lv.label(win)
txt.set_text(
"""This is the content of the window

You can add control buttons to
the window header

The content area becomes automatically 
scrollable if it's large enough.
    power.setPowerOutPut(ttgo.axp202.AXP202_LDO2, False)
    esp32.wake_on_ext1((machine.Pin(35), ), esp32.WAKEUP_ALL_LOW)
    power.clearIRQ()
    machine.deepsleep()


# Init watch
watch = ttgo.Watch()
power = watch.pmu
tft = watch.tft

# Init lvgl
lv.init()
watch.lvgl_begin()

# Init interface
scr = lv.obj()
win = lv.win(scr)
win.set_title("PowerKey Sleep Example")
text_label = lv.label(win)
text_label.set_text("Wait for the PEKKey\n interrupt to come...")
lv.scr_load(scr)

# Init irq
watch.pmu_attach_interrupt(axp_callback)
power.enableIRQ(ttgo.axp202.AXP202_PEK_SHORTPRESS_IRQ, True)
power.clearIRQ()

# Enable backlight
watch.tft.backlight_fade(100)