multiprocessing used to update images in background

This commit is contained in:
Neythen 2021-05-14 13:55:43 +01:00
parent 5c0fb44766
commit 3e59b011e1
3 changed files with 19 additions and 11 deletions

BIN
final.ppm

Binary file not shown.

Binary file not shown.

View File

@ -16,7 +16,7 @@ import requests
import pexpect
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from rgbmatrix.graphics import *
from multiprocessing import Process
def getInput(Block=False):
if Block or select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
@ -91,7 +91,7 @@ class StockTicker():
image = self.openImage(image_file)
img_width, img_height = image.size
print(offset_x, offset_y)
while offset_x > -img_width:
offset_x -= 1
@ -107,14 +107,22 @@ class StockTicker():
while True:
if current_img == 1:
if stocks: self.getFullStockImage(1)
if stocks:
update_process = Process(target = self.getFullStockImage, args = (1,))
update_process.start()
image1 = self.openImage(image_files[0])
image2 = self.openImage(image_files[1])
elif current_img == 2:
if stocks: self.getFullStockImage(2)
if stocks:
update_process = Process(target = self.getFullStockImage, args = (2,))
update_process.start()
image1 = self.openImage(image_files[1])
image2 = self.openImage(image_files[0])
img_width, img_height = image1.size
@ -143,7 +151,8 @@ class StockTicker():
if kill: break
if stocks:
update_process.join()
if current_img == 1:
current_img = 2
elif current_img == 2:
@ -261,9 +270,7 @@ class StockTicker():
change = float(info[0])-float(info[1]) #TEXT
ticker = symbol #TEXT
current = '%.2f' % float(info[0]) #TEXT
arrow, change = self.getArrow(change)
change = '%.2f' % change
midFrame = self.textToImage(ticker, current, change, arrow) #IMAGE THE TEXT
@ -332,7 +339,7 @@ class StockTicker():
CSV = csv.reader(f)
next(CSV)
for row in CSV:
print(row)
try:
symbol, current_price, opening_price = row
self.symbols.append(symbol)
@ -350,7 +357,7 @@ class StockTicker():
CSV = csv.reader(f)
next(CSV)
for row in CSV:
print(row)
try:
coin, current_price, day_change = row
self.coins.append(coin)
@ -432,7 +439,8 @@ if __name__ == '__main__':
#stock_ticker.getFullStockImage(1)
#stock_ticker.displayStocks()
stock_ticker.delay = 0.001
stock_ticker.scrollImageTransition(['final.ppm', 'final.ppm'], offset_x = 0, offset_y = 0)
while True:
msg = getInput()