kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Button widget: improve lit_color code.
rodzic
059eefb67c
commit
87eeb92ca0
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
import uasyncio as asyncio
|
import uasyncio as asyncio
|
||||||
from gui.core.ugui import Screen, Widget, display
|
from gui.core.ugui import Screen, Widget, display
|
||||||
from gui.primitives.delay_ms import Delay_ms
|
|
||||||
from gui.core.colors import *
|
from gui.core.colors import *
|
||||||
|
|
||||||
dolittle = lambda *_: None
|
dolittle = lambda *_: None
|
||||||
|
@ -46,8 +45,6 @@ class Button(Widget):
|
||||||
self.text = text
|
self.text = text
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.callback_args = args
|
self.callback_args = args
|
||||||
if self.litcolor is not None:
|
|
||||||
self.delay = Delay_ms(self.shownormal)
|
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
if self.screen is not Screen.current_screen:
|
if self.screen is not Screen.current_screen:
|
||||||
|
@ -86,21 +83,22 @@ class Button(Widget):
|
||||||
self.writer, xc, yc, self.text, self.textcolor, self.bgcolor
|
self.writer, xc, yc, self.text, self.textcolor, self.bgcolor
|
||||||
)
|
)
|
||||||
|
|
||||||
async def shownormal(self):
|
async def shownormal(self): # Revert to normal color after a delay
|
||||||
# Handle case where screen changed while timer was active: delay repaint
|
try:
|
||||||
# until screen is current. Pathological app behaviour where another
|
await asyncio.sleep_ms(Button.lit_time)
|
||||||
# control caused a screen change while timer running.
|
except asyncio.CancelledError: # Or prior to a screen change
|
||||||
while self.screen is not Screen.current_screen:
|
pass
|
||||||
await asyncio.sleep_ms(500)
|
|
||||||
self.bgcolor = self.def_bgcolor
|
self.bgcolor = self.def_bgcolor
|
||||||
self.draw = True # Redisplay
|
self.draw = True # Redisplay
|
||||||
|
|
||||||
def do_sel(self): # Select was pushed
|
def do_sel(self): # Select was pushed
|
||||||
self.callback(self, *self.callback_args) # CB takes self as 1st arg.
|
self.callback(self, *self.callback_args) # CB takes self as 1st arg.
|
||||||
if self.litcolor is not None and self.has_focus(): # CB may have changed focus
|
if self.litcolor is not None and self.has_focus(): # CB may have changed focus
|
||||||
|
if self.bgcolor != self.litcolor:
|
||||||
self.bgcolor = self.litcolor
|
self.bgcolor = self.litcolor
|
||||||
self.draw = True # Redisplay
|
self.draw = True # Redisplay
|
||||||
self.delay.trigger(Button.lit_time)
|
revert = asyncio.create_task(self.shownormal())
|
||||||
|
Screen.current_screen.reg_task(revert, True) # Cancel on screen change
|
||||||
|
|
||||||
|
|
||||||
# Preferred way to close a screen or dialog. Produces an X button at the top RHS.
|
# Preferred way to close a screen or dialog. Produces an X button at the top RHS.
|
||||||
|
|
Ładowanie…
Reference in New Issue