Exemplo n.º 1
0
    def set_caption(self, caption_text, caption_position, caption_color):
        # pylint: disable=line-too-long
        """A caption. Requires setting ``caption_font`` in init!

        :param caption_text: The text of the caption.
        :param caption_position: The position of the caption text.
        :param caption_color: The color of your caption text. Must be a hex value, e.g.
                              ``0x808000``.

        """
        # pylint: enable=line-too-long
        if self._debug:
            print("Setting caption to", caption_text)

        if (not caption_text) or (not self._caption_font) or (
                not caption_position):
            return  # nothing to do!

        if self._caption:
            self._caption._update_text(str(caption_text))  # pylint: disable=protected-access
            board.DISPLAY.refresh_soon()
            board.DISPLAY.wait_for_frame()
            return

        self._caption = Label(self._caption_font, text=str(caption_text))
        self._caption.x = caption_position[0]
        self._caption.y = caption_position[1]
        self._caption.color = caption_color
        self.splash.append(self._caption)
Exemplo n.º 2
0
    def set_text(self, val, index=0):
        """Display text, with indexing into our list of text boxes.

        :param str val: The text to be displayed
        :param index: Defaults to 0.

        """
        if self._text_font:
            string = str(val)
            if self._text_maxlen[index]:
                string = string[:self._text_maxlen[index]]
            if self._text[index]:
                # print("Replacing text area with :", string)
                # self._text[index].text = string
                # return
                try:
                    text_index = self.splash.index(self._text[index])
                except AttributeError:
                    for i in range(len(self.splash)):
                        if self.splash[i] == self._text[index]:
                            text_index = i
                            break

                self._text[index] = Label(self._text_font, text=string)
                self._text[index].color = self._text_color[index]
                self._text[index].x = self._text_position[index][0]
                self._text[index].y = self._text_position[index][1]
                self.splash[text_index] = self._text[index]
                return

            if self._text_position[index]:  # if we want it placed somewhere...
                print("Making text area with string:", string)
                self._text[index] = Label(self._text_font, text=string)
                self._text[index].color = self._text_color[index]
                self._text[index].x = self._text_position[index][0]
                self._text[index].y = self._text_position[index][1]
                self.splash.append(self._text[index])
Exemplo n.º 3
0
    def set_text(self, val, index=0):
        """Display text, with indexing into our list of text boxes.

        :param str val: The text to be displayed
        :param index: Defaults to 0.

        """
        if self._text_font:
            string = str(val)
            if self._text_maxlen[index]:
                string = string[:self._text_maxlen[index]]
            if self._text[index]:
                # print("Replacing text area with :", string)
                # self._text[index].text = string
                # return
                items = []
                while len(self.splash):  # pylint: disable=len-as-condition
                    item = self.splash.pop()
                    if item == self._text[index]:
                        break
                    items.append(item)
                self._text[index] = Label(self._text_font, text=string)
                self._text[index].color = self._text_color[index]
                self._text[index].x = self._text_position[index][0]
                self._text[index].y = self._text_position[index][1]
                self.splash.append(self._text[index])
                for g in items:
                    self.splash.append(g)
                return

            if self._text_position[index]:  # if we want it placed somewhere...
                print("Making text area with string:", string)
                self._text[index] = Label(self._text_font, text=string)
                self._text[index].color = self._text_color[index]
                self._text[index].x = self._text_position[index][0]
                self._text[index].y = self._text_position[index][1]
                self.splash.append(self._text[index])
Exemplo n.º 4
0
def updateBootProgress(phrase, step):
    global progressLabel

    if progressLabel is None:
        progressLabel = Label(arialFont, text = str(phrase))
        progressLabel.x = 30
        progressLabel.y = 30
        progressLabel.color = 0xFFFFFF
        primaryDisplayGroup.append(progressLabel)
    else:
        progressLabel._update_text(str(phrase))

    board.DISPLAY.refresh_soon()
    board.DISPLAY.wait_for_frame()
    pass
