Browse Source

FIX: (performances) Avoid unnecessary updatepaint events

pull/95/head
Eugenio Parodi 3 years ago
parent
commit
8396ffd0dc
  1. 2
      TermTk/TTkCore/helper.py
  2. 3
      TermTk/TTkCore/ttk.py
  3. 9
      TermTk/TTkWidgets/widget.py
  4. 7
      docs/MDNotes/tests/Widechar_Performances.canvas
  5. 45
      tests/test.generic.002.py

2
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():

3
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()

9
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

7
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":[]
}

45
tests/test.generic.002.py

@ -0,0 +1,45 @@
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2021 Eugenio Parodi <ceccopierangiolieugenio AT googlemail DOT com>
#
# 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)
Loading…
Cancel
Save