Exemple #1
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
    def __init__(self, config):

        self.config = config

        # Basic Inky settings
        inkyphat.set_colour(self.config.inky_color)
        inkyphat.set_border(self.config.inky_border_color)
        inkyphat.set_rotation(self.config.inky_rotate)

        # startup vars
        self.api_key = self.config.api_key
        self.coin_id = self.config.coin_id
        self.currency = self.config.currency
        self.coin_invest = self.config.coin_invest
        self.coin_amount = self.config.coin_amount
        self.show_roi = self.config.show_roi
        self.font = self.config.font_path
Exemple #3
0
def init_display(rotate):
    global icons, masks

    if not has_inky:
        print("Information for %s:" % (city))
        return

    if rotate:
        inkyphat.set_rotation(180)

    #----- Loads icon files and generates masks
    for icon in glob(PATH_FILENAME + ICON_SOURCE):
        icon_name = icon.split("icon-")[1].replace(".png", "")
        icon_image = Image.open(icon)
        icons[icon_name] = icon_image
        masks[icon_name] = inkyphat.create_mask(icon_image)

    return
Exemple #4
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()
Exemple #5
0
def draw_weather():
    weather = get_weather()
    if weather == None:
        print 'No weather!'
        return

    if ROTATE_180 == True:
        inkyphat.set_rotation(180)
    # TODO configurable color
    inkyphat.set_colour('red')
    inkyphat.set_border(inkyphat.RED)

    # background
    inkyphat.rectangle((0, 0, inkyphat.WIDTH, inkyphat.HEIGHT), inkyphat.RED)

    # draw columns
    # (assuming get_weather has returned using NUM_COLS)
    for i in range(0, NUM_COLS):
        # draw time label
        time = weather['hours'][i]['time']
        w, h = timeFont.getsize(time)
        draw_shadowed_text(get_x(w, i), 4, time, timeFont)

        # draw icon
        try:
            # This could be optimized to not load the same file more than once
            img = Image.open('assets/' + weather['hours'][i]['icon'] + '.png')
            inkyphat.paste(img, (get_x(30, i), 22))
            # drawing icons without transparency as it didn't work with whatever gimp was producing
        except:
            print 'Error with icon:' + weather['hours'][i]['icon']

        # draw temperature label
        temp = weather['hours'][i]['temperature']
        w, h = temperatureFont.getsize(temp)
        draw_shadowed_text(get_x(w, i), 56, temp, temperatureFont)

    # TODO multiple lines if too long
    draw_shadowed_text(5, 84, weather['summary'], summaryFont)

    inkyphat.show()
    item['online'] = online
    if online:
        item['viewers'] = data['stream']['viewers']
    STATE.append(item)
    sys.stdout.write('Done\n')

img = Image.new('RGBA', IMG_SIZE)
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
with io.BytesIO() as f:
    fig.savefig(f,
                dpi=dpi,
                cmap="bwr",
                interpolation="none",
                origin="lower",
                pad_inches=0)  #bbox_inches='tight')
    f.seek(0)
    i = Image.open(f)  #.convert('P', palette=(0,1,2))
    d = ImageDraw.Draw(i)
    ypos = 0 if ymax - last_high > last_low - ymin else h - 6

    if not args.output:
        from inkyphat import RED, BLACK, text, set_image, set_rotation, show
        set_image(i)
        if args.flip:
            set_rotation(180)
    else:
        RED = (255, 0, 0)
        BLACK = (0, 0, 0)
        text = d.text

    text((148, ypos), '{:.2f}'.format(last_close), BLACK, font)
    text((176, ypos), args.pair, RED, font)

    if args.output:
        i.save(args.output)
        raise SystemExit

    show()
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import inkyphat
import PIL
from PIL import ImageFont

inkyphat.set_rotation(180)

font = ImageFont.truetype(inkyphat.fonts.AmaticSC, 12)

