Is there any way to access the internal parameters of widgets, in python there are no private variables and get/set methods are generally hidden.
The one I particular I am looking to access is the step variable in the spin box widget, normally in python I would expect to be able simply use val =spinbox.step or at least val=spinbox._step but while there is a set_step function I can’t find a get_stem one.
Hi @minyiky!
Currently it’s not possible to access the widget internal state in Micropython.
If some internal variable is interesting - there should be an accessor function (set/get function) to access that variable.
In case of “step”, only lv_spinbox_set_step was defined in the C API.
I can suggest one of the following:
Add a new lv_spinbox_get_step function to the C API. Once you add this C function and rebuild lv_micropython it will become available in Python. You can open a PR in LVGL GitHub repo to add this.
Create a Python class that inherits from spinbox and implements this function. Keep the step state as part of the new Python class and use the new class instead of spinbox
Thanks for the detailed response, just to confirm for adjusting the c api are you referring to the main lvgl repo, when looking for functions I did manage to find the set step function in the spin box there so I assume that is the place to add it?
Yes.
Just edit lv_spinbox.h and add lv_spinbox_get_step there, preferably as static inline function so it would have zero impact on the C footprint when not in use.
Thank you for the help with this, and I am going to appologise in advance for my lack of knowledge.
I can see how I would set up a get function in the .c and .h file but I am very inexperienced when it comes to c and so not sure how I would add this as an inilne funtion, and specifically in the header.
This is what I have so far:
In lv_spinbox.c
/**
* Get the spinbox step value (user has to convert to float according to its digit format)
* @param spinbox pointer to spinbox
* @return value integer step value of the spinbox
*/
int32_t lv_spinbox_get_step(lv_obj_t * spinbox)
{
LV_ASSERT_OBJ(spinbox, LV_OBJX_NAME);
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
return ext->step;
}
In lv_spinbox.h
/**
* Get the spinbox step value (user has to convert to float according to its digit format)
* @param spinbox pointer to spinbox
* @return value integer step value of the spinbox
*/
int32_t lv_spinbox_get_step(lv_obj_t * spinbox);