Exemplo n.º 5
0
def showTwitterStats(twitterName):

    global rootDirectory
    global statusNeopixel
    global setBackground
    global jsonTraverse
    global board
    global collegiateFont
    global primaryDisplayGroup

    url = "https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=" + twitterName
    countJsonPropPath = [0, "followers_count"]

    # get data from url
    statusNeopixel.fill((100, 100, 0))   # yellow = fetching data
    gc.collect()
    r = requests.get(url)
    gc.collect()
    statusNeopixel.fill((0, 0, 100))   # green = got data
    jsonData = r.json()
    r.close()
    gc.collect()

    count = jsonTraverse(jsonData, countJsonPropPath)

    # display data
    countLabel = Label(collegiateFont, text=str(count))
    countLabel.x = 200
    countLabel.y = 100
    countLabel.color = 0xFFFFFF
    primaryDisplayGroup.append(countLabel)

    # load github stat background
    setBackground(rootDirectory + "/twitter_background.bmp")

    # wait
    time.sleep(60)

    # cleanup!
    while countLabel:
        countLabel.pop()
Exemplo n.º 6
0
def showRedditStats(subreddit):

    global rootDirectory
    global statusNeopixel
    global setBackground
    global jsonTraverse
    global board
    global collegiateFont
    global primaryDisplayGroup

    url = "https://www.reddit.com/r/" + subreddit + "/about.json"
    countJsonPropPath = ["data", "subscribers"]

    # get data from url
    statusNeopixel.fill((100, 100, 0))   # yellow = fetching data
    gc.collect()
    r = requests.get(url)
    gc.collect()
    statusNeopixel.fill((0, 0, 100))   # green = got data
    jsonData = r.json()
    r.close()
    gc.collect()

    count = jsonTraverse(jsonData, countJsonPropPath)

    # display data
    countLabel = Label(collegiateFont, text=str(count))
    countLabel.x = 200
    countLabel.y = 100
    countLabel.color = 0xFFFFFF
    primaryDisplayGroup.append(countLabel)

    # load github stat background
    setBackground(rootDirectory + "/reddit_background.bmp")

    # wait
    time.sleep(60)

    # cleanup!
    while countLabel:
        countLabel.pop()
Exemplo n.º 7
0
def showGithubStats(repo):

    global rootDirectory
    global statusNeopixel
    global setBackground
    global jsonTraverse
    global board
    global collegiateFont
    global primaryDisplayGroup

    url = "https://api.github.com/repos" + repo + "?access_token="+secrets['github_token']
    countJsonPropPath = ["stargazers_count"]

    # get data from url
    statusNeopixel.fill((100, 100, 0))   # yellow = fetching data
    gc.collect()
    r = requests.get(url)
    gc.collect()
    statusNeopixel.fill((0, 0, 100))   # green = got data
    jsonData = r.json()
    r.close()
    gc.collect()

    count = jsonTraverse(jsonData, countJsonPropPath)

    # display data
    countLabel = Label(collegiateFont, text=str(count))
    countLabel.x = 200
    countLabel.y = 100
    countLabel.color = 0xFFFFFF
    primaryDisplayGroup.append(countLabel)

    # load github stat background
    setBackground(rootDirectory + "/githubstar.bmp")

    # wait
    time.sleep(60)

    # cleanup!
    while countLabel:
        countLabel.pop()
Exemplo n.º 8
0
def showLocalTemperature(LogToSd):

    global rootDirectory
    global setBackground
    global board
    global collegiateFont
    global primaryDisplayGroup

    temp = 

    # display data
    countLabel = Label(collegiateFont, text=str(count))
    countLabel.x = 100
    countLabel.y = 129
    countLabel.color = 0xFFFFFF

    countLabel2 = Label(collegiateFont, text=str(count))
    countLabel2.x = 155
    countLabel2.y = 180
    countLabel2.color = 0xFFFFFF

    primaryDisplayGroup.append(countLabel)
    primaryDisplayGroup.append(countLabel2)

    # load github stat background
    setBackground(rootDirectory + "/youtube_background.bmp")

    # wait
    time.sleep(60)

    # cleanup!
    while countLabel:
        countLabel.pop()

    while countLabel2:
        countLabel.pop()
