kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Minor changes to README and demo code format.
rodzic
ced79c49d6
commit
fc7c91fa20
48
README.md
48
README.md
|
@ -1003,7 +1003,7 @@ constructor and is closed by issuing the `close()` static method.
|
|||
## 6.1 Label widget
|
||||
|
||||
```python
|
||||
from gui.widgets import Label
|
||||
from gui.widgets import Label # File: label.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -1089,7 +1089,7 @@ Screen.change(BaseScreen)
|
|||
### 6.1.1 Grid widget
|
||||
|
||||
```python
|
||||
from gui.widgets import Grid
|
||||
from gui.widgets import Grid # File: grid.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -1152,7 +1152,7 @@ See the example [calendar.py](https://github.com/peterhinch/micropython-micro-gu
|
|||
## 6.2 LED widget
|
||||
|
||||
```python
|
||||
from gui.widgets import LED
|
||||
from gui.widgets import LED # File: led.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -1191,7 +1191,7 @@ controlled with `led(True)` or `led(False)`.
|
|||
## 6.3 Checkbox widget
|
||||
|
||||
```python
|
||||
from gui.widgets import Checkbox
|
||||
from gui.widgets import Checkbox # File: checkbox.py
|
||||
```
|
||||

|
||||
This provides for Boolean data entry and display. In the `True` state the
|
||||
|
@ -1233,7 +1233,7 @@ Methods:
|
|||
|
||||
```python
|
||||
from gui.core.colors import * # Colors and shapes
|
||||
from gui.widgets import Button
|
||||
from gui.widgets import Button # File: buttons.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -1310,7 +1310,7 @@ Optional keyword only arguments:
|
|||
|
||||
```python
|
||||
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
|
||||
|
@ -1369,7 +1369,7 @@ for t in table: # Buttons overlay each other at same location
|
|||
|
||||
```python
|
||||
from gui.core.colors import * # Colors and shapes
|
||||
from gui.widgets import Button, RadioButtons
|
||||
from gui.widgets import Button, RadioButtons # File: buttons.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -1416,7 +1416,7 @@ for t in table:
|
|||
## 6.7 Listbox widget
|
||||
|
||||
```python
|
||||
from gui.widgets import Listbox
|
||||
from gui.widgets import Listbox # File: listbox.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -1525,7 +1525,7 @@ Screen.change(BaseScreen)
|
|||
## 6.8 Dropdown widget
|
||||
|
||||
```python
|
||||
from gui.widgets import Dropdown
|
||||
from gui.widgets import Dropdown # File: dropdown.py
|
||||
```
|
||||
|
||||

|
||||
|
@ -1640,7 +1640,7 @@ Screen.change(BaseScreen)
|
|||
## 6.9 DialogBox class
|
||||
|
||||
```python
|
||||
from gui.widgets import DialogBox
|
||||
from gui.widgets import DialogBox # File: dialog.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -1694,7 +1694,7 @@ in `gui/demos/screens.py`.
|
|||
## 6.10 Textbox widget
|
||||
|
||||
```python
|
||||
from gui.widgets import Textbox
|
||||
from gui.widgets import Textbox # File: textbox.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -1763,7 +1763,7 @@ the oldest (topmost) being discarded as required.
|
|||
This `passive` widget displays a single floating point value on a vertical
|
||||
linear scale. Optionally it can support data dependent callbacks.
|
||||
```python
|
||||
from gui.widgets import Meter
|
||||
from gui.widgets import Meter # File: meter.py
|
||||
```
|
||||

|
||||
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
|
||||
|
||||
```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
|
||||
a `Meter`). Constructor positional args are as follows:
|
||||
|
@ -1915,7 +1915,7 @@ callbacks to run as appropriate.
|
|||
## 6.12 Slider and HorizSlider widgets
|
||||
|
||||
```python
|
||||
from gui.widgets import Slider, HorizSlider
|
||||
from gui.widgets import Slider, HorizSlider # File: sliders.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -1995,7 +1995,7 @@ around sliders to display all legends.
|
|||
## 6.13 Scale widget
|
||||
|
||||
```python
|
||||
from gui.widgets import Scale
|
||||
from gui.widgets import Scale # File: scale.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -2132,7 +2132,7 @@ precision. Each visible division on the control represents 10 integer units.
|
|||
## 6.14 ScaleLog widget
|
||||
|
||||
```python
|
||||
from gui.widgets import ScaleLog
|
||||
from gui.widgets import ScaleLog # File: scale_log.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -2272,7 +2272,7 @@ def tickcb(f, c):
|
|||
## 6.15 Dial widget
|
||||
|
||||
```python
|
||||
from gui.widgets import Dial, Pointer
|
||||
from gui.widgets import Dial, Pointer # File: dial.py
|
||||
```
|
||||
 
|
||||
|
||||
|
@ -2388,7 +2388,7 @@ Screen.change(BaseScreen)
|
|||
## 6.16 Knob widget
|
||||
|
||||
```python
|
||||
from gui.widgets import Knob
|
||||
from gui.widgets import Knob # File: knob.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -2446,7 +2446,7 @@ value changes. This enables dynamic color change.
|
|||
## 6.17 Adjuster widget
|
||||
|
||||
```python
|
||||
from gui.widgets import Adjuster
|
||||
from gui.widgets import Adjuster, FloatAdj # File: adjuster.py
|
||||
```
|
||||
 