bulb_width = 64
bulb_space = 5
bulb_fill = bulb_width - (bulb_space * 2)
margin_bottom = 5
margin_top = 5
margin_left = (inkyphat.HEIGHT - bulb_width) / 2
margin_right = (inkyphat.HEIGHT - bulb_width) / 2
hi_temp = 50
low_temp = -20
lowpoint = margin_bottom
hipoint = inkyphat.WIDTH - margin_top
# bulb_open_left =
# bulb_open_right =

def draw_bulb():
    # Main bulb
    inkyphat.arc((lowpoint, margin_left, lowpoint+bulb_width, margin_left+bulb_width), 30, 330, 1)
    inkyphat.arc((lowpoint-1, margin_left-1, lowpoint+bulb_width+1, margin_left+bulb_width+1), 30, 330, 1)

def draw_tube():
def main():
    """Shows basic usage of the Google Calendar API.

    Creates a Google Calendar API service object and outputs a list of the next
    10 events on the user's calendar.
    """
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('calendar', 'v3', http=http)

    now = datetime.datetime.utcnow().isoformat(
    ) + 'Z'  # 'Z' indicates UTC time
    print('Getting the upcoming 3 events')
    eventsResult = service.events().list(
        calendarId=
        '*****@*****.**',
        timeMin=now,
        maxResults=3,
        singleEvents=True,
        orderBy='startTime').execute()
    events = eventsResult.get('items', [])
    #inkyphat.set_border(inkyphat.BLACK)
    inkyphat.set_rotation(180)

    inkyphat.rectangle((0, 0, inkyphat.WIDTH, inkyphat.HEIGHT),
                       fill=inkyphat.WHITE)
    font = ImageFont.truetype(
        "/usr/share/fonts/truetype/freefont/FreeSans.ttf", 14)
    fontBold = ImageFont.truetype(
        "/usr/share/fonts/truetype/freefont/FreeSansBold.ttf", 14)
    fontBoldBig = ImageFont.truetype(
        "/usr/share/fonts/truetype/freefont/FreeSansBold.ttf", 15)
    offset_x, offset_y = 5, 0
    hasCurEvent = False
    if not events:
        print('No upcoming events found.')
        text = "No upcoming events found."
        inkyphat.text((offset_x, offset_y), text, inkyphat.RED, font=font)
    for event in events:
        start = parse(event['start'].get('dateTime',
                                         event['start'].get('date')))
        end = parse(event['end'].get('dateTime', event['end'].get('date')))
        print(start, end, event['summary'])
        colour = inkyphat.BLACK
        prefix = 'Next '
        if start < datetime.datetime.now(
                tzlocal()) and end > datetime.datetime.now(tzlocal()):
            hasCurEvent = True
            colour = inkyphat.RED
        #text = "{} - {}: {}".format(start.strftime('%a %H:%M'), end.strftime('%H:%M'), event['summary'])
        text = "{} - {}:".format(start.strftime('%a %H:%M'),
                                 end.strftime('%H:%M'))
        inkyphat.text((offset_x, offset_y), text, colour, font=fontBold)
        offset_y += fontBold.getsize(text)[1] + 2
        text = event['summary']
        inkyphat.text((offset_x + 10, offset_y), text, colour, font=font)
        offset_y += font.getsize(text)[1] + 2
        if offset_y >= inkyphat.HEIGHT:
            break
    curTime = datetime.datetime.now(tzlocal()).strftime('%H:%M')
    timeOffset = fontBoldBig.getsize(curTime)
    timeBox = [
        inkyphat.WIDTH - timeOffset[0] - 8, inkyphat.HEIGHT - timeOffset[1],
        inkyphat.WIDTH, inkyphat.HEIGHT
    ]
    inkyphat.rectangle(timeBox,
                       fill=inkyphat.RED if hasCurEvent else inkyphat.BLACK)
    inkyphat.text(
        (inkyphat.WIDTH - timeOffset[0] - 6, inkyphat.HEIGHT - timeOffset[1]),
        curTime,
        inkyphat.WHITE,
        font=fontBoldBig)
    inkyphat.show()