diff --git a/test/python/PikaUI/PikaUI.py b/test/python/PikaUI/PikaUI.py index 6f7533215..203af624f 100644 --- a/test/python/PikaUI/PikaUI.py +++ b/test/python/PikaUI/PikaUI.py @@ -28,6 +28,7 @@ class Widget: align = None text = None isroot = False + needbuild = True _label = None _child = [] @@ -50,6 +51,12 @@ class Widget: self.parent = weakref.ref(parent) def update(self): + if self.needbuild: + built = self.build() + if not built is None: + self = self.add(built) + self.needbuild = False + if self.parent is None: print('self.parent is None') return @@ -96,13 +103,23 @@ class Widget: self._child.append(c) return self + def clean(self): + if self.backend is None: + return + if self.needbuild: + return + self.backend.clean() + self.needbuild = True + #! Memory Error + # self._child = [] + class Page(Widget): def __init__(self): super().__init__() self._setPerent(self) self.isroot = True - self.backend = _backend.Screen() + self.backend = _backend.screen() class Button(Widget): @@ -119,22 +136,21 @@ class Text(Widget): class PageManager: - pageThis = None + pageThis: Page = None pageList = [] def enter(self, page: Page): self.clean() self.pageThis = page self.pageList.append(page) - page = page.add(page.build()) self.update() def back(self): if len(self.pageList) <= 1: return + self.clean() _ = self.pageList.pop() self.pageThis = self.pageList[-1] - self.clean() self.update() def update(self): @@ -143,7 +159,9 @@ class PageManager: self.pageThis.update() def clean(self): - _backend.clean() + if self.pageThis is None: + return + self.pageThis.clean() class _App: diff --git a/test/python/PikaUI/PikaUI_backend_text.py b/test/python/PikaUI/PikaUI_backend_text.py index fe2141379..8f5358c80 100644 --- a/test/python/PikaUI/PikaUI_backend_text.py +++ b/test/python/PikaUI/PikaUI_backend_text.py @@ -20,8 +20,11 @@ class widget: def set_text(self, text): print('%s.set_text("%s")' % (self.name, text)) + + def clean(self): + print("%s.clean()" % (self.name)) -class Screen: +class Screen(widget): name = "screen" _screen = Screen(None) @@ -31,6 +34,3 @@ class label(widget): def screen(): return _screen - -def clean(): - print('screen.clean()') diff --git a/test/python/PikaUI/test_page.py b/test/python/PikaUI/test_page.py index 2ab51756d..8bb0de140 100644 --- a/test/python/PikaUI/test_page.py +++ b/test/python/PikaUI/test_page.py @@ -1,10 +1,9 @@ import PikaUI as ui from PikaStdLib import MemChecker as mem -page1 = ui.Page().add( - ui.Text('Hello Page1') -) - +class Page1(ui.Page): + def build(self): + return ui.Text('Hello Page1') class Page2(ui.Page): def build(self): @@ -12,6 +11,6 @@ class Page2(ui.Page): app = ui.App() -app.pageManager.enter(page1) +app.pageManager.enter(Page1()) app.pageManager.enter(Page2()) app.pageManager.back()