From 8396ffd0dcfbe534ca4623b84c0d23c134c2942f Mon Sep 17 00:00:00 2001 From: Eugenio Parodi Date: Thu, 29 Dec 2022 16:29:47 +0100 Subject: [PATCH] FIX: (performances) Avoid unnecessary updatepaint events --- TermTk/TTkCore/helper.py | 2 + TermTk/TTkCore/ttk.py | 3 ++ TermTk/TTkWidgets/widget.py | 9 ++-- .../tests/Widechar_Performances.canvas | 7 +++ tests/test.generic.002.py | 45 +++++++++++++++++++ 5 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 docs/MDNotes/tests/Widechar_Performances.canvas create mode 100644 tests/test.generic.002.py diff --git a/TermTk/TTkCore/helper.py b/TermTk/TTkCore/helper.py index 039f4c1e..221a71a6 100644 --- a/TermTk/TTkCore/helper.py +++ b/TermTk/TTkCore/helper.py @@ -158,6 +158,8 @@ class TTkHelper: TTkHelper._rootWidget.rootLayout().addWidget(widget) widget.setFocus() widget.raiseWidget() + for w in widget.rootLayout().iterWidgets(onlyVisible=True): + w.update() @staticmethod def getOverlay(): diff --git a/TermTk/TTkCore/ttk.py b/TermTk/TTkCore/ttk.py index 0e0f9882..15d24729 100644 --- a/TermTk/TTkCore/ttk.py +++ b/TermTk/TTkCore/ttk.py @@ -288,3 +288,6 @@ class TTk(TTkWidget): # so CTRL-C can be redirected to the default handler if the app does not exit signal.signal(signal.SIGINT, signal.SIG_DFL) self.quit() + + def isVisibleAndParent(self): + return self.isVisible() \ No newline at end of file diff --git a/TermTk/TTkWidgets/widget.py b/TermTk/TTkWidgets/widget.py index 5d26b953..039f344f 100644 --- a/TermTk/TTkWidgets/widget.py +++ b/TermTk/TTkWidgets/widget.py @@ -534,6 +534,8 @@ class TTkWidget(TMouseEvents,TKeyEvents, TDragEvents): self._visible = True self._canvas.show() self.update(updateLayout=True, updateParent=True) + for w in self.rootLayout().iterWidgets(onlyVisible=True): + w.update() @pyTTkSlot() def hide(self): @@ -570,10 +572,9 @@ class TTkWidget(TMouseEvents,TKeyEvents, TDragEvents): else: self.hide() def isVisibleAndParent(self): - if self._parent is None: - return self._visible - else: - return self._visible & self._parent.isVisible() + return ( self._visible and + ( self._parent is not None ) and + self._parent.isVisibleAndParent() ) def isVisible(self): return self._visible diff --git a/docs/MDNotes/tests/Widechar_Performances.canvas b/docs/MDNotes/tests/Widechar_Performances.canvas new file mode 100644 index 00000000..a973ac4f --- /dev/null +++ b/docs/MDNotes/tests/Widechar_Performances.canvas @@ -0,0 +1,7 @@ +{ + "nodes":[ + {"id":"a4573e875ea36f20","x":-1246,"y":-354,"width":928,"height":275,"type":"text","text":"```\n3537923 function calls (3418179 primitive calls) in 6.790 seconds\n\n185542/179027 0.010 0.000 0.011 0.000 {built-in method builtins.len}\n 176870 0.009 0.000 0.009 0.000 {built-in method unicodedata.east_asian_width}\n 174285 0.009 0.000 0.009 0.000 {built-in method unicodedata.category}\n 169998 0.020 0.000 0.029 0.000 /home/one/github/Varie/pyTermTk.002/TermTk/TTkCore/string.py:603\n 169998 0.022 0.000 0.031 0.000 /home/one/github/Varie/pyTermTk.002/TermTk/TTkCore/string.py:604\n \n 21356 0.003 0.000 0.004 0.000 /home/one/github/Varie/pyTermTk.002/TermTk/TTkCore/string.py:593\n\n```"}, + {"id":"e0d1286c4dfd7bd0","x":-1246,"y":-49,"width":928,"height":250,"type":"text","text":"```\n3559400 function calls (3440738 primitive calls) in 16.278 seconds\n\n184908/178405 0.010 0.000 0.011 0.000 {built-in method builtins.len}\n 184286 0.009 0.000 0.009 0.000 {built-in method unicodedata.east_asian_width}\n 182038 0.009 0.000 0.009 0.000 {built-in method unicodedata.category}\n 177747 0.021 0.000 0.029 0.000 /home/one/github/Varie/pyTermTk.002/TermTk/TTkCore/string.py:603\n 177747 0.023 0.000 0.032 0.000 /home/one/github/Varie/pyTermTk.002/TermTk/TTkCore/string.py:604\n\n 21851 0.003 0.000 0.004 0.000 /home/one/github/Varie/pyTermTk.002/TermTk/TTkCore/string.py:593\n```"} + ], + "edges":[] +} \ No newline at end of file diff --git a/tests/test.generic.002.py b/tests/test.generic.002.py new file mode 100644 index 00000000..baff4af7 --- /dev/null +++ b/tests/test.generic.002.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +class A(): + __slots__ = ('a') + def __init__(self): + self.a = 1 + +class B(): + # __slots__ = ('b') + def __init__(self): + self.b = 1 + +class C(A,B): + __slots__ = ('c') + def __init__(self): + A.__init__(self) + B.__init__(self) + self.c = 1 + # self.d = 1 + +c = C() + +print(c) \ No newline at end of file