

def update(self, pygsurf=None):
    if (pygsurf is None):
        pygsurf = self.pygsurf
    (x, y, width, height) = pygsurf.getregion((self.x, self.y, self.width, self.height))
    if ((x, y, width, height) == (None, None, None, None)):
        return
    fgcolor = (((self.fgcolor is None) and pygsurf.fgcolor) or self.fgcolor)
    bgcolor = (((self.bgcolor is None) and pygsurf.bgcolor) or self.bgcolor)
    for ix in range(x, (x + width)):
        for iy in range(y, (y + height)):
            pygsurf._screenfgcolor[ix][iy] = fgcolor
            pygsurf._screenbgcolor[ix][iy] = bgcolor
            pygsurf._screenchar[ix][iy] = ' '
            pygsurf._screendirty[ix][iy] = True
    (x, y, width, height) = pygsurf.getregion((self.x, self.y, self.width, self.height), False)
    if ((x, y, width, height) == (None, None, None, None)):
        return
    if (self.border in ('basic', 'rounded')):
        if pygsurf.isonscreen(x, y):
            pygsurf._screenchar[x][y] = (((self.border == 'basic') and '+') or '/')
        if pygsurf.isonscreen(((x + width) - 1), y):
            pygsurf._screenchar[((x + width) - 1)][y] = (((self.border == 'basic') and '+') or '\\')
        if pygsurf.isonscreen(x, ((y + height) - 1)):
            pygsurf._screenchar[x][((y + height) - 1)] = (((self.border == 'basic') and '+') or '\\')
        if pygsurf.isonscreen(((x + width) - 1), ((y + height) - 1)):
            pygsurf._screenchar[((x + width) - 1)][((y + height) - 1)] = (((self.border == 'basic') and '+') or '/')
        for ix in range((x + 1), ((x + width) - 1)):
            if pygsurf.isonscreen(ix, y):
                pygsurf._screenchar[ix][y] = '-'
            if pygsurf.isonscreen(ix, ((y + height) - 1)):
                pygsurf._screenchar[ix][((y + height) - 1)] = '-'
        for iy in range((y + 1), ((y + height) - 1)):
            if pygsurf.isonscreen(x, iy):
                pygsurf._screenchar[x][iy] = '|'
            if pygsurf.isonscreen(((x + width) - 1), iy):
                pygsurf._screenchar[((x + width) - 1)][iy] = '|'
    elif ((self.border is not None) and (len(self.border) == 1)):
        for ix in range(x, (x + width)):
            if pygsurf.isonscreen(ix, y):
                pygsurf._screenchar[ix][y] = self.border
            if pygsurf.isonscreen(ix, ((y + height) - 1)):
                pygsurf._screenchar[ix][((y + height) - 1)] = self.border
        for iy in range((y + 1), ((y + height) - 1)):
            if pygsurf.isonscreen(x, iy):
                pygsurf._screenchar[x][iy] = border
            if pygsurf.isonscreen(((x + width) - 1), iy):
                pygsurf._screenchar[((x + width) - 1)][iy] = border
    if self.caption:
        for i in range(len(self.caption)):
            if (((i + 2) > (self.width - 2)) or (not pygsurf.isonscreen(((x + i) + 2), y))):
                continue
            pygsurf._screenchar[((x + i) + 2)][y] = self.caption[i]
    if (self.shadow is not None):
        pygsurf.addshadow(x=x, y=y, width=width, height=height, amount=self.shadowamount, direction=self.shadow, xoffset=self.shadowxoffset, yoffset=self.shadowyoffset)
    if (self.text == ''):
        return
    text = self.getdisplayedtext()
    if (text == ''):
        return
    if (self.border is not None):
        x += 1
        y += 1
        width -= 2
        height -= 2
    if ((not self.border) and self.caption):
        y += 1
        height -= 1
    x += self.marginleft
    y += self.margintop
    width -= (self.marginleft + self.marginright)
    height -= (self.margintop + self.marginbottom)
    if (y < 0):
        text = text[abs(y):]
        y = 0
    maxDisplayedLines = ((((y + height) < pygsurf._height) and height) or max(0, (pygsurf._height - y)))
    truncateLeftChars = (((x < 0) and abs(x)) or 0)
    maxDisplayedLength = ((((x + width) < pygsurf._width) and width) or max(0, (pygsurf._width - x)))
    iy = 0
    for line in text:
        if ((y + iy) >= pygsurf._height):
            break
        for ix in range(truncateLeftChars, min(len(line), maxDisplayedLength)):
            pygsurf._screenchar[(x + ix)][(y + iy)] = line[ix]
        iy += 1

dataset/ETHPy150Open asweigart/pygcurse/pygcurse/__init__.py PygcurseTextbox.update/original