From bfb4feae182af577d421cafec160145a185e3371 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 20 Jul 2023 15:29:45 +0800 Subject: [PATCH] fixed spacing issues with e-mini items in prof display --- stockTicker.py | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/stockTicker.py b/stockTicker.py index b46bd58..85eabad 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -946,27 +946,47 @@ class StockTicker(): img = img.crop((0,0,max(w1, w2) + 20,32)) return img - + + def textToImageProf(self, TICKER, CURRENT, CHANGE, ARROW, font): - text_width_current, text_height = self.get_text_dimensions(CURRENT, font) - - img = Image.new('RGB', (text_width_current +100 , 32)) - d = ImageDraw.Draw(img) + if 'E-MINI' in TICKER: + w1, text_height = self.get_text_dimensions(TICKER, font) + w2, text_height = self.get_text_dimensions(CURRENT, font) + text_width_current = max(w1,w2) - d.text((4, 0), TICKER, fill=(255, 255, 255), font=font) - d.text((4, 8), CURRENT, fill=self.greenORred, font=font) + img = Image.new('RGB', (text_width_current +100 , 32)) + d = ImageDraw.Draw(img) - img.paste(ARROW, ((text_width_current + 7),10)) - d.text(((text_width_current+18), 8), CHANGE, fill=self.greenORred, font=font) + d.text((4, 0), TICKER, fill=(255, 255, 255), font=font) + d.text((4, 8), CURRENT, fill=self.greenORred, font=font) - text_width_change, text_height = self.get_text_dimensions(CHANGE, font) + img.paste(ARROW, ((w2 + 7),10)) + d.text(((w2+18), 8), CHANGE, fill=self.greenORred, font=font) - newWidth = text_width_current + text_width_change +30 + text_width_change, text_height = self.get_text_dimensions(CHANGE, font) + newWidth = max(w2 + text_width_change, text_width_current) +15 + img = img.crop((0,0,newWidth,32)) - img = img.crop((0,0,newWidth,32)) + else: + text_width_current, text_height = self.get_text_dimensions(CURRENT, font) + + img = Image.new('RGB', (text_width_current +100 , 32)) + d = ImageDraw.Draw(img) + + d.text((4, 0), TICKER, fill=(255, 255, 255), font=font) + d.text((4, 8), CURRENT, fill=self.greenORred, font=font) + + img.paste(ARROW, ((text_width_current + 7),10)) + d.text(((text_width_current+18), 8), CHANGE, fill=self.greenORred, font=font) + + text_width_change, text_height = self.get_text_dimensions(CHANGE, font) + newWidth = text_width_current + text_width_change +30 + img = img.crop((0,0,newWidth,32)) + return img + #Stitch the logo & prices picture into one image def stitchImage(self, image_list): widths, heights = zip(*(i.size for i in image_list))