# determine the current working directory
# needed so we know where to find files
cwd = ("/" + __file__).rsplit('/', 1)[0]
# Initialize the pyportal object and let us know what data to fetch and where
# to display it
mogwai_image = cwd + "/mogwai_background.bmp"
mogwai_sound = cwd + "/mogwai_alarm.wav"
gremlin_image = cwd + "/gremlin_background.bmp"
gremlin_sound = cwd + "/gremlin_alarm.wav"
pyportal = PyPortal(status_neopixel=board.NEOPIXEL,
                    default_bg="pyportal_startup.bmp")

big_font = bitmap_font.load_font(cwd + "/fonts/DSEG14ModernMiniBI-44.bdf")
big_font.load_glyphs(b'0123456789:AP')  # pre-load glyphs for fast printing

time_textarea = Label(big_font)
time_textarea.x = 0
time_textarea.y = 130
time_textarea.color = 0xFF0000
pyportal.splash.append(time_textarea)

# To help us know if we've changed the times, print them out!
gremlin_hour, gremlin_min = gremlin_time[3:5]
print("Gremlin time: %02d:%02d" % (gremlin_hour, gremlin_min))
mogwai_hour, mogwai_min = mogwai_time[3:5]
print("Mogwai time: %02d:%02d" % (mogwai_hour, mogwai_min))
gremlin_since_midnite = gremlin_hour * 60 + gremlin_min
mogwai_since_midnite = mogwai_hour * 60 + mogwai_min

# this is how we track whether to flip images
is_gremlin_time = None
Exemplo n.º 10
0
# determine the current working directory
# needed so we know where to find files
cwd = ("/" + __file__).rsplit('/', 1)[0]
# Initialize the pyportal object and let us know what data to fetch and where
# to display it
mogwai_image = cwd + "/mogwai_background.bmp"
mogwai_sound = cwd + "/mogwai_alarm.wav"
gremlin_image = cwd + "/gremlin_background.bmp"
gremlin_sound = cwd + "/gremlin_alarm.wav"
pyportal = PyPortal(status_neopixel=board.NEOPIXEL,
                    default_bg="pyportal_startup.bmp")

big_font = bitmap_font.load_font(cwd + "/fonts/DSEG14ModernMiniBI-44.bdf")
big_font.load_glyphs(b'0123456789:AP')  # pre-load glyphs for fast printing

time_textarea = Label(big_font, max_glyphs=15)
time_textarea.x = 0
time_textarea.y = 130
time_textarea.color = 0xFF0000
pyportal.splash.append(time_textarea)

# To help us know if we've changed the times, print them out!
gremlin_hour, gremlin_min = gremlin_time[3:5]
print("Gremlin time: %02d:%02d" % (gremlin_hour, gremlin_min))
mogwai_hour, mogwai_min = mogwai_time[3:5]
print("Mogwai time: %02d:%02d" % (mogwai_hour, mogwai_min))
gremlin_since_midnite = gremlin_hour * 60 + gremlin_min
mogwai_since_midnite = mogwai_hour * 60 + mogwai_min

# this is how we track whether to flip images
is_gremlin_time = None
Exemplo n.º 11
0
def showYoutubeStats(channelId):

    global rootDirectory
    global statusNeopixel
    global setBackground
    global jsonTraverse
    global board
    global collegiateFont
    global primaryDisplayGroup

    url = "https://www.googleapis.com/youtube/v3/channels/?part=statistics&id=" + channelId + "&key=" + secrets['youtube_token']
    countJsonPropPath = ["items", 0, "statistics", "viewCount"]
    count2JsonPropPath = ["items", 0, "statistics", "subscriberCount"]

    # get data from url
    statusNeopixel.fill((100, 100, 0))   # yellow = fetching data
    gc.collect()
    r = requests.get(url)
    gc.collect()
    statusNeopixel.fill((0, 0, 100))   # green = got data
    jsonData = r.json()
    r.close()
    gc.collect()

    count = jsonTraverse(jsonData, countJsonPropPath)
    count2 = jsonTraverse(jsonData, count2JsonPropPath)

    # display data
    countLabel = Label(collegiateFont, text=str(count))
    countLabel.x = 100
    countLabel.y = 129
    countLabel.color = 0xFFFFFF

    countLabel2 = Label(collegiateFont, text=str(count))
    countLabel2.x = 155
    countLabel2.y = 180
    countLabel2.color = 0xFFFFFF

    primaryDisplayGroup.append(countLabel)
    primaryDisplayGroup.append(countLabel2)

    # load github stat background
    setBackground(rootDirectory + "/youtube_background.bmp")

    # wait
    time.sleep(60)

    # cleanup!
    while countLabel:
        countLabel.pop()

    while countLabel2:
        countLabel.pop()
