def __init__(self): self.composite = PapirusComposite(False) width = self.composite.papirus.width height = self.composite.papirus.height # logo logo_side = height - self.padding_y * 2 self.composite.AddImg(self.logo, self.padding_x, self.padding_y, size=(logo_side, logo_side)) # graph graph_X = logo_side + self.padding_x * 2 # next to logo graph_y = (1 - self.graph_height_ratio) * height # lower part graph_width = width - graph_X graph_height = height - graph_y self.graph = Graph(graph_X, graph_y, graph_width, graph_height) # rate rate_x = graph_X # left aligned with graph rate_y = graph_y / 2 - self.rate_text_size / 2 # center upper part self.composite.AddText('', rate_x, rate_y, size=self.rate_text_size, Id='rate') self.stop_event = threading.Event() self.thread = None
def update_display(self): """ Writes the image and text (if any) stored in the state to the display. """ # Get the set text and image (if any) img, img_width, img_height, img_xpos, img_ypos = self.state.get_image() text, text_xpos, text_ypos = self.state.get_text() if eink_present: # There is an e-ink display connected screen = PapirusComposite(False, self.rotation) if img: # There is an image to display screen.AddImg(img, img_xpos, img_ypos, (img_width, img_height)) if text: screen.AddText(text, text_xpos, text_ypos, size=16) # Write the updates to the display screen.WriteAll() else: # There is no e-ink display connected, so just print to the console if img: print('Displaying image: {}'.format(img)) if text: # There is text to display print('Displaying text: {}'.format(text))
def __init__(self): PiWeather.__init__(self) self.display = PapirusComposite(False) self.unknown_icon = "3200.png" self.order = [] self.gotWeather = False self.initalize_order() self.initalize_display()
class PiDisplay: def update(self): # API interaction response = requests.get(complete_url) x = response.json() y = x["main"] w = x["weather"] desc = w[0]['description'] temp_min = y['temp_min'] temp_max = y['temp_max'] current_temperature = y["temp"] americanunits = (9 / 5) * (current_temperature - 273.15) + 32 americanunits_min = (9 / 5) * (temp_min - 273.15) + 32 americanunits_max = (9 / 5) * (temp_max - 273.15) + 32 current_temperature = americanunits temp_min = americanunits_min temp_max = americanunits_max #end of API interaction self.display = PapirusComposite(False) condition_icon = w[0]['icon'] self.display.AddImg( os.path.join(DIRECTORY, 'weather icons', condition_icon[:2] + 'd.png'), 0, 0, (32, 32)) self.display.AddText(str(round(current_temperature)) + ' ℉', 30, 5, size=12) self.display.AddText(str(round(temp_min)) + '/' + str(round(temp_max)) + ' ℉', 30, 20, size=12) self.display.AddText(str(desc), 70, 5, size=10, Id="lin2ne") # self.display.AddText(z, 20, 190, size = 16, Id = "test") # self.display.AddImg(os.path.join(DIRECTORY, self.unknown_icon),0,0, (100,100), Id = "testimg") # self.display.AddImg(os.path.join(), 1, 63, (32, 32), Id="ForecastIconOne") self.display.WriteAll()
def draw_home_screen(self, first_unused_addr, total_balance=None, price=None, value=None, gfx=None): if papirus is None: print('Fake: ', self.__coin, first_unused_addr, total_balance, price, value) return qr = pyqrcode.create(first_unused_addr) qr.png('/tmp/addr.png', scale=5) comp = PapirusComposite(False) comp.AddImg('/tmp/addr.png', -10, -10, (96, 96), Id='addr') if total_balance is None: comp.AddText('Offline', 10, 77, Id='total') else: comp.AddText('{} {}'.format(total_balance, self.__coin), 10, 77, Id='total') comp.AddText('{}'.format(COIN_NAMES[self.__coin]), 90, 10, Id='title') if price is not None: comp.AddText('{}'.format(value), 90, 30, Id='value') comp.AddText('{}'.format(price), 90, 50, Id='price') if self.__gui and papirus: if gfx == MENU_TOP: comp.AddImg(MENU_TOP, 0, 0, (200, 14), Id='menu') else: # Show the menu icon top right comp.AddImg(MENU_ICON, 160, 0, (40, 14), Id='menu') comp.WriteAll()
def refresh_eink(configfile): if configfile['Output'].getboolean('eink', False): handlers.debug("headlights.py importing papirus") from papirus import PapirusComposite screen = PapirusComposite(False) eink.push(screen, configfile['General']['HelloMyNameIs']) pluginlist = configfile['Plugins']['toload'].split(',') for plugin in pluginlist: pluginloader.init(plugin) pluginloader.updateAllPlugins() eink.push_plugins(screen) else: handlers.debug( "Skipping e-ink due to it being disabled in the config file")
def update_wall_text(project): base64Img = load_base64_qr_code_image(project) # create image from base64 string imgPaPiRus = BytesIO(base64.b64decode(base64Img)) textNImg = PapirusComposite(False) artist_title_year_audio = "%s\n\n%s\n%s\n%s" % ( project['artist'], project['title'], project['year'], "" if project["has_audio_track"] else " (no audio)") textNImg.AddText(artist_title_year_audio, 10, 10, 16, Id="ArtistTitleYearAudio", fontPath=FONTPATH) if project['social'] and len(project['social']) > 0: textNImg.AddText(project['social'], 10, 140, 14, Id="Social", fontPath=FONTPATH) textNImg.AddImg(imgPaPiRus, 200, 110, (60, 60)) textNImg.WriteAll()
def __init__(self): self._screen = PapirusComposite(False, 180)
class PiDisplay(PiWeather): def __init__(self): PiWeather.__init__(self) self.display = PapirusComposite(False) self.unknown_icon = "3200.png" self.order = [] self.gotWeather = False self.initalize_order() self.initalize_display() def initalize_order(self): """Create the order that information is displayed """ for stat in self.config["stats"]: if self.config["stats"][stat]: self.order.append(stat) def initalize_display(self): """Add all the screen elements to the e-ink display """ if self.config["forecast"]["enabled"]: self.display.AddImg(os.path.join( DIRECTORY, 'images', 'weather', self.unknown_icon), 0, 0, (48, 48), Id="WeatherIcon") self.display.AddText("Loading...", 48, 0, size=13, Id="LineOne", fontPath='/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf') self.display.AddText("Loading...", 48, 20, size=12, Id="LineTwo") self.display.AddText("Loading...", 48, 34, size=12, Id="LineThree") if self.config["forecast"]["sixday"]: self.display.AddText("...", 3, 49, size=12, Id="ForecastOne") self.display.AddText("...", 35, 49, size=12, Id="ForecastTwo") self.display.AddText( "...", 68, 49, size=12, Id="ForecastThree") self.display.AddText( "...", 101, 49, size=12, Id="ForecastFour") self.display.AddText( "...", 135, 49, size=12, Id="ForecastFive") self.display.AddText("...", 167, 49, size=12, Id="ForecastSix") self.display.AddImg(os.path.join( DIRECTORY, 'images', 'weather', self.unknown_icon), 1, 63, (32, 32), Id="ForecastIconOne") self.display.AddImg(os.path.join( DIRECTORY, 'images', 'weather', self.unknown_icon), 34, 63, (32, 32), Id="ForecastIconTwo") self.display.AddImg(os.path.join( DIRECTORY, 'images', 'weather', self.unknown_icon), 67, 63, (32, 32), Id="ForecastIconThree") self.display.AddImg(os.path.join( DIRECTORY, 'images', 'weather', self.unknown_icon), 100, 63, (32, 32), Id="ForecastIconFour") self.display.AddImg(os.path.join( DIRECTORY, 'images', 'weather', self.unknown_icon), 133, 63, (32, 32), Id="ForecastIconFive") self.display.AddImg(os.path.join( DIRECTORY, 'images', 'weather', self.unknown_icon), 166, 63, (32, 32), Id="ForecastIconSix") else: self.display.AddText("Today: ...", 25, 51, size=12, Id="ForecastOne") self.display.AddText("Tomorrow: ...", 25, 74, size=12, Id="ForecastTwo") self.display.AddImg(os.path.join( DIRECTORY, 'images', 'weather', self.unknown_icon), 1, 49, (23, 23), Id="ForecastIconOne") self.display.AddImg(os.path.join( DIRECTORY, 'images', 'weather', self.unknown_icon), 1, 72, (23, 23), Id="ForecastIconTwo") else: self.display.AddImg(os.path.join( DIRECTORY, 'images', 'weather', self.unknown_icon), 1, 15, (80, 80), Id="WeatherIcon") self.display.AddText("Loading...", 1, 1, size=13, Id="LineOne", fontPath='/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf') self.display.AddText("Loading...", 82, 15, size=12, Id="LineTwo") self.display.AddText("Loading...", 82, 30, size=12, Id="LineThree") self.display.WriteAll() def update(self): """Regurlarly update the screen with new information """ self.gotWeather = False while not self.gotWeather: try: self.get_weather() self.gotWeather = True except: sleep(60) if not self.lookup: print("Invalid Location") exit() self.display.UpdateImg("WeatherIcon", os.path.join( DIRECTORY, 'images', 'weather', str(self.lookup["weather_code"])+'.png')) self.display.UpdateText("LineOne", self.lookup["weather_type"]) if self.config["forecast"]["enabled"]: if self.config["forecast"]["sixday"]: self.display.UpdateText( "ForecastOne", self.lookup["forecast"][0].day) self.display.UpdateText( "ForecastTwo", self.lookup["forecast"][1].day) self.display.UpdateText( "ForecastThree", self.lookup["forecast"][2].day) self.display.UpdateText( "ForecastFour", self.lookup["forecast"][3].day) self.display.UpdateText( "ForecastFive", self.lookup["forecast"][4].day) self.display.UpdateText( "ForecastSix", self.lookup["forecast"][5].day) self.display.UpdateImg("ForecastIconOne", os.path.join( DIRECTORY, 'images', 'weather', str(self.lookup["forecast"][0].code)+'.png')) self.display.UpdateImg("ForecastIconTwo", os.path.join( DIRECTORY, 'images', 'weather', str(self.lookup["forecast"][1].code)+'.png')) self.display.UpdateImg("ForecastIconThree", os.path.join( DIRECTORY, 'images', 'weather', str(self.lookup["forecast"][2].code)+'.png')) self.display.UpdateImg("ForecastIconFour", os.path.join( DIRECTORY, 'images', 'weather', str(self.lookup["forecast"][3].code)+'.png')) self.display.UpdateImg("ForecastIconFive", os.path.join( DIRECTORY, 'images', 'weather', str(self.lookup["forecast"][4].code)+'.png')) self.display.UpdateImg("ForecastIconSix", os.path.join( DIRECTORY, 'images', 'weather', str(self.lookup["forecast"][5].code)+'.png')) else: self.display.UpdateText( "ForecastOne", "Today: "+self.lookup["forecast"][0].text) self.display.UpdateText( "ForecastTwo", "Tomorrow: "+self.lookup["forecast"][1].text) self.display.UpdateImg("ForecastIconOne", os.path.join( DIRECTORY, 'images', 'weather', str(self.lookup["forecast"][0].code)+'.png')) self.display.UpdateImg("ForecastIconTwo", os.path.join( DIRECTORY, 'images', 'weather', str(self.lookup["forecast"][1].code)+'.png')) for stat in self.order: if stat == "temperature": self.display.UpdateText("LineTwo", "Temp: "+self.lookup[stat]) self.display.UpdateText( "LineThree", "Hi: "+self.lookup["forecast"][0].high+" Lo: "+self.lookup["forecast"][0].low) elif stat == "humidity": self.display.UpdateText( "LineTwo", "Humidity: "+self.lookup[stat]) humidity = int(self.lookup[stat][:-1]) scale = "" if humidity < 25: scale = "Very Dry" elif humidity < 60: scale = "Dry" elif humidity < 80: scale = "Wet" else: scale = "Very Wet" self.display.UpdateText("LineThree", scale) elif stat == "wind": self.display.UpdateText( "LineTwo", "Speed: "+self.lookup[stat]["speed"]) self.display.UpdateText( "LineThree", "Direction: "+self.lookup[stat]["direction"]) elif stat == "pressure": self.display.UpdateText("LineTwo", "Pressure") self.display.UpdateText("LineThree", self.lookup[stat]) elif stat == "visibility": self.display.UpdateText("LineTwo", "Visibility") self.display.UpdateText("LineThree", self.lookup[stat]) elif stat == "sunrise": self.display.UpdateText("LineTwo", "Sunrise") self.display.UpdateText("LineThree", self.lookup[stat]) elif stat == "sunset": self.display.UpdateText("LineTwo", "Sunset") self.display.UpdateText("LineThree", self.lookup[stat]) self.display.WriteAll() if len(self.order) >= 3: sleep(20) else: sleep(int(60/len(self.order)))
def draw_address(cls, addr): comp = PapirusComposite(False) comp.AddText(addr, 10, 30, (180, 66), Id='addr') comp.WriteAll()
def draw_shutdown_option(cls): comp = PapirusComposite(False) comp.AddImg(MENU_OFF, 0, 0, (200, 96), Id='off') comp.WriteAll()
def update_weather(): try: textNImg = PapirusComposite(False) # os.system("sudo hwclock --hctosys") weekday = date.today() print(key) with forecast(key, *LEXINGTON) as lexington: long_date_name = date.strftime(weekday, '%A, %b %d') prefix = "./assets/icons/" path = prefix + lexington.currently.icon + ".bmp" low = None high = None for hour in lexington.hourly[6:21]: print(hour.temperature) if low is None or hour.temperature < low: low = hour.temperature if high is None or hour.temperature > high: high = hour.temperature textNImg.AddText(long_date_name, 10, 0, size=22, Id="Day Name") try: textNImg.AddImg(path, 10, 25, (90,90), Id="Icon") except: textNImg.AddText(lexington.daily[0].icon, 10,25, Id="Icon") precipSummary = getattr(lexington.daily[0], "precipType", None) if hasattr(lexington.daily[0], "precipAccumulation"): precipSummary += ": " + "{0:.1f}".format((lexington.daily[0].precipAccumulation)) + '"' if precipSummary: chance = "{0:.0%}".format(lexington.daily[0].precipProbability) precipSummary = " ".join([chance, precipSummary.capitalize()]) offset = len(precipSummary) * 5 textNImg.AddText(precipSummary, 185 - offset, 35, size=15, Id="Precipitation") textNImg.AddText(format_temp(low) + "-" + format_temp(high), 110, 65, size=35, Id="TempRange") textNImg.AddText(lexington.daily[0].summary, 10, 120, size=15, Id="Forecast") textNImg.AddText(datetime.now().strftime("%I:%M%p"), 10, 164, size=10, Id="Time") textNImg.AddText("Powered by Dark Sky", 145, 164, size=10, Id="Attribution") textNImg.WriteAll() except: textNImg.AddText("Error reaching Dark Sky API", 10, 10, Id="Error") textNImg.AddText("{0}".format(weekday), 10, 60, Id="Date") textNImg.WriteAll()
from time import sleep, time from datetime import datetime from papirus import PapirusComposite import json import tzlocal import sys import os.path import redis text = PapirusComposite(False) # config config_file = "/home/pi/git/code/wetter-display/config.json" redishost = "" # init interval = "" global_refresh = 0 token = "" # drawing stuff pos_x = 0 pos_y = 0 fsize = 18 rot = 0 def config_initialize(): global token, redishost, location, interval if os.path.isfile(config_file) and os.access(config_file, os.R_OK): with open(config_file) as data_file:
class PapirusController(): def __init__(self): self._screen = PapirusComposite(False, 180) # todo: init animation def drawGroupName(self, groupName): self._screen.SetText(groupName, 10, 10, "groupName", size=18) def drawLines(self): self._screen.AddImg("pixel.tif", 10, 30, size=(185, 1)) self._screen.AddImg("pixel.tif", 10, 77, size=(244, 1)) self._screen.AddImg("pixel.tif", 10, 146, size=(244, 1)) def drawCeviZeichen(self): self._screen.AddImg("cevilogo.tif", 204, 10, size=(50, 50)) def drawScreen(self, lastUpdated, cost, callList): self.drawGroupName("MC NUGGET") self.drawCeviZeichen() self.drawLastUpdated(lastUpdated) self.drawCost(cost) self.drawGroupDate(datetime.date(2019, 02, 10), datetime.date(2019, 02, 15)) self.drawLines() self.drawList(callList) self._screen.WriteAll() def drawLastUpdated(self, lastUpdated): self._screen.SetText( lastUpdated.strftime("Zuletzt aktualisiert: %d.%m.%Y %H:%M:%S"), 10, 158, size=12, Id="lastupdated") def drawCost(self, cost): self._screen.SetText("Fr. " + "%.2f" % cost, 10, 40, size=30, Id="cost") def drawList(self, callList): for call in callList: print(call) start_y = 82 for i in range(0, 4): self._screen.RemoveText("date" + str(i)) self._screen.RemoveText("duration" + str(i)) self._screen.RemoveText("cost" + str(i)) if not callList: self._screen.SetText("Keine ausgehende Telefonate", 10, start_y, size=12, Id="date0") else: i = 0 for call in callList: if i < 3 or (i == 3 and callList.__len__() == 4): self._screen.SetText(call.time.strftime("%d.%m.%Y %H:%M"), 10, start_y + i * 15, size=12, Id="date" + str(i)) self._screen.SetText("%02i min" % call.billedMinutes, 133, start_y + i * 15, size=12, Id="duration" + str(i)) self._screen.SetText(str(call.cost) + " CHF", 187, start_y + i * 15, size=12, Id="cost" + str(i)) elif i < 4: self._screen.SetText( "sowie " + str(callList.__len__() - 3) + " weitere", 10, start_y + i * 15, Id="weitere", size=12) else: break i += 1 self.callList = test_callList() def drawGroupDate(self, fromDate, toDate): dateformat = "%d.%m" self._screen.SetText(fromDate.strftime(dateformat) + " - " + toDate.strftime(dateformat), 146, 56, "groupDate", size=12) pass
# Wait / display for 15 seconds time.sleep(15) #time.sleep(3) # For dev # 2 Display Hobbies and Interests 15 seconds # Write image to the epaper screen image.write('./factsnametagbox.png') # Wait / display for 10 seconds time.sleep(10) #time.sleep(3) # For Dev # 3 Display Time and Date 10 seconds # Calling PapirusComposite this way will mean nothing is written to the screen until WriteAll is called textNImg = PapirusComposite(False, 180) # String storing time and data into respective strings t = datetime.datetime.now() timeString = t.strftime("%I:%M %p") dateString = t.strftime("%a %b %d") # Add image with default layout date text and time text textNImg.AddImg("./Basenametagbox.png", 0, 0, (200, 96), Id="NameLogo") textNImg.AddText(dateString, 65, 20, Id="date") textNImg.AddText(timeString, 65, 40, Id="time") # Now display all elements on the scrren textNImg.WriteAll() time.sleep(10)
class BitcoinTicker: api = 'https://bitcoinapi.de/widget/current-btc-price/rate.json?culture=de' logo = os.path.join(os.path.dirname(__file__), 'bitcoin.bmp') update_rate = 60 # seconds max_partial_redraws = 5 padding_x = 10 padding_y = 20 graph_height_ratio = 0.5 graph_rate_range = 50 # upper/lower bound relative to current rate in euro rate_text_size = 20 def __init__(self): self.composite = PapirusComposite(False) width = self.composite.papirus.width height = self.composite.papirus.height # logo logo_side = height - self.padding_y * 2 self.composite.AddImg(self.logo, self.padding_x, self.padding_y, size=(logo_side, logo_side)) # graph graph_X = logo_side + self.padding_x * 2 # next to logo graph_y = (1 - self.graph_height_ratio) * height # lower part graph_width = width - graph_X graph_height = height - graph_y self.graph = Graph(graph_X, graph_y, graph_width, graph_height) # rate rate_x = graph_X # left aligned with graph rate_y = graph_y / 2 - self.rate_text_size / 2 # center upper part self.composite.AddText('', rate_x, rate_y, size=self.rate_text_size, Id='rate') self.stop_event = threading.Event() self.thread = None def start(self): self.stop_event.clear() self.thread = threading.Thread(target=self.run) self.thread.start() def stop(self): self.stop_event.set() if self.thread is not None: self.thread.join() def is_running(self): return not self.stop_event.is_set() def _sleep(self, duration): self.stop_event.wait(timeout=duration) def run(self): num_partial_updates = self.max_partial_redraws # full redraw on 1. run while self.is_running(): # get rate from api try: rate = self.get_rate() except requests.exceptions.RequestException as e: print(e) self._sleep(self.update_rate) continue # retry # update rate rate_text = u'%.2f €' % rate print(rate_text) self.composite.UpdateText('rate', rate_text) # update graph self.graph.add(rate) high = rate + self.graph_rate_range / 2 low = rate - self.graph_rate_range / 2 self.graph.draw(self.composite.image, low, high) # draw if num_partial_updates < self.max_partial_redraws: self.composite.WriteAll(partialUpdate=True) num_partial_updates += 1 else: self.composite.WriteAll(partialUpdate=False) num_partial_updates = 0 # delay self._sleep(self.update_rate) def get_rate(self): response = requests.get(self.api) rate_text = response.json()['price_eur'] rate = ''.join(c for c in rate_text if c.isdigit() or c == ',') return float(rate.replace(',', '.'))
def main(): comp = PapirusComposite(False) comp.WriteAll() #build frame #comp.AddText(u"",0,0,14,fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') #cpu comp.AddText( u"\u256d\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u256e", 2, 0, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') comp.AddText( u"\u2570\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u256f", 2, 22, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') comp.AddText(u"\u2502", 2, 10, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') comp.AddText(u"\u2502", 122, 10, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') #mem comp.AddText( u"\u256d\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u256e", 132, 0, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') comp.AddText( u"\u2570\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u256f", 132, 22, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') comp.AddText(u"\u2502", 132, 10, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') comp.AddText(u"\u2502", 252, 10, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') #hdd comp.AddText( u"\u256d\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u256e", 2, 45, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') comp.AddText( u"\u2570\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u256f", 2, 83, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') comp.AddText(u"\u2502", 2, 57, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') comp.AddText(u"\u2502", 250, 57, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') comp.AddText(u"\u2502", 2, 70, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') comp.AddText(u"\u2502", 250, 70, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf') #fetch init data os, name, version, _, _, _ = platform.uname() version = version.split('-')[0] ipaddr = get_ips(network_adaptor) cpupercent = str(int(psutil.cpu_percent())) disk_free = psutil.disk_usage(mountpoint)[2] disk_used = psutil.disk_usage(mountpoint)[1] disk_percent = str(int(psutil.disk_usage(mountpoint)[3])) memory_percent = psutil.virtual_memory()[2] disk_total = int(psutil.disk_usage(mountpoint)[1]) + int( psutil.disk_usage(mountpoint)[2]) diskinfo = convert_size(disk_used) + ' / ' + convert_size(disk_total) center_diskinfo = int((264 // 2) - (len(diskinfo) // 2) - len(diskinfo) % 2) - 10 memory_info = psutil.virtual_memory() mem_total = memory_info.total mem_used = memory_info.used mem_info = convert_size(mem_used) + ' / ' + convert_size(mem_total) center_meminfo = int((264 // 2) - (len(mem_info) // 2) - len(mem_info) % 2) + 20 net = psutil.net_io_counters(pernic=True) tx_data = net[network_adaptor].bytes_sent rx_data = net[network_adaptor].bytes_recv net_data = convert_size(rx_data) + ' RX / ' + convert_size(tx_data) + ' TX' #add text comp.AddText("Uptime: " + uptime(), 2, 108, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf', Id="uptime") comp.AddText("Host: " + name + ' - ' + version, 2, 124, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf', Id="name_version") comp.AddText("Net: " + net_data, 2, 142, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf', Id="netdata") comp.AddText("IP: " + ipaddr, 2, 160, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf', Id="ipaddr") comp.AddText( cpupercent, 10, 25, 12, fontPath= '/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf', Id="cpupercentid") comp.AddText(drawProgressBar(psutil.cpu_percent()), 10, 10, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf', Id="cpubar") comp.AddText(drawProgressBar(memory_percent), 142, 10, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf', Id="membar") comp.AddText( mem_info, center_meminfo, 25, 10, fontPath= '/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf', Id="meminfo") comp.AddText(drawProgressBar(psutil.disk_usage(mountpoint)[3]), 10, 56, 29, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf', Id="diskbar") comp.AddText(diskinfo, center_diskinfo, 90, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf', Id="diskfree") while True: cpupercent = str(int(psutil.cpu_percent())) ipaddr = get_ips(network_adaptor) disk_free = psutil.disk_usage(mountpoint)[2] disk_used = psutil.disk_usage(mountpoint)[1] disk_percent = str(int(psutil.disk_usage(mountpoint)[3])) disk_total = int(psutil.disk_usage(mountpoint)[1]) + int( psutil.disk_usage(mountpoint)[2]) diskinfo = convert_size(disk_used) + ' / ' + convert_size(disk_total) center_diskinfo = int((264 // 2) - (len(diskinfo) // 2) - len(diskinfo) % 2) - 10 memory_info = psutil.virtual_memory() mem_info = convert_size(mem_used) + ' / ' + convert_size(mem_total) mem_total = memory_info.total mem_used = memory_info.used center_meminfo = int((264 // 2) - (len(mem_info) // 2) - len(mem_info) % 2) + 10 net = psutil.net_io_counters(pernic=True) tx_data = net[network_adaptor].bytes_sent rx_data = net[network_adaptor].bytes_recv net_data = convert_size(rx_data) + ' RX / ' + convert_size( tx_data) + ' TX' comp.UpdateText("ipaddr", "IP: " + ipaddr) comp.UpdateText("uptime", "Uptime: " + uptime()) comp.UpdateText("netdata", "Net: " + net_data) comp.UpdateText("cpubar", drawProgressBar(psutil.cpu_percent())) comp.UpdateText("membar", drawProgressBar(psutil.virtual_memory()[2])) comp.UpdateText("cpupercentid", cpupercent + '%') comp.RemoveText("diskfree") comp.AddText( diskinfo, center_diskinfo, 90, 14, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf', Id="diskfree") comp.RemoveText("meminfo") comp.AddText( mem_info, center_meminfo, 25, 10, fontPath= '/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf', Id="meminfo") comp.UpdateText("diskbar", drawProgressBar(psutil.disk_usage(mountpoint)[3])) comp.WriteAll(True) time.sleep(0.7) comp.clear()
try: f = urllib2.urlopen('http://192.168.1.104/admin/api.php') json_string = f.read() parsed_json = json.loads(json_string) adsblocked = parsed_json['ads_blocked_today'] ratioblocked = parsed_json['ads_percentage_today'] f.close() except: queries = '?' adsblocked = '?' ratio = '?' ratioblocked = '?' # Calling PapirusComposite this way will mean nothing is written to the screen until WriteAll is called textNImg = PapirusComposite(False) # Write text to the screen at selected point, with an Id # Nothing will show on the screen textNImg.AddText(str(adsblocked), 5, 5, Id="blocked", size=45) textNImg.AddText(str("%.1f" % round(ratioblocked, 2)) + "%", 5, 45, Id="percentage", size=45) # Add image # Nothing will show on the screen # textNImg.AddImg(path, posX,posY,(w,h),id) textNImg.AddImg(img, 120, 5, (80, 80), Id="pihole")
from time import sleep from papirus import PapirusComposite icons = [ "clear-day.bmp", "clear-night.bmp", "rain.bmp", "snow.bmp", "sleet.bmp", "wind.bmp", "fog.bmp", "cloudy.bmp", "partly-cloudy-day.bmp", "partly-cloudy-night.bmp" ] prefix = './assets/icons/' for icon in icons: path = prefix + icon textNImg = PapirusComposite(False) textNImg.AddText(icon, 10, 110, Id="Icon_Name") textNImg.AddImg(path, 10, 0, (100, 100), Id="Icon_Image") textNImg.WriteAll() sleep(1)
SW1 = 16 SW2 = 19 SW3 = 20 SW4 = 21 GPIO.setmode(GPIO.BCM) #Use BCM GPIO numbering #Set GPIO pins as inputs GPIO.setup(SW1, GPIO.IN) GPIO.setup(SW2, GPIO.IN) GPIO.setup(SW3, GPIO.IN) GPIO.setup(SW4, GPIO.IN) papirus = Papirus() #create papirus object textNImg = PapirusComposite(False) #create variable to store image/text #Boot image when started if server_status == True: textNImg.AddText("Press a button", 50, 5, Id="Start" ) textNImg.AddImg("images/StakeBox-Black.bmp",69,25,(125,125), Id="BigImg") textNImg.AddText("Server Status: Active ", 10, 156, Id="bottom") textNImg.WriteAll() else: textNImg.AddText("Press a button", 50, 5, Id="Start" ) textNImg.AddImg("images/StakeBox-Black.bmp",69,25,(125,125), Id="BigImg") textNImg.AddText("Server Status: Down ", 10, 156, Id="bottom") textNImg.WriteAll() #Exit program if RPC server is not running sys.exit('server not running')
def main(): print("Writing to Papirus.......") textNImg = PapirusComposite(False) textNImg.AddText('PiDrivR', 83, 20, 20) textNImg.AddText('WELCOME!', 92, 50, 15) textNImg.AddText('https://pidrivr.f0wl.cc', 54, 80, 10) image = 'logo.jpg' textNImg.AddImg(image, 0, 0, (55, 95)) textNImg.WriteAll() print("Finished Splashscreen!") time.sleep(10) papirus.clear() textNImg = PapirusComposite(False) textNImg.AddText('PiDrivR', 83, 5, 15) textNImg.AddText('https://pidrive.f0wl.cc', 55, 80, 10) image = 'logo.jpg' textNImg.AddImg(image, 0, 0, (55, 95)) while True: k.listen() runKismet() runGPSD() update_aps(wpa, wep, wps, none, total) if kismet_stat == 1: image2 = 'kismet.jpg' textNImg.AddImg(image2, 100, 2, (10, 12)) if gpsd_stat == 1: image3 = 'gps.jpg' textNImg.AddImg(image3, 115, 2, (12, 12)) textNImg.WriteAll() papirus.update()
def draw_image(papirus): # initially set all white background image = Image.new('1', papirus.size, WHITE) # prepare for drawing draw = ImageDraw.Draw(image) width, height = image.size clock_font_size = int((width - 4)/(20*0.65)) # 18 chars HH:MM:SS clock_font = ImageFont.truetype(CLOCK_FONT_FILE, clock_font_size) # clear the display buffer draw.rectangle((0, 0, width, height), fill=WHITE, outline=WHITE) while True: if GPIO.input(SW1) == False: textNImg = PapirusComposite(False) #Clears the draw buffer textNImg.AddImg("images/qr.png",60,10,(150,150), Id="BigImg") textNImg.WriteAll() if GPIO.input(SW3) == False: papirus.clear() while GPIO.input(SW3) == True & GPIO.input(SW1) == True & GPIO.input(SW4) == True: #Get info from RPC connection if config_path == trezarcoinpath: get_blocks = rpc_connection.getmininginfo()["blocks"] get_difficulty = rpc_connection.getmininginfo()["posdifficulty"] blocks = ('Blocks: %d' % get_blocks) difficulty = ('POS Difficulty: %d' % get_difficulty) get_curr_block_size = rpc_connection.getmininginfo()["currentblocksize"] get_curr_block_tx = rpc_connection.getmininginfo()["currentblocktx"] get_pooledtx = rpc_connection.getmininginfo()["pooledtx"] get_netweight = rpc_connection.getmininginfo()["stakeweight"] else: get_staking = rpc_connection.getstakinginfo()["staking"] get_search = rpc_connection.getstakinginfo()["search-interval"] get_weight = rpc_connection.getstakinginfo()["weight"] get_exp_time = rpc_connection.getstakinginfo()["expectedtime"] search_int = ('Search: %d' % get_search) weight = ('Weight: %d' % get_weight) staking = ('Staking: %s' % get_staking) expectedtime = ('Expected: %f' % get_exp_time) get_curr_block_size = rpc_connection.getstakinginfo()["currentblocksize"] get_curr_block_tx = rpc_connection.getstakinginfo()["currentblocktx"] get_pooledtx = rpc_connection.getstakinginfo()["pooledtx"] get_netweight = rpc_connection.getstakinginfo()["stakeweight"] #Append value to string currentblocksize = ('Block Size: %d' % get_curr_block_size) currentblocktx = ('Block Tx: %d' % get_curr_block_tx) pooledtx = ('PooledTx: %d' % get_pooledtx) netweight = ('Net Weight: %d' % get_netweight) #Write to the PaPiRus screen draw.rectangle((2, 2, width - 2, height - 2), fill=WHITE, outline=BLACK) if config_path == trezarcoinpath: draw.text((5, 10), blocks, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 70), difficulty, fill=BLACK, font=clock_font) else: draw.text((5, 10), staking, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 70), search_int, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 90), weight, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 130), expectedtime, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 10), currentblocksize, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 30), currentblocktx, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 50), pooledtx, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 110), netweight, fill=BLACK, font=clock_font) papirus.display(image) papirus.partial_update() if GPIO.input(SW4) == False: papirus.clear() while GPIO.input(SW3) == True & GPIO.input(SW1) == True & GPIO.input(SW4) == True: get_version = rpc_connection.getinfo()["version"] get_balance = rpc_connection.getinfo()["balance"] get_stake = rpc_connection.getinfo()["stake"] get_connection = rpc_connection.getinfo()["connections"] get_blocks = rpc_connection.getinfo()["blocks"] if config_path == trezarcoinpath: get_pos = rpc_connection.getmininginfo()["posdifficulty"] else: get_pos = rpc_connection.getstakinginfo()["posdifficulty"] version = ('Version: %s' % get_version) balance = ('Balance: %f' % get_balance) stake = ('Stake: %f' % get_stake) connections = ('Connections: %d' % get_connection) blocks = ('Blocks: %d' % get_blocks) pos = ('PoS: %f' % get_pos) #Write to the PaPiRus screen draw.rectangle((2, 2, width - 2, height - 2), fill=WHITE, outline=BLACK) draw.text((5, 10), version, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 10), balance, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 30), stake, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 50), connections, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 70), blocks, fill=BLACK, font=clock_font) draw.text((5, clock_font_size + 90), pos, fill=BLACK, font=clock_font) papirus.display(image) papirus.partial_update() sleep(0.1)