def write_weather_forecast(inkyphat):
    global weather_forecast_counter
    global weather_forecasts
    if weather_forecast_counter > 14:
        weather_forecast_counter = 0
        # get data from Yr
        # Paste link and append /varsel.xml
        r = requests.get(
            'https://www.yr.no/nb/oversikt/dag/2-6296790/Sverige/V%C3%A4stra%20G%C3%B6taland/H%C3%A4rryda%20Kommun/Landvetter%20lufthavn/varsel.xml',
            timeout=10)
        mydoc = minidom.parseString(r.text)
        temperatures = mydoc.getElementsByTagName('temperature')
        precipitations = mydoc.getElementsByTagName('precipitation')

        for i in range(3):
            t = str(temperatures[i].attributes['value'].value) + '° '
            if (precipitations[i].hasAttribute('minvalue')):
                minv = precipitations[i].attributes['minvalue'].value
                maxv = precipitations[i].attributes['maxvalue'].value
                t += str(maxv)
            else:
                t += '0'
            weather_forecasts[i] = t

    forecast_font = ImageFont.truetype(inkyphat.fonts.PressStart2P, 14)
    for i in range(3):
        inkyphat.text((0, i * inkyphat.HEIGHT / 3 + 10), weather_forecasts[i],
                      inkyphat.BLACK, forecast_font)

    weather_forecast_counter += 1
    return
Example #2
0
def printTitle(caption):
    nowTime = datetime.datetime.now()
    inkyphat.text((0, fontSize * 0),
                  caption + ' @' + nowTime.isoformat()[0:19],
                  inkyphat.RED,
                  font=font)
    inkyphat.line((0, fontSize, inkyphat.WIDTH, fontSize), inkyphat.BLACK, 1)
Example #3
0
def draw_ticket_id(rect, label, font):
    inkyphat.rectangle(rect, fill=inkyphat.WHITE)
    left, top, right, bottom = rect
    y_middle = (top + bottom)/2
    fw, fh = font.getsize(label)
    x = right - fw
    y = y_middle - fh/2
    inkyphat.text((x, y), label, inkyphat.BLACK, font)
def write_time(inkyphat):
    current = datetime.now().strftime('%H:%M')
    time_font = ImageFont.truetype(inkyphat.fonts.PressStart2P, 20)
    w, h = time_font.getsize(current)
    x = inkyphat.WIDTH - w
    y = inkyphat.HEIGHT - h
    inkyphat.text((x, y), current, inkyphat.BLACK, time_font)
    return
