.. _gui: .. module:: gui :synopsis: Provides GUI class drawing functions :mod:`gui` --- Provides GUI class drawing functions =================================================== .. class:: UI UI Class ---------- Provides UI interface class controls .. class:: UI(oled) Construct a UI object. - ``oled`` - Pass in an object of the framebuf class; for the mPython OLED display, it is the oled object. .. method:: UI.ProgressBar(x, y, width, height, progress) Draw a progress bar. - ``x`` , ``y`` - The top-left corner as the starting coordinate - ``width`` - The progress bar width - ``height`` - The progress bar height - ``progress`` - The progress bar percentage :: from mpython import * myUI=UI(oled) myUI.ProgressBar(30,30,70,8,60) oled.show() .. method:: UI.stripBar(x, y, width, height, progress,dir=1,frame=1) Draw a vertical or horizontal bar - ``x`` , ``y`` - The top-left corner as the starting coordinate - ``width`` - The bar width - ``height`` - The bar height - ``progress`` - The bar percentage - ``dir`` - The bar direction. When dir=1, horizontal; when dir=0, vertical. - ``frame`` - When frame=1, show the outer frame; when frame=0, do not show the outer frame. .. method:: UI.qr_code(str,x,y,scale=2) Draw a 29*29 QR code - ``str`` - The QR code data, of string type - ``x`` , ``y`` - The top-left corner as the starting coordinate - ``scale`` - The magnification factor: can be 1 or 2. Default is 2x magnification. :: import gui from mpython import * ui=gui.UI(oled) ui.qr_code('https://mpython.readthedocs.io',0,0) oled.show() Clock Class +++++++++++ Provides an analog clock display function .. class:: Clock(oled,x,y,radius) Construct a Clock object. - ``oled`` - Pass in an object of the framebuf class; for the mPython OLED display, it is the oled object. - ``x`` , ``y`` - The top-left corner as the starting coordinate - ``radius`` - The clock radius .. method:: Clock.settime() Get the local time and set the analog clock time .. method:: Clock.drawClock() Draw the clock .. method:: Clock.clear() Clear the clock :: from mpython import* from machine import Timer import time clock=Clock(oled,64,32,30) def Refresh(): clock.settime() clock.drawClock() oled.show() clock.clear() tim1 = Timer(1) tim1.init(period=1000, mode=Timer.PERIODIC, callback=lambda _:Refresh()) Image +++++++++ Supports `pbm` and `bmp` 1-bit image formats. .. Class:: Image() Construct an Image object .. method:: Image.load(path, invert=0) Load a `pbm` or `bmp` image format file and return the :class:`framebuf.FrameBuffer` object of the image. - ``path`` - The image file path - ``invert`` - Pixel inversion. 0 means no inversion, 1 means inversion. Example:: from mpython import * from gui import Image image = Image() fb = image.load('clown_1.bmp',1 ) oled.blit(fb, 0, 0) oled.show()