Textarea implemented into Tabview => Freeze!

Hi all,

I’m struggling with the Textarea widget implemented into the Tabview widget.
The Textarea get displayed well inside the Tabview, but if i press any input, the screen freezes and REPL outputs:

File “lv_utils.py”, line 108, in task_handler
TypeError: function takes 1 positional arguments but 2 were given

I know that the class handover automatically “self” as argument which does indeed has now two arguments. - it’s just that the first one is implicit, from the point of view of the caller.

Is there any possible workaround known to get this working??

:upside_down_face:

Here is the code snippet:

class Screen_Main(lv.obj):
def init(self, app, *args, **kwds):
self.app = app
super().init(*args, **kwds)
self.theme = AdvancedDemoTheme()
self.tabview = lv.tabview(self, lv.DIR.BOTTOM, 30)
self.screen_uebersicht = screen_uebersicht(self.app, self.tabview.add_tab(“Viev”))
self.screen_klima = screen_klima(self.app, self.tabview.add_tab(“Clima”))
self.screen_licht = screen_licht(self.app, self.tabview.add_tab(“Light”))
self.screen_settings = screen_settings(self.app, self.tabview.add_tab(“Settings”))

class screen_uebersicht:
def init(self, app, page):
self.app = app
self.page = page
self.test_events = []

    self.page.set_flex_flow(lv.FLEX_FLOW.COLUMN)
    self.page.set_flex_align(lv.FLEX_ALIGN.SPACE_EVENLY, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)

   #Uhrzeit Licht 1
    #
    # Automatically format text like a clock. E.g. "12:34"
    # Add the ':' automatically
    #
    # Create the text area

    LV_HOR_RES = page.get_disp().driver.hor_res
    LV_VER_RES = page.get_disp().driver.ver_res

    self.ta = lv.textarea(page)
    self.ta.add_event_cb(self.ta_event_cb, lv.EVENT.VALUE_CHANGED, None)
    self.ta.set_accepted_chars("0123456789:")
    self.ta.set_max_length(5)
    self.ta.set_one_line(True)
    self.ta.add_state(lv.STATE.FOCUSED)

    # Create a keyboard
    self.kb = lv.keyboard(page)
    self.kb.set_size(LV_HOR_RES, LV_VER_RES // 2)
    self.kb.set_mode(lv.keyboard.MODE.NUMBER)
    self.kb.set_textarea(self.ta)


def ta_event_cb(e):
    ta = e.get_target()
    txt = ta.get_text()
    # print(txt)
    pos = ta.get_cursor_pos()
    # print("cursor pos: ",pos)
    # find position of ":" in text
    colon_pos = txt.find(":")
    # if there are more than 2 digits before the colon, remove the last one entered
    if colon_pos == 3:
        ta.del_char()
    if colon_pos != -1:
        # if there are more than 3 digits after the ":" remove the last one entered
        rest = txt[colon_pos:]
        if len(rest) > 3:
            ta.del_char()

    if len(txt) < 2:
        return
    if ":" in txt:
        return
    if txt[0] >= '0' and txt[0] <= '9' and \
            txt[1] >= '0' and txt[1] <= '9':
        if len(txt) == 2 or txt[2] != ':':
            ta.set_cursor_pos(2)
            ta.add_char(ord(':'))

Hi, can you provide a minimal “working” sample?

and put it between </> marks?


import lvgl as lv
import display_driver

try:
    display_driver.getdisplay_landscape()
except Exception:
    pass

class Screen_Main(lv.obj):
    def __init__(self, app, *args, **kwds):
        self.app = app
        super().__init__(*args, **kwds)
        #self.theme = AdvancedDemoTheme()
        self.tabview = lv.tabview(self, lv.DIR.BOTTOM, 30)
        self.screen_uebersicht = screen_uebersicht(self.app, self.tabview.add_tab('Viev'))
        #   self.screen_klima = screen_klima(self.app, self.tabview.add_tab(“Clima”))
        #   self.screen_licht = screen_licht(self.app, self.tabview.add_tab(“Light”))
        #   self.screen_settings = screen_settings(self.app, self.tabview.add_tab(“Settings”))

class screen_uebersicht:
    def __init__(self, app, page):
        self.app = app
        self.page = page
        self.test_events = []
        self.page.set_flex_flow(lv.FLEX_FLOW.COLUMN)
        self.page.set_flex_align(lv.FLEX_ALIGN.SPACE_EVENLY, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)

    #Uhrzeit Licht 1
        #
        # Automatically format text like a clock. E.g. "12:34"
        # Add the ':' automatically
        #
        # Create the text area

        LV_HOR_RES = page.get_disp().driver.hor_res
        LV_VER_RES = page.get_disp().driver.ver_res

        self.ta = lv.textarea(page)
        self.ta.add_event_cb(self.ta_event_cb, lv.EVENT.VALUE_CHANGED, None)
        self.ta.set_accepted_chars("0123456789:")
        self.ta.set_max_length(5)
        self.ta.set_one_line(True)
        self.ta.add_state(lv.STATE.FOCUSED)

        # Create a keyboard
        self.kb = lv.keyboard(page)
        self.kb.set_size(LV_HOR_RES, LV_VER_RES // 2)
        self.kb.set_mode(lv.keyboard.MODE.NUMBER)
        self.kb.set_textarea(self.ta)


    def ta_event_cb(self, e):
        ta = e.get_target()
        txt = ta.get_text()
        # print(txt)
        pos = ta.get_cursor_pos()
        # print("cursor pos: ",pos)
        # find position of ":" in text
        colon_pos = txt.find(":")
        # if there are more than 2 digits before the colon, remove the last one entered
        if colon_pos == 3:
            ta.del_char()
        if colon_pos != -1:
            # if there are more than 3 digits after the ":" remove the last one entered
            rest = txt[colon_pos:]
            if len(rest) > 3:
                ta.del_char()

        if len(txt) < 2:
            return
        if ":" in txt:
            return
        if txt[0] >= '0' and txt[0] <= '9' and \
                txt[1] >= '0' and txt[1] <= '9':
            if len(txt) == 2 or txt[2] != ':':
                ta.set_cursor_pos(2)
                ta.add_char(ord(':'))


s = Screen_Main(lv.scr_act())
1 Like

@4NU5511 - Trying to make your example work: “app” is the parent?? need to pass it to __super__.
Also set Screen_Main size.

Here is a link to your example in the simulator, seems to work. I didn’t see the error you are referring to.

Are you using latest lv_micropython? On which platform?

Thank you Karijn and amirgon.
amirgon was right. “app” wasnt’ parent.

@amirgon : beside - is there any way to hide the softkeyboard?

By softkeyboard do you mean all the soft keys buttons?
I don’t think so, this is the whole idea of the keyboard widget.
If you don’t need the soft keys buttons, just use a text area.

No, the whole keyboard/numkeyboard.
Just that it disappears after pressing the “cancel” or “enter” button.

Hide the entire keyboard?
Something like this:

kb.add_flag(lv.obj.FLAG.HIDDEN)

or just delete it

Thanks amirgon and Karijn.
Solved the problem :slight_smile: