kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Mod demos for 128x128 minimum screen.
rodzic
3f37900d12
commit
6485678b51
13
README.md
13
README.md
|
@ -80,7 +80,7 @@ of some display drivers.
|
||||||
4.1 [Class methods](./README.md#41-class-methods)
|
4.1 [Class methods](./README.md#41-class-methods)
|
||||||
4.2 [Constructor](./README.md#42-constructor)
|
4.2 [Constructor](./README.md#42-constructor)
|
||||||
4.3 [Callback methods](./README.md#43-callback-methods) Methods which run in response to events.
|
4.3 [Callback methods](./README.md#43-callback-methods) Methods which run in response to events.
|
||||||
4.4 [Method](./README.md#44-method) Optional interface to usayncio code.
|
4.4 [Method](./README.md#44-method) Optional interface to uasyncio code.
|
||||||
5. [Window class](./README.md#5-window-class)
|
5. [Window class](./README.md#5-window-class)
|
||||||
5.1 [Constructor](./README.md#51-constructor)
|
5.1 [Constructor](./README.md#51-constructor)
|
||||||
5.2 [Class method](./README.md#52-class-method)
|
5.2 [Class method](./README.md#52-class-method)
|
||||||
|
@ -374,6 +374,10 @@ files in `gui/core` are:
|
||||||
* `colors.py` Constants including colors and shapes.
|
* `colors.py` Constants including colors and shapes.
|
||||||
* `ugui.py` The main GUI code.
|
* `ugui.py` The main GUI code.
|
||||||
* `writer.py` Supports the `Writer` and `CWriter` classes.
|
* `writer.py` Supports the `Writer` and `CWriter` classes.
|
||||||
|
* `framebuf_utils.mpy` Accelerator for the `CWriter` class. This optional file
|
||||||
|
is compiled for STM hardware. It is specific to Pyboards (1.x and D) and will
|
||||||
|
be ignored on other ports. Details may be found
|
||||||
|
[here](https://github.com/peterhinch/micropython-font-to-py/blob/master/writer/WRITER.md#224-a-performance-boost).
|
||||||
|
|
||||||
The `gui/primitives` directory contains the following files:
|
The `gui/primitives` directory contains the following files:
|
||||||
* `switch.py` Interface to physical pushbuttons.
|
* `switch.py` Interface to physical pushbuttons.
|
||||||
|
@ -2207,12 +2211,17 @@ have the following bound variables, which should be considered read-only:
|
||||||
* `width` Ditto.
|
* `width` Ditto.
|
||||||
* `mrow` Maximum absolute row occupied by the widget.
|
* `mrow` Maximum absolute row occupied by the widget.
|
||||||
* `mcol` Maximum absolute col occupied by the widget.
|
* `mcol` Maximum absolute col occupied by the widget.
|
||||||
|
|
||||||
|
A further aid to metrics is the `Writer` method `.stringlen(s)`. This takes a
|
||||||
|
string as its arg and returns its length in pixels when rendered using that
|
||||||
|
`Writer` instance's font.
|
||||||
|
|
||||||
The `mrow` and `mcol` values enable other widgets to be positioned relative to
|
The `mrow` and `mcol` values enable other widgets to be positioned relative to
|
||||||
the one previously instantiated. In the cases of sliders, `Dial` and `Meter`
|
the one previously instantiated. In the cases of sliders, `Dial` and `Meter`
|
||||||
widgets these take account of space ocupied by legends or labels.
|
widgets these take account of space ocupied by legends or labels.
|
||||||
|
|
||||||
The `aclock.py` demo provides a simple example of this approach.
|
The `aclock.py` and `linked_sliders.py` demos provide simple examples of this
|
||||||
|
approach.
|
||||||
|
|
||||||
## Use of graphics primitives
|
## Use of graphics primitives
|
||||||
|
|
||||||
|
|
Plik binarny nie jest wyświetlany.
|
@ -32,7 +32,7 @@ class BaseScreen(Screen):
|
||||||
# Trailing spaces ensure Label is wide enough to show results
|
# Trailing spaces ensure Label is wide enough to show results
|
||||||
self.lbl = Label(wri, row, col, 'Dialog box test ')
|
self.lbl = Label(wri, row, col, 'Dialog box test ')
|
||||||
# DialogBox constructor arguments. Here we pass all as keyword wargs.
|
# DialogBox constructor arguments. Here we pass all as keyword wargs.
|
||||||
kwargs = {'writer' : wri,
|
kwargs = {'writer' : wri, 'row': 20, 'col' : 2,
|
||||||
'elements' : (('Yes', GREEN), ('No', RED), ('Foo', YELLOW)),
|
'elements' : (('Yes', GREEN), ('No', RED), ('Foo', YELLOW)),
|
||||||
'label' : 'Test dialog',
|
'label' : 'Test dialog',
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ from gui.widgets.dropdown import Dropdown
|
||||||
from gui.core.writer import CWriter
|
from gui.core.writer import CWriter
|
||||||
|
|
||||||
# Font for CWriter
|
# Font for CWriter
|
||||||
import gui.fonts.font10 as font
|
import gui.fonts.arial10 as font
|
||||||
from gui.core.colors import *
|
from gui.core.colors import *
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,14 +26,17 @@ class BaseScreen(Screen):
|
||||||
|
|
||||||
col = 2
|
col = 2
|
||||||
row = 2
|
row = 2
|
||||||
Dropdown(wri, row, col,
|
self.dd = Dropdown(wri, row, col,
|
||||||
elements = ('hydrogen', 'helium', 'neon', 'xenon', 'radon'),
|
elements = ('hydrogen', 'helium', 'neon', 'xenon', 'radon'),
|
||||||
bdcolor = GREEN, bgcolor = DARKGREEN,
|
bdcolor = GREEN, bgcolor = DARKGREEN,
|
||||||
callback=self.ddcb)
|
callback=self.ddcb)
|
||||||
row += 30
|
row += 30
|
||||||
self.lbl = Label(wri, row, col, 90, bdcolor=RED)
|
self.lbl = Label(wri, row, col, self.dd.width, bdcolor=RED)
|
||||||
CloseButton(wri) # Quit the application
|
CloseButton(wri) # Quit the application
|
||||||
|
|
||||||
|
def after_open(self):
|
||||||
|
self.lbl.value(self.dd.textvalue())
|
||||||
|
|
||||||
def ddcb(self, dd):
|
def ddcb(self, dd):
|
||||||
if hasattr(self, 'lbl'):
|
if hasattr(self, 'lbl'):
|
||||||
self.lbl.value(dd.textvalue())
|
self.lbl.value(dd.textvalue())
|
||||||
|
|
|
@ -12,7 +12,7 @@ from gui.widgets.sliders import Slider
|
||||||
from gui.core.writer import CWriter
|
from gui.core.writer import CWriter
|
||||||
|
|
||||||
# Font for CWriter
|
# Font for CWriter
|
||||||
import gui.fonts.arial10 as arial10
|
import gui.fonts.arial10 as font
|
||||||
from gui.core.colors import *
|
from gui.core.colors import *
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,19 +22,18 @@ class BaseScreen(Screen):
|
||||||
args = {
|
args = {
|
||||||
'bdcolor' : RED,
|
'bdcolor' : RED,
|
||||||
'slotcolor' : BLUE,
|
'slotcolor' : BLUE,
|
||||||
'legends' : ('0.0', '0.5', '1.0'),
|
'legends' : ('0', '5', '10'),
|
||||||
'value' : 0.5,
|
'value' : 0.5,
|
||||||
}
|
}
|
||||||
super().__init__()
|
super().__init__()
|
||||||
wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
|
wri = CWriter(ssd, font, GREEN, BLACK, verbose=False)
|
||||||
col = 2
|
col = 2
|
||||||
row = 2
|
row = 2
|
||||||
dc = 45
|
|
||||||
# Note: callback runs now, but other sliders have not yet been instantiated.
|
# Note: callback runs now, but other sliders have not yet been instantiated.
|
||||||
self.s0 = Slider(wri, row, col, callback=self.slider_cb, **args)
|
self.s0 = Slider(wri, row, col, callback=self.slider_cb, **args)
|
||||||
col += dc
|
col = self.s0.mcol + 2
|
||||||
self.s1 = Slider(wri, row, col, **args)
|
self.s1 = Slider(wri, row, col, **args)
|
||||||
col += dc
|
col = self.s1.mcol + 2
|
||||||
self.s2 = Slider(wri, row, col, **args)
|
self.s2 = Slider(wri, row, col, **args)
|
||||||
CloseButton(wri)
|
CloseButton(wri)
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ from gui.widgets.label import Label
|
||||||
from gui.core.writer import CWriter
|
from gui.core.writer import CWriter
|
||||||
|
|
||||||
# Font for CWriter
|
# Font for CWriter
|
||||||
import gui.fonts.font10 as font10
|
import gui.fonts.arial10 as font
|
||||||
from gui.core.colors import *
|
from gui.core.colors import *
|
||||||
|
|
||||||
# Defining a button in this way enables it to be re-used on
|
# Defining a button in this way enables it to be re-used on
|
||||||
|
@ -22,11 +22,11 @@ def fwdbutton(wri, row, col, cls_screen, text='Next'):
|
||||||
def fwd(button):
|
def fwd(button):
|
||||||
Screen.change(cls_screen) # Callback
|
Screen.change(cls_screen) # Callback
|
||||||
|
|
||||||
Button(wri, row, col, height = 30, callback = fwd,
|
Button(wri, row, col, callback = fwd,
|
||||||
fgcolor = BLACK, bgcolor = GREEN,
|
fgcolor = BLACK, bgcolor = GREEN,
|
||||||
text = text, shape = RECTANGLE, width = 100)
|
text = text, shape = RECTANGLE)
|
||||||
|
|
||||||
wri = CWriter(ssd, font10, GREEN, BLACK, verbose=False)
|
wri = CWriter(ssd, font, GREEN, BLACK, verbose=False)
|
||||||
|
|
||||||
# This screen overlays BaseScreen.
|
# This screen overlays BaseScreen.
|
||||||
class BackScreen(Screen):
|
class BackScreen(Screen):
|
||||||
|
|
|
@ -29,7 +29,7 @@ class BaseScreen(Screen):
|
||||||
col = 2
|
col = 2
|
||||||
row = 2
|
row = 2
|
||||||
Label(wri, row, col, 'Simple Demo')
|
Label(wri, row, col, 'Simple Demo')
|
||||||
row = 20
|
row = 50
|
||||||
Button(wri, row, col, text='Yes', callback=my_callback, args=('Yes',))
|
Button(wri, row, col, text='Yes', callback=my_callback, args=('Yes',))
|
||||||
col += 60
|
col += 60
|
||||||
Button(wri, row, col, text='No', callback=my_callback, args=('No',))
|
Button(wri, row, col, text='No', callback=my_callback, args=('No',))
|
||||||
|
|
|
@ -21,13 +21,13 @@ from gui.widgets.buttons import Button, CloseButton
|
||||||
|
|
||||||
wri = CWriter(ssd, arial10, verbose=False)
|
wri = CWriter(ssd, arial10, verbose=False)
|
||||||
|
|
||||||
def fwdbutton(wri, row, col, cls_screen, width, text='Next'):
|
def fwdbutton(wri, row, col, cls_screen, text='Next'):
|
||||||
def fwd(button):
|
def fwd(button):
|
||||||
Screen.change(cls_screen)
|
Screen.change(cls_screen)
|
||||||
Button(wri, row, col, height = 20, width = width,
|
b = Button(wri, row, col,
|
||||||
callback = fwd, fgcolor = BLACK, bgcolor = GREEN,
|
callback = fwd, fgcolor = BLACK, bgcolor = GREEN,
|
||||||
text = text, shape = RECTANGLE)
|
text = text, shape = RECTANGLE)
|
||||||
return width
|
return b.mrow
|
||||||
|
|
||||||
|
|
||||||
async def wrap(tb):
|
async def wrap(tb):
|
||||||
|
@ -53,7 +53,7 @@ async def clip(tb):
|
||||||
|
|
||||||
# Args for textboxes
|
# Args for textboxes
|
||||||
# Positional
|
# Positional
|
||||||
pargs = (2, 2, 124, 7) # Row, Col, Width, nlines
|
pargs = (2, 2, 100, 7) # Row, Col, Width, nlines
|
||||||
|
|
||||||
# Keyword
|
# Keyword
|
||||||
tbargs = {'fgcolor' : YELLOW,
|
tbargs = {'fgcolor' : YELLOW,
|
||||||
|
@ -103,10 +103,10 @@ class MainScreen(Screen):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
Label(wri, 2, 2, 'Select test to run')
|
Label(wri, 2, 2, 'Select test to run')
|
||||||
col = 2
|
col = 2
|
||||||
row = 60
|
row = 20
|
||||||
col += fwdbutton(wri, row, col, TBWScreen, 50, 'Wrap') + 10
|
row = fwdbutton(wri, row, col, TBWScreen, 'Wrap') + 2
|
||||||
col += fwdbutton(wri, row, col, TBCScreen, 50, 'Clip') + 10
|
row = fwdbutton(wri, row, col, TBCScreen, 'Clip') + 2
|
||||||
fwdbutton(wri, row, col, TBUScreen, 50, 'Scroll')
|
fwdbutton(wri, row, col, TBUScreen, 'Scroll')
|
||||||
CloseButton(wri)
|
CloseButton(wri)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class DialogBox(Window):
|
||||||
callback(Window, *args)
|
callback(Window, *args)
|
||||||
|
|
||||||
height = 80
|
height = 80
|
||||||
spacing = 10
|
spacing = 5
|
||||||
buttonwidth = max(max(writer.stringlen(e[0]) for e in elements) + 14, buttonwidth)
|
buttonwidth = max(max(writer.stringlen(e[0]) for e in elements) + 14, buttonwidth)
|
||||||
buttonheight = max(writer.height, 15)
|
buttonheight = max(writer.height, 15)
|
||||||
nelements = len(elements)
|
nelements = len(elements)
|
||||||
|
|
|
@ -1,54 +1,60 @@
|
||||||
# ili9341_pico.py Customise for your hardware config
|
# st7735r144_setup.py For my PCB with 1.44 inch 128*128 TFT Customise for your hardware config
|
||||||
|
|
||||||
# Released under the MIT License (MIT). See LICENSE.
|
# Released under the MIT License (MIT). See LICENSE.
|
||||||
# Copyright (c) 2021 Peter Hinch
|
# Copyright (c) 2020 Peter Hinch
|
||||||
|
|
||||||
# As written, supports:
|
# As written, supports:
|
||||||
# ili9341 240x320 displays on Pi Pico
|
# Adfruit 1.44 inch Color TFT LCD display with MicroSD Card Breakout:
|
||||||
# Edit the driver import for other displays.
|
# https://www.adafruit.com/product/2088
|
||||||
|
|
||||||
# Demo of initialisation procedure designed to minimise risk of memory fail
|
# WIRING (Adafruit pin nos and names).
|
||||||
# when instantiating the frame buffer. The aim is to do this as early as
|
# Pyb SSD
|
||||||
# possible before importing other modules.
|
# Gnd Gnd
|
||||||
|
# 3V3 Vcc
|
||||||
|
# Y11 RESET
|
||||||
|
# Y12 D/C
|
||||||
|
# W32 TFT_CS
|
||||||
|
# Y8 MOSI
|
||||||
|
# Y6 SCK
|
||||||
|
# Vin LITE (10) Backlight
|
||||||
|
|
||||||
# WIRING
|
# Switch wiring
|
||||||
# Pico Display
|
# X1 Next
|
||||||
# GPIO Pin
|
# X2 Sel
|
||||||
# 3v3 36 Vin
|
# X3 Prev
|
||||||
# IO6 9 CLK Hardware SPI0
|
# X4 Increase
|
||||||
# IO7 10 DATA (AKA SI MOSI)
|
# X5 Decrease
|
||||||
# IO8 11 DC
|
|
||||||
# IO9 12 Rst
|
|
||||||
# Gnd 13 Gnd
|
|
||||||
# IO10 14 CS
|
|
||||||
|
|
||||||
# Pushbuttons are wired between the pin and Gnd
|
import machine
|
||||||
# Pico pin Meaning
|
|
||||||
# 16 Operate current control
|
|
||||||
# 17 Decrease value of current control
|
|
||||||
# 18 Select previous control
|
|
||||||
# 19 Select next control
|
|
||||||
# 20 Increase value of current control
|
|
||||||
|
|
||||||
from machine import Pin, SPI, freq
|
|
||||||
import gc
|
import gc
|
||||||
|
|
||||||
from drivers.ili93xx.ili9341 import ILI9341 as SSD
|
from machine import Pin, SPI
|
||||||
freq(250_000_000) # RP2 overclock
|
import gc
|
||||||
# Create and export an SSD instance
|
import time
|
||||||
pdc = Pin(8, Pin.OUT, value=0) # Arbitrary pins
|
|
||||||
prst = Pin(9, Pin.OUT, value=1)
|
|
||||||
pcs = Pin(10, Pin.OUT, value=1)
|
|
||||||
spi = SPI(0, baudrate=30_000_000)
|
|
||||||
gc.collect() # Precaution before instantiating framebuf
|
|
||||||
ssd = SSD(spi, pcs, pdc, prst, usd=True)
|
|
||||||
|
|
||||||
|
from drivers.st7735r.st7735r144_4bit import ST7735R as SSD
|
||||||
|
pp = Pin('EN_3V3')
|
||||||
|
pp(1)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
pdc = Pin('Y12', Pin.OUT_PP, value=0)
|
||||||
|
pcs = Pin('W32', Pin.OUT_PP, value=1)
|
||||||
|
prst = Pin('Y11', Pin.OUT_PP, value=1)
|
||||||
|
spi = SPI(2, baudrate=6_000_000)
|
||||||
|
gc.collect() # Precaution before instantiating framebuf
|
||||||
|
ssd = SSD(spi, pcs, pdc, prst) # Create a display instance
|
||||||
from gui.core.ugui import Display
|
from gui.core.ugui import Display
|
||||||
|
|
||||||
# Create and export a Display instance
|
# Create and export a Display instance
|
||||||
# Define control buttons
|
# Define control buttons
|
||||||
nxt = Pin(19, Pin.IN, Pin.PULL_UP) # Move to next control
|
nxt = Pin(Pin.board.X5, Pin.IN, Pin.PULL_UP) # Move to next control
|
||||||
sel = Pin(16, Pin.IN, Pin.PULL_UP) # Operate current control
|
sel = Pin(Pin.board.X1, Pin.IN, Pin.PULL_UP) # Operate current control
|
||||||
prev = Pin(18, Pin.IN, Pin.PULL_UP) # Move to previous control
|
prev = Pin(Pin.board.X4, Pin.IN, Pin.PULL_UP) # Move to previous control
|
||||||
increase = Pin(20, Pin.IN, Pin.PULL_UP) # Increase control's value
|
increase = Pin(Pin.board.X2, Pin.IN, Pin.PULL_UP) # Increase control's value
|
||||||
decrease = Pin(17, Pin.IN, Pin.PULL_UP) # Decrease control's value
|
decrease = Pin(Pin.board.X3, Pin.IN, Pin.PULL_UP) # Decrease control's value
|
||||||
display = Display(ssd, nxt, sel, prev, increase, decrease)
|
display = Display(ssd, nxt, sel, prev, increase, decrease)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue