def drawNRE(device, width, height): device.clear() virtualViewport = viewport(device, width=width, height=height) with canvas(device) as draw: poweredSize = draw.textsize("Powered by", fontBold) NRESize = draw.textsize("National Rail Enquiries", fontBold) rowOne = snapshot(width, 10, renderPoweredBy((width - poweredSize[0]) / 2), interval=10) rowTwo = snapshot(width, 10, renderNRE((width - NRESize[0]) / 2), interval=10) rowTime = snapshot(width, 14, renderTime, interval=1) #renderWelcomeTo((width - poweredSize[0]) / 2) if len(virtualViewport._hotspots) > 0: for hotspot, xy in virtualViewport._hotspots: virtualViewport.remove_hotspot(hotspot, xy) virtualViewport.add_hotspot(rowOne, (0, 0)) virtualViewport.add_hotspot(rowTwo, (0, 12)) virtualViewport.add_hotspot(rowTime, (0, 50)) return virtualViewport
def drawBlankSignage(device, width, height, departureStation): global stationRenderCount, pauseCount with canvas(device) as draw: welcomeSize = draw.textsize("Welcome to", fontBold) with canvas(device) as draw: stationSize = draw.textsize(departureStation, fontBold) device.clear() virtualViewport = viewport(device, width=width, height=height) rowOne = snapshot(width, 10, renderWelcomeTo((width - welcomeSize[0]) / 2), interval=10) rowTwo = snapshot(width, 10, renderDepartureStation(departureStation, (width - stationSize[0]) / 2), interval=10) rowThree = snapshot(width, 10, renderDots, interval=10) rowTime = snapshot(width, 14, renderTime, interval=1) if len(virtualViewport._hotspots) > 0: for hotspot, xy in virtualViewport._hotspots: virtualViewport.remove_hotspot(hotspot, xy) virtualViewport.add_hotspot(rowOne, (0, 0)) virtualViewport.add_hotspot(rowTwo, (0, 12)) virtualViewport.add_hotspot(rowThree, (0, 24)) virtualViewport.add_hotspot(rowTime, (0, 50)) return virtualViewport
def main(): global device, input_data with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((HOST, PORT)) s.listen() while True: conn, addr = s.accept() # Setup the display widget_width = device.width // 2 widget_height = device.height md = snapshot(widget_width, widget_height, render_disk_memory_battery, interval=2.0) cpuwlan = snapshot(widget_width, widget_height, render_network_cpu, interval=0.5) virtual = viewport(device, width=device.width, height=device.height) virtual.add_hotspot(cpuwlan, (0, 0)) virtual.add_hotspot(md, (device.width // 2, 0)) with conn: logging.info('Connection from address ({}).'.format(addr)) while True: data = conn.recv(1024).decode('utf-8') logging.info('Incoming data: ({}) bytes.'.format( len(data))) try: input_data = json.loads(data) logging.info('Got JSON data: {}'.format(input_data)) except: logging.error( 'Unable to process incoming data as JSON.') device.cleanup() device = get_device() break try: logging.info('Sending OK.') conn.sendall('OK'.encode('utf-8')) except: logging.error('Unable to send OK.') device.cleanup() device = get_device() break virtual.set_position((0, 0))
def __init__(self, null_device): self.font1 = ImageFont.truetype( "/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf", 14) self.font2 = ImageFont.truetype( "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 12) self.font3 = ImageFont.truetype( "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 10) self.font4 = ImageFont.truetype( "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 8) self.wifiIcon_path = os.path.abspath( os.path.join(os.path.dirname(__file__), 'images', '58-wifi.png')) self.wifiIcon = Image.open(self.wifiIcon_path).convert("RGBA") self.linkedIcon_path = os.path.abspath( os.path.join(os.path.dirname(__file__), 'images', 'linked.png')) self.linkedIcon = Image.open(self.linkedIcon_path).convert("RGBA") self.showSSID = False self.showSS = False # Screensaver self.messages = [] # set up the display widgets if null_device: self.device = None else: self.device = self.__get_device__() banner = snapshot(self.device.width, 22, self.render_banner, interval=1.0) messages = snapshot(self.device.width, 80, self.render_messages, interval=0.05) # Longer interval as it toggles SSID/IP status = snapshot(self.device.width, 25, self.render_status, interval=5.0) self.virtual = viewport(self.device, width=self.device.width, height=self.device.height) self.virtual.add_hotspot(banner, (0, 0)) self.virtual.add_hotspot(messages, (0, 22)) self.virtual.add_hotspot(status, (0, 102)) self.start_time = None self.no_display = False self.lowBattery = 0
def main(): if device.rotate in (0, 2): # Horizontal widget_width = device.width // WIDGETS_PER_SCREEN widget_height = device.height else: # Vertical widget_width = device.width widget_height = device.height // WIDGETS_PER_SCREEN # Either function or subclass # cpuload = hotspot(widget_width, widget_height, cpu_load.render) # cpuload = cpu_load.CPU_Load(widget_width, widget_height, interval=1.0) utime = snapshot(widget_width, widget_height, uptime.render, interval=1.0) mem = snapshot(widget_width, widget_height, memory.render, interval=2.0) dsk = snapshot(widget_width, widget_height, disk.render, interval=2.0) cpuload = snapshot(widget_width, widget_height, cpu_load.render, interval=0.5) clk = snapshot(widget_width, widget_height, clock.render, interval=1.0) mdsong = snapshot(widget_width, widget_height, moode.render, interval=1.0) mdart = snapshot(widget_width, widget_height, moode.cover_art(device.mode), interval=5.0) network_ifs = psutil.net_if_stats().keys() wlan = first(intersect(network_ifs, ["wlan0", "wl0"]), "wlan0") eth = first(intersect(network_ifs, ["eth0", "en0"]), "eth0") lo = first(intersect(network_ifs, ["lo", "lo0"]), "lo") net_wlan = snapshot(widget_width, widget_height, network.stats(wlan), interval=2.0) net_eth = snapshot(widget_width, widget_height, network.stats(eth), interval=2.0) net_lo = snapshot(widget_width, widget_height, network.stats(lo), interval=2.0) # widgets = [cpuload, mda, utime, clk, net_wlan, net_eth, net_lo, mem, dsk] widgets = [mdsong, mdsong] if device.rotate in (0, 2): virtual = viewport(device, width=widget_width * len(widgets), height=widget_height) for i, widget in enumerate(widgets): virtual.add_hotspot(widget, (i * widget_width, 0)) for x in pause_every(widget_width, position(widget_width * (len(widgets) - WIDGETS_PER_SCREEN))): virtual.set_position((x, 0)) else: virtual = viewport(device, width=widget_width, height=widget_height * len(widgets)) for i, widget in enumerate(widgets): virtual.add_hotspot(widget, (0, i * widget_height)) for y in pause_every(widget_height, position(widget_height * (len(widgets) - WIDGETS_PER_SCREEN))): virtual.set_position((0, y))
def main(): if device.rotate in (0, 2): # Horizontal widget_width = device.width widget_height = device.height else: # Vertical widget_width = device.width widget_height = device.height // 2 # Either function or subclass # cpuload = hotspot(widget_width, widget_height, cpu_load.render) # cpuload = cpu_load.CPU_Load(widget_width, widget_height, interval=1.0) mem = snapshot(widget_width, widget_height, memory.render, interval=1) dsk = snapshot(widget_width, widget_height, disk.render, interval=1.0) cpuload = snapshot(widget_width, widget_height, cpu_load.render, interval=1.0) weathers = snapshot(widget_width, widget_height, WEather.render, interval=0.1) news = snapshot(widget_width, widget_height, Message.render, interval=60.0) widgets = [weathers, cpuload, mem, news, dsk] if device.rotate in (0, 2): virtual = viewport(device, width=widget_width * len(widgets), height=widget_height) for i, widget in enumerate(widgets): virtual.add_hotspot(widget, (i * widget_width, 0)) for x in pause_every(widget_width, position(widget_width * (len(widgets) - 2))): virtual.set_position((x, 0)) else: virtual = viewport(device, width=widget_width, height=widget_height * len(widgets)) for i, widget in enumerate(widgets): virtual.add_hotspot(widget, (0, i * widget_height)) for y in pause_every(widget_height, position(widget_height * (len(widgets) - 2))): virtual.set_position((0, y))
def drawSignage(self, station, departures): self._device.clear() virtualViewport = viewport(self._device, width=self._WIDTH, height=self._HEIGHT) maxWidthStatus = self._STATUS_DELAYED width = virtualViewport.width # Maximum text size with canvas(self._device) as draw: w, h = draw.textsize(maxWidthStatus, self._fonts["fontBold"]) stationText = "{} ({})".format(station["name"], station["line"]) rowStation = snapshot(width, 10, self._renderDepartureStation(stationText, 0), interval=10) maxD = min([len(departures), 3]) c, r = 2, maxD rows = [[0 for x in range(c)] for y in range(r)] for i in range(maxD): f = self._fonts["font"] rows[i][0] = snapshot(width - w, 10, self._renderDestination(departures[i], f), interval=10) rows[i][1] = snapshot(w, 10, self._renderServiceStatus(departures[i], f), interval=1) rowTime = snapshot(width, 14, self._renderTime, interval=0.1) if len(virtualViewport._hotspots) > 0: for hotspot, xy in virtualViewport._hotspots: virtualViewport.remove_hotspot(hotspot, xy) virtualViewport.add_hotspot(rowStation, (0, 0)) for i in range(maxD): virtualViewport.add_hotspot(rows[i][0], (0, (i + 1) * 12)) virtualViewport.add_hotspot(rows[i][1], (width - w, (i + 1) * 12)) virtualViewport.add_hotspot(rowTime, (0, 50)) return virtualViewport
def make_snapshot(width, height, text, fonts, fgcolor="white", bgcolor="black"): def render(draw, width, height): # Try in reducing font size until we find one where the width fits for font in fonts: size = draw.multiline_textsize(text, font) if size[0] <= width: break # Render in the center left = (width - size[0]) // 2 top = (height - size[1]) // 2 draw.rectangle(((left, top), (left + size[0], top + size[1])), fill=bgcolor) s2 = draw.multiline_text((left, top), text=text, font=font, fill=fgcolor, align="center", spacing=-2) return snapshot(width, height, render, interval=10)
def __init__(self, device): self.DEPARTURE_TOP_MARGIN = 2 self.DEPARTURE_HEIGHT = 10 self.viewport = viewport(device, width=device.width, height=device.height) # Add departure rows. First row has larger title text. self.departures = [ DepartureRenderer(device.width, self.DEPARTURE_HEIGHT, font_bold, font), DepartureRenderer(device.width, self.DEPARTURE_HEIGHT, font, font), DepartureRenderer(device.width, self.DEPARTURE_HEIGHT, font, font), DepartureRenderer(device.width, self.DEPARTURE_HEIGHT, font, font) ] h = 0 for d in self.departures: self.viewport.add_hotspot(d, (0, h)) h = h + d.height + self.DEPARTURE_TOP_MARGIN # Add clock self.viewport.add_hotspot( snapshot(device.width, 14, self.render_clock, interval=0.1), (0, 50))
def hard_refresh_top_viewport(): global top_viewport logger.debug('hard_refresh_top_viewport') new_top_viewport = snapshot(256, 27, top_snap, 60.0) virtual.remove_hotspot(top_viewport, (0, 0)) top_viewport = new_top_viewport virtual.add_hotspot(top_viewport, (0, 0))
def drawSignage(device, width, height, data): global stationRenderCount, pauseCount device.clear() virtualViewport = viewport(device, width=width, height=height) status = "On time" callingAt = "Calling at:" departures, firstDepartureDestinations, departureStation = data with canvas(device) as draw: w, h = draw.textsize(callingAt, font) callingWidth = w width = virtualViewport.width # First measure the text size with canvas(device) as draw: w, h = draw.textsize(status, font) rowOneA = snapshot(width - w, 16, renderDestination(departures[0]), interval=10) rowOneB = snapshot(w, 16, renderServiceStatus(departures[0]), interval=10) rowTwoA = snapshot(callingWidth, 16, renderCallingAt, interval=100) rowTwoB = snapshot(width - callingWidth, 16, renderStations(", ".join(firstDepartureDestinations)), interval=0.1) rowThreeA = snapshot(width - w, 16, renderDestination(departures[1]), interval=10) rowThreeB = snapshot(w, 16, renderServiceStatus(departures[1]), interval=10) rowTime = snapshot(width, 14, renderTime, interval=1) if len(virtualViewport._hotspots) > 0: for hotspot, xy in virtualViewport._hotspots: virtualViewport.remove_hotspot(hotspot, xy) stationRenderCount = 0 pauseCount = 0 virtualViewport.add_hotspot(rowOneA, (0, 0)) virtualViewport.add_hotspot(rowOneB, (width - w, 0)) virtualViewport.add_hotspot(rowTwoA, (0, 16)) virtualViewport.add_hotspot(rowTwoB, (callingWidth, 16)) virtualViewport.add_hotspot(rowThreeA, (0, 32)) virtualViewport.add_hotspot(rowThreeB, (width - w, 32)) virtualViewport.add_hotspot(rowTime, (0, 50)) return virtualViewport
def drawBlankSignage(self, station): lineText = "Metro {}".format(station["line"]) # Maximum text sizes with canvas(self._device) as draw: welcomeSize = draw.textsize(self._STATUS_NODATA, self._fonts["font"]) stationSize = draw.textsize(station["name"], self._fonts["fontBold"]) lineSize = draw.textsize(lineText, self._fonts["fontBold"]) self._device.clear() virtualViewport = viewport(self._device, width=self._WIDTH, height=self._HEIGHT) width = virtualViewport.width rowOne = snapshot(width, 10, self._renderNoDataText((width - welcomeSize[0]) / 2), interval=10) rowTwo = snapshot(width, 10, self._renderDepartureStation( station["name"], (width - stationSize[0]) / 2), interval=10) rowThree = snapshot(width, 10, self._renderDepartureStation( lineText, (width - lineSize[0]) / 2), interval=10) rowTime = snapshot(width, 14, self._renderTime, interval=1) if len(virtualViewport._hotspots) > 0: for hotspot, xy in virtualViewport._hotspots: virtualViewport.remove_hotspot(hotspot, xy) virtualViewport.add_hotspot(rowOne, (0, 0)) virtualViewport.add_hotspot(rowTwo, (0, 12)) virtualViewport.add_hotspot(rowThree, (0, 24)) virtualViewport.add_hotspot(rowTime, (0, 50)) return virtualViewport
def _setup_state_standby(): global standby_viewport global sleep_time sleep_time = 60 standby_viewport = snapshot(256, 64, standby_snap, 60) virtual.add_hotspot(standby_viewport, (0, 0)) display_device.contrast(CONST.BRIGHTNESS_STANDBY)
def _setup_state_powered(): global top_viewport global main_viewport global sleep_time sleep_time = 1 / CONST.FPS top_viewport = snapshot(256, 27, top_snap, 60) main_viewport = Main_Hotspot(256, 28) virtual.add_hotspot(top_viewport, (0, 0)) virtual.add_hotspot(main_viewport, (0, 64 - 29))
def test_snapshot_last_updated(): interval = 0.5 def draw_fn(draw, width, height): assert height == 10 assert width == 10 sshot = snapshot(10, 10, draw_fn, interval) assert sshot.last_updated == 0.0 assert sshot.should_redraw() is True sshot.paste_into(Image.new("RGB", (10, 10)), (0, 0)) assert sshot.should_redraw() is False time.sleep(interval * 1.5) assert sshot.should_redraw() is True sshot.paste_into(Image.new("RGB", (10, 10)), (0, 0)) assert sshot.last_updated > 0.0 assert sshot.should_redraw() is False
def make_snapshot(width, height, text, fonts, color="white"): def render(draw, width, height): t = text for font in fonts: size = draw.multiline_textsize(t, font) if size[0] > width: t = text.replace(" ", "\n") size = draw.multiline_textsize(t, font) else: break left = (width - size[0]) // 2 top = (height - size[1]) // 2 draw.multiline_text((left, top), text=t, font=font, fill=color, align="center", spacing=-2) return snapshot(width, height, render, interval=10)
contentHotspot = None contentHotspotXY = None def set_contentHotspot(hotspot, xy): global deviceViewport, contentHotspot, contentHotspotXY if contentHotspot != None: deviceViewport.remove_hotspot(contentHotspot, contentHotspotXY) deviceViewport.add_hotspot(hotspot, xy) contentHotspot = hotspot contentHotspotXY = xy clockSnapshot = snapshot(29, 8, drawClock, 1.0) dateSnapshot = dateAndWeatherSnapshot(weatherProvider, 15.0) deviceViewport.add_hotspot(clockSnapshot, (0, 0)) set_contentHotspot(dateSnapshot, (29, 0)) deviceViewport.refresh() set_brightness(weatherProvider.lightIntensity) @tl.job(interval=timedelta(milliseconds=30)) def onDraw(): global deviceViewport deviceViewport.refresh()
def drawSignage(device, width, height, data): global stationRenderCount, pauseCount device.clear() virtualViewport = viewport(device, width=width, height=height) status = "Exp 00:00" callingAt = "Calling at:" departures, firstDepartureDestinations, departureStation = data with canvas(device) as draw: w, h = draw.textsize(callingAt, font) callingWidth = w width = virtualViewport.width # First measure the text size with canvas(device) as draw: w, h = draw.textsize(status, font) pw, ph = draw.textsize("Plat 88", font) rowOneA = snapshot(width - w - pw - 5, 10, renderDestination(departures[0], fontBold), interval=10) rowOneB = snapshot(w, 10, renderServiceStatus(departures[0]), interval=1) rowOneC = snapshot(pw, 10, renderPlatform(departures[0]), interval=10) rowTwoA = snapshot(callingWidth, 10, renderCallingAt, interval=100) rowTwoB = snapshot(width - callingWidth, 10, renderStations(", ".join(firstDepartureDestinations)), interval=0.1) if (len(departures) > 1): rowThreeA = snapshot(width - w - pw, 10, renderDestination(departures[1], font), interval=10) rowThreeB = snapshot(w, 10, renderServiceStatus(departures[1]), interval=1) rowThreeC = snapshot(pw, 10, renderPlatform(departures[1]), interval=10) if (len(departures) > 2): rowFourA = snapshot(width - w - pw, 10, renderDestination(departures[2], font), interval=10) rowFourB = snapshot(w, 10, renderServiceStatus(departures[2]), interval=1) rowFourC = snapshot(pw, 10, renderPlatform(departures[2]), interval=10) rowTime = snapshot(width, 14, renderTime, interval=0.1) if len(virtualViewport._hotspots) > 0: for hotspot, xy in virtualViewport._hotspots: virtualViewport.remove_hotspot(hotspot, xy) stationRenderCount = 0 pauseCount = 0 virtualViewport.add_hotspot(rowOneA, (0, 0)) virtualViewport.add_hotspot(rowOneB, (width - w, 0)) virtualViewport.add_hotspot(rowOneC, (width - w - pw, 0)) virtualViewport.add_hotspot(rowTwoA, (0, 12)) virtualViewport.add_hotspot(rowTwoB, (callingWidth, 12)) if (len(departures) > 1): virtualViewport.add_hotspot(rowThreeA, (0, 24)) virtualViewport.add_hotspot(rowThreeB, (width - w, 24)) virtualViewport.add_hotspot(rowThreeC, (width - w - pw, 24)) if (len(departures) > 2): virtualViewport.add_hotspot(rowFourA, (0, 36)) virtualViewport.add_hotspot(rowFourB, (width - w, 36)) virtualViewport.add_hotspot(rowFourC, (width - w - pw, 36)) virtualViewport.add_hotspot(rowTime, (0, 50)) return virtualViewport
def hw_monitor(device, args): collect_sensor_data = init_sensors() sensors_spec = dict(CPU='it8686-isa-0a40.temp3', GPU='amdgpu-pci-4200.edge', Chipset='it8686-isa-0a40.temp2', System='it8792-isa-0a60.temp3') fan_spec = dict(CPU='it8686-isa-0a40.fan1', GPU='amdgpu-pci-4200.fan1', Rear='it8792-isa-0a60.fan3', SYS1='it8686-isa-0a40.fan2') sensors_data_logger = DataLogger(collect_sensor_data, max_entries=(device.width / 2) - 10).start() loadavg_data_logger = DataLogger(psutil.getloadavg, max_entries=device.width - 2).start() network_data_logger = DataLogger( lambda: psutil.net_io_counters(pernic=True)[args.network], max_entries=device.width / 2 - 15).start() def shutdownHandler(signal, frame): loadavg_data_logger.stop() sensors_data_logger.stop() network_data_logger.stop() exit(0) signal.signal(signal.SIGINT, shutdownHandler) signal.signal(signal.SIGTERM, shutdownHandler) virtual = viewport(device, width=device.width, height=1024, mode='RGBA', dither=True) with canvas(virtual) as draw: y_offset = render_logo(draw, 0, device.width, args.title) hotspots = [ snapshot(device.width, 9, cpu_percent.render, interval=0.5), snapshot(device.width, cpu_barchart.height + 4, cpu_barchart.render, interval=0.5), snapshot(device.width, cpu_stats.height + 11, cpu_stats.render, interval=2), snapshot(device.width, uptime.height, uptime.render, interval=10), snapshot(device.width, 10, system_load.render, interval=1.0), snapshot(device.width, loadavg_chart.height, loadavg_chart.using(loadavg_data_logger), interval=1.0), snapshot(device.width, 10, memory.render, interval=5.0), snapshot(device.width, 28, disk.directory('/'), interval=5.0), snapshot(device.width, network.height, network.using(args.network, network_data_logger), interval=2.0), snapshot(device.width, 64, sensors_chart.using(sensors_data_logger, sensors_spec, fan_spec), interval=1.0), snapshot(device.width, 64 * 6, device_list.init('http://192.168.1.254'), interval=30) ] for hotspot in hotspots: virtual.add_hotspot(hotspot, (0, y_offset)) y_offset += hotspot.height render_logo(draw, y_offset, device.width, args.title) # time.sleep(5.0) # for y in pause_every(64, 96, infinite(y_offset)): for y in stepper(64, y_offset, 512): with framerate_regulator(): virtual.set_position((0, y))
def main(): if device.rotate in (0, 2): # Horizontal widget_width = device.width // 2 widget_height = device.height else: # Vertical widget_width = device.width widget_height = device.height // 2 token = open('mytokenfile').read() roonapid = roonapi.RoonApi(appinfo, token) # save the token for next time with open('mytokenfile', 'w') as f: f.write(roonapid.token) # save the token for next time # Either function or subclass # cpuload = hotspot(widget_width, widget_height, cpu_load.render) # cpuload = cpu_load.CPU_Load(widget_width, widget_height, interval=1.0) # utime = snapshot(widget_width, widget_height, uptime.render, interval=1.0) # mem = snapshot(widget_width, widget_height, memory.render, interval=2.0) # dsk = snapshot(widget_width, widget_height, disk.render, interval=2.0) zoneid = 0 widgets = [] for zone in roonapid.zones: widgets.append( snapshot(widget_width, widget_height, music.get_data(roonapid, zone), interval=1.0)) # shair = snapshot(widget_width, widget_height, shairplay.render, interval=2.0) # cpuload = snapshot(widget_width, widget_height, cpu_load.render, interval=0.5) # clk = snapshot(widget_width, widget_height, clock.render, interval=1.0) # network_ifs = psutil.net_if_stats().keys() # wlan = first(intersect(network_ifs, ["wlan0", "wl0"]), "wlan0") # eth = first(intersect(network_ifs, ["eth0", "en0"]), "eth0") # lo = first(intersect(network_ifs, ["lo", "lo0"]), "lo") # net_wlan = snapshot(widget_width, widget_height, network.stats(wlan), interval=2.0) # net_eth = snapshot(widget_width, widget_height, network.stats(eth), interval=2.0) # net_lo = snapshot(widget_width, widget_height, network.stats(lo), interval=2.0) # widgets = [cpuload, msc, net_eth, msc, mem, msc, dsk, msc] if device.rotate in (0, 2): virtual = viewport(device, width=widget_width * len(widgets), height=widget_height) for i, widget in enumerate(widgets): virtual.add_hotspot(widget, (i * widget_width, 0)) for x in pause_every(widget_width, position(widget_width * (len(widgets) - 2))): virtual.set_position((x, 0)) else: virtual = viewport(device, width=widget_width, height=widget_height * len(widgets)) for i, widget in enumerate(widgets): virtual.add_hotspot(widget, (0, i * widget_height)) for y in pause_every(widget_height, position(widget_height * (len(widgets) - 2))): virtual.set_position((0, y))
def drawSignage(device, width, height, data, first): device.clear() virtualViewport = viewport(device, width=width, height=height) status = ' odjechal' lineExample = '504 ' departures = data width = virtualViewport.width # First measure the text size with canvas(device) as draw: w, h = draw.textsize(status, font) with canvas(device) as draw: w1, h1 = draw.textsize(lineExample, font) startIndex = 0 + 3 * (0 if first or len(departures) <= 3 else 1) if len(departures) > startIndex: row1A = snapshot(w1, 16, renderLine(departures[startIndex + 0]), interval=0.5) row1B = snapshot(width - w - w1 - 5, 16, renderDestination(departures[startIndex + 0]), interval=0.5) row1C = snapshot(w, 16, renderDepartureTime(departures[startIndex + 0]), interval=0.5) if len(departures) > startIndex + 1: row2A = snapshot(w1, 16, renderLine(departures[startIndex + 1]), interval=0.5) row2B = snapshot(width - w - w1 - 5, 16, renderDestination(departures[startIndex + 1]), interval=0.5) row2C = snapshot(w, 16, renderDepartureTime(departures[startIndex + 1]), interval=0.5) if len(departures) > startIndex + 2: row3A = snapshot(w1, 16, renderLine(departures[startIndex + 2]), interval=0.5) row3B = snapshot(width - w - w1 - 5, 16, renderDestination(departures[startIndex + 2]), interval=0.5) row3C = snapshot(w, 16, renderDepartureTime(departures[startIndex + 2]), interval=0.5) rowTime = snapshot(width, 14, renderTime, interval=0.05) if len(virtualViewport._hotspots) > 0: for hotspot, xy in virtualViewport._hotspots: virtualViewport.remove_hotspot(hotspot, xy) if len(departures) > startIndex + 0: virtualViewport.add_hotspot(row1A, (0, 0 + 0)) virtualViewport.add_hotspot(row1B, (w1, 0 + 0)) virtualViewport.add_hotspot(row1C, (width - w - 5, 0 + 0)) if len(departures) > startIndex + 1: virtualViewport.add_hotspot(row2A, (0, 0 + 16)) virtualViewport.add_hotspot(row2B, (w1, 0 + 16)) virtualViewport.add_hotspot(row2C, (width - w - 5, 0 + 16)) if len(departures) > startIndex + 2: virtualViewport.add_hotspot(row3A, (0, 0 + 32)) virtualViewport.add_hotspot(row3B, (w1, 0 + 32)) virtualViewport.add_hotspot(row3C, (width - w - 5, 0 + 32)) virtualViewport.add_hotspot(rowTime, (0, 50)) return virtualViewport