Example #5
0
def printlines(msg, pos=None, color=inkyphat.BLACK):
    lines = msg.splitlines()
    if pos is not None:
        x, y = pos
    else:
        x, y = (2, inkyphat.HEIGHT // 2 - fontheight * len(lines) // 2)
    for i, l in enumerate(lines):
        inkyphat.text((x, y + i * (fontheight + linespace)), l, color, font)
Example #6
0
def render_error(error):
    try:
        print("Error while updating display, attempting to render:", error)
        inkyphat.clear()
        inkyphat.set_border(inkyphat.WHITE)
        inkyphat.text((1, 1), repr(error), inkyphat.BLACK, font_errors)
    except Exception as error2:
        print("Exception while trying to render error:", error2)
Example #7
0
def printText(row, caption, value, postValueCaption):
    inkyphat.text((0, fontSize * (row + textLineOffset)),
                  caption,
                  inkyphat.BLACK,
                  font=font)
    inkyphat.text((65, fontSize * (row + textLineOffset)),
                  str(value) + " " + postValueCaption,
                  inkyphat.RED,
                  font=font)
    def update(self, temperature, weather):
        if temperature and weather:
            self.temp = temperature
            self.weather = weather
            self.active = True
        else:
            self.active = False
        self.update_colors()
        try:
            inkyphat.set_colour(self.color)
        except ValueError:
            print('Invalid colour "{}" for V{}\n'.format(
                self.color, inkyphat.get_version()))
            if inkyphat.get_version() == 2:
                sys.exit(1)
            print('Defaulting to "red"')

        inkyphat.set_border(inkyphat.BLACK)

        # Load our backdrop image
        inkyphat.set_image("resources/backdrop.png")

        # Let's draw some lines!
        inkyphat.line((69, 36, 69, 81))  # Vertical line
        inkyphat.line((31, 35, 184, 35))  # Horizontal top line
        inkyphat.line((69, 58, 174, 58))  # Horizontal middle line
        inkyphat.line((169, 58, 169, 58), 2)  # Red seaweed pixel :D

        # And now some text

        dt = (datetime.datetime.now() +
              datetime.timedelta(seconds=self.tz)).strftime("%m/%d %H:%M")

        inkyphat.text((36, 12), dt, inkyphat.WHITE, font=font)

        inkyphat.text((72, 34), "T", inkyphat.WHITE, font=font)
        inkyphat.text(
            (92, 34),
            u"{:.2f}°".format(self.temp),
            inkyphat.WHITE if self.temp < WARNING_TEMP else inkyphat.RED,
            font=font)

        inkyphat.text((72, 58),
                      "Active" if self.active else "Disconn",
                      inkyphat.WHITE,
                      font=font)

        # Draw the current weather icon over the backdrop
        if self.weather is not None:
            inkyphat.paste(icons[icon_mapping[self.weather]], (28, 36),
                           masks[icon_mapping[self.weather]])

        else:
            inkyphat.text((28, 36), "?", inkyphat.RED, font=font)

        self.display()
Example #9
0
def printFooter():
    nowTime = datetime.datetime.now()

    inkyphat.text((0, inkyphat.HEIGHT - fontSize),
                  "@",
                  inkyphat.BLACK,
                  font=font)
    inkyphat.text((15, inkyphat.HEIGHT - fontSize),
                  nowTime.isoformat()[0:19],
                  inkyphat.RED,
                  font=font)
Example #10
0
def display_tide(tide_hours, tide_coef, country):
    """
		Displays the tide info on inky display
	"""
    if not has_inky:
        print("Current tide:")
        print("Tide hours: %s, %s" % (tide_hours[0], tide_hours[1]))
        print("Coefficient: %s" % (tide_coef))

        return True

    #----- Display tide info

    if country == 'Fr':
        high_tide = "PM:"
    else:
        high_tide = "Hi:"
    inkyphat.text((12, 31), high_tide, inkyphat.BLACK, font=font18)
    if len(tide_hours) > 0:
        inkyphat.text((2, 50), tide_hours[0], inkyphat.RED, font=font18)
    if len(tide_hours) > 1:
        inkyphat.text((2, 68), tide_hours[1], inkyphat.RED, font=font18)
    inkyphat.text((8, 84), '(' + tide_coef + ')', inkyphat.BLACK, font=font18)

    return (True)
Example #11
0
def display_info(text, rotate = True):

	title = "%s %s" % (text, time.strftime('%d/%m %H:%M'))

	local_IP = "IP loc.: %s" % (read_local_ip())
	public_IP = "IP pub.: %s" % (read_public_ip())
	info_CPU = "CPU: T. {:2.0f} C, load {:2.0f} %".format(read_CPU_temp(), cpu_percent())

	if has_inky:
		inkyphat.clear()
		font18 = inkyphat.ImageFont.truetype(inkyphat.fonts.FredokaOne, 18)
		font20 = inkyphat.ImageFont.truetype(inkyphat.fonts.FredokaOne, 20)
		font24 = inkyphat.ImageFont.truetype(inkyphat.fonts.FredokaOne, 24)
		if rotate:
			inkyphat.set_rotation(180)

		inkyphat.rectangle((0, 0, 212, 30), red, red)
		width, height = font20.getsize(title)
		d, r = divmod(width, 2)
		inkyphat.text((106-d, 3), title, white, font=font20)
		inkyphat.rectangle((0, 31, 212, 104), white, white)

		inkyphat.text((5, 31), local_IP, black, font=font18)
		inkyphat.text((5, 53), public_IP, black, font=font18)
		inkyphat.text((5, 78), info_CPU, red, font=font18)
		inkyphat.show()
	else:
		print(title)
		print(local_IP)
		print(public_IP)
		print(temp_CPU)
	
	return local_IP, public_IP, info_CPU
Example #12
0
    def mode3(self):

        # background image
        img = Image.open(self.config.back_simple)
        inkyphat.set_image(img)

        # Add ranking text
        font = ImageFont.truetype(self.font, 22)
        inkyphat.text((45, 5), "#" + self.rank, inkyphat.WHITE, font)

        # Add the price text
        font = ImageFont.truetype(self.font, 48)
        price = str("%.3f" % self.price)
        inkyphat.text((44, 25), price, inkyphat.WHITE, font)

        # Add ROI Percentage
        actual_value = self.price * self.coin_amount
        percentage = (actual_value / self.coin_invest * 100) - 100
        font = ImageFont.truetype(self.font, 32)
        roistr = str("%.2f" % percentage + '%')
        if percentage > 0.0:
            inkyphat.text((44, 67), roistr, inkyphat.WHITE, font)
        else:
            inkyphat.text((44, 67), roistr, inkyphat.RED, font)

        inkyphat.show()
Example #13
0
def render_service(service, y):
    time_string = service.std
    destination_string = service.destination_text

    time_string_x = LEFT_PADDING
    time_string_y = y + font_services_offset
    destination_string_x = LEFT_PADDING + TIME_WIDTH
    destination_string_y = y + font_services_offset

    inkyphat.text((time_string_x, time_string_y), time_string, inkyphat.BLACK,
                  font_services)
    inkyphat.text((destination_string_x, destination_string_y),
                  destination_string, inkyphat.BLACK, font_services)

    cutout_start = inkyphat.WIDTH - DELAY_TEXT_WIDTH
    clear_area(cutout_start, y, DELAY_TEXT_WIDTH, LINE_HEIGHT)
    right_column_string_x = cutout_start + DELAY_TEXT_PADDING

    service_is_delayed = service.etd != 'On time'
    if (service_is_delayed):
        estimated_time_string = '({expected})'.format(expected=service.etd)
        inkyphat.text((right_column_string_x, y + font_times_offset),
                      estimated_time_string, inkyphat.BLACK, font_times)

    try:
        text_offset = 10 if service_is_delayed else 0
        text_offset = text_offset + font_times_offset
        time_departure_delta_string = pretty_time_delta(
            service.time_until_departure.total_seconds())
        inkyphat.text((right_column_string_x, y + text_offset),
                      time_departure_delta_string, inkyphat.YELLOW, font_times)
    except AttributeError:
        pass
Example #14
0
def display_title(text):

    now_time = strftime('%d/%m %H:%M')

    title_string = text + " " + now_time

    if not has_inky:
        print(title_string)
        return

    clear_display()
    inkyphat.rectangle((0, 0, 212, 30), inkyphat.RED, inkyphat.RED)
    width, height = font20.getsize(title_string)
    d, r = divmod(width, 2)
    inkyphat.text((106 - d, 3), title_string, inkyphat.WHITE, font=font20)
    return
Example #15
0
def draw_temperature():
    """Draw current temperature in the bulb area"""
    font = ImageFont.truetype(inkyphat.fonts.PressStart2P, font_size)
    text = str(int(round(currtemp))) + "C"
    pr = inkyphat.text(
        (margin_bottom + bulb_space + (bulb_width / 4), tubeline_top_y +
         (font_size - bulb_space)), text, inkyphat.WHITE, font)
Example #16
0
def display_data(data):
    font_file = inkyphat.fonts.FredokaOne

    top = 0
    left = 0
    offset_left = 5

    text_lines = [
        "Ada's Adventures in Science", "Backers {}".format(data['backers']),
        "{} - {:.1f}%".format(data['pledged'], data['percent'])
    ]
    font = inkyphat.ImageFont.truetype(font_file, 20)
    for text in text_lines:
        width, height = font.getsize(text)
        inkyphat.text((0, top), text, 1, font=font)
        top += height + 1
    inkyphat.show()
    return
Example #17
0
def updateDisplay(sunrise,  sunset, weather):
    fontSize = 16
    # Load the built-in FredokaOne font
    font = ImageFont.truetype(inkyphat.fonts.FredokaOne, fontSize)
    inkyphat.set_border(inkyphat.BLACK)
    inkyphat.text((0, fontSize * 0), "Tank", inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 1), "Sunrise: " + sunrise.isoformat(), inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 2), "Sunset: " + sunset.isoformat(), inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 3), "Weather: " + weather, inkyphat.BLACK, font=font)
    
    # And show it!
    inkyphat.show()
