diff --git a/TTkAbstract/abstractscrollarea.html b/TTkAbstract/abstractscrollarea.html index cfde17be..32310424 100644 --- a/TTkAbstract/abstractscrollarea.html +++ b/TTkAbstract/abstractscrollarea.html @@ -411,7 +411,6 @@ class TTkAbstractScrollArea(TTkWidget):
  • moveEvent
  • paintChildCanvas
  • paintEvent
  • -
  • paintNotifyParent
  • removeWidget
  • resize
  • resizeEvent
  • diff --git a/TTkAbstract/abstractscrollview.html b/TTkAbstract/abstractscrollview.html index 344296a3..475d7e14 100644 --- a/TTkAbstract/abstractscrollview.html +++ b/TTkAbstract/abstractscrollview.html @@ -375,7 +375,6 @@ def viewMoveTo(self, x, y):
  • moveEvent
  • paintChildCanvas
  • paintEvent
  • -
  • paintNotifyParent
  • removeWidget
  • resize
  • resizeEvent
  • diff --git a/TTkCore/canvas.html b/TTkCore/canvas.html index db502222..d46fb1e3 100644 --- a/TTkCore/canvas.html +++ b/TTkCore/canvas.html @@ -55,10 +55,9 @@ import math import TermTk.libbpytop as lbt from TermTk.TTkCore.constant import TTkK from TermTk.TTkCore.log import TTkLog -from TermTk.TTkCore.cfg import * -from TermTk.TTkCore.color import * -from TermTk.TTkCore.helper import * -from TermTk.TTkGui.theme import * +from TermTk.TTkCore.cfg import TTkCfg, TTkGlbl +from TermTk.TTkCore.color import TTkColor +from TermTk.TTkCore.helper import TTkHelper class TTkCanvas: ''' @@ -77,10 +76,17 @@ class TTkCanvas: in w = the width of the new canvas in h = the height of the new canvas ''' - __slots__ = ('_widget', '_width', '_height', '_newWidth', '_newHeight','_theme', '_data', '_colors', '_visible') + __slots__ = ( + '_widget', + '_width', '_height', '_newWidth', '_newHeight', + '_theme', + '_data', '_colors', + '_bufferedData', '_bufferedColors', + '_visible', '_doubleBuffer') def __init__(self, *args, **kwargs): self._widget = kwargs.get('widget', None) self._visible = True + self._doubleBuffer = False self._width = 0 self._height = 0 self._data = [[0]] @@ -93,6 +99,10 @@ class TTkCanvas: def getWidget(self): return self._widget + def enableDoubleBuffer(self): + self._doubleBuffer = True + self._bufferedData, self._bufferedColors = self.copy() + def updateSize(self): if not self._visible: return w,h = self._newWidth, self._newHeight @@ -103,8 +113,14 @@ class TTkCanvas: for i in range(0,h): self._data[i] = [' ']*w self._colors[i] = [TTkColor.RST]*w - self._width = w + if self._doubleBuffer: + self._bufferedData = [[]]*h + self._bufferedColors = [[]]*h + for i in range(0,h): + self._bufferedData[i] = ['']*w + self._bufferedColors[i] = [TTkColor.RST]*w self._height = h + self._width = w def resize(self, w, h): self._newWidth = w @@ -119,6 +135,18 @@ class TTkCanvas: self._data[iy][ix] = ' ' self._colors[iy][ix] = TTkColor.RST + def copy(self): + w,h = self._width, self._height + retData = [[]]*h + retColors = [[]]*h + for iy in range(h): + retData[iy] = [' ']*w + retColors[iy] = [TTkColor.RST]*w + for ix in range(w): + retData[iy][ix] = self._data[iy][ix] + retColors[iy][ix] = self._colors[iy][ix] + return retData, retColors + def hide(self): self._visible = False @@ -209,6 +237,8 @@ class TTkCanvas: elif alignment == TTkK.JUSTIFY: # TODO: Text Justification text = text + " "*pad + else: + text=text[:width] arr = list(text) for i in range(0, len(arr)): @@ -532,7 +562,40 @@ class TTkCanvas: ansi += color-lastcolor lastcolor = color ansi+=ch - lbt.Term.push(ansi) + lbt.Term.push(ansi) + + def pushToTerminalBuffered(self, x, y, w, h): + # TTkLog.debug("pushToTerminal") + oldData, oldColors = self._bufferedData, self._bufferedColors + lastcolor = TTkColor.RST + empty = True + ansi = "" + for y in range(0, self._height): + for x in range(0, self._width): + if self._data[y][x] == oldData[y][x] and \ + self._colors[y][x] == oldColors[y][x]: + if not empty: + lbt.Term.push(ansi) + empty=True + continue + ch = self._data[y][x] + color = self._colors[y][x] + if empty: + ansi = color+lbt.Mv.t(y+1,x+1) + #lastcolor = color + empty = False + if color != lastcolor: + ansi += color-lastcolor + lastcolor = color + ansi+=ch + if not empty: + lbt.Term.push(ansi) + empty=True + # Reset the color at the end + lbt.Term.push(TTkColor.RST) + # Switch the buffer + self._bufferedData, self._bufferedColors = self._data, self._colors + self._data, self._colors = oldData, oldColors
    @@ -584,10 +647,17 @@ h = the height of the new canvas

    in w = the width of the new canvas in h = the height of the new canvas ''' - __slots__ = ('_widget', '_width', '_height', '_newWidth', '_newHeight','_theme', '_data', '_colors', '_visible') + __slots__ = ( + '_widget', + '_width', '_height', '_newWidth', '_newHeight', + '_theme', + '_data', '_colors', + '_bufferedData', '_bufferedColors', + '_visible', '_doubleBuffer') def __init__(self, *args, **kwargs): self._widget = kwargs.get('widget', None) self._visible = True + self._doubleBuffer = False self._width = 0 self._height = 0 self._data = [[0]] @@ -600,6 +670,10 @@ h = the height of the new canvas

    def getWidget(self): return self._widget + def enableDoubleBuffer(self): + self._doubleBuffer = True + self._bufferedData, self._bufferedColors = self.copy() + def updateSize(self): if not self._visible: return w,h = self._newWidth, self._newHeight @@ -610,8 +684,14 @@ h = the height of the new canvas

    for i in range(0,h): self._data[i] = [' ']*w self._colors[i] = [TTkColor.RST]*w - self._width = w + if self._doubleBuffer: + self._bufferedData = [[]]*h + self._bufferedColors = [[]]*h + for i in range(0,h): + self._bufferedData[i] = ['']*w + self._bufferedColors[i] = [TTkColor.RST]*w self._height = h + self._width = w def resize(self, w, h): self._newWidth = w @@ -626,6 +706,18 @@ h = the height of the new canvas

    self._data[iy][ix] = ' ' self._colors[iy][ix] = TTkColor.RST + def copy(self): + w,h = self._width, self._height + retData = [[]]*h + retColors = [[]]*h + for iy in range(h): + retData[iy] = [' ']*w + retColors[iy] = [TTkColor.RST]*w + for ix in range(w): + retData[iy][ix] = self._data[iy][ix] + retColors[iy][ix] = self._colors[iy][ix] + return retData, retColors + def hide(self): self._visible = False @@ -716,6 +808,8 @@ h = the height of the new canvas

    elif alignment == TTkK.JUSTIFY: # TODO: Text Justification text = text + " "*pad + else: + text=text[:width] arr = list(text) for i in range(0, len(arr)): @@ -1039,7 +1133,40 @@ h = the height of the new canvas

    ansi += color-lastcolor lastcolor = color ansi+=ch - lbt.Term.push(ansi) + lbt.Term.push(ansi) + + def pushToTerminalBuffered(self, x, y, w, h): + # TTkLog.debug("pushToTerminal") + oldData, oldColors = self._bufferedData, self._bufferedColors + lastcolor = TTkColor.RST + empty = True + ansi = "" + for y in range(0, self._height): + for x in range(0, self._width): + if self._data[y][x] == oldData[y][x] and \ + self._colors[y][x] == oldColors[y][x]: + if not empty: + lbt.Term.push(ansi) + empty=True + continue + ch = self._data[y][x] + color = self._colors[y][x] + if empty: + ansi = color+lbt.Mv.t(y+1,x+1) + #lastcolor = color + empty = False + if color != lastcolor: + ansi += color-lastcolor + lastcolor = color + ansi+=ch + if not empty: + lbt.Term.push(ansi) + empty=True + # Reset the color at the end + lbt.Term.push(TTkColor.RST) + # Switch the buffer + self._bufferedData, self._bufferedColors = self._data, self._colors + self._data, self._colors = oldData, oldColors

    Methods

    @@ -1062,6 +1189,28 @@ h = the height of the new canvas

    self._colors[iy][ix] = TTkColor.RST +
    +def copy(self) +
    +
    +
    +
    + +Expand source code + +
    def copy(self):
    +    w,h = self._width, self._height
    +    retData = [[]]*h
    +    retColors = [[]]*h
    +    for iy in range(h):
    +        retData[iy] = [' ']*w
    +        retColors[iy] = [TTkColor.RST]*w
    +        for ix in range(w):
    +            retData[iy][ix] = self._data[iy][ix]
    +            retColors[iy][ix] = self._colors[iy][ix]
    +    return retData, retColors
    +
    +
    def drawBox(self, pos, size, color=<TermTk.TTkCore.color._TTkColor object>, grid=0)
    @@ -1493,6 +1642,8 @@ h = the height of the new canvas

    elif alignment == TTkK.JUSTIFY: # TODO: Text Justification text = text + " "*pad + else: + text=text[:width] arr = list(text) for i in range(0, len(arr)): @@ -1519,6 +1670,20 @@ h = the height of the new canvas

    self._set(y+i, x, ln[1], color) +
    +def enableDoubleBuffer(self) +
    +
    +
    +
    + +Expand source code + +
    def enableDoubleBuffer(self):
    +    self._doubleBuffer = True
    +    self._bufferedData, self._bufferedColors = self.copy()
    +
    +
    def execPaint(self, winw, winh)
    @@ -1628,6 +1793,49 @@ h = the height of the new canvas

    lbt.Term.push(ansi) +
    +def pushToTerminalBuffered(self, x, y, w, h) +
    +
    +
    +
    + +Expand source code + +
    def pushToTerminalBuffered(self, x, y, w, h):
    +    # TTkLog.debug("pushToTerminal")
    +    oldData, oldColors = self._bufferedData, self._bufferedColors
    +    lastcolor = TTkColor.RST
    +    empty = True
    +    ansi = ""
    +    for y in range(0, self._height):
    +        for x in range(0, self._width):
    +            if self._data[y][x] == oldData[y][x] and \
    +               self._colors[y][x] == oldColors[y][x]:
    +                if not empty:
    +                    lbt.Term.push(ansi)
    +                    empty=True
    +                continue
    +            ch = self._data[y][x]
    +            color = self._colors[y][x]
    +            if empty:
    +                ansi = color+lbt.Mv.t(y+1,x+1)
    +                #lastcolor = color
    +                empty = False
    +            if color != lastcolor:
    +                ansi += color-lastcolor
    +                lastcolor = color
    +            ansi+=ch
    +        if not empty:
    +            lbt.Term.push(ansi)
    +            empty=True
    +    # Reset the color at the end
    +    lbt.Term.push(TTkColor.RST)
    +    # Switch the buffer
    +    self._bufferedData, self._bufferedColors = self._data, self._colors
    +    self._data, self._colors = oldData, oldColors
    +
    +
    def resize(self, w, h)
    @@ -1674,8 +1882,14 @@ h = the height of the new canvas

    for i in range(0,h): self._data[i] = [' ']*w self._colors[i] = [TTkColor.RST]*w - self._width = w - self._height = h + if self._doubleBuffer: + self._bufferedData = [[]]*h + self._bufferedColors = [[]]*h + for i in range(0,h): + self._bufferedData[i] = ['']*w + self._bufferedColors[i] = [TTkColor.RST]*w + self._height = h + self._width = w
    @@ -1698,8 +1912,9 @@ h = the height of the new canvas