Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, jsonify, request
- import threading
- import pygame
- from queue import Queue
- import socket
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- s.connect(("8.8.8.8", 80))
- q = Queue()
- q.put('Make Put Reqest To Update Text, ip: ' + s.getsockname()[0])
- s.close()
- app = Flask(__name__)
- @app.route("/", methods=['GET', 'PUT'])
- def home():
- if request.method == 'PUT':
- try:
- Text = request.args.get('text')
- print(f"Text was: {Text}")
- data = {"satus": "Screen is updating", "Text": Text}
- q.put(Text)
- return jsonify(data)
- except Exception as e:
- print(e)
- data = {"error": "an error as accored"}
- return jsonify(data)
- else:
- data = {'Text': 'Make put request to update screen'}
- print(request.host)
- return jsonify(data)
- def blit(surface, text, center):
- blitsurface = font.render("A", False, (0, 0, 0))
- did_blit = False
- median = blitsurface.get_size()
- max_size = [surface.get_width()-50, surface.get_height()]
- allwords = ''
- wordict = []
- y = 0
- for line in text.split('\n'):
- for word in line.split(' '):
- blitsurface = font.render(allwords + word, False, (0, 0, 0))
- word_size = blitsurface.get_size()
- w, h = blitsurface.get_size()
- if word_size[0] > max_size[0]:
- blitsurface = font.render(allwords, False, (0, 0, 0))
- w, h = blitsurface.get_size()
- wordict.append({"word":allwords, "width":w, "y":y})
- allwords = ''
- y+=median[1]
- allwords += word + ' '
- if wordict[-1]["word"] != allwords:
- blitsurface = font.render(allwords, False, (0, 0, 0))
- w, h = blitsurface.get_size()
- wordict.append({"word":allwords, "width":w, "y":y})
- for item in wordict:
- item['y'] -= median[1]*0.5*(len(wordict)-1)
- blitsurface = font.render(item["word"], False, (0, 0, 0))
- surface.blit(blitsurface, (center[0]-(item["width"]/2), center[1]-(median[1]/2)+item['y']))
- def pyg(q):
- global font
- pygame.init()
- pygame.font.init()
- font = pygame.font.Font('footlight-mt-std-extra-bold.otf', 35)
- window = pygame.display.set_mode((800, 480))
- center = (window.get_width()/2, window.get_height()/2)
- if not q.empty():
- text = q.get()
- while True:
- events = pygame.event.get()
- for event in events:
- if event.type == pygame.QUIT:
- pygame.quit()
- exit()
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_ESCAPE:
- pygame.quit()
- exit()
- if not q.empty():
- text = q.get()
- window.fill((200, 200, 200))
- bkg = pygame.image.load("./images/background.png")
- window.blit(bkg, (0, 0))
- blit(window, text, center)
- pygame.display.update()
- t1 = threading.Thread(target=pyg, args=(q,))
- t1.start()
- app.run(debug = False, host="0.0.0.0", port=5000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement