kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Adjuster can now take min-delta and max-delta args.
rodzic
d319f72c40
commit
7cb2277363
12
README.md
12
README.md
|
@ -67,7 +67,7 @@ target and a C device driver (unless you can acquire a suitable binary).
|
||||||
|
|
||||||
# Project status
|
# Project status
|
||||||
|
|
||||||
Oct 2024: Oct 2024: Refresh locking can now be handled by device driver.
|
Oct 2024: Refresh locking can now be handled by device driver.
|
||||||
Sept 2024: Refresh control is now via a `Lock`. See [Realtime applications](./README.md#9-realtime-applications).
|
Sept 2024: Refresh control is now via a `Lock`. See [Realtime applications](./README.md#9-realtime-applications).
|
||||||
This is a breaking change for applications which use refresh control.
|
This is a breaking change for applications which use refresh control.
|
||||||
Sept 2024: Dropdown and Listbox widgets support dynamically variable lists of elements.
|
Sept 2024: Dropdown and Listbox widgets support dynamically variable lists of elements.
|
||||||
|
@ -2652,6 +2652,8 @@ Optional keyword only arguments:
|
||||||
* `callback=dolittle` Callback function runs when the user moves the knob or
|
* `callback=dolittle` Callback function runs when the user moves the knob or
|
||||||
the value is changed programmatically.
|
the value is changed programmatically.
|
||||||
* `args=[]` A list/tuple of arguments for above callback.
|
* `args=[]` A list/tuple of arguments for above callback.
|
||||||
|
* `min_delta=0.01` Amount value changes for one click in fine mode.
|
||||||
|
* `max_delta=0.1` Amount value changes for one click in normal mode.
|
||||||
|
|
||||||
Methods:
|
Methods:
|
||||||
* `greyed_out` Optional Boolean argument `val=None`. If `None` returns the
|
* `greyed_out` Optional Boolean argument `val=None`. If `None` returns the
|
||||||
|
@ -2672,12 +2674,12 @@ linked label.
|
||||||
### A numeric entry device
|
### A numeric entry device
|
||||||
|
|
||||||
The file [widgets/adjuster.py](./gui/widgets/adjuster.py) includes an example
|
The file [widgets/adjuster.py](./gui/widgets/adjuster.py) includes an example
|
||||||
class which combines an `Adjuster` with one or two `Label` instances. The
|
class `FloatAdj` which combines an `Adjuster` with one or two `Label` instances.
|
||||||
`Adjuster` changes the displayed value in the `Label` to its left. Its use is
|
The `Adjuster` changes the displayed value in the `Label` to its left. Its use
|
||||||
illustrated in [demos/adjuster.py](./gui/demos/adjuster.py). The class can be
|
is illustrated in [demos/adjuster.py](./gui/demos/adjuster.py). The class can be
|
||||||
used as a template for a user class, which may have a different layout on
|
used as a template for a user class, which may have a different layout on
|
||||||
screen. It supports arbitrary mapping and number formatting on a per-instance
|
screen. It supports arbitrary mapping and number formatting on a per-instance
|
||||||
basis. See code comments for further details.
|
basis.
|
||||||
|
|
||||||
###### [Contents](./README.md#0-contents)
|
###### [Contents](./README.md#0-contents)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# adjuster.py Tiny control knob (rotary potentiometer) widget
|
# adjuster.py Tiny control knob (rotary potentiometer) widget
|
||||||
|
|
||||||
# Released under the MIT License (MIT). See LICENSE.
|
# Released under the MIT License (MIT). See LICENSE.
|
||||||
# Copyright (c) 2021 Peter Hinch
|
# Copyright (c) 2021-2024 Peter Hinch
|
||||||
|
|
||||||
from gui.core.ugui import LinearIO, display
|
from gui.core.ugui import LinearIO, display
|
||||||
from gui.widgets.label import Label
|
from gui.widgets.label import Label
|
||||||
|
@ -11,17 +11,42 @@ TWOPI = 2 * math.pi
|
||||||
# Null function
|
# Null function
|
||||||
dolittle = lambda *_: None
|
dolittle = lambda *_: None
|
||||||
|
|
||||||
# *********** CONTROL KNOB CLASS ***********
|
# *********** ADJUSTER CLASS ***********
|
||||||
|
|
||||||
|
|
||||||
class Adjuster(LinearIO):
|
class Adjuster(LinearIO):
|
||||||
def __init__(self, writer, row, col, *,
|
def __init__(
|
||||||
value=0.0, fgcolor=None, bgcolor=None, color=None,
|
self,
|
||||||
prcolor=None, callback=dolittle, args=[]):
|
writer,
|
||||||
|
row,
|
||||||
|
col,
|
||||||
|
*,
|
||||||
|
value=0.0,
|
||||||
|
fgcolor=None,
|
||||||
|
bgcolor=None,
|
||||||
|
color=None,
|
||||||
|
prcolor=None,
|
||||||
|
callback=dolittle,
|
||||||
|
args=[],
|
||||||
|
min_delta=0.01,
|
||||||
|
max_delta=0.1,
|
||||||
|
):
|
||||||
height = writer.height # Match a user-linked Label
|
height = writer.height # Match a user-linked Label
|
||||||
super().__init__(writer, row, col, height, height,
|
super().__init__(
|
||||||
fgcolor, bgcolor, False, value,
|
writer,
|
||||||
True, prcolor)
|
row,
|
||||||
|
col,
|
||||||
|
height,
|
||||||
|
height,
|
||||||
|
fgcolor,
|
||||||
|
bgcolor,
|
||||||
|
False,
|
||||||
|
value,
|
||||||
|
True,
|
||||||
|
prcolor,
|
||||||
|
min_delta,
|
||||||
|
max_delta,
|
||||||
|
)
|
||||||
super()._set_callbacks(callback, args)
|
super()._set_callbacks(callback, args)
|
||||||
radius = height / 2
|
radius = height / 2
|
||||||
self.arc = 1.5 * math.pi # Usable angle of control
|
self.arc = 1.5 * math.pi # Usable angle of control
|
||||||
|
@ -51,6 +76,7 @@ class Adjuster(LinearIO):
|
||||||
y_end = int(self.yorigin - length * math.cos(angle))
|
y_end = int(self.yorigin - length * math.cos(angle))
|
||||||
display.line(int(self.xorigin), int(self.yorigin), x_end, y_end, color)
|
display.line(int(self.xorigin), int(self.yorigin), x_end, y_end, color)
|
||||||
|
|
||||||
|
|
||||||
# This class combines an Adjuster with one or two labels. Numerous layout
|
# This class combines an Adjuster with one or two labels. Numerous layout
|
||||||
# options exist: users may wish to write a version of this example with
|
# options exist: users may wish to write a version of this example with
|
||||||
# different visual characteristics.
|
# different visual characteristics.
|
||||||
|
@ -59,10 +85,23 @@ class Adjuster(LinearIO):
|
||||||
# The object's value is that of the Adjuster, in range 0.0-1.0. The scaled
|
# The object's value is that of the Adjuster, in range 0.0-1.0. The scaled
|
||||||
# value is retrieved with .mapped_value()
|
# value is retrieved with .mapped_value()
|
||||||
class FloatAdj(Adjuster):
|
class FloatAdj(Adjuster):
|
||||||
def __init__(self, wri, row, col, *,
|
def __init__(
|
||||||
lbl_width=60, value=0.0, color=None,
|
self,
|
||||||
fstr="{:4.2f}", map_func=lambda v: v, text="",
|
wri,
|
||||||
callback=dolittle, args=[]):
|
row,
|
||||||
|
col,
|
||||||
|
*,
|
||||||
|
lbl_width=60,
|
||||||
|
value=0.0,
|
||||||
|
color=None,
|
||||||
|
fstr="{:4.2f}",
|
||||||
|
map_func=lambda v: v,
|
||||||
|
text="",
|
||||||
|
callback=dolittle,
|
||||||
|
args=[],
|
||||||
|
min_delta=0.01,
|
||||||
|
max_delta=0.1,
|
||||||
|
):
|
||||||
|
|
||||||
self.map_func = map_func
|
self.map_func = map_func
|
||||||
self.facb = callback
|
self.facb = callback
|
||||||
|
@ -70,8 +109,16 @@ class FloatAdj(Adjuster):
|
||||||
self.fstr = fstr
|
self.fstr = fstr
|
||||||
|
|
||||||
self.lbl = Label(wri, row, col, lbl_width, bdcolor=color)
|
self.lbl = Label(wri, row, col, lbl_width, bdcolor=color)
|
||||||
super().__init__(wri, row, self.lbl.mcol + 2, value=value,
|
super().__init__(
|
||||||
fgcolor=color, callback=self.cb)
|
wri,
|
||||||
|
row,
|
||||||
|
self.lbl.mcol + 2,
|
||||||
|
value=value,
|
||||||
|
fgcolor=color,
|
||||||
|
callback=self.cb,
|
||||||
|
min_delta=min_delta,
|
||||||
|
max_delta=max_delta,
|
||||||
|
)
|
||||||
if text:
|
if text:
|
||||||
self.legend = Label(wri, row, self.mcol + 2, text)
|
self.legend = Label(wri, row, self.mcol + 2, text)
|
||||||
self.mcol = self.legend.mcol # For relative positioning
|
self.mcol = self.legend.mcol # For relative positioning
|
||||||
|
|
Ładowanie…
Reference in New Issue