|
||||
|
||||
|
@ -2512,7 +2512,7 @@ basis. See code comments for further details.
|
|||
## 6.18 Menu class
|
||||
|
||||
```python
|
||||
from gui.widgets import Menu
|
||||
from gui.widgets import Menu # File: menu.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -2620,7 +2620,7 @@ different callback if the application required it.
|
|||
## 6.19 BitMap Widget
|
||||
|
||||
```python
|
||||
from gui.widgets import BitMap
|
||||
from gui.widgets import BitMap # File: bitmap.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -2662,7 +2662,7 @@ See `gui/demos/bitmap.py` for a usage example.
|
|||
## 6.20 QRMap Widget
|
||||
|
||||
```python
|
||||
from gui.widgets import QRMap
|
||||
from gui.widgets import QRMap # File: qrcode.py
|
||||
```
|
||||

|
||||
|
||||
|
@ -3079,6 +3079,10 @@ async def full_refresh():
|
|||
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)
|
||||
|
||||
# Appendix 1 Application design
|
||||
|
|
|
@ -43,8 +43,7 @@ audio_out = I2S(I2S_ID, **config)
|
|||
|
||||
# ======= GUI =======
|
||||
|
||||
from gui.widgets.label import Label
|
||||
from gui.widgets import Button, CloseButton, HorizSlider, Listbox
|
||||
from gui.widgets import Button, CloseButton, HorizSlider, Listbox, Label
|
||||
from gui.core.writer import CWriter
|
||||
|
||||
# Font for CWriter
|
||||
|
|
|
@ -15,8 +15,21 @@ import gui.fonts.arial10 as arial10 # Font for CWriter
|
|||
import gui.fonts.freesans20 as large
|
||||
|
||||
from gui.core.colors import *
|
||||
|
||||
# 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 math import sin, pi
|
||||
|
@ -25,6 +38,7 @@ import uasyncio as asyncio
|
|||
import utime
|
||||
import gc
|
||||
|
||||
|
||||
async def full_refresh():
|
||||
Screen.rfsh_done.clear() # Enable completion flag
|
||||
await Screen.rfsh_done.wait() # Wait for a refresh to end
|
||||
|
@ -40,8 +54,8 @@ class FooScreen(Screen):
|
|||
|
||||
# A ButtonList with two entries
|
||||
table_buttonset = (
|
||||
{'fgcolor' : RED, 'text' : 'Disable', 'args' : (buttons, True)},
|
||||
{'fgcolor' : GREEN, 'text' : 'Enable', 'args' : (buttons, False)},
|
||||
{"fgcolor": RED, "text": "Disable", "args": (buttons, True)},
|
||||
{"fgcolor": GREEN, "text": "Enable", "args": (buttons, False)},
|
||||
)
|
||||
|
||||
def tickcb(f, c):
|
||||
|
@ -52,49 +66,86 @@ class FooScreen(Screen):
|
|||
return c
|
||||
|
||||
def bcb(b):
|
||||
print('Button pressed', b)
|
||||
print("Button pressed", b)
|
||||
|
||||
super().__init__()
|
||||
self.rb0 = None
|
||||
self.bs0 = None
|
||||
wri = CWriter(ssd, arial10, 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,
|
||||
label='Meter', style=Meter.BAR, legends=('0.0', '0.5', '1.0'))
|
||||
m0 = Meter(
|
||||
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.
|
||||
dial = Dial(wri, 2, 2, height = 75, ticks = 12, bgcolor=BLACK, bdcolor=None, label=120) # Border in fg color
|
||||
scale = Scale(wri, 2, 100, width = 124, tickcb = tickcb,
|
||||
pointercolor=RED, fontcolor=YELLOW, bdcolor=CYAN)
|
||||
dial = Dial(
|
||||
wri, 2, 2, height=75, ticks=12, bgcolor=BLACK, bdcolor=None, label=120
|
||||
) # Border in fg color
|
||||
scale = Scale(
|
||||
wri, 2, 100, width=124, tickcb=tickcb, pointercolor=RED, fontcolor=YELLOW, bdcolor=CYAN
|
||||
)
|
||||
|
||||
row = 105
|
||||
col = 2
|
||||
Label(wri, row, col, 'Normal buttons')
|
||||
Label(wri, row, col, "Normal buttons")
|
||||
# Four Button instances
|
||||
row = 120
|
||||
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)
|
||||
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
|
||||
self.bs = ButtonList(self.callback)
|
||||
self.bs0 = None
|
||||
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
|
||||
button = self.bs.add_button(wri, row, col, shape=RECTANGLE, textcolor=BLUE, height=30, **t)
|
||||
button = self.bs.add_button(
|
||||
wri, row, col, shape=RECTANGLE, textcolor=BLUE, height=30, **t
|
||||
)
|
||||
if self.bs0 is None: # Save for reset button callback
|
||||
self.bs0 = button
|
||||
|
||||
# Reset button
|
||||
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
|
||||
# Checkbox
|
||||
Label(wri, row - 15, col, 'Checkbox and LED')
|
||||
Label(wri, row - 15, col, "Checkbox and LED")
|
||||
Checkbox(wri, row, col, callback=self.cbcb)
|
||||
col += 40
|
||||
self.led = LED(wri, row, col, color=YELLOW, bdcolor=GREEN)
|
||||
|
@ -104,28 +155,26 @@ class FooScreen(Screen):
|
|||
ht = 75
|
||||
wd = 200
|
||||
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 - 8 + int(wd//2), '0.0')
|
||||
lbl = Label(wri, row + ht + 5, col - 10 + wd, '2.0')
|
||||
Label(wri, row + ht + 5, col - 10, "-2.0")
|
||||
Label(wri, row + ht + 5, col - 8 + int(wd // 2), "0.0")
|
||||
lbl = Label(wri, row + ht + 5, col - 10 + wd, "2.0")
|
||||
Label(wri_large, lbl.mrow + 5, col, "y = sinc(x)")
|
||||
|
||||
|
||||
CloseButton(wri, bgcolor=BLACK)
|
||||
asyncio.create_task(run(dial, lbltim, m0, scale))
|
||||
|
||||
|
||||
def callback(self, button, buttons, val):
|
||||
buttons[2].greyed_out(val)
|
||||
|
||||
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)
|
||||
asyncio.create_task(full_refresh())
|
||||
|
||||
def cbcb(self, cb):
|
||||
self.led.value(cb.value())
|
||||
gc.collect()
|
||||
print('Free RAM:', gc.mem_free())
|
||||
print("Free RAM:", gc.mem_free())
|
||||
|
||||
def after_open(self):
|
||||
def populate():
|
||||
|
@ -140,10 +189,21 @@ class FooScreen(Screen):
|
|||
|
||||
|
||||
async def run(dial, lbltim, m0, scale):
|
||||
days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
|
||||
'Sunday')
|
||||
months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July',
|
||||
'Aug', 'Sept', 'Oct', 'Nov', 'Dec')
|
||||
days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
|
||||
months = (
|
||||
"Jan",
|
||||
"Feb",
|
||||
"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
|
||||
hrs = Pointer(dial)
|
||||
|
@ -161,8 +221,8 @@ async def run(dial, lbltim, m0, scale):
|
|||
hrs.value(hstart * uv(-t[3] * pi / 6 - t[4] * pi / 360), YELLOW)
|
||||
mins.value(mstart * uv(-t[4] * pi / 30), YELLOW)
|
||||
secs.value(sstart * uv(-t[5] * pi / 30), RED)
|
||||
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]))
|
||||
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]))
|
||||
m0.value(t[5] / 60)
|
||||
scale.value(cv)
|
||||
await asyncio.sleep_ms(200)
|
||||
|
@ -173,9 +233,10 @@ async def run(dial, lbltim, m0, scale):
|
|||
|
||||
|
||||
def test():
|
||||
print('Testing micro-gui...')
|
||||
print("Testing micro-gui...")
|
||||
Screen.change(FooScreen)
|
||||
print("End")
|
||||
ssd.sleep() # Tidy shutdown of EPD
|
||||
|
||||
|
||||
test()
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
import hardware_setup # Create a display instance
|
||||
from gui.core.ugui import Screen, Window, ssd
|
||||
|
||||
from gui.widgets.label import Label
|
||||
from gui.widgets import Button, RadioButtons, CloseButton, Listbox, Dropdown, DialogBox
|
||||
from gui.widgets import Button, RadioButtons, CloseButton, Listbox, Dropdown, DialogBox, Label
|
||||
from gui.core.writer import CWriter
|
||||
|
||||
# Font for CWriter
|
||||
|
|
|
@ -11,14 +11,21 @@ from gui.core.ugui import Screen, ssd
|
|||
from gui.core.writer import CWriter
|
||||
import gui.fonts.arial10 as arial10 # Font for CWriter
|
||||
from gui.core.colors import *
|
||||
|
||||
# Widgets
|
||||
from gui.widgets.label import Label
|
||||
from gui.widgets.dial import Dial, Pointer
|
||||
from gui.widgets.meter import Meter
|
||||
from gui.widgets.scale import Scale
|
||||
from gui.widgets.buttons import Button, ButtonList, RadioButtons, CloseButton
|
||||
from gui.widgets.checkbox import Checkbox
|
||||
from gui.widgets.led import LED
|
||||
from gui.widgets import (
|
||||
Label,
|
||||
Dial,
|
||||
Pointer,
|
||||
Meter,
|
||||
Scale,
|
||||
Button,
|
||||
ButtonList,
|
||||
RadioButtons,
|
||||
CloseButton,
|
||||
Checkbox,
|
||||
LED,
|
||||
)
|
||||
|
||||
import cmath
|
||||
import uasyncio as asyncio
|
||||
|
@ -32,15 +39,15 @@ class FooScreen(Screen):
|
|||
|
||||
# A ButtonList with two entries
|
||||
table_buttonset = (
|
||||
{'fgcolor' : RED, 'text' : 'Disable', 'args' : (buttons, True)},
|
||||
{'fgcolor' : GREEN, 'text' : 'Enable', 'args' : (buttons, False)},
|
||||
{"fgcolor": RED, "text": "Disable", "args": (buttons, True)},
|
||||
{"fgcolor": GREEN, "text": "Enable", "args": (buttons, False)},
|
||||
)
|
||||
|
||||
table_radiobuttons = (
|
||||
{'text' : '1', 'args' : ('1',)},
|
||||
{'text' : '2', 'args' : ('2',)},
|
||||
{'text' : '3', 'args' : ('3',)},
|
||||
{'text' : '4', 'args' : ('4',)},
|
||||
{"text": "1", "args": ("1",)},
|
||||
{"text": "2", "args": ("2",)},
|
||||
{"text": "3", "args": ("3",)},
|
||||
{"text": "4", "args": ("4",)},
|
||||
)
|
||||
|
||||
def tickcb(f, c):
|
||||
|
@ -51,89 +58,146 @@ class FooScreen(Screen):
|
|||
return c
|
||||
|
||||
def bcb(b):
|
||||
print('Button pressed', b)
|
||||
print("Button pressed", b)
|
||||
|
||||
super().__init__()
|
||||
self.rb0 = None
|
||||
self.bs0 = None
|
||||
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,
|
||||
label='Meter example', style=Meter.BAR, legends=('0.0', '0.5', '1.0'))
|
||||
m0 = Meter(
|
||||
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.
|
||||
dial = Dial(wri, 2, 2, height = 75, ticks = 12, bgcolor=BLACK, bdcolor=None, label=120) # Border in fg color
|
||||
scale = Scale(wri, 2, 100, width = 124, tickcb = tickcb,
|
||||
pointercolor=RED, fontcolor=YELLOW, bdcolor=CYAN)
|
||||
dial = Dial(
|
||||
wri, 2, 2, height=75, ticks=12, bgcolor=BLACK, bdcolor=None, label=120
|
||||
) # Border in fg color
|
||||
scale = Scale(
|
||||
wri, 2, 100, width=124, tickcb=tickcb, pointercolor=RED, fontcolor=YELLOW, bdcolor=CYAN
|
||||
)
|
||||
|
||||
row = 105
|
||||
col = 2
|
||||
Label(wri, row, col, 'Normal buttons')
|
||||
Label(wri, row, col, "Normal buttons")
|
||||
# Four Button instances
|
||||
row = 120
|
||||
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)
|
||||
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
|
||||
self.bs = ButtonList(self.callback)
|
||||
self.bs0 = None
|
||||
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
|
||||
button = self.bs.add_button(wri, row, col, shape=RECTANGLE, textcolor=BLUE, height=30, **t)
|
||||
button = self.bs.add_button(
|
||||
wri, row, col, shape=RECTANGLE, textcolor=BLUE, height=30, **t
|
||||
)
|
||||
if self.bs0 is None: # Save for reset button callback
|
||||
self.bs0 = button
|
||||
|
||||
# Reset button
|
||||
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
|
||||
row = 170
|
||||
Label(wri, row, col, 'Radio buttons')
|
||||
Label(wri, row, col, "Radio buttons")
|
||||
# Radio buttons
|
||||
row = 185
|
||||
self.rb = RadioButtons(BLUE, self.rbcb) # color of selected button
|
||||
self.rb0 = None
|
||||
for t in table_radiobuttons:
|
||||
button = self.rb.add_button(wri, row, col, textcolor = WHITE,
|
||||
fgcolor = BLUE, bgcolor = DARKBLUE, shape=CIRCLE, height = 30, **t)
|
||||
button = self.rb.add_button(
|
||||
wri,
|
||||
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
|
||||
col += 35
|
||||
# Checkbox
|
||||
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)
|
||||
col += 40
|
||||
self.led = LED(wri, row, col, color=YELLOW, bdcolor=GREEN)
|
||||
CloseButton(wri)
|
||||
asyncio.create_task(run(dial, lbltim, m0, scale))
|
||||
|
||||
|
||||
def callback(self, button, buttons, val):
|
||||
buttons[2].greyed_out(val)
|
||||
|
||||
def rbcb(self, button, val):
|
||||
print('RadioButtons callback', val)
|
||||
print("RadioButtons callback", val)
|
||||
|
||||
def rstcb(self, button):
|
||||
print('Reset button: init ButtonList and RadioButtons')
|
||||
print("Reset button: init ButtonList and RadioButtons")
|
||||
self.bs.value(self.bs0)
|
||||
self.rb.value(self.rb0)
|
||||
|
||||
def cbcb(self, cb):
|
||||
self.led.value(cb.value())
|
||||
gc.collect()
|
||||
print('Free RAM:', gc.mem_free())
|
||||
print("Free RAM:", gc.mem_free())
|
||||
|
||||
|
||||
async def run(dial, lbltim, m0, scale):
|
||||
days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
|
||||
'Sunday')
|
||||
months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July',
|
||||
'Aug', 'Sept', 'Oct', 'Nov', 'Dec')
|
||||
days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
|
||||
months = (
|
||||
"Jan",
|
||||
"Feb",
|
||||
"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
|
||||
hrs = Pointer(dial)
|
||||
|
@ -151,8 +215,8 @@ async def run(dial, lbltim, m0, scale):
|
|||
hrs.value(hstart * uv(-t[3] * pi / 6 - t[4] * pi / 360), YELLOW)
|
||||
mins.value(mstart * uv(-t[4] * pi / 30), YELLOW)
|
||||
secs.value(sstart * uv(-t[5] * pi / 30), RED)
|
||||
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]))
|
||||
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]))
|
||||
m0.value(t[5] / 60)
|
||||
scale.value(cv)
|
||||
await asyncio.sleep_ms(200)
|
||||
|
@ -164,9 +228,10 @@ async def run(dial, lbltim, m0, scale):
|
|||
|
||||
def test():
|
||||
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:
|
||||
print('Testing micro-gui...')
|
||||
print("Testing micro-gui...")
|
||||
Screen.change(FooScreen)
|
||||
|
||||
|
||||
test()
|
||||
|
|
Ładowanie…
Reference in New Issue