Example #18
0
def display_weather(weather_data):
    """
		Displays the weather data on inky display
	"""
    global icons, masks
    global inkyphat

    if weather_data['condition_code'] in icon_mapping:
        icon_current = icon_mapping[weather_data['condition_code']]
        tolog("...icon %s" % (icon_current))
    else:
        icon_current = None
        tolog("...no icon found")

    if not has_inky:
        print("Current weather:")
        print("Temperature = %s" % (weather_data['temp']))
        print("Time weather = %s" % (weather_data['time']))
        print("Condition = %s" % (weather_data['condition_name']))
        return True

    if icon_current is not None:
        inkyphat.paste(icons[icon_current], (8, 44), masks[icon_current])
    else:
        inkyphat.text((16, 54), "?", inkyphat.RED, font=font20)

    inkyphat.text((14, 84),
                  u"{:.0f}°".format(weather_data['temp']),
                  inkyphat.RED,
                  font=font18)
    inkyphat.text((3, 32), weather_data['time'], inkyphat.BLACK, font=font18)

    return True
Example #19
0
def printBusTimes(times):
    prefix = ["82:", "Rosa:", bustimes.Either("158:", "82B:")]
    m = "min"
    op = []
    toL5 = lambda s: " " * (max(5 - len(s), 0)) + s
    for i, ts in enumerate(times):
        if type(ts) is bustimes.Either:
            pf = prefix[i].left if ts.left else prefix[i].right
            next_times = ts.left if ts.left else ts.right
        else:
            pf = prefix[i]
            next_times = ts
        s = [pf, "-", "-"]
        for j, t in enumerate(next_times):
            s[j + 1] = "Núna!" if t == 0 else str(t) + m
        op.append(" ".join(map(toL5, s)))
    bt = "\n".join(op)
    inkyphat.clear()
    td = datetime.now().strftime("%Y-%m-%d %H:%M")
    inkyphat.text(((inkyphat.WIDTH - 16 * fontwidth) // 2, 18), td,
                  inkyphat.RED, font)
    inkyphat.text((inkyphat.WIDTH // 2 - 14 * fontwidth // 2, 2),
                  "Strætóferðir", inkyphat.RED, bigfont)
    printlines(bt)
    vtc = ((inkyphat.WIDTH - 10 * 14 - vt.size[0] - 10) // 2,
           inkyphat.HEIGHT - 2 - 14)
    inkyphat.text((vtc[0] + vt.size[0] + 2, vtc[1] - 4), "Västtrafik",
                  inkyphat.RED, bigfont)
    inkyphat.paste(vt, ((vtc[0], vtc[1] - vt.size[1] + 14 - 2)))
    inkyphat.show()
Example #20
0
    def display_notification_message(self, data):

        message = data[0]
        message2 = data[1]
        message3 = data[2]

        inkyphat.set_colour("black")

        font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 26)
        font2 = ImageFont.truetype(inkyphat.fonts.FredokaOne, 20)
        font3 = ImageFont.truetype(inkyphat.fonts.FredokaOne, 14)

        print(message)
        print(message2)
        print(message3)

        w, h = font.getsize(message)
        x = (inkyphat.WIDTH / 2) - (w / 2)
        y = (inkyphat.HEIGHT / 3) - (h / 1.5)
        inkyphat.text((x, y), message, inkyphat.BLACK, font)

        w, h = font2.getsize(message2)
        x = (inkyphat.WIDTH / 2) - (w / 2)
        y = (inkyphat.HEIGHT / 2) - 5
        inkyphat.text((x, y), message2, inkyphat.BLACK, font2)

        w, h = font2.getsize(message3)
        x = (inkyphat.WIDTH / 2) - (w / 2)
        y = (inkyphat.HEIGHT / 3) * 2
        inkyphat.text((x, y), message3, inkyphat.BLACK, font2)

        inkyphat.show()
Example #21
0
    def mode1(self):

        # background image
        img = Image.open(self.config.background)
        inkyphat.set_image(img)

        # Add the price text
        font = ImageFont.truetype(self.font, 36)
        price = str("%.3f" % self.price)
        inkyphat.text((4, 5), price, inkyphat.RED, font)

        # Add the day change text
        font = ImageFont.truetype(self.font, 22)
        day = "%.2f" % self.day
        if self.day > 0.0:
            inkyphat.text((7, 42), str(day), inkyphat.BLACK, font)
        if self.day < 0.0:
            inkyphat.text((7, 42), str(day), inkyphat.RED, font)

        # Add the ROI as FIAT
        if self.config.show_roi == True:

            font = ImageFont.truetype(self.font, 34)
            roi = self.price * self.coin_amount
            roistr = str("%.2f" % roi)
            inkyphat.text((4, 75), roistr, inkyphat.WHITE, font)

        # Add the ROI as percentage
        else:

            actual_value = self.price * self.coin_amount
            percentage = (actual_value / self.coin_invest * 100) - 100
            font = ImageFont.truetype(self.font, 34)
            roistr = str("%.2f" % percentage + '%')
            inkyphat.text((4, 75), roistr, inkyphat.WHITE, font)

        inkyphat.show()
Example #22
0
def main():
    fontSize = 16
    mySunrise = sunRiseSet() # Get sunrise and sunset from DB
    mySunrise.getSunriseset();
    
    myWeather  = weather()
    myWeather.getWeather()
    
    # Load the built-in FredokaOne font
    font = ImageFont.truetype(inkyphat.fonts.FredokaOne, fontSize)

    inkyphat.set_border(inkyphat.BLACK)
    
    inkyphat.text((0, fontSize * 0), "Tank", inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 1), "Sunrise: " + mySunrise.sunrise.isoformat(), inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 2), "Sunset: " + mySunrise.sunset.isoformat(), inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 3), "Weather: " + myWeather.weather, inkyphat.BLACK, font=font)
    
    # And show it!
    inkyphat.show()
