您尚未登录。

楼主 #1 2019-01-15 18:28:23

Zodiac
会员
注册时间: 2018-11-28
已发帖子: 42
积分: 42

LittlevGL的Python绑定(非micropython)

https://github.com/rreilink/pylvgl

又一个lvgl的python绑定,只可惜目前仅支持到 v5.1.1 版。与最新版相比,少了一些绘图模块。
可以拿来作为熟悉API和快速设计界面的一个工具。
使用效果与mpy版相同。

使用步骤:

1、下载
    git clone --recurse-submodules https://github.com/rreilink/pylvgl.git

2、按需修改分辨率
    lv_conf.h:LV_HOR_RES,LV_VER_RES

3、生成扩展模块

$ python3 ./setup.py

4、安装PyQt5

$ pip3 install PyQt5

5、进入python交互界面,导入模块,开始体验。

$ python3
Python 3.6.5 (default, May  9 2018, 10:02:20) 
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> from pylvgl import Demo, lvgl
>>> d = Demo()
>>>
>>> b1 = lvgl.Btn(lvgl.scr_act())        
>>> b1.set_size(200,50)
>>> b1.align(b1.get_parent(), lvgl.ALIGN_IN_LEFT_MID, 0, 0)
>>>
>>> l1 = lvgl.Label(b1)
>>> l1.set_text('LittlevGL')
>>>
>>> lm = lvgl.Lmeter(lvgl.scr_act())
>>> lm.align(cal.get_parent(), lvgl.ALIGN_IN_LEFT_MID, 300, 0)
>>> lm.set_range(0,100)
>>> lm.set_value(10)
>>>
>>> style_lm1.line_width = 4
>>> style_lm1.body_main_color = 0x2200
>>> style_lm1.body_grad_color = 0x0022
>>> lm.set_style(style_lm1)
>>>
>>> lb2 = lvgl.Label(lm)
>>> lb2.set_text('10%')
>>> lb2.align(lm, lvgl.ALIGN_CENTER, 0, 0)

-2019-01-15-5_52_10.png

附:
步骤5中所导入的辅助模版,另存为pylvgl.py,放在工程目录。

import lvgl
from PyQt5 import QtGui, QtWidgets, QtCore

class LvglWindow(QtWidgets.QLabel):
    def __init__(self):
        super().__init__()
        self.setMinimumSize(lvgl.HOR_RES, lvgl.VER_RES)
        self.setMaximumSize(lvgl.HOR_RES, lvgl.VER_RES)
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(10)

    def mousePressEvent(self, evt):
        self.mouseMoveEvent(evt)
    def mouseReleaseEvent(self, evt):
        self.mouseMoveEvent(evt)
    def mouseMoveEvent(self, evt):
        pos = evt.pos()
        lvgl.send_mouse_event(pos.x(), pos.y(), evt.buttons() & QtCore.Qt.LeftButton)
    def update(self):
        # Poll lvgl and display the framebuffer
        for i in range(10):
            lvgl.poll()
    
        data = bytes(lvgl.framebuffer)
        img = QtGui.QImage(data, lvgl.HOR_RES, lvgl.VER_RES, QtGui.QImage.Format_RGB16) 
        pm = QtGui.QPixmap.fromImage(img)
        
        self.setPixmap(pm)

class Demo():
    def __init__(self):
        self.app = QtWidgets.QApplication([])
        self.window = LvglWindow();
        self.window.show()
    def run(self):
        self.app.exec_()

补充:
该工程使用bindingsgen.py和sourceparser.py两个自定义工具,及lvglmodule_template.c模版,自动解析lvgl源码并生成编译扩展模块所需的接口代码,即lvglmodule.c。
上述工具基于pycparser模块,且根据lvgl定制,与API版本关联,目前支持到v5.1.1。
有兴趣的朋友,可以尝试自行编译。

 $ pip3 install pycparser
 $ python3 ./bindingsgen.py

离线

#2 2019-01-17 08:58:48

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,224
积分: 9197

Re: LittlevGL的Python绑定(非micropython)

太棒了, 感谢分享!





离线

#3 2019-01-17 09:01:41

大帅
会员
注册时间: 2019-01-17
已发帖子: 167
积分: 131.5

Re: LittlevGL的Python绑定(非micropython)

谢谢分享

离线

#4 2020-03-12 22:39:34

1066950103
会员
注册时间: 2017-11-17
已发帖子: 61
积分: 46

Re: LittlevGL的Python绑定(非micropython)

谢谢分享 关注一下

离线

#5 2020-05-08 19:00:12

zhuxiya
会员
注册时间: 2020-04-18
已发帖子: 8
积分: 8

Re: LittlevGL的Python绑定(非micropython)

这个是用python开发的?怎么感觉很像C++?

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn