From a3dc83f357230113fbf43bb10f31f28fa0afcce1 Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Thu, 13 Jan 2022 17:47:34 +0000 Subject: [PATCH] Fix window with one active widget closing on pressing button. --- gui/core/ugui.py | 9 ++++++--- gui/widgets/listbox.py | 4 ++-- gui/widgets/menu.py | 2 +- hardware_setup.py | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gui/core/ugui.py b/gui/core/ugui.py index a97dfd2..649b739 100644 --- a/gui/core/ugui.py +++ b/gui/core/ugui.py @@ -261,6 +261,8 @@ class Screen: if isinstance(cs_old, Window): raise ValueError('Windows are modal.') new_screen = cls_new_screen(*args, **kwargs) + if not len(new_screen.lstactive): + raise ValueError("Screen has no active widgets.") else: raise ValueError('Must pass Screen class or subclass (not instance)') new_screen.parent = cs_old @@ -411,10 +413,10 @@ class Screen: lo.show() # Re-display with new status co.enter() # Tell object it has currency co.show() - elif isinstance(self, Window): + #elif isinstance(self, Window): # Special case of Window with one object: leave # without making changes (Dropdown in particular) - Screen.back() + #Screen.back() done = True # Move currency to a specific control. @@ -488,7 +490,8 @@ class Window(Screen): cls._value = val 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) self.row = row self.col = col diff --git a/gui/widgets/listbox.py b/gui/widgets/listbox.py index f72ed12..239c7b2 100644 --- a/gui/widgets/listbox.py +++ b/gui/widgets/listbox.py @@ -1,7 +1,7 @@ # listbox.py Extension to ugui providing the Listbox class # 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. @@ -18,7 +18,7 @@ class Listbox(Widget): ON_MOVE = 1 # Also run whenever the currency moves. 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 def dimensions(writer, elements, dlines): # Height of a single entry in list. diff --git a/gui/widgets/menu.py b/gui/widgets/menu.py index b1923bf..11b3b6e 100644 --- a/gui/widgets/menu.py +++ b/gui/widgets/menu.py @@ -26,7 +26,7 @@ class SubMenu(Window): # depends on number and length of elements. te = [x[0] for x in elements] # Text part 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 # Calculate Window dimensions ap_height = lb_height + 6 # Allow for listbox border diff --git a/hardware_setup.py b/hardware_setup.py index 3049d80..a1ece16 100644 --- a/hardware_setup.py +++ b/hardware_setup.py @@ -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 increase = Pin(20, Pin.IN, Pin.PULL_UP) # Increase 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)