def write_temperature(inkyphat):
    # get sensor data (top line)
    temperature = get_sensor_data(TEMP_SENSOR_1)
    time_font = ImageFont.truetype(inkyphat.fonts.PressStart2P, 25)
    w, h = time_font.getsize(temperature)
    inkyphat.text((inkyphat.WIDTH / 2 + 4, 5), temperature + '°',
                  inkyphat.BLACK, time_font)
    # write a 'v' indicating west sensor
    message = 'V'
    message_font = ImageFont.truetype(inkyphat.fonts.PressStart2P, 14)
    wm, hm = message_font.getsize(message)
    inkyphat.text((inkyphat.WIDTH - wm, 5), message, inkyphat.RED,
                  message_font)
    # get sensor data (second line)
    temperature = get_sensor_data(TEMP_SENSOR_2)
    inkyphat.text((inkyphat.WIDTH / 2 + 4, h + 20), temperature + '°',
                  inkyphat.BLACK, time_font)
    # write 'n' for north sensor
    message = 'N'
    wm, hm = message_font.getsize(message)
    inkyphat.text((inkyphat.WIDTH - wm, h + 20), message, inkyphat.RED,
                  message_font)
    return
Example #24
0
def display_forecast(forecast_data):
    """
		Displays the forecast data on inky display
	"""
    global icons, masks
    global inkyphat

    if not has_inky:
        print("Forecast weather:")
        for day in range(nb_forecast):
            daily_forecast = forecast_data[day]
            print("For %s at Noon: Weather is %s, temperature is %s" %
                  (daily_forecast['nameday'], daily_forecast['condition_name'],
                   daily_forecast['temp']))
        return True

    for day in range(nb_forecast):
        daily_forecast = forecast_data[day]

        if daily_forecast['condition_code'] in icon_mapping:
            icon_current = icon_mapping[daily_forecast['condition_code']]
            tolog("...icon %s" % (icon_current))
        else:
            icon_current = None
            tolog("...no icon found")

        # Draw the current weather icon over the backdrop
        if icon_current is not None:
            inkyphat.paste(icons[icon_current], (52 + day * 38, 44),
                           masks[icon_current])
        else:
            inkyphat.text((56 + day * 38, 54), "?", inkyphat.RED, font=font20)

        inkyphat.text((64 + day * 38, 84),
                      u"{:.0f}°".format(daily_forecast['temp']),
                      inkyphat.RED,
                      font=font18)
        inkyphat.text((64 + day * 38, 32),
                      daily_forecast['nameday'],
                      inkyphat.BLACK,
                      font=font18)

    return True
Example #25
0
def displayStatus(statusString):
    # Prepare the String into two lines
    wrapped = textwrap.wrap(statusString, width=20)

    # Show the backdrop image
    inkyphat.set_colour(config["inkyphatConfig"]["colour"])
    inkyphat.set_border(inkyphat.RED)
    inkyphat.set_image("background.png")
    inkyphat.set_rotation(config["inkyphatConfig"]["rotation"])

    # Add the text
    font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 21)

    # Title Line
    line_one = config["inkyphatConfig"]["line_one"]
    w, h = font.getsize(line_one)
    # Center the text and align it with the name strip
    x = (inkyphat.WIDTH / 2) - (w / 2)
    y = 18 - (h / 2)
    inkyphat.text((x, y), line_one, inkyphat.WHITE, font)

    if(len(wrapped) >= 1):
        # Status Line 1
        status_one = wrapped[0]
        w, h = font.getsize(status_one)
        # Center the text and align it with the name strip
        x = (inkyphat.WIDTH / 2) - (w / 2)
        y = 50 - (h / 2)
        inkyphat.text((x, y), status_one, inkyphat.BLACK, font)


    if(len(wrapped) >= 2):
        # Status Line 2
        status_two = wrapped[1]
        w, h = font.getsize(status_two)
        # Center the text and align it with the name strip
        x = (inkyphat.WIDTH / 2) - (w / 2)
        y = 80 - (h / 2)
        inkyphat.text((x, y), status_two, inkyphat.BLACK, font)


    inkyphat.show()
