kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Fix window with one active widget closing on pressing button.
rodzic
5ed42f918d
commit
a3dc83f357
|
@ -261,6 +261,8 @@ class Screen:
|
||||||
if isinstance(cs_old, Window):
|
if isinstance(cs_old, Window):
|
||||||
raise ValueError('Windows are modal.')
|
raise ValueError('Windows are modal.')
|
||||||
new_screen = cls_new_screen(*args, **kwargs)
|
new_screen = cls_new_screen(*args, **kwargs)
|
||||||
|
if not len(new_screen.lstactive):
|
||||||
|
raise ValueError("Screen has no active widgets.")
|
||||||
else:
|
else:
|
||||||
raise ValueError('Must pass Screen class or subclass (not instance)')
|
raise ValueError('Must pass Screen class or subclass (not instance)')
|
||||||
new_screen.parent = cs_old
|
new_screen.parent = cs_old
|
||||||
|
@ -411,10 +413,10 @@ class Screen:
|
||||||
lo.show() # Re-display with new status
|
lo.show() # Re-display with new status
|
||||||
co.enter() # Tell object it has currency
|
co.enter() # Tell object it has currency
|
||||||
co.show()
|
co.show()
|
||||||
elif isinstance(self, Window):
|
#elif isinstance(self, Window):
|
||||||
# Special case of Window with one object: leave
|
# Special case of Window with one object: leave
|
||||||
# without making changes (Dropdown in particular)
|
# without making changes (Dropdown in particular)
|
||||||
Screen.back()
|
#Screen.back()
|
||||||
done = True
|
done = True
|
||||||
|
|
||||||
# Move currency to a specific control.
|
# Move currency to a specific control.
|
||||||
|
@ -488,7 +490,8 @@ class Window(Screen):
|
||||||
cls._value = val
|
cls._value = val
|
||||||
return cls._value
|
return cls._value
|
||||||
|
|
||||||
def __init__(self, row, col, height, width, *, draw_border=True, bgcolor=None, fgcolor=None):
|
def __init__(self, row, col, height, width, *, draw_border=True,
|
||||||
|
bgcolor=None, fgcolor=None):
|
||||||
Screen.__init__(self)
|
Screen.__init__(self)
|
||||||
self.row = row
|
self.row = row
|
||||||
self.col = col
|
self.col = col
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# listbox.py Extension to ugui providing the Listbox class
|
# listbox.py Extension to ugui providing the Listbox class
|
||||||
|
|
||||||
# Released under the MIT License (MIT). See LICENSE.
|
# Released under the MIT License (MIT). See LICENSE.
|
||||||
# Copyright (c) 2021 Peter Hinch
|
# Copyright (c) 2021-2022 Peter Hinch
|
||||||
|
|
||||||
# 12 Sep 21 Support for scrolling.
|
# 12 Sep 21 Support for scrolling.
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ class Listbox(Widget):
|
||||||
ON_MOVE = 1 # Also run whenever the currency moves.
|
ON_MOVE = 1 # Also run whenever the currency moves.
|
||||||
ON_LEAVE = 2 # Also run on exit from the control.
|
ON_LEAVE = 2 # Also run on exit from the control.
|
||||||
|
|
||||||
# This is used by dropdown.py
|
# This is used by dropdown.py and menu.py
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def dimensions(writer, elements, dlines):
|
def dimensions(writer, elements, dlines):
|
||||||
# Height of a single entry in list.
|
# Height of a single entry in list.
|
||||||
|
|
|
@ -26,7 +26,7 @@ class SubMenu(Window):
|
||||||
# depends on number and length of elements.
|
# depends on number and length of elements.
|
||||||
te = [x[0] for x in elements] # Text part
|
te = [x[0] for x in elements] # Text part
|
||||||
self.elements = elements
|
self.elements = elements
|
||||||
entry_height, lb_height, textwidth = Listbox.dimensions(wri, te)
|
entry_height, lb_height, _, textwidth = Listbox.dimensions(wri, te, None)
|
||||||
lb_width = textwidth + 2
|
lb_width = textwidth + 2
|
||||||
# Calculate Window dimensions
|
# Calculate Window dimensions
|
||||||
ap_height = lb_height + 6 # Allow for listbox border
|
ap_height = lb_height + 6 # Allow for listbox border
|
||||||
|
|
|
@ -51,4 +51,4 @@ sel = Pin(16, Pin.IN, Pin.PULL_UP) # Operate current control
|
||||||
prev = Pin(18, Pin.IN, Pin.PULL_UP) # Move to previous control
|
prev = Pin(18, Pin.IN, Pin.PULL_UP) # Move to previous control
|
||||||
increase = Pin(20, Pin.IN, Pin.PULL_UP) # Increase control's value
|
increase = Pin(20, Pin.IN, Pin.PULL_UP) # Increase control's value
|
||||||
decrease = Pin(17, Pin.IN, Pin.PULL_UP) # Decrease control's value
|
decrease = Pin(17, Pin.IN, Pin.PULL_UP) # Decrease control's value
|
||||||
display = Display(ssd, nxt, sel, prev, increase, decrease, 5)
|
display = Display(ssd, nxt, sel, prev, increase, decrease) #, 5)
|
||||||
|
|
Ładowanie…
Reference in New Issue