Examples for lvgl in micropython

But what is the difference between init_script and import init_script.py? Aren’t they both going to be able to run a single, shared script?

@amirgon mentioned that lv_micropython will be updated soon.

init_script in the url doesn’t require changing example files, import init_script.py requires adding these lines to every example and maybe sys.append(url_to_init_script).

But maybe I am missing something. Let’s say we want to make an online demo for this script:
https://raw.githubusercontent.com/littlevgl/lv_examples/rework/src/lv_ex_bar/lv_ex_bar_1.py

How do you imagine the process here?

@embeddedt unfortunately, single line import is not enough. You need at least a few lines.

You need something like:

import imp, sys
sys.path.append('https://raw.githubusercontent.com/littlevgl/lv_binding_micropython/master/lib')
import display_driver
import lvgl as lv

Before importing the display_driver, you must set the sys.path. before setting the sys.path you must import sys and imp
And you would also want to import lvgl as lv

So the init script could be these 4 lines and possibly more. For example, additional paths to sys.path when needed, registering image decoders, themes, loading fonts (when this is implemented) etc.

I think it makes sense to keep the example scripts clean, so they only contain the important lvgl code, and let the init script do all the initialization.

I didn’t suggest that the “save” combine them to a single script.
I suggested loading both the init script and the main script to the editor when the web page loads them, as @Stepan_Snigirev suggested here.
Saving them to snippetbin would work just like today, with the complete text that appears on the text editor.

I don’t understand how you can have one and not the other. If you are loading the two scripts into the same editor window (and thus the same underlying JS string), they are being combined into a single script.

On the other hand, if you load them into separate editor windows, they will still be two separate underlying JS strings, but how do they then get saved to Snippetbin (which only takes one file)?

I’m probably not understanding something here because you both seem to be in agreement on this. :slightly_smiling_face: Can you clarify the basic summary of how it should work with regards to Snippetbin and the editor windows?

I’ll try to explain what I had in mind.
It’s really simple actually, just get two scripts, concatenate them together and proceed just like today.

For example:

The rational here is that we would like the same main script to be used in two different contexts - in the docs and in the simulator.

However -

  • We don’t want the init code in the docs
  • We need the init code in the simulator
  • We want to use the same script on both and avoid code duplication

So the “init_script” solves these problems.

Please let me know if this is clearer

I made a small proof-of-concept.
This is how I imagine functionality:
https://stepansnigirev.github.io/sim/?init_script=https://gist.githubusercontent.com/stepansnigirev/d360caaca643a17989b1b41ceef417d1/raw&script=https://raw.githubusercontent.com/littlevgl/lv_examples/rework/src/lv_ex_bar/lv_ex_bar_1.py

It actually works, try it out.

Now with any example we can use the same init code:
https://stepansnigirev.github.io/sim/?init_script=https://gist.githubusercontent.com/stepansnigirev/d360caaca643a17989b1b41ceef417d1/raw&script=https://raw.githubusercontent.com/stepansnigirev/lv_examples/rework/src/lv_ex_chart/lv_ex_chart_1.py

Exactly.

Could you send a PR to lv_micropython lvgl_javascript branch?

Done.