Minor changes to README and demo code format.

encoder_driver
peterhinch 2023-04-16 18:24:33 +01:00
rodzic ced79c49d6
commit fc7c91fa20
5 zmienionych plików z 258 dodań i 130 usunięć

Wyświetl plik

@ -1003,7 +1003,7 @@ constructor and is closed by issuing the `close()` static method.
## 6.1 Label widget ## 6.1 Label widget
```python ```python
from gui.widgets import Label from gui.widgets import Label # File: label.py
``` ```
![Image](./images/label.JPG) ![Image](./images/label.JPG)
@ -1089,7 +1089,7 @@ Screen.change(BaseScreen)
### 6.1.1 Grid widget ### 6.1.1 Grid widget
```python ```python
from gui.widgets import Grid from gui.widgets import Grid # File: grid.py
``` ```
![Image](./images/grid.JPG) ![Image](./images/grid.JPG)
@ -1152,7 +1152,7 @@ See the example [calendar.py](https://github.com/peterhinch/micropython-micro-gu
## 6.2 LED widget ## 6.2 LED widget
```python ```python
from gui.widgets import LED from gui.widgets import LED # File: led.py
``` ```
![Image](./images/led.JPG) ![Image](./images/led.JPG)
@ -1191,7 +1191,7 @@ controlled with `led(True)` or `led(False)`.
## 6.3 Checkbox widget ## 6.3 Checkbox widget
```python ```python
from gui.widgets import Checkbox from gui.widgets import Checkbox # File: checkbox.py
``` ```
![Image](./images/checkbox.JPG) ![Image](./images/checkbox.JPG)
This provides for Boolean data entry and display. In the `True` state the This provides for Boolean data entry and display. In the `True` state the
@ -1233,7 +1233,7 @@ Methods:
```python ```python
from gui.core.colors import * # Colors and shapes from gui.core.colors import * # Colors and shapes
from gui.widgets import Button from gui.widgets import Button # File: buttons.py
``` ```
![Image](./images/pushbuttons.JPG) ![Image](./images/pushbuttons.JPG)
@ -1310,7 +1310,7 @@ Optional keyword only arguments:
```python ```python
from gui.core.colors import * # Colors and shapes from gui.core.colors import * # Colors and shapes
from gui.widgets import Button, ButtonList from gui.widgets import Button, ButtonList # File: buttons.py
``` ```
A `ButtonList` groups a number of buttons together to implement a button which A `ButtonList` groups a number of buttons together to implement a button which
@ -1369,7 +1369,7 @@ for t in table: # Buttons overlay each other at same location
```python ```python
from gui.core.colors import * # Colors and shapes from gui.core.colors import * # Colors and shapes
from gui.widgets import Button, RadioButtons from gui.widgets import Button, RadioButtons # File: buttons.py
``` ```
![Image](./images/radiobuttons.JPG) ![Image](./images/radiobuttons.JPG)
@ -1416,7 +1416,7 @@ for t in table:
## 6.7 Listbox widget ## 6.7 Listbox widget
```python ```python
from gui.widgets import Listbox from gui.widgets import Listbox # File: listbox.py
``` ```
![Image](./images/listbox.JPG) ![Image](./images/listbox.JPG)
@ -1525,7 +1525,7 @@ Screen.change(BaseScreen)
## 6.8 Dropdown widget ## 6.8 Dropdown widget
```python ```python
from gui.widgets import Dropdown from gui.widgets import Dropdown # File: dropdown.py
``` ```
![Image](./images/dd_closed.JPG) ![Image](./images/dd_closed.JPG)
@ -1640,7 +1640,7 @@ Screen.change(BaseScreen)
## 6.9 DialogBox class ## 6.9 DialogBox class
```python ```python
from gui.widgets import DialogBox from gui.widgets import DialogBox # File: dialog.py
``` ```
![Image](./images/dialog.JPG) ![Image](./images/dialog.JPG)
@ -1694,7 +1694,7 @@ in `gui/demos/screens.py`.
## 6.10 Textbox widget ## 6.10 Textbox widget
```python ```python
from gui.widgets import Textbox from gui.widgets import Textbox # File: textbox.py
``` ```
![Image](./images/textbox.JPG) ![Image](./images/textbox.JPG)
@ -1763,7 +1763,7 @@ the oldest (topmost) being discarded as required.
This `passive` widget displays a single floating point value on a vertical This `passive` widget displays a single floating point value on a vertical
linear scale. Optionally it can support data dependent callbacks. linear scale. Optionally it can support data dependent callbacks.
```python ```python
from gui.widgets import Meter from gui.widgets import Meter # File: meter.py
``` ```
![Image](./images/meter.JPG) ![Image](./images/meter.JPG)
The two styles of `meter`, both showing a value of 0.65. This `passive` widget The two styles of `meter`, both showing a value of 0.65. This `passive` widget
@ -1855,7 +1855,7 @@ behaves similarly for data values between 0.9 and 1.0.
### 6.11.1 Region class ### 6.11.1 Region class
```python ```python
from gui.widgets import Region from gui.widgets import Region # File: region.py
``` ```
Instantiating a `Region` associates it with a supporting widget (currently only Instantiating a `Region` associates it with a supporting widget (currently only
a `Meter`). Constructor positional args are as follows: a `Meter`). Constructor positional args are as follows:
@ -1915,7 +1915,7 @@ callbacks to run as appropriate.
## 6.12 Slider and HorizSlider widgets ## 6.12 Slider and HorizSlider widgets
```python ```python
from gui.widgets import Slider, HorizSlider from gui.widgets import Slider, HorizSlider # File: sliders.py
``` ```
![Image](./images/sliders.JPG) ![Image](./images/sliders.JPG)
@ -1995,7 +1995,7 @@ around sliders to display all legends.
## 6.13 Scale widget ## 6.13 Scale widget
```python ```python
from gui.widgets import Scale from gui.widgets import Scale # File: scale.py
``` ```
![Image](./images/scale.JPG) ![Image](./images/scale.JPG)
@ -2132,7 +2132,7 @@ precision. Each visible division on the control represents 10 integer units.
## 6.14 ScaleLog widget ## 6.14 ScaleLog widget
```python ```python
from gui.widgets import ScaleLog from gui.widgets import ScaleLog # File: scale_log.py
``` ```
![Image](./images/log_scale.JPG) ![Image](./images/log_scale.JPG)
@ -2272,7 +2272,7 @@ def tickcb(f, c):
## 6.15 Dial widget ## 6.15 Dial widget
```python ```python
from gui.widgets import Dial, Pointer from gui.widgets import Dial, Pointer # File: dial.py
``` ```
![Image](./images/dial.JPG) ![Image](./images/dial1.JPG) ![Image](./images/dial.JPG) ![Image](./images/dial1.JPG)
@ -2388,7 +2388,7 @@ Screen.change(BaseScreen)
## 6.16 Knob widget ## 6.16 Knob widget
```python ```python
from gui.widgets import Knob from gui.widgets import Knob # File: knob.py
``` ```
![Image](./images/knob.JPG) ![Image](./images/knob.JPG)
@ -2446,7 +2446,7 @@ value changes. This enables dynamic color change.
## 6.17 Adjuster widget ## 6.17 Adjuster widget
```python ```python
from gui.widgets import Adjuster from gui.widgets import Adjuster, FloatAdj # File: adjuster.py
``` ```
![Image](./images/adjusters.jpg) ![Image](./images/adj_vector.jpg) ![Image](./images/adjusters.jpg) ![Image](./images/adj_vector.jpg)
@ -2512,7 +2512,7 @@ basis. See code comments for further details.
## 6.18 Menu class ## 6.18 Menu class
```python ```python
from gui.widgets import Menu from gui.widgets import Menu # File: menu.py
``` ```
![Image](./images/menu.JPG) ![Image](./images/menu.JPG)
@ -2620,7 +2620,7 @@ different callback if the application required it.
## 6.19 BitMap Widget ## 6.19 BitMap Widget
```python ```python
from gui.widgets import BitMap from gui.widgets import BitMap # File: bitmap.py
``` ```
![Image](./images/bitmap.JPG) ![Image](./images/bitmap.JPG)
@ -2662,7 +2662,7 @@ See `gui/demos/bitmap.py` for a usage example.
## 6.20 QRMap Widget ## 6.20 QRMap Widget
```python ```python
from gui.widgets import QRMap from gui.widgets import QRMap # File: qrcode.py
``` ```
![Image](./images/qrcode.JPG) ![Image](./images/qrcode.JPG)
@ -3079,6 +3079,10 @@ async def full_refresh():
ssd.set_partial() ssd.set_partial()
``` ```
The driver for the supported display uses 1-bit color mapping: this means that
greying-out has no visible effect. Greyed-out controls cannot accept the focus
and are therefore disabled but appearance is unchanged.
###### [Contents](./README.md#0-contents) ###### [Contents](./README.md#0-contents)
# Appendix 1 Application design # Appendix 1 Application design

Wyświetl plik

@ -43,8 +43,7 @@ audio_out = I2S(I2S_ID, **config)
# ======= GUI ======= # ======= GUI =======
from gui.widgets.label import Label from gui.widgets import Button, CloseButton, HorizSlider, Listbox, Label
from gui.widgets import Button, CloseButton, HorizSlider, Listbox
from gui.core.writer import CWriter from gui.core.writer import CWriter
# Font for CWriter # Font for CWriter

Wyświetl plik

@ -15,8 +15,21 @@ import gui.fonts.arial10 as arial10 # Font for CWriter
import gui.fonts.freesans20 as large import gui.fonts.freesans20 as large
from gui.core.colors import * from gui.core.colors import *
# Widgets # Widgets
from gui.widgets import Label, Dial, Pointer, Meter, Scale, Button, ButtonList, RadioButtons, CloseButton, Checkbox, LED from gui.widgets import (
Label,
Dial,
Pointer,
Meter,
Scale,
Button,
ButtonList,
RadioButtons,
CloseButton,
Checkbox,
LED,
)
from gui.widgets.graph import CartesianGraph, Curve from gui.widgets.graph import CartesianGraph, Curve
from math import sin, pi from math import sin, pi
@ -25,6 +38,7 @@ import uasyncio as asyncio
import utime import utime
import gc import gc
async def full_refresh(): async def full_refresh():
Screen.rfsh_done.clear() # Enable completion flag Screen.rfsh_done.clear() # Enable completion flag
await Screen.rfsh_done.wait() # Wait for a refresh to end await Screen.rfsh_done.wait() # Wait for a refresh to end
@ -40,8 +54,8 @@ class FooScreen(Screen):
# A ButtonList with two entries # A ButtonList with two entries
table_buttonset = ( table_buttonset = (
{'fgcolor' : RED, 'text' : 'Disable', 'args' : (buttons, True)}, {"fgcolor": RED, "text": "Disable", "args": (buttons, True)},
{'fgcolor' : GREEN, 'text' : 'Enable', 'args' : (buttons, False)}, {"fgcolor": GREEN, "text": "Enable", "args": (buttons, False)},
) )
def tickcb(f, c): def tickcb(f, c):
@ -52,80 +66,115 @@ class FooScreen(Screen):
return c return c
def bcb(b): def bcb(b):
print('Button pressed', b) print("Button pressed", b)
super().__init__() super().__init__()
self.rb0 = None self.rb0 = None
self.bs0 = None self.bs0 = None
wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False) wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
wri_large = CWriter(ssd, large, GREEN, BLACK, verbose=False) wri_large = CWriter(ssd, large, GREEN, BLACK, verbose=False)
lbltim = Label(wri, 65, 100, 'this is a test', bdcolor=RED) lbltim = Label(wri, 65, 100, "this is a test", bdcolor=RED)
m0 = Meter(wri, 10, 240, divisions = 4, ptcolor=YELLOW, height=80, width=15, m0 = Meter(
label='Meter', style=Meter.BAR, legends=('0.0', '0.5', '1.0')) wri,
10,
240,
divisions=4,
ptcolor=YELLOW,
height=80,
width=15,
label="Meter",
style=Meter.BAR,
legends=("0.0", "0.5", "1.0"),
)
# Instantiate displayable objects. bgcolor forces complete redraw. # Instantiate displayable objects. bgcolor forces complete redraw.
dial = Dial(wri, 2, 2, height = 75, ticks = 12, bgcolor=BLACK, bdcolor=None, label=120) # Border in fg color dial = Dial(
scale = Scale(wri, 2, 100, width = 124, tickcb = tickcb, wri, 2, 2, height=75, ticks=12, bgcolor=BLACK, bdcolor=None, label=120
pointercolor=RED, fontcolor=YELLOW, bdcolor=CYAN) ) # Border in fg color
scale = Scale(
wri, 2, 100, width=124, tickcb=tickcb, pointercolor=RED, fontcolor=YELLOW, bdcolor=CYAN
)
row = 105 row = 105
col = 2 col = 2
Label(wri, row, col, 'Normal buttons') Label(wri, row, col, "Normal buttons")
# Four Button instances # Four Button instances
row = 120 row = 120
ht = 30 ht = 30
for i, s in enumerate(('a', 'b', 'c', 'd')): for i, s in enumerate(("a", "b", "c", "d")):
col= 2 + i * (ht + 5) col = 2 + i * (ht + 5)
buttons.append(Button(wri, row, col, height=ht, callback=bcb, text=s, litcolor=RED, shape=CIRCLE, bgcolor=DARKGREEN)) buttons.append(
Button(
wri,
row,
col,
height=ht,
callback=bcb,
text=s,
litcolor=RED,
shape=CIRCLE,
bgcolor=DARKGREEN,
)
)
# ButtonList # ButtonList
self.bs = ButtonList(self.callback) self.bs = ButtonList(self.callback)
self.bs0 = None self.bs0 = None
col+= 50 col += 50
Label(wri, row - 15, col, 'ButtonList') Label(wri, row - 15, col, "ButtonList")
for t in table_buttonset: # Buttons overlay each other at same location for t in table_buttonset: # Buttons overlay each other at same location
button = self.bs.add_button(wri, row, col, shape=RECTANGLE, textcolor=BLUE, height=30, **t) button = self.bs.add_button(
if self.bs0 is None: # Save for reset button callback wri, row, col, shape=RECTANGLE, textcolor=BLUE, height=30, **t
)
if self.bs0 is None: # Save for reset button callback
self.bs0 = button self.bs0 = button
# Reset button # Reset button
col+= 60 col += 60
btn = Button(wri, row, col, height=30, callback=self.rstcb, text='reset', litcolor=RED, fgcolor=GREEN, bgcolor=DARKGREEN) btn = Button(
wri,
row,
col,
height=30,
callback=self.rstcb,
text="reset",
litcolor=RED,
fgcolor=GREEN,
bgcolor=DARKGREEN,
)
col = btn.mcol + 15 col = btn.mcol + 15
# Checkbox # Checkbox
Label(wri, row - 15, col, 'Checkbox and LED') Label(wri, row - 15, col, "Checkbox and LED")
Checkbox(wri, row, col, callback=self.cbcb) Checkbox(wri, row, col, callback=self.cbcb)
col+= 40 col += 40
self.led = LED(wri, row, col, color=YELLOW, bdcolor=GREEN) self.led = LED(wri, row, col, color=YELLOW, bdcolor=GREEN)
row = self.bs0.mrow + 5 row = self.bs0.mrow + 5
col = 20 col = 20
ht = 75 ht = 75
wd = 200 wd = 200
self.graph = CartesianGraph(wri, row, col, height = ht, width = wd, bdcolor=False) self.graph = CartesianGraph(wri, row, col, height=ht, width=wd, bdcolor=False)
Label(wri, row + ht + 5, col - 10, '-2.0') Label(wri, row + ht + 5, col - 10, "-2.0")
Label(wri, row + ht + 5, col - 8 + int(wd//2), '0.0') Label(wri, row + ht + 5, col - 8 + int(wd // 2), "0.0")
lbl = Label(wri, row + ht + 5, col - 10 + wd, '2.0') lbl = Label(wri, row + ht + 5, col - 10 + wd, "2.0")
Label(wri_large, lbl.mrow + 5, col, "y = sinc(x)") Label(wri_large, lbl.mrow + 5, col, "y = sinc(x)")
CloseButton(wri, bgcolor=BLACK) CloseButton(wri, bgcolor=BLACK)
asyncio.create_task(run(dial, lbltim, m0, scale)) asyncio.create_task(run(dial, lbltim, m0, scale))
def callback(self, button, buttons, val): def callback(self, button, buttons, val):
buttons[2].greyed_out(val) buttons[2].greyed_out(val)
def rstcb(self, button): def rstcb(self, button):
print('Reset button: init ButtonList, do full refresh.') print("Reset button: init ButtonList, do full refresh.")
self.bs.value(self.bs0) self.bs.value(self.bs0)
asyncio.create_task(full_refresh()) asyncio.create_task(full_refresh())
def cbcb(self, cb): def cbcb(self, cb):
self.led.value(cb.value()) self.led.value(cb.value())
gc.collect() gc.collect()
print('Free RAM:', gc.mem_free()) print("Free RAM:", gc.mem_free())
def after_open(self): def after_open(self):
def populate(): def populate():
@ -140,30 +189,41 @@ class FooScreen(Screen):
async def run(dial, lbltim, m0, scale): async def run(dial, lbltim, m0, scale):
days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
'Sunday') months = (
months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', "Jan",
'Aug', 'Sept', 'Oct', 'Nov', 'Dec') "Feb",
uv = lambda phi : cmath.rect(1, phi) # Return a unit vector of phase phi "March",
"April",
"May",
"June",
"July",
"Aug",
"Sept",
"Oct",
"Nov",
"Dec",
)
uv = lambda phi: cmath.rect(1, phi) # Return a unit vector of phase phi
pi = cmath.pi pi = cmath.pi
hrs = Pointer(dial) hrs = Pointer(dial)
mins = Pointer(dial) mins = Pointer(dial)
secs = Pointer(dial) secs = Pointer(dial)
hstart = 0 + 0.7j # Pointer lengths and position at top hstart = 0 + 0.7j # Pointer lengths and position at top
mstart = 0 + 0.92j mstart = 0 + 0.92j
sstart = 0 + 0.92j sstart = 0 + 0.92j
cv = -1.0 # Scale cv = -1.0 # Scale
dv = 0.005 dv = 0.005
while True: while True:
t = utime.localtime() t = utime.localtime()
hrs.value(hstart * uv(-t[3]*pi/6 - t[4]*pi/360), YELLOW) hrs.value(hstart * uv(-t[3] * pi / 6 - t[4] * pi / 360), YELLOW)
mins.value(mstart * uv(-t[4] * pi/30), YELLOW) mins.value(mstart * uv(-t[4] * pi / 30), YELLOW)
secs.value(sstart * uv(-t[5] * pi/30), RED) secs.value(sstart * uv(-t[5] * pi / 30), RED)
lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5])) lbltim.value("{:02d}.{:02d}.{:02d}".format(t[3], t[4], t[5]))
dial.text('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0])) dial.text("{} {} {} {}".format(days[t[6]], t[2], months[t[1] - 1], t[0]))
m0.value(t[5]/60) m0.value(t[5] / 60)
scale.value(cv) scale.value(cv)
await asyncio.sleep_ms(200) await asyncio.sleep_ms(200)
cv += dv cv += dv
@ -173,9 +233,10 @@ async def run(dial, lbltim, m0, scale):
def test(): def test():
print('Testing micro-gui...') print("Testing micro-gui...")
Screen.change(FooScreen) Screen.change(FooScreen)
print("End") print("End")
ssd.sleep() # Tidy shutdown of EPD ssd.sleep() # Tidy shutdown of EPD
test() test()

Wyświetl plik

@ -7,8 +7,7 @@
import hardware_setup # Create a display instance import hardware_setup # Create a display instance
from gui.core.ugui import Screen, Window, ssd from gui.core.ugui import Screen, Window, ssd
from gui.widgets.label import Label from gui.widgets import Button, RadioButtons, CloseButton, Listbox, Dropdown, DialogBox, Label
from gui.widgets import Button, RadioButtons, CloseButton, Listbox, Dropdown, DialogBox
from gui.core.writer import CWriter from gui.core.writer import CWriter
# Font for CWriter # Font for CWriter

Wyświetl plik

@ -11,14 +11,21 @@ from gui.core.ugui import Screen, ssd
from gui.core.writer import CWriter from gui.core.writer import CWriter
import gui.fonts.arial10 as arial10 # Font for CWriter import gui.fonts.arial10 as arial10 # Font for CWriter
from gui.core.colors import * from gui.core.colors import *
# Widgets # Widgets
from gui.widgets.label import Label from gui.widgets import (
from gui.widgets.dial import Dial, Pointer Label,
from gui.widgets.meter import Meter Dial,
from gui.widgets.scale import Scale Pointer,
from gui.widgets.buttons import Button, ButtonList, RadioButtons, CloseButton Meter,
from gui.widgets.checkbox import Checkbox Scale,
from gui.widgets.led import LED Button,
ButtonList,
RadioButtons,
CloseButton,
Checkbox,
LED,
)
import cmath import cmath
import uasyncio as asyncio import uasyncio as asyncio
@ -32,15 +39,15 @@ class FooScreen(Screen):
# A ButtonList with two entries # A ButtonList with two entries
table_buttonset = ( table_buttonset = (
{'fgcolor' : RED, 'text' : 'Disable', 'args' : (buttons, True)}, {"fgcolor": RED, "text": "Disable", "args": (buttons, True)},
{'fgcolor' : GREEN, 'text' : 'Enable', 'args' : (buttons, False)}, {"fgcolor": GREEN, "text": "Enable", "args": (buttons, False)},
) )
table_radiobuttons = ( table_radiobuttons = (
{'text' : '1', 'args' : ('1',)}, {"text": "1", "args": ("1",)},
{'text' : '2', 'args' : ('2',)}, {"text": "2", "args": ("2",)},
{'text' : '3', 'args' : ('3',)}, {"text": "3", "args": ("3",)},
{'text' : '4', 'args' : ('4',)}, {"text": "4", "args": ("4",)},
) )
def tickcb(f, c): def tickcb(f, c):
@ -51,109 +58,166 @@ class FooScreen(Screen):
return c return c
def bcb(b): def bcb(b):
print('Button pressed', b) print("Button pressed", b)
super().__init__() super().__init__()
self.rb0 = None self.rb0 = None
self.bs0 = None self.bs0 = None
wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False) wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
lbltim = Label(wri, 65, 100, 'this is a test', bdcolor=RED) lbltim = Label(wri, 65, 100, "this is a test", bdcolor=RED)
m0 = Meter(wri, 10, 240, divisions = 4, ptcolor=YELLOW, height=80, width=15, m0 = Meter(
label='Meter example', style=Meter.BAR, legends=('0.0', '0.5', '1.0')) wri,
10,
240,
divisions=4,
ptcolor=YELLOW,
height=80,
width=15,
label="Meter example",
style=Meter.BAR,
legends=("0.0", "0.5", "1.0"),
)
# Instantiate displayable objects. bgcolor forces complete redraw. # Instantiate displayable objects. bgcolor forces complete redraw.
dial = Dial(wri, 2, 2, height = 75, ticks = 12, bgcolor=BLACK, bdcolor=None, label=120) # Border in fg color dial = Dial(
scale = Scale(wri, 2, 100, width = 124, tickcb = tickcb, wri, 2, 2, height=75, ticks=12, bgcolor=BLACK, bdcolor=None, label=120
pointercolor=RED, fontcolor=YELLOW, bdcolor=CYAN) ) # Border in fg color
scale = Scale(
wri, 2, 100, width=124, tickcb=tickcb, pointercolor=RED, fontcolor=YELLOW, bdcolor=CYAN
)
row = 105 row = 105
col = 2 col = 2
Label(wri, row, col, 'Normal buttons') Label(wri, row, col, "Normal buttons")
# Four Button instances # Four Button instances
row = 120 row = 120
ht = 30 ht = 30
for i, s in enumerate(('a', 'b', 'c', 'd')): for i, s in enumerate(("a", "b", "c", "d")):
col= 2 + i * (ht + 5) col = 2 + i * (ht + 5)
buttons.append(Button(wri, row, col, height=ht, callback=bcb, text=s, litcolor=RED, shape=CIRCLE, bgcolor=DARKGREEN)) buttons.append(
Button(
wri,
row,
col,
height=ht,
callback=bcb,
text=s,
litcolor=RED,
shape=CIRCLE,
bgcolor=DARKGREEN,
)
)
# ButtonList # ButtonList
self.bs = ButtonList(self.callback) self.bs = ButtonList(self.callback)
self.bs0 = None self.bs0 = None
col+= 50 col += 50
Label(wri, row - 15, col, 'ButtonList') Label(wri, row - 15, col, "ButtonList")
for t in table_buttonset: # Buttons overlay each other at same location for t in table_buttonset: # Buttons overlay each other at same location
button = self.bs.add_button(wri, row, col, shape=RECTANGLE, textcolor=BLUE, height=30, **t) button = self.bs.add_button(
if self.bs0 is None: # Save for reset button callback wri, row, col, shape=RECTANGLE, textcolor=BLUE, height=30, **t
)
if self.bs0 is None: # Save for reset button callback
self.bs0 = button self.bs0 = button
# Reset button # Reset button
col+= 60 col += 60
btn = Button(wri, row, col, height=30, callback=self.rstcb, text='reset', litcolor=RED, fgcolor=GREEN, bgcolor=DARKGREEN) btn = Button(
wri,
row,
col,
height=30,
callback=self.rstcb,
text="reset",
litcolor=RED,
fgcolor=GREEN,
bgcolor=DARKGREEN,
)
col = 2 col = 2
row = 170 row = 170
Label(wri, row, col, 'Radio buttons') Label(wri, row, col, "Radio buttons")
# Radio buttons # Radio buttons
row = 185 row = 185
self.rb = RadioButtons(BLUE, self.rbcb) # color of selected button self.rb = RadioButtons(BLUE, self.rbcb) # color of selected button
self.rb0 = None self.rb0 = None
for t in table_radiobuttons: for t in table_radiobuttons:
button = self.rb.add_button(wri, row, col, textcolor = WHITE, button = self.rb.add_button(
fgcolor = BLUE, bgcolor = DARKBLUE, shape=CIRCLE, height = 30, **t) wri,
if self.rb0 is None: # Save for reset button callback row,
col,
textcolor=WHITE,
fgcolor=BLUE,
bgcolor=DARKBLUE,
shape=CIRCLE,
height=30,
**t
)
if self.rb0 is None: # Save for reset button callback
self.rb0 = button self.rb0 = button
col+= 35 col += 35
# Checkbox # Checkbox
col+= 35 col += 35
Label(wri, row - 15, col, 'Checkbox and LED') Label(wri, row - 15, col, "Checkbox and LED")
Checkbox(wri, row, col, callback=self.cbcb) Checkbox(wri, row, col, callback=self.cbcb)
col+= 40 col += 40
self.led = LED(wri, row, col, color=YELLOW, bdcolor=GREEN) self.led = LED(wri, row, col, color=YELLOW, bdcolor=GREEN)
CloseButton(wri) CloseButton(wri)
asyncio.create_task(run(dial, lbltim, m0, scale)) asyncio.create_task(run(dial, lbltim, m0, scale))
def callback(self, button, buttons, val): def callback(self, button, buttons, val):
buttons[2].greyed_out(val) buttons[2].greyed_out(val)
def rbcb(self, button, val): def rbcb(self, button, val):
print('RadioButtons callback', val) print("RadioButtons callback", val)
def rstcb(self, button): def rstcb(self, button):
print('Reset button: init ButtonList and RadioButtons') print("Reset button: init ButtonList and RadioButtons")
self.bs.value(self.bs0) self.bs.value(self.bs0)
self.rb.value(self.rb0) self.rb.value(self.rb0)
def cbcb(self, cb): def cbcb(self, cb):
self.led.value(cb.value()) self.led.value(cb.value())
gc.collect() gc.collect()
print('Free RAM:', gc.mem_free()) print("Free RAM:", gc.mem_free())
async def run(dial, lbltim, m0, scale): async def run(dial, lbltim, m0, scale):
days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
'Sunday') months = (
months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', "Jan",
'Aug', 'Sept', 'Oct', 'Nov', 'Dec') "Feb",
uv = lambda phi : cmath.rect(1, phi) # Return a unit vector of phase phi "March",
"April",
"May",
"June",
"July",
"Aug",
"Sept",
"Oct",
"Nov",
"Dec",
)
uv = lambda phi: cmath.rect(1, phi) # Return a unit vector of phase phi
pi = cmath.pi pi = cmath.pi
hrs = Pointer(dial) hrs = Pointer(dial)
mins = Pointer(dial) mins = Pointer(dial)
secs = Pointer(dial) secs = Pointer(dial)
hstart = 0 + 0.7j # Pointer lengths and position at top hstart = 0 + 0.7j # Pointer lengths and position at top
mstart = 0 + 0.92j mstart = 0 + 0.92j
sstart = 0 + 0.92j sstart = 0 + 0.92j
cv = -1.0 # Scale cv = -1.0 # Scale
dv = 0.005 dv = 0.005
while True: while True:
t = utime.localtime() t = utime.localtime()
hrs.value(hstart * uv(-t[3]*pi/6 - t[4]*pi/360), YELLOW) hrs.value(hstart * uv(-t[3] * pi / 6 - t[4] * pi / 360), YELLOW)
mins.value(mstart * uv(-t[4] * pi/30), YELLOW) mins.value(mstart * uv(-t[4] * pi / 30), YELLOW)
secs.value(sstart * uv(-t[5] * pi/30), RED) secs.value(sstart * uv(-t[5] * pi / 30), RED)
lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5])) lbltim.value("{:02d}.{:02d}.{:02d}".format(t[3], t[4], t[5]))
dial.text('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0])) dial.text("{} {} {} {}".format(days[t[6]], t[2], months[t[1] - 1], t[0]))
m0.value(t[5]/60) m0.value(t[5] / 60)
scale.value(cv) scale.value(cv)
await asyncio.sleep_ms(200) await asyncio.sleep_ms(200)
cv += dv cv += dv
@ -164,9 +228,10 @@ async def run(dial, lbltim, m0, scale):
def test(): def test():
if ssd.height < 240 or ssd.width < 320: if ssd.height < 240 or ssd.width < 320:
print(' This test requires a display of at least 320x240 pixels.') print(" This test requires a display of at least 320x240 pixels.")
else: else:
print('Testing micro-gui...') print("Testing micro-gui...")
Screen.change(FooScreen) Screen.change(FooScreen)
test() test()