Revert "Update components.py"

This reverts commit d18b1c6a2d.
This commit is contained in:
Jeroen Oudshoorn
2023-11-18 17:35:23 +01:00
parent 31262b249f
commit 61ed4ba653

View File

@ -40,37 +40,21 @@ class FilledRect(Widget):
class Text(Widget): class Text(Widget):
def __init__(self, value="", position=(0, 0), font=None, color=0, wrap=False, max_length=0, png=False): def __init__(self, value="", position=(0, 0), font=None, color=0, wrap=False, max_length=0):
super().__init__(position, color) super().__init__(position, color)
self.value = value self.value = value
self.font = font self.font = font
self.wrap = wrap self.wrap = wrap
self.max_length = max_length self.max_length = max_length
self.wrapper = TextWrapper(width=self.max_length, replace_whitespace=False) if wrap else None self.wrapper = TextWrapper(width=self.max_length, replace_whitespace=False) if wrap else None
self.png = png
def draw(self, canvas, drawer): def draw(self, canvas, drawer):
if self.value is not None: if self.value is not None:
if not self.png: if self.wrap:
if self.wrap: text = '\n'.join(self.wrapper.wrap(self.value))
text = '\n'.join(self.wrapper.wrap(self.value))
else:
text = self.value
drawer.text(self.xy, text, font=self.font, fill=self.color)
else: else:
self.image = Image.open(self.value) text = self.value
self.image = self.image.convert('RGBA') drawer.text(self.xy, text, font=self.font, fill=self.color)
self.pixels = self.image.load()
for y in range(self.image.size[1]):
for x in range(self.image.size[0]):
if self.pixels[x,y][3] < 255: # check alpha
self.pixels[x,y] = (255, 255, 255, 255)
if self.color == 255:
self._image = ImageOps.colorize(self.image.convert('L'), black = "black", white = "yellow")
else:
self._image = self.image
self.image = self._image.convert('1')
canvas.paste(self.image, self.xy)
class LabeledValue(Widget): class LabeledValue(Widget):