Exemplo n.º 12
0
            data.append(entry)
    the_day = raw_data[0]['DATE_TIME']
    pyportal.set_caption('UV Index for {0}'.format(extract_date(the_day)),
                         (80, 20),
                         0x000000)
    number_of_readings = len(data)
    whitespace = (number_of_readings - 1) * SPACE_BETWEEN_BARS + 2 * MARGIN
    bar_width = (320 - whitespace) // number_of_readings
    max_reading = max([d['value'] for d in data])

    while len(canvas) > 0:
        canvas.pop()

    for i, reading in enumerate(data):
        bar_height = (MAX_BAR_HEIGHT * reading['value']) // max_reading
        x = int(MARGIN + i * (bar_width + SPACE_BETWEEN_BARS))
        canvas.append(Rect(x, 200 - bar_height,
                           bar_width, bar_height,
                           fill=COLORS[reading['value']]))
        canvas.append(Label(bar_font,
                            x=x+3, y=220,
                            text=reading['hour'],
                            color=0x000000,
                            line_spacing=0.6))
        canvas.append(Label(bar_font,
                            x=x+(bar_width//2)-4, y=208-bar_height,
                            text=str(reading['value']),
                            color=0x000000))

    time.sleep(3600)                  #refresh hourly
Exemplo n.º 13
0
backlight_on = 0.8
pyportal.set_backlight(backlight_off)

# assign fonts
big_font = bitmap_font.load_font(cwd + "/fonts/Nunito-Light-75.bdf")
big_font.load_glyphs(b'0123456789:AP')  # pre-load glyphs for fast printing
print('loading fonts...')
info_font = bitmap_font.load_font(cwd + "/fonts/Nunito-Black-17.bdf")
info_font.load_glyphs(
    b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:/ ')

time_color = 0xFFFFFF
time_position = (75, 130)
time_textarea = Label(big_font,
                      max_glyphs=15,
                      color=time_color,
                      x=time_position[0],
                      y=time_position[1])

wakeup_time_color = 0xFFFFFF
wakeup_time_position = (15, 200)
wakeup_time_textarea = Label(info_font,
                             max_glyphs=30,
                             color=wakeup_time_color,
                             x=wakeup_time_position[0],
                             y=wakeup_time_position[1])

light_on_time_color = 0xFFFFFF
light_on_time_position = (15, 220)
light_on_time_textarea = Label(info_font,
                               max_glyphs=30,
Exemplo n.º 14
0
pages = []

pp = displayio.Group(max_size=10, x=0, y=0)
pages.append(pp)
page = 0

preload = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!,.%_ "\'?!\u00b0'  # NOQA

font1 = bitmap_font.load_font(cwd + "/fonts/Anton-Regular-30.bdf")
font1.load_glyphs(preload)
font1_height = font1.get_bounding_box()[1]

date_label = Label(font1,
                   max_glyphs=30,
                   color=0xbbbbff,
                   x=160,
                   y=int(font1_height / 2) + 20)
pp.append(date_label)

current_label = Label(font1, max_glyphs=30, color=0xbbbbff, x=20, y=210)
pp.append(current_label)

yy = 90
temp_label = Label(font1, max_glyphs=10, color=0xbbbbff, x=0, y=yy)
pp.append(temp_label)
yy += font1_height + 5

humid_label = Label(font1, max_glyphs=10, color=0xbbbbff, x=0, y=yy)
pp.append(humid_label)
yy += font1_height + 5