Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interface to force-load next source #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions billboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import signal
import tempfile
import logging

import queue

from PyQt4.QtGui import QApplication

Expand Down Expand Up @@ -47,11 +47,14 @@ def main():
logging.debug('Creating {}'.format(workdir))
os.makedirs(workdir)

server = Server(workdir, args.port)
# We use a queue to communicate between threads
q = queue.Queue()

server = Server(workdir, args.port, q)
display = BillboardDisplay(workdir=workdir)
sources = [RedditSource()]

billboard = Billboard(display, sources, args.period)
billboard = Billboard(display, sources, args.period, q)

billboard.start()
display.showFullScreen()
Expand Down
14 changes: 12 additions & 2 deletions billboard/billboard.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import time
from threading import Thread
from itertools import cycle
from queue import Empty


class Billboard(Thread):

def __init__(self, display, sources, period):
def __init__(self, display, sources, period, q):
super(Billboard, self).__init__()
self.display = display
self.sources = sources
self.period = period
self.q = q
self.daemon = True

def run(self):
Expand All @@ -21,5 +23,13 @@ def run(self):
self.display.update_image(image)
if text is not None:
self.display.display_text(text)
# HACK: We sleep for a moment to make sure that this
# display has updated before we take the screenshot. This
# is not an issue on slower devices, but can occur on
# faster machines.
time.sleep(1)
self.display.update_current()
time.sleep(self.period)
try:
self.q.get(timeout=self.period)
except Empty:
pass
13 changes: 11 additions & 2 deletions billboard/server.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import os
import threading

from flask import Flask,request, send_from_directory
from flask import Flask, request, send_from_directory


class Server(threading.Thread):

def __init__(self, workdir, port):
def __init__(self, workdir, port, q):
super(Server, self).__init__()
self.daemon = True
self.workdir = workdir
self.port = port
self.q = q

def run(self):
app = Flask('billboard')
Expand All @@ -26,6 +27,14 @@ def current():
response.headers['Pragma'] = 'no-cache'
return response

@app.route('/next')
def next():
# We just put SOMETHING into the queue. It doesn't matter
# what it is as we discard it anyhow.
self.q.put(None)
return "Loading the next image!"


app.run(host='0.0.0.0', port=self.port)


Expand Down