Implement Display events
This commit is contained in:
27
display.py
27
display.py
@@ -29,3 +29,30 @@ class DisplayLyrics(DisplayContent):
|
||||
multiline=True,
|
||||
batch=obj.audiencebatch))
|
||||
|
||||
class DisplayImage(DisplayContent):
|
||||
def __init__(self, image, background=None):
|
||||
self._image = image
|
||||
self._background = background
|
||||
|
||||
def create(self, obj, width, height, x, y):
|
||||
|
||||
super().create(obj, width, height, x, y)
|
||||
|
||||
scale = min(width / self._image.width, height / self._image.height)
|
||||
|
||||
if self._background is not None:
|
||||
print("Background is {}".format(self._background))
|
||||
rectangle = pyglet.shapes.Rectangle(x=x + width//2, y=y + height//2,
|
||||
width=width, height=height,
|
||||
color=self._background,
|
||||
batch=obj.audiencebatch)
|
||||
rectangle.anchor_x = width//2
|
||||
rectangle.anchor_y = height//2
|
||||
obj.audiencecontent.append(rectangle)
|
||||
|
||||
sprite = pyglet.sprite.Sprite(img=self._image,
|
||||
x=x + width//2, y=y + height//2,
|
||||
batch=obj.audiencebatch)
|
||||
sprite.scale = scale
|
||||
obj.audiencecontent.append(sprite)
|
||||
|
||||
|
||||
19
events.py
19
events.py
@@ -8,6 +8,8 @@ import display
|
||||
|
||||
import numpy as np
|
||||
|
||||
import pyglet.image
|
||||
|
||||
class Event:
|
||||
def __init__(self, at='start'):
|
||||
self._at = timings.Timing(at)
|
||||
@@ -46,10 +48,25 @@ class Event:
|
||||
pass
|
||||
|
||||
class Display(Event):
|
||||
def __init__(self, media, *args, **kwargs):
|
||||
def __init__(self, media, background=None, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._media = media
|
||||
self._background = background
|
||||
self._image = pyglet.image.load(self._media)
|
||||
self._image.anchor_x = self._image.width // 2
|
||||
self._image.anchor_y = self._image.height // 2
|
||||
|
||||
def start(self):
|
||||
self._audiencecontent.new_content(display.DisplayImage(self._image, self._background))
|
||||
print("Started displaying image")
|
||||
|
||||
def stop(self):
|
||||
self._audiencecontent.new_content(display.DisplayContent())
|
||||
print("Stopped displaying image")
|
||||
|
||||
def notify(self, message, *args, **kwargs):
|
||||
if message == 'newdisplay':
|
||||
self._eventrunner.finished(self)
|
||||
|
||||
class Playback(Event):
|
||||
def __init__(self, media, device=None, channels=[1,2], tempo=None, beats=None, leadin=0, loop=False, gain=0, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user