MicroPython examples for V7?

Hi Amir,
Actually I was waiting for this. Now I will first have to get it going on my hardware. The Unix port compiles fine. The esp32 port says that my cmake version is too old (3.16 instead of 3.18 on my Ubuntu 20.04 LTS system)
In fact reducing cmake version requirement to 3.16 in CMakeLists.txt seems to be ok. It compiles ok with version 3.16.
Give me some time to check everything on my hardware and I will have a look at the examples as promised.

1 Like

I started to have a look at the examples and I am not missing problems! As far as I can see, there is no v8 specific doc yet? Then I would need to get the new C examples to work with the SDL driver to know how they should behave.
Even simple examples like the first button example don’t work as I expect yet. Even though the second button works as a toggle button, I don’t see the EVENT.VALUE_CHANGED event.
In the C version of the button example LV_LOG_USER is used. Is there an equivalent in lv_micropython?
I will upload the examples as I progress to


How do I have to build lv_micropython to get the correct color depth (16) and color swap without modifying lv_conf.h?

I tried to publish the first revision of the v8 docs (still incomplete) yesterday but GitHub is causing some problems at the moment. Hopefully it will be fixed within the next week or two.

I don’t think there should be a “value_changed” event for button. I’ve tested “value_changed” on v8 for slider for example. On button you have the “clicked” event.

I think that was missed.
I’ll raise this problem on [v8] Review LVGL API for Micropython Binding compatibility · Issue #1763 · lvgl/lvgl · GitHub

You can also use it for discussion by opening GitHub issues there and mentioning @amirgon.

You can do it like this (on both v7 and v8):

make -C ports/esp32 LV_CFLAGS="-DLV_COLOR_DEPTH=16 -DLV_COLOR_16_SWAP=1" BOARD=GENERIC_SPIRAM deploy

I am trying to translate the examples as literally as possible from C to Python. If you have a look at lv-example_btn_1.c you will see that 2 buttons are created:
a pushbutton
and a toggle button (btn with flag “checkable”)
The pushbutton emits clicked events while the toggle button should be able to emit LV_EVENT_VALUE_CHANGED.
When connecting the callback, no filters are set. Filtering happens in the event handler, where the distinction between the buttons is made through the type of event emitted.
Now I don’t know if the C example works as expected but if it does, then the btn with FLAG_CHECKABLE should also emit value changed events.
In my current version of this example I pass the source which emitted the event in a lambda function to the callback and I can make the distinction looking at the event source in the event handler.
In the 2nd arc example lv.timer_create is used and the arc to be updated is passed in the 3rd argument, user_data. user_data is a void * and (to my knowledge) cannot be used in MicroPython. I therefore use lv.timer_create_basic() and pass the arc to be updated by the timer again as a parameter to a lambda function.

@kisvegabor @embeddedt - Is there a way to make a “btn” widget emit “value_changed” events? Setting the “checkable” flag to make it a toggle button does not seem sufficient for that.

Using lambda function to pass additional data to the callback (such as the object that triggered it) is a perfectly good practice and works well.
The user_data is generally not directly used in Micropython by the user, and can be NULL.
There is a way to use user_data by passing a dict, but this is not recommend so it’s best to stick with lambda.
Another option is to pass a member function of an object. In such case, like in the lambda case, the callback function has access to additional data (the object that the member function belongs to).
In general you can pass any Python callable object, lambda and member function are examples of callable objects.

The button widget is essentially a placebo in v8, as everything is being driven by the styles, so it does not fire “value_changed” events. I think it would be most consistent to keep using the “clicked” event as that is the event which gets used if it’s not toggleable.

In the meantime I managed to get the C versions to compile. Thanks @embeddedt!
… and you are right, also the C example does not see value changed events.
Then however the second part of the event handler in lv_example_btn_1.c makes no sense since the LV_EVENT_VALUE_CHANGED is never emitted.

Hm, there is an inconsistency in v8 that I’ve just noticed. See here:

If any object is CHECKABLE lv_obj will fire LV_EVENT_VALUE_CHANGED but only if it was checked by a KEY. I think it should be fired when normally released too. Do you agree?

Hmm… that’s a good point. I agree that events should be consistent regardless of input device.

Added https://github.com/lvgl/lvgl/commit/e06e7b5e5dc95940ffa8f6cd222110228cff65e0