Example #26
0
def show_image(infile, temp_data=None, pressure_data=None, humidity_data=None):
    font = ImageFont.truetype("/usr/local/share/fonts/DejaVuSans.ttf", 14)

    temp_info = create_informatics(temp_data)
    press_info = create_informatics(pressure_data)
    humidity_info = create_informatics(humidity_data)

    inkyphat.set_image(Image.open(infile))
    inkyphat.text((110, 10), "{0:.1f}°F \n {1}".format(temp_data[-1],
                                                       temp_info),
                  inkyphat.BLACK, font)
    inkyphat.text((110, 40),
                  "{0:.0f} hPa \n {1}".format(pressure_data[-1], press_info),
                  inkyphat.BLACK, font)
    inkyphat.text((110, 70),
                  "{0:.0f} %RH \n {1}".format(humidity_data[-1],
                                              humidity_info), inkyphat.BLACK,
                  font)

    inkyphat.show()
Example #27
0
fnt = ImageFont.truetype(FONT_PATH, FONT_SIZE)

title_text_w, title_text_h = fnt.getsize(TITLE)
date_text_w, date_text_h = fnt.getsize(NOW)

DATE_POSITION = ((IMG_WIDTH - date_text_w - MARGIN * 2), MARGIN)
TITLE_POSITION = (MARGIN * 2, MARGIN)

inkyphat.set_rotation(180)
inkyphat.set_border(config['FOREGROUND_COLOR'])
inkyphat.rectangle((0, 0, IMG_WIDTH, IMG_HEIGHT),
                   fill=config['BACKGROUND_COLOR'])

inkyphat.rectangle((0, 0, IMG_WIDTH, MARGIN_TOP - MARGIN),
                   fill=config['FOREGROUND_COLOR'])
inkyphat.text(DATE_POSITION, NOW, font=fnt, fill=config['BACKGROUND_COLOR'])
inkyphat.text(TITLE_POSITION, TITLE, font=fnt, fill=config['BACKGROUND_COLOR'])

index = 0
for stream in STATE:
    magic = (MARGIN * 2)
    right_offset = 40
    text_x = MARGIN * 3 + FONT_SIZE + right_offset
    text_y = MARGIN_TOP + (FONT_SIZE + MARGIN) * index + magic

    circle_x1 = MARGIN + right_offset
    circle_y1 = text_y + 2 - magic
    circle_x2 = MARGIN + FONT_SIZE - 2 + right_offset
    circle_y2 = text_y + FONT_SIZE - magic
    circle_fill = config['BACKGROUND_COLOR']
