fixed cutoff bug

This commit is contained in:
Neythen Treloar 2022-02-22 21:31:04 +00:00
parent c59a8cb709
commit ff4aa4376f

View File

@ -57,7 +57,7 @@ class StockTicker():
options.chain_length = 2 options.chain_length = 2
options.parallel = 1 options.parallel = 1
options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat' options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat'
options.gpio_slowdown = 1 options.gpio_slowdown = 4
options.brightness = self.brightness options.brightness = self.brightness
self.matrix = RGBMatrix(options = options) self.matrix = RGBMatrix(options = options)
print(dir(self.matrix)) print(dir(self.matrix))
@ -835,44 +835,34 @@ class StockTicker():
#Draw Ticker, current and change onto one image #Draw Ticker, current and change onto one image
def textToImage(self, TICKER, CURRENT, ARROW, percent_change = False, point_change = False, font = ImageFont.load("./fonts/10x20.pil")): def textToImage(self, TICKER, CURRENT, ARROW, percent_change = False, point_change = False, font = ImageFont.load("./fonts/10x20.pil")):
w1, text_height = self.get_text_dimensions(TICKER, font)
w2, text_height = self.get_text_dimensions(CURRENT, font)
w1, text_height = self.get_text_dimensions(CURRENT, font)
w2, text_height = self.get_text_dimensions(TICKER, font)
text_width_current = max(w1,w2) text_width_current = max(w1,w2)
img = Image.new('RGB', (text_width_current +100 , 32)) img = Image.new('RGB', (text_width_current +1000 , 32))
d = ImageDraw.Draw(img) d = ImageDraw.Draw(img)
d.text((4, 0), TICKER, fill=(255, 255, 255), font=font) d.text((4, 0), TICKER, fill=(255, 255, 255), font=font)
d.text((4, 16), CURRENT, fill=self.greenORred, font=font) d.text((4, 16), CURRENT, fill=self.greenORred, font=font)
if percent_change:
d.text(((w1+7), 14 - text_height), percent_change, fill=self.greenORred, font=font)
w, h = self.get_text_dimensions(percent_change, font)
w1 += 7 + w
if point_change: if point_change:
d.text(((w1+29), 16), point_change, fill=self.greenORred, font=font) img.paste(ARROW, ((w2+ 9),18))
d.text(((w2+29), 16), point_change, fill=self.greenORred, font=font)
if percent_change: w,h = self.get_text_dimensions(point_change, font)
d.text(((w2+7), 14 - text_height), percent_change, fill=self.greenORred, font=font) w2 += 29 + w
if point_change or percent_change:
img.paste(ARROW, ((w1+ 9),18))
text_width_change=0
if percent_change:
width, text_height = self.get_text_dimensions(percent_change, font)
text_width_change = max(width, text_width_change)
elif point_change:
width, text_height = self.get_text_dimensions(point_change, font)
text_width_change = max(width, text_width_change)
newWidth = text_width_current + text_width_change +30 img = img.crop((0,0,max(w1, w2) + 20,32))
img = img.crop((0,0,newWidth,32))
return img return img
def textToImageProf(self, TICKER, CURRENT, CHANGE, ARROW, font): def textToImageProf(self, TICKER, CURRENT, CHANGE, ARROW, font):
@ -945,7 +935,7 @@ class StockTicker():
arrow, change = self.getArrow(point_change) arrow, change = self.getArrow(point_change)
percent_change = str(abs(percent_change)) percent_change = str(abs(percent_change)) + '%'
point_change = str(abs(point_change)) point_change = str(abs(point_change))
current = str(current) current = str(current)