Add support for popup windows.

pull/8/head
Peter Hinch 2022-01-14 10:29:53 +00:00
rodzic a3dc83f357
commit 8370ebc752
2 zmienionych plików z 28 dodań i 5 usunięć

Wyświetl plik

@ -100,6 +100,7 @@ there is a workround if it's impossible to upgrade. See
5. [Window class](./README.md#5-window-class)
5.1 [Constructor](./README.md#51-constructor)
5.2 [Class method](./README.md#52-class-method)
5.3 [Popup windows](./README.md#53-popup-windows)
6. [Label widget](./README.md#6-label-widget) Single line text display.
7. [LED widget](./README.md#7-led-widget) Display Boolean values.
8. [Checkbox widget](./README.md#8-checkbox-widget) Enter Boolean values.
@ -912,6 +913,7 @@ Followed by keyword-only args
* `draw_border=True`
* `bgcolor=None` Background color, default black.
* `fgcolor=None` Foreground color, default white.
* `writer=None` See Popups below.
## 5.2 Class method
@ -925,6 +927,14 @@ callbacks to the user window constructor args. These may be called by widgets
to send data to the calling screen. Note that widgets on the screen below will
not be updated until the window has closed.
## 5.3 Popup windows
In general `Screen` and `Window` instances need at least one active widget.
There is a special case of a popup window which typically displays status data,
possibly with a progress meter. A popup has no user controls and is closed by
user code. A popup is created by passing a `Writer` (or `CWriter`) to the
constructor and is closed by issuing the `close()` static method.
###### [Contents](./README.md#0-contents)
# 6. Label widget

Wyświetl plik

@ -1,7 +1,7 @@
# ugui.py Micropython GUI library
# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2019-2021 Peter Hinch
# Copyright (c) 2019-2022 Peter Hinch
# Requires uasyncio V3
@ -21,7 +21,7 @@ display = None # Singleton instance
ssd = None
gc.collect()
__version__ = (0, 1, 3)
__version__ = (0, 1, 4)
# Null function
dolittle = lambda *_ : None
@ -490,8 +490,12 @@ class Window(Screen):
cls._value = val
return cls._value
@staticmethod
def close(): # More intuitive name for popup window
Screen.back()
def __init__(self, row, col, height, width, *, draw_border=True,
bgcolor=None, fgcolor=None):
bgcolor=None, fgcolor=None, writer=None):
Screen.__init__(self)
self.row = row
self.col = col
@ -500,6 +504,8 @@ class Window(Screen):
self.draw_border = draw_border
self.fgcolor = fgcolor if fgcolor is not None else color_map[FG]
self.bgcolor = bgcolor if bgcolor is not None else color_map[BG]
if writer is not None: # Special case of popup message
DummyWidget(writer, self) # Invisible active widget
def _do_open(self, old_screen):
dev = display.usegrey(False)
@ -516,7 +522,6 @@ class Window(Screen):
y = self.row
return x, y, x + w, y + h, w, h
# Base class for all displayable objects
class Widget:
@ -622,7 +627,7 @@ class Widget:
y = self.row - 2
w = self.width + 4
h = self.height + 4
if self.has_focus():
if self.has_focus() and not isinstance(self, DummyWidget):
color = color_map[FOCUS]
if hasattr(self, 'precision') and self.precision and self.prcolor is not None:
color = self.prcolor
@ -747,3 +752,11 @@ class LinearIO(Widget):
def leave(self): # Control has lost focus
self.precise(False)
# The dummy enables popup windows by satisfying the need for at least one active
# widget on a screen. It is invisible and is drawn by Window constructor before
# any user labels..
class DummyWidget(Widget):
def __init__(self, writer, window):
super().__init__(writer, window.row + 1, window.col + 1, 4, 4,
window.fgcolor, window.bgcolor, False, None, True)