Example #28
0
if inkyphat.get_version() == 1:
    inkyphat.show()

# FONTS
font10 = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Regular.ttf', 10)
font10b = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 10)
font22 = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 22)
font28 = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 28)

# TOP infos
Rdatew, Rdateh = font10.getsize(Rdate)
inkyphat.text((3, -2), str(Rhour), inkyphat.RED, font22)
inkyphat.text((inkyphat.WIDTH - Rdatew - 6, 6), str(Rdate + ' '),
              inkyphat.BLACK, font10)
inkyphat.line((3, 23, inkyphat.WIDTH - 3, 23),
              inkyphat.BLACK)  # Horizontal separator

# INSIDE readings
insideT = str(d["inside"]["temp"])
insideH = str(d["inside"]["humi"])
inkyphat.text((6, 30), "IN: ", inkyphat.RED, font10)
inkyphat.text((35, 25), insideT + degSign, inkyphat.RED, font28)
inkyphat.text((35, 50), insideH + '%', inkyphat.BLACK, font22)

# OUTSUDE readings
outsideT = str(d["outside"]["temp"])
outsideP = str(d["outside"]["press"])
Example #29
0
inkyphat.set_border(inkyphat.RED)
inkyphat.set_image("resources/hello-badge.png")

# Partial update if using Inky pHAT display v1

if inkyphat.get_version() == 1:
    inkyphat.show()

# Add the text

font = ImageFont.truetype(inkyphat.fonts.AmaticSCBold, 38)

name = sys.argv[1]

w, h = font.getsize(name)

# Center the text and align it with the name strip

x = (inkyphat.WIDTH / 2) - (w / 2)
y = 71 - (h / 2)

inkyphat.text((x, y), name, inkyphat.BLACK, font)

# Partial update if using Inky pHAT display v1

if inkyphat.get_version() == 1:
    inkyphat.set_partial_mode(56, 96, 0, inkyphat.WIDTH)

inkyphat.show()
Example #30
0
def draw_shadowed_text(x, y, text, font):
    inkyphat.text((x + 1, y + 1), text, inkyphat.BLACK, font=font)
    inkyphat.text((x, y), text, inkyphat.WHITE, font=font)
    parser = SafeConfigParser()
    parser.read('/etc/pithermostat.conf')
    redishost=parser.get('redis','broker')
    redisport=int(parser.get('redis','port'))
    redisdb=parser.get('redis','db')
    redistimeout=float(parser.get('redis','timeout'))
    room_location = parser.get('locale','location')
    redthis=redis.StrictRedis(host=redishost,
                              port=redisport,  
                              db=redisdb, 
                              socket_timeout=redistimeout)
except:
    import inkyphat
    inkyphat.set_border(inkyphat.BLACK)
    inkyphat.text((36, 12), "No WiFi", inkyphat.WHITE, font=font)
    inkyphat.show()
    exit("Unable to read from /etc/pithermostat.conf")

try:
    import requests
except ImportError:
    exit("This script requires the requests module\nInstall with: sudo pip install requests")

import inkyphat


inkyphat.set_border(inkyphat.BLACK)

CITY = "Bradford"
COUNTRYCODE = "GB"
    parser = SafeConfigParser()
    parser.read('/etc/pithermostat.conf')
    redishost=parser.get('redis','broker')
    redisport=int(parser.get('redis','port'))
    redisdb=parser.get('redis','db')
    redistimeout=float(parser.get('redis','timeout'))
    room_location = parser.get('locale','location')
    redthis=redis.StrictRedis(host=redishost,
                              port=redisport,  
                              db=redisdb, 
                              socket_timeout=redistimeout)
except:
    import inkyphat
    inkyphat.set_border(inkyphat.BLACK)
    inkyphat.text((36, 12), "No WiFi", inkyphat.WHITE, font=font)
    inkyphat.show()
    exit("Unable to read from /etc/pithermostat.conf")

try:
    import requests
except ImportError:
    exit("This script requires the requests module\nInstall with: sudo pip install requests")

import inkyphat


inkyphat.set_border(inkyphat.BLACK)

CITY = "Bradford"
COUNTRYCODE = "GB"