kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Provide for splash screens.
rodzic
3367c306ae
commit
c767ebf6b9
|
@ -1036,7 +1036,11 @@ See `demos/plot.py` for an example of multi-screen design, or
|
||||||
|
|
||||||
## 4.2 Constructor
|
## 4.2 Constructor
|
||||||
|
|
||||||
This takes no arguments.
|
This takes one optional argument.
|
||||||
|
* `writer=None` In general a `Screen` must have at least on active widget. In
|
||||||
|
the special case where there are none (e.g. a splash screen), a `Writer`
|
||||||
|
instance should be passed. Application code should close the splash screen by
|
||||||
|
issuing `Screen.back()`.
|
||||||
|
|
||||||
## 4.3 Callback methods
|
## 4.3 Callback methods
|
||||||
|
|
||||||
|
|
|
@ -477,7 +477,7 @@ class Screen:
|
||||||
def shutdown(cls):
|
def shutdown(cls):
|
||||||
cls.is_shutdown.set() # Tell monitor() to shutdown
|
cls.is_shutdown.set() # Tell monitor() to shutdown
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, writer=None):
|
||||||
self.lstactive = [] # Controls which respond to Select button
|
self.lstactive = [] # Controls which respond to Select button
|
||||||
self.selected_obj = None # Index of currently selected object
|
self.selected_obj = None # Index of currently selected object
|
||||||
self.displaylist = [] # All displayable objects
|
self.displaylist = [] # All displayable objects
|
||||||
|
@ -491,6 +491,8 @@ class Screen:
|
||||||
asyncio.create_task(self._garbage_collect())
|
asyncio.create_task(self._garbage_collect())
|
||||||
Screen.current_screen = self
|
Screen.current_screen = self
|
||||||
self.parent = None
|
self.parent = None
|
||||||
|
if writer is not None: # Special case of no active widgets (e.g. popup message)
|
||||||
|
DummyWidget(writer, self) # Invisible active widget
|
||||||
|
|
||||||
def _do_open(self, old_screen): # Window overrides
|
def _do_open(self, old_screen): # Window overrides
|
||||||
dev = display.usegrey(False)
|
dev = display.usegrey(False)
|
||||||
|
@ -621,7 +623,7 @@ class Window(Screen):
|
||||||
fgcolor=None,
|
fgcolor=None,
|
||||||
writer=None,
|
writer=None,
|
||||||
):
|
):
|
||||||
Screen.__init__(self)
|
Screen.__init__(self, writer)
|
||||||
self.row = row
|
self.row = row
|
||||||
self.col = col
|
self.col = col
|
||||||
self.height = height
|
self.height = height
|
||||||
|
@ -629,8 +631,6 @@ class Window(Screen):
|
||||||
self.draw_border = draw_border
|
self.draw_border = draw_border
|
||||||
self.fgcolor = fgcolor if fgcolor is not None else color_map[FG]
|
self.fgcolor = fgcolor if fgcolor is not None else color_map[FG]
|
||||||
self.bgcolor = bgcolor if bgcolor is not None else color_map[BG]
|
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):
|
def _do_open(self, old_screen):
|
||||||
dev = display.usegrey(False)
|
dev = display.usegrey(False)
|
||||||
|
@ -898,8 +898,8 @@ class DummyWidget(Widget):
|
||||||
window.col + 1,
|
window.col + 1,
|
||||||
4,
|
4,
|
||||||
4,
|
4,
|
||||||
window.fgcolor,
|
None,
|
||||||
window.bgcolor,
|
None,
|
||||||
False,
|
False,
|
||||||
None,
|
None,
|
||||||
True,
|
True,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# screen_change.py Minimal micro-gui demo showing a Button causing a screen change.
|
# screen_change.py Minimal micro-gui demo showing a Button causing a screen change.
|
||||||
|
|
||||||
# Released under the MIT License (MIT). See LICENSE.
|
# Released under the MIT License (MIT). See LICENSE.
|
||||||
# Copyright (c) 2021 Peter Hinch
|
# Copyright (c) 2021-2025 Peter Hinch
|
||||||
|
|
||||||
# hardware_setup must be imported before other modules because of RAM use.
|
# hardware_setup must be imported before other modules because of RAM use.
|
||||||
import hardware_setup # Create a display instance
|
import hardware_setup # Create a display instance
|
||||||
|
@ -13,41 +13,62 @@ from gui.core.writer import CWriter
|
||||||
# Font for CWriter
|
# Font for CWriter
|
||||||
import gui.fonts.arial10 as font
|
import gui.fonts.arial10 as font
|
||||||
from gui.core.colors import *
|
from gui.core.colors import *
|
||||||
|
import asyncio
|
||||||
|
import time
|
||||||
|
|
||||||
# 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
|
||||||
# multiple Screen instances. Note that a Screen class is
|
# multiple Screen instances. Note that a Screen class is
|
||||||
# passed, not an instance.
|
# passed, not an instance.
|
||||||
def fwdbutton(wri, row, col, cls_screen, text='Next'):
|
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, callback = fwd,
|
Button(wri, row, col, callback=fwd, fgcolor=BLACK, bgcolor=GREEN, text=text, shape=RECTANGLE)
|
||||||
fgcolor = BLACK, bgcolor = GREEN,
|
|
||||||
text = text, shape = RECTANGLE)
|
|
||||||
|
|
||||||
wri = CWriter(ssd, font, 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):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
Label(wri, 2, 2, 'New screen.')
|
Label(wri, 2, 2, "New screen.")
|
||||||
CloseButton(wri)
|
CloseButton(wri)
|
||||||
|
|
||||||
|
|
||||||
|
# The splash screen is a special case of a Screen with no active widgets.
|
||||||
|
class SplashScreen(Screen):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(wri) # No sctive widgets: must pass writer
|
||||||
|
Label(wri, 10, 10, "Splash screen")
|
||||||
|
Label(wri, 40, 10, "Please wait", fgcolor=YELLOW)
|
||||||
|
|
||||||
|
def after_open(self): # Cle after a period
|
||||||
|
asyncio.create_task(self.close_me())
|
||||||
|
|
||||||
|
async def close_me(self):
|
||||||
|
await asyncio.sleep(3)
|
||||||
|
Screen.back()
|
||||||
|
|
||||||
|
|
||||||
class BaseScreen(Screen):
|
class BaseScreen(Screen):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
Label(wri, 2, 2, 'Base screen.')
|
Label(wri, 2, 2, "Base screen.")
|
||||||
fwdbutton(wri, 40, 2, BackScreen)
|
fwdbutton(wri, 40, 2, BackScreen)
|
||||||
CloseButton(wri)
|
CloseButton(wri)
|
||||||
|
self.splash_done = False
|
||||||
|
|
||||||
|
def after_open(self):
|
||||||
|
if not self.splash_done: # Only show splash on initial opening.
|
||||||
|
Screen.change(SplashScreen)
|
||||||
|
self.splash_done = True
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
print('Screen change demo.')
|
print("Screen change demo.")
|
||||||
Screen.change(BaseScreen) # Pass class, not instance!
|
Screen.change(BaseScreen) # Pass class, not instance!
|
||||||
|
|
||||||
|
|
||||||
test()
|
test()
|
||||||
|
|
Ładowanie…
Reference in New Issue