Example #1
0
def loop():
    # drawing code here
    if ip_address:
        screen.image(ready_image)
        screen.text(
            ip_address,
            xy=(10, 230),
            align='bottomleft',
            color='white',
            font_size=10,
        )
    else:
        screen.image(no_network_image)
Example #2
0
def loop2():
    # drawing code here
    screen.fill(color='black')  # Use a black background
    # screen.text('Hello world!')

    # Draw the on-screen buttons
    # "plus-box-outline" (Increase the thermostat temperature)
    screen.text(button_inc_text,
                xy=button_inc_xy,
                align=button_inc_align,
                font_size=button_font_size,
                font=icon_font)
    # "minus-box-outline" (Decrease the thermostat temperature)
    screen.text(button_dec_text,
                xy=button_dec_xy,
                align=button_dec_align,
                font_size=button_font_size,
                font=icon_font)

    # Draw the info text in the center of the screen in the format of:
    # "[current temp] ([thermostat wanted temp] ; [thermostat state])"
    screen.text('{0} ({1} ; {2})'.format(temp, climate_temp, climate_state))

    # Prepare the thermostat state icon
    color = 'gray'  # Initialize color as gray
    if climate_state == 'idle' or climate_state == 'off':
        # If the climate is idle or off, set the icon as inactive (idle
        # color)
        color = color_idle
    else:
        # Otherwise set the icon as active/on
        color = color_active

    # Draw the thermostat state icon
    screen.text(icon, xy=(20, 20), color=color, font=icon_font)
Example #3
0
def draw_clock_page():
    screen.text(gui.current_time,
                xy=CLOCK_LABEL_TIME["xy"],
                color=CLOCK_LABEL_TIME["color"],
                font_size=CLOCK_LABEL_TIME["font_size"],
                align=CLOCK_LABEL_TIME["align"])
    if time.localtime().tm_sec % 2 == 1:
        # Draw the time separator every other second (blink the separator)
        screen.text(":",
                    xy=CLOCK_LABEL_TIME["xy"],
                    color=CLOCK_LABEL_TIME["color"],
                    font_size=CLOCK_LABEL_TIME["font_size"],
                    align=CLOCK_LABEL_TIME["align"])

    screen.text(gui.current_date,
                xy=CLOCK_LABEL_DATE["xy"],
                color=CLOCK_LABEL_DATE["color"],
                font_size=CLOCK_LABEL_DATE["font_size"],
                align=CLOCK_LABEL_DATE["align"])
    # next_alarm = "(no current alarms)"
    next_alarm = localized_strings.get_alarm(None)
    if alarm.next_alarm() is not None:
        # Humanize the next alarm datetime to a string
        next_alarm = localized_strings.get_alarm(
            arrow.get(alarm.next_alarm()).humanize(locale=current_locale))
        # next_alarm = arrow.get(alarm.next_alarm()).humanize()
    # Draw the next alarm info on the bottom left of the the screen
    screen.text(next_alarm,
                xy=CLOCK_LABEL_ALARM_NEXT["xy"],
                color=CLOCK_LABEL_ALARM_NEXT["color"],
                font_size=CLOCK_LABEL_ALARM_NEXT["font_size"],
                align=CLOCK_LABEL_ALARM_NEXT["align"])
Example #4
0
def loop():
    if data['background_image']:
        screen.image(data['background_image'])
    else:
        screen.fill(color='black')

    screen.text(
        data['location'],
        xy=(22, 30),
        align='left',
        color='white',
        font='HelveticaNeue-Bold.ttf',
        font_size=24,
    )
    screen.text(
        data['temp'],
        xy=(22, 160),
        align='left',
        color='white',
        font='HelveticaNeue-Bold.ttf',
        font_size=70,
    )
    screen.text(
        data['description'],
        xy=(22, 213),
        align='left',
        color='white',
        font='HelveticaNeue.ttf',
        font_size=22,
    )
    screen.text(
        data['current_date'],
        xy=(300, 190),
        align='right',
        font='HelveticaNeue.ttf',
        font_size=22,
        color='white',
    )
    screen.text(
        data['current_time'],
        xy=(300, 213),
        align='right',
        font='HelveticaNeue.ttf',
        font_size=22,
        color='white',
    )
Example #5
0
def loop():
    if data['background_image']:
        screen.image(data['background_image'])
    else:
        screen.fill(color='black')

    screen.text (
        data['location'],
        xy=(22,30),
        align='left',
        color='white',
        font='HelveticaNeue-Bold.ttf',
        font_size=24,
    )
    screen.text (
        data['temp'],
        xy=(22,160),
        align='left',
        color='white',
        font='HelveticaNeue-Bold.ttf',
        font_size=70,
    )
    screen.text (
        data['description'],
        xy=(22,213),
        align='left',
        color='white',
        font='HelveticaNeue.ttf',
        font_size=22,
    )
    screen.text (
        data['current_date'],
        xy=(300,190),
        align='right',
        font='HelveticaNeue.ttf',
        font_size=22,
        color='white',
    )
    screen.text (
        data['current_time'],
        xy=(300,213),
        align='right',
        font='HelveticaNeue.ttf',
        font_size=22,
        color='white',
    )
Example #6
0
def loop():
    if data["background_image"]:
        screen.image(data["background_image"])
    else:
        screen.fill(color="black")

    screen.text(data["location"], xy=(22, 30), align="left", color="white", font="HelveticaNeue-Bold.ttf", font_size=24)
    screen.text(data["temp"], xy=(22, 160), align="left", color="white", font="HelveticaNeue-Bold.ttf", font_size=70)
    screen.text(data["description"], xy=(22, 213), align="left", color="white", font="HelveticaNeue.ttf", font_size=22)
    screen.text("Now", xy=(300, 213), align="right", font="HelveticaNeue.ttf", font_size=22, color="white")
Example #7
0
def loop():
    screen.fill(color='black')

    screen.text (
        'Hello World',
        xy=(22,30),
        align='left',
        color='white',
        font_size=12,
    )

    screen.text (
        messages[0]['subject'],
        xy=(22,100),
        align='left',
        color='white',
        font_size=12,
    )
Example #8
0
def loop():
    for child in root[0]:
        name = child.get("name")
        position = child.find("position")
        align = child.get("align")
        xy = None
        if position is not None:
            xy = (int(position.get("x")), int(position.get("y")))
        if child.tag in ["text", "rectangle", "scroll_text"]:
            color_node = child.find("color")
            color = (int(color_node.get("red")), int(color_node.get("green")), int(color_node.get("blue")))
            if child.tag == "text":
                font_size = int(child.get("font_size"))
                text = child.find("text").text

                screen.text(text, color=color, xy=xy, align=align, font_size=font_size)
            elif child.tag == "scroll_text":
                font_size = int(child.get("font_size"))
                text = child.find("text").text
                hpos = int(child.get("hpos"))
                margin_node = child.find("margin")
                margin = (int(margin_node.get("left")), int(margin_node.get("right")))
                if name not in scroll_texts:
                    scroll_texts[name] = ScrollText(screen.surface, 
                    text, hpos, color, margin, font_size,
                    font=os.path.join(os.path.dirname(inspect.getfile(tingbot)), 'Geneva.ttf'))
                else:
                    scroll_texts[name].update_text(text)
                    scroll_texts[name].update()
            elif child.tag == "rectangle":
                size_node = child.find("size")
                align = child.get("align")
                size = (int(size_node.get("w")), int(size_node.get("h")))

                screen.rectangle(xy=xy, size=size, color=color, align=align)
        elif child.tag == "image":
            scale = float(child.get("scale"))
            src = child.get("src")
            screen.image(src, xy=xy, scale=scale, align=align)
Example #9
0
def draw_clock_page():
    screen.text(
        gui.current_time,
        xy=CLOCK_LABEL_TIME["xy"],
        color=CLOCK_LABEL_TIME["color"],
        font_size=CLOCK_LABEL_TIME["font_size"],
        align=CLOCK_LABEL_TIME["align"]
    )
    if time.localtime().tm_sec%2 == 1:
        # Draw the time separator every other second (blink the separator)
        screen.text(
            ":",
            xy=CLOCK_LABEL_TIME["xy"],
            color=CLOCK_LABEL_TIME["color"],
            font_size=CLOCK_LABEL_TIME["font_size"],
            align=CLOCK_LABEL_TIME["align"]
        )

    screen.text(
        gui.current_date,
        xy=CLOCK_LABEL_DATE["xy"],
        color=CLOCK_LABEL_DATE["color"],
        font_size=CLOCK_LABEL_DATE["font_size"],
        align=CLOCK_LABEL_DATE["align"]
    )
    # next_alarm = "(no current alarms)"
    next_alarm = localized_strings.get_alarm(None)
    if alarm.next_alarm() is not None:
        # Humanize the next alarm datetime to a string
        next_alarm = localized_strings.get_alarm(arrow.get(alarm.next_alarm()).humanize(locale=current_locale))
        # next_alarm = arrow.get(alarm.next_alarm()).humanize()
    # Draw the next alarm info on the bottom left of the the screen
    screen.text(
        next_alarm,
        xy=CLOCK_LABEL_ALARM_NEXT["xy"],
        color=CLOCK_LABEL_ALARM_NEXT["color"],
        font_size=CLOCK_LABEL_ALARM_NEXT["font_size"],
        align=CLOCK_LABEL_ALARM_NEXT["align"]
    )
Example #10
0
def loop():
    if not gui.initialized:
        if config.MOUSE_VISIBLE:
            pygame.mouse.set_visible(config.MOUSE_VISIBLE)
        pygame.display.set_caption(localized_strings.title)
        gui.initialized = True
    perform_key_events()
    screen.fill(color=COLOR_BLUE_DARK)

    screen.image("res/images/banner-911778_1280.jpg", xy=(0, 0), align="top")

    if alarm.current_alarm is not None:
        # Alarm currently firing - Show the Alarm Page
        screen.text(ALARM_LABEL_TITLE["text"] % alarm.current_alarm,
                    xy=ALARM_LABEL_TITLE["xy"],
                    color=ALARM_LABEL_TITLE["color"],
                    font_size=ALARM_LABEL_TITLE["font_size"],
                    align=ALARM_LABEL_TITLE["align"])
        p.player.mute()
    else:
        for child in gui.root[gui.current_page - 1]:
            name = child.get("name")
            position = child.find("position")
            align = child.get("align")
            xy = None
            if position is not None:
                xy = (int(position.get("x")), int(position.get("y")))
            if child.tag in ["text", "rectangle", "scroll_text"]:
                color_node = child.find("color")
                color = (int(color_node.get("red")),
                         int(color_node.get("green")),
                         int(color_node.get("blue")))
                if child.tag == "text":
                    font_size = int(child.get("font_size"))
                    text = child.find("text").text
                    if name == "time":
                        text = gui.current_time
                    elif name == "date":
                        text = gui.current_date
                    elif name == "time_sep" and time.localtime(
                    ).tm_sec % 2 != 1:
                        continue
                    if gui.current_page == PAGE_INDEX_RADIO:
                        if child.get("name") == "station_name":
                            text = gui.radio_station_name_text + ''
                    screen.text(text,
                                color=color,
                                xy=xy,
                                align=align,
                                font_size=font_size)
                elif child.tag == "scroll_text":
                    font_size = int(child.get("font_size"))
                    text = child.find("text").text
                    hpos = int(child.get("hpos"))
                    margin_node = child.find("margin")
                    margin = (int(margin_node.get("left")),
                              int(margin_node.get("right")))
                    if gui.current_page == PAGE_INDEX_RADIO:
                        if name == "station_info":
                            text = gui.radio_station_info_text + ''
                    if name not in gui.scroll_texts:
                        gui.scroll_texts[name] = ScrollText(
                            screen.surface,
                            text,
                            hpos,
                            color,
                            margin,
                            font_size,
                            font=os.path.join(
                                os.path.dirname(inspect.getfile(tingbot)),
                                'Geneva.ttf'))
                    else:
                        gui.scroll_texts[name].update_text(text)
                        gui.scroll_texts[name].update()

                elif child.tag == "rectangle":
                    size_node = child.find("size")
                    align = child.get("align")
                    size = (int(size_node.get("w")), int(size_node.get("h")))

                    screen.rectangle(xy=xy,
                                     size=size,
                                     color=color,
                                     align=align)
            elif child.tag == "image":
                scale = float(child.get("scale"))
                src = child.get("src")
                screen.image(src, xy=xy, scale=scale, align=align)
Example #11
0
def draw_radio_page():
    screen.text(
        gui.current_time,
        #xy=(160, 20),
        #font_size=40,
        #color=COLOR_BLUE_LIGHT,
        xy=PAGE_RADIO_TEXT_TIME["xy"],
        font_size=PAGE_RADIO_TEXT_TIME["font_size"],
        color=PAGE_RADIO_TEXT_TIME["color"],
        align=PAGE_RADIO_TEXT_TIME["align"])
    if time.localtime().tm_sec % 2 == 1:
        # Blink the time separator every second by
        # display it every other second
        screen.text(
            ":",
            #xy=(160, 20),
            #font_size=40,
            #color=COLOR_BLUE_LIGHT,
            xy=PAGE_RADIO_TEXT_TIME["xy"],
            font_size=PAGE_RADIO_TEXT_TIME["font_size"],
            color=PAGE_RADIO_TEXT_TIME["color"],
            align=PAGE_RADIO_TEXT_TIME["align"])
    screen.text(
        gui.current_date,
        #xy=(160, 50),
        #font_size=20,
        #color=COLOR_TAN
        xy=PAGE_RADIO_TEXT_DATE["xy"],
        font_size=PAGE_RADIO_TEXT_DATE["font_size"],
        color=PAGE_RADIO_TEXT_DATE["color"],
        align=PAGE_RADIO_TEXT_DATE["align"])

    # Radio Info Panel outer border
    screen.rectangle(
        #xy=(8,70),
        #size=(304,108),
        #color=COLOR_TAN,
        #align="topleft"
        xy=PAGE_RADIO_RECT_INFO_PANEL_OUTER["xy"],
        size=PAGE_RADIO_RECT_INFO_PANEL_OUTER["size"],
        color=PAGE_RADIO_RECT_INFO_PANEL_OUTER["color"],
        align=PAGE_RADIO_RECT_INFO_PANEL_OUTER["align"])

    # Radio Info Top Panel - playback buttons and info
    screen.rectangle(
        #xy=(10,72),
        #size=(300,69),
        #color=COLOR_BLUE_DARK,
        #align="topleft"
        xy=PAGE_RADIO_RECT_INFO_PANEL_TOP["xy"],
        size=PAGE_RADIO_RECT_INFO_PANEL_TOP["size"],
        color=PAGE_RADIO_RECT_INFO_PANEL_TOP["color"],
        align=PAGE_RADIO_RECT_INFO_PANEL_TOP["align"])

    # Radio Info Bottom Panel - Stream info (stream name and title/info)
    screen.rectangle(
        #xy=(10,143),
        #size=(300,33),
        #color=COLOR_BLUE_DARK,
        #align="topleft"
        xy=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["xy"],
        size=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["size"],
        color=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["color"],
        align=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["align"])

    # Setup of the Stream Name and Title/Info
    radio_info = '(none)'  # Initial value of the Stream Info
    station_name = p.player.get_name(
    )  # Get the Stream Name from the player output
    if station_name is None and 'name' in p.get_active_channel():
        # If the Stream Name could not be set/not yet set from the player output,
        # then set the Station Name to the name from the station list instead
        station_name = p.get_active_channel()['name']
    if p.player.title is not None:
        radio_info = p.player.title
    else:
        radio_info = '(none)'
    # if p.player.info is not None:
    # If the Player info is set, then try to get the latest StreamTitle (Info)
    # radio_info = p.player.info.get("StreamTitle")
    #else:
    # Otherwise, set the Info to the default "(none)" value
    #radio_info = '(none)'
    if radio_info is None:
        # If the Player info was set but the latest StreamTitle (Info) was not,
        # then set the Info to the default "(none)" value
        radio_info = '(none)'

    if current_coding is not None:
        # try decode the radio_info with the current coding
        # This is necessary with Windows systems where the
        # encoding is not Unicode or ASCII
        radio_info = radio_info.decode(current_coding)
        try:
            station_name = station_name.decode(current_coding)
        except Exception:
            station_name = p.get_active_channel()['name']

    # Update the Web Frontend API Data with the current radio info
    web_frontend.api_data["radio"]["station"] = station_name
    # p.get_active_channel()['name']
    web_frontend.api_data["radio"]["info"] = radio_info
    # radio_info = filter(onlyascii, radio_info)
    # radio_info = ''.join(c if is_ascii(c) else onlyascii(c) for c in radio_info)
    # radio_info = filter(lambda x: x in string.printable, radio_info)

    # Draw the Station Name at the start/top in the bottom info panel
    screen.text(
        station_name,
        #xy=(13, 143),
        #font_size=15,
        #color=COLOR_TAN,
        #align="topleft"
        xy=PAGE_RADIO_TEXT_STATION_NAME["xy"],
        font_size=PAGE_RADIO_TEXT_STATION_NAME["font_size"],
        color=PAGE_RADIO_TEXT_STATION_NAME["color"],
        align=PAGE_RADIO_TEXT_STATION_NAME["align"])

    # Draw the Station Info at the end/bottom in the bottom info panel
    if gui.radio_info_scroll_text is None:
        gui.radio_info_scroll_text = ScrollText(
            screen.surface,
            radio_info,
            159,
            COLOR_BLUE_LIGHT, (12, 12),
            15,
            font=os.path.join(os.path.dirname(inspect.getfile(tingbot)),
                              'Geneva.ttf'))
    else:
        gui.radio_info_scroll_text.update_text(radio_info)
        gui.radio_info_scroll_text.update()
        # pygame.display.flip()
    #screen.text(
    #    radio_info,
    #    xy=(12, 159),
    #    font_size=15,
    #    color=COLOR_BLUE_LIGHT,
    #    align="topleft"
    #)

    # Play Button - Drawn at the left in the top info panel
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_play_circle_outline_white_24dp.png",
        #xy=(21,81),
        #align="topleft"
        PAGE_RADIO_BUTTON_PLAY["src"],
        xy=PAGE_RADIO_BUTTON_PLAY["xy"],
        scale=PAGE_RADIO_BUTTON_PLAY["scale"],
        align=PAGE_RADIO_BUTTON_PLAY["align"])

    # Pause button - Drawn to the right of the Play button in the top info panel
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_pause_circle_outline_white_24dp.png",
        #xy=(81,81),
        #align="topleft"
        PAGE_RADIO_BUTTON_PAUSE["src"],
        xy=PAGE_RADIO_BUTTON_PAUSE["xy"],
        scale=PAGE_RADIO_BUTTON_PAUSE["scale"],
        align=PAGE_RADIO_BUTTON_PAUSE["align"])

    # Previous Station button - Drawn at the bottom left of the screen window
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_skip_previous_white_24dp.png",
        #xy=(11,181),
        #align="topleft"
        PAGE_RADIO_BUTTON_STATION_PREV["src"],
        xy=PAGE_RADIO_BUTTON_STATION_PREV["xy"],
        scale=PAGE_RADIO_BUTTON_STATION_PREV["scale"],
        align=PAGE_RADIO_BUTTON_STATION_PREV["align"])

    # Next Station button - Drawn to the right of the Previous Station button
    #                       at the bottom of the screen window
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_skip_next_white_24dp.png",
        #xy=(71,181),
        #align="topleft"
        PAGE_RADIO_BUTTON_STATION_NEXT["src"],
        xy=PAGE_RADIO_BUTTON_STATION_NEXT["xy"],
        scale=PAGE_RADIO_BUTTON_STATION_NEXT["scale"],
        align=PAGE_RADIO_BUTTON_STATION_NEXT["align"])

    # Volume Down button - Drawn to the right of the Next Station button at
    #                      the bottom center of the screen window
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_volume_down_white_24dp.png",
        #xy=(131,181),
        #align="topleft"
        PAGE_RADIO_BUTTON_VOL_DOWN["src"],
        xy=PAGE_RADIO_BUTTON_VOL_DOWN["xy"],
        scale=PAGE_RADIO_BUTTON_VOL_DOWN["scale"],
        align=PAGE_RADIO_BUTTON_VOL_DOWN["align"])

    # Volume Up button - Drawn to the right of the Volume Down button at
    #                    the bottom of the screen window
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_volume_up_white_24dp.png",
        #xy=(191,181),
        #align="topleft"
        PAGE_RADIO_BUTTON_VOL_UP["src"],
        xy=PAGE_RADIO_BUTTON_VOL_UP["xy"],
        scale=PAGE_RADIO_BUTTON_VOL_UP["scale"],
        align=PAGE_RADIO_BUTTON_VOL_UP["align"])

    # Volume Mute button - Drawn at the bottom right of the screen window
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_volume_mute_white_24dp.png",
        #xy=(251,181),
        #align="topleft"
        PAGE_RADIO_BUTTON_VOL_MUTE["src"],
        xy=PAGE_RADIO_BUTTON_VOL_MUTE["xy"],
        scale=PAGE_RADIO_BUTTON_VOL_MUTE["scale"],
        align=PAGE_RADIO_BUTTON_VOL_MUTE["align"])
Example #12
0
def refresh():
    screen.fill(color=(26,26,26))
    
    screen.rectangle(
        xy=(0,16),
        align='left',
        size=(320,31),
        color=(255,30,82),
    )
    
    screen.text(
        'Bustle',
        xy=(10,15),
        align='left',
        color='white',
        font='Arial Rounded Bold.ttf',
        font_size=14,    
    )
    
    screen.text(
        'J, Green Park Station',
        xy=(310,17),
        align='right',
        color='white',
        font='JohnstonITCStd-Light.ttf',
        font_size=14,   
    )

    r = requests.get('http://countdown.api.tfl.gov.uk/interfaces/ura/instant_V1?StopCode1=52053&DirectionID=1&VisitNumber=1&ReturnList=StopPointName,LineName,DestinationText,EstimatedTime')

    json_lines = list(json.loads(line) for line in r.iter_lines())
    first_line = json_lines[0]
    current_time = datetime.fromtimestamp(first_line[2] / 1000)

    buses = json_lines[1:]
    
    row_y = 31
    
    for line_num, bus in enumerate(buses):
        if line_num > 3:
            break

        print bus
        
        screen.rectangle(
            xy=(0,row_y),
            align='topleft',
            size=(320,51),
            color=(39,40,34),
        )
        
        bus_number = bus[2]
        bus_destination = bus[3]
        bus_estimated_time = datetime.fromtimestamp(bus[4]/1000)
        bus_delta = bus_estimated_time - current_time
        bus_minutes = int(bus_delta.total_seconds() / 60)
        
        screen.text(
            bus_number,
            xy=(35,row_y+27),
            align='center',
            color='white',
            font='JohnstonITCStd-Bold.ttf',
            font_size=26,
        )
        
        screen.text(
            bus_destination,
            xy=(75,row_y+27),
            align='left',
            color=(220,220,220),
            font='JohnstonITCStd-Light.ttf',
            font_size=17,
        )
        
        screen.text(
            'due' if bus_minutes == 0 else '%i min' % bus_minutes,
            xy=(305,row_y+27),
            align='right',
            color='white',
            font='JohnstonITCStd-Bold.ttf',
            font_size=18,
        )
        
        row_y += 52
Example #13
0
def loop():
    if not gui.initialized:
        if config.MOUSE_VISIBLE:
            pygame.mouse.set_visible(config.MOUSE_VISIBLE)
        pygame.display.set_caption(localized_strings.title)
        gui.initialized = True
    perform_key_events()
    screen.fill(
        color=COLOR_BLUE_DARK
    )

    screen.image(
        "res/images/banner-911778_1280.jpg",
        xy=(0,0),
        align="top"
    )

    if alarm.current_alarm is not None:
        # Alarm currently firing - Show the Alarm Page
        screen.text(
            ALARM_LABEL_TITLE["text"] % alarm.current_alarm,
            xy=ALARM_LABEL_TITLE["xy"],
            color=ALARM_LABEL_TITLE["color"],
            font_size=ALARM_LABEL_TITLE["font_size"],
            align=ALARM_LABEL_TITLE["align"]
        )
        p.player.mute()
    else:
        for child in gui.root[gui.current_page-1]:
            name = child.get("name")
            position = child.find("position")
            align = child.get("align")
            xy = None
            if position is not None:
                xy = (int(position.get("x")), int(position.get("y")))
            if child.tag in ["text", "rectangle", "scroll_text"]:
                color_node = child.find("color")
                color = (int(color_node.get("red")), int(color_node.get("green")), int(color_node.get("blue")))
                if child.tag == "text":
                    font_size = int(child.get("font_size"))
                    text = child.find("text").text
                    if name == "time":
                        text = gui.current_time
                    elif name == "date":
                        text = gui.current_date
                    elif name == "time_sep" and time.localtime().tm_sec%2 != 1:
                        continue
                    if gui.current_page == PAGE_INDEX_RADIO:
                        if child.get("name") == "station_name":
                            text = gui.radio_station_name_text + ''
                    screen.text(text, color=color, xy=xy, align=align, font_size=font_size)
                elif child.tag == "scroll_text":
                    font_size = int(child.get("font_size"))
                    text = child.find("text").text
                    hpos = int(child.get("hpos"))
                    margin_node = child.find("margin")
                    margin = (int(margin_node.get("left")), int(margin_node.get("right")))
                    if gui.current_page == PAGE_INDEX_RADIO:
                        if name == "station_info":
                            text = gui.radio_station_info_text + ''
                    if name not in gui.scroll_texts:
                        gui.scroll_texts[name] = ScrollText(screen.surface, 
                        text, hpos, color, margin, font_size,
                        font=os.path.join(os.path.dirname(inspect.getfile(tingbot)), 'Geneva.ttf'))
                    else:
                        gui.scroll_texts[name].update_text(text)
                        gui.scroll_texts[name].update()

                    
                elif child.tag == "rectangle":
                    size_node = child.find("size")
                    align = child.get("align")
                    size = (int(size_node.get("w")), int(size_node.get("h")))

                    screen.rectangle(xy=xy, size=size, color=color, align=align)
            elif child.tag == "image":
                scale = float(child.get("scale"))
                src = child.get("src")
                screen.image(src, xy=xy, scale=scale, align=align)
Example #14
0
def draw_radio_page():
    screen.text(
        gui.current_time,
        #xy=(160, 20),
        #font_size=40,
        #color=COLOR_BLUE_LIGHT,
        xy=PAGE_RADIO_TEXT_TIME["xy"],
        font_size=PAGE_RADIO_TEXT_TIME["font_size"],
        color=PAGE_RADIO_TEXT_TIME["color"],
        align=PAGE_RADIO_TEXT_TIME["align"]
    )
    if time.localtime().tm_sec%2 == 1:
        # Blink the time separator every second by
        # display it every other second
        screen.text(
            ":",
            #xy=(160, 20),
            #font_size=40,
            #color=COLOR_BLUE_LIGHT,
            xy=PAGE_RADIO_TEXT_TIME["xy"],
            font_size=PAGE_RADIO_TEXT_TIME["font_size"],
            color=PAGE_RADIO_TEXT_TIME["color"],
            align=PAGE_RADIO_TEXT_TIME["align"]
        )
    screen.text(
        gui.current_date,
        #xy=(160, 50),
        #font_size=20,
        #color=COLOR_TAN
        xy=PAGE_RADIO_TEXT_DATE["xy"],
        font_size=PAGE_RADIO_TEXT_DATE["font_size"],
        color=PAGE_RADIO_TEXT_DATE["color"],
        align=PAGE_RADIO_TEXT_DATE["align"]
    )

    # Radio Info Panel outer border
    screen.rectangle(
        #xy=(8,70),
        #size=(304,108),
        #color=COLOR_TAN,
        #align="topleft"
        xy=PAGE_RADIO_RECT_INFO_PANEL_OUTER["xy"],
        size=PAGE_RADIO_RECT_INFO_PANEL_OUTER["size"],
        color=PAGE_RADIO_RECT_INFO_PANEL_OUTER["color"],
        align=PAGE_RADIO_RECT_INFO_PANEL_OUTER["align"]
    )

    # Radio Info Top Panel - playback buttons and info
    screen.rectangle(
        #xy=(10,72),
        #size=(300,69),
        #color=COLOR_BLUE_DARK,
        #align="topleft"
        xy=PAGE_RADIO_RECT_INFO_PANEL_TOP["xy"],
        size=PAGE_RADIO_RECT_INFO_PANEL_TOP["size"],
        color=PAGE_RADIO_RECT_INFO_PANEL_TOP["color"],
        align=PAGE_RADIO_RECT_INFO_PANEL_TOP["align"]
    )

    # Radio Info Bottom Panel - Stream info (stream name and title/info)
    screen.rectangle(
        #xy=(10,143),
        #size=(300,33),
        #color=COLOR_BLUE_DARK,
        #align="topleft"
        xy=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["xy"],
        size=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["size"],
        color=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["color"],
        align=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["align"]
    )

    # Setup of the Stream Name and Title/Info
    radio_info = '(none)' # Initial value of the Stream Info
    station_name = p.player.get_name() # Get the Stream Name from the player output
    if station_name is None and 'name' in p.get_active_channel():
        # If the Stream Name could not be set/not yet set from the player output,
        # then set the Station Name to the name from the station list instead
        station_name = p.get_active_channel()['name']
    if p.player.title is not None:
        radio_info = p.player.title
    else:
        radio_info = '(none)'
    # if p.player.info is not None:
        # If the Player info is set, then try to get the latest StreamTitle (Info)
        # radio_info = p.player.info.get("StreamTitle")
    #else:
        # Otherwise, set the Info to the default "(none)" value
        #radio_info = '(none)'
    if radio_info is None:
        # If the Player info was set but the latest StreamTitle (Info) was not,
        # then set the Info to the default "(none)" value
        radio_info = '(none)'

    if current_coding is not None:
        # try decode the radio_info with the current coding
        # This is necessary with Windows systems where the
        # encoding is not Unicode or ASCII
        radio_info = radio_info.decode(current_coding)
        try:
            station_name = station_name.decode(current_coding)
        except Exception:
            station_name = p.get_active_channel()['name']

    # Update the Web Frontend API Data with the current radio info
    web_frontend.api_data["radio"]["station"] = station_name
    # p.get_active_channel()['name']
    web_frontend.api_data["radio"]["info"] = radio_info
    # radio_info = filter(onlyascii, radio_info)
    # radio_info = ''.join(c if is_ascii(c) else onlyascii(c) for c in radio_info) 
    # radio_info = filter(lambda x: x in string.printable, radio_info)

    # Draw the Station Name at the start/top in the bottom info panel
    screen.text(
        station_name,
        #xy=(13, 143),
        #font_size=15,
        #color=COLOR_TAN,
        #align="topleft"
        xy=PAGE_RADIO_TEXT_STATION_NAME["xy"],
        font_size=PAGE_RADIO_TEXT_STATION_NAME["font_size"],
        color=PAGE_RADIO_TEXT_STATION_NAME["color"],
        align=PAGE_RADIO_TEXT_STATION_NAME["align"]
    )

    # Draw the Station Info at the end/bottom in the bottom info panel
    if gui.radio_info_scroll_text is None:
        gui.radio_info_scroll_text = ScrollText(screen.surface, 
        radio_info, 159, COLOR_BLUE_LIGHT, (12,12), 15,
        font=os.path.join(os.path.dirname(inspect.getfile(tingbot)), 'Geneva.ttf'))
    else:
        gui.radio_info_scroll_text.update_text(radio_info)
        gui.radio_info_scroll_text.update()
        # pygame.display.flip()
    #screen.text(
    #    radio_info,
    #    xy=(12, 159),
    #    font_size=15,
    #    color=COLOR_BLUE_LIGHT,
    #    align="topleft"
    #)

    # Play Button - Drawn at the left in the top info panel
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_play_circle_outline_white_24dp.png",
        #xy=(21,81),
        #align="topleft"
        PAGE_RADIO_BUTTON_PLAY["src"],
        xy=PAGE_RADIO_BUTTON_PLAY["xy"],
        scale=PAGE_RADIO_BUTTON_PLAY["scale"],
        align=PAGE_RADIO_BUTTON_PLAY["align"]
    )

    # Pause button - Drawn to the right of the Play button in the top info panel
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_pause_circle_outline_white_24dp.png",
        #xy=(81,81),
        #align="topleft"
        PAGE_RADIO_BUTTON_PAUSE["src"],
        xy=PAGE_RADIO_BUTTON_PAUSE["xy"],
        scale=PAGE_RADIO_BUTTON_PAUSE["scale"],
        align=PAGE_RADIO_BUTTON_PAUSE["align"]
    )

    # Previous Station button - Drawn at the bottom left of the screen window
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_skip_previous_white_24dp.png",
        #xy=(11,181),
        #align="topleft"
        PAGE_RADIO_BUTTON_STATION_PREV["src"],
        xy=PAGE_RADIO_BUTTON_STATION_PREV["xy"],
        scale=PAGE_RADIO_BUTTON_STATION_PREV["scale"],
        align=PAGE_RADIO_BUTTON_STATION_PREV["align"]
    )

    # Next Station button - Drawn to the right of the Previous Station button 
    #                       at the bottom of the screen window
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_skip_next_white_24dp.png",
        #xy=(71,181),
        #align="topleft"
        PAGE_RADIO_BUTTON_STATION_NEXT["src"],
        xy=PAGE_RADIO_BUTTON_STATION_NEXT["xy"],
        scale=PAGE_RADIO_BUTTON_STATION_NEXT["scale"],
        align=PAGE_RADIO_BUTTON_STATION_NEXT["align"]
    )

    # Volume Down button - Drawn to the right of the Next Station button at 
    #                      the bottom center of the screen window
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_volume_down_white_24dp.png",
        #xy=(131,181),
        #align="topleft"
        PAGE_RADIO_BUTTON_VOL_DOWN["src"],
        xy=PAGE_RADIO_BUTTON_VOL_DOWN["xy"],
        scale=PAGE_RADIO_BUTTON_VOL_DOWN["scale"],
        align=PAGE_RADIO_BUTTON_VOL_DOWN["align"]
    )

    # Volume Up button - Drawn to the right of the Volume Down button at 
    #                    the bottom of the screen window
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_volume_up_white_24dp.png",
        #xy=(191,181),
        #align="topleft"
        PAGE_RADIO_BUTTON_VOL_UP["src"],
        xy=PAGE_RADIO_BUTTON_VOL_UP["xy"],
        scale=PAGE_RADIO_BUTTON_VOL_UP["scale"],
        align=PAGE_RADIO_BUTTON_VOL_UP["align"]
    )

    # Volume Mute button - Drawn at the bottom right of the screen window
    screen.image(
        #"res/icons/material-design-icons-2.0/av/2x_web/ic_volume_mute_white_24dp.png",
        #xy=(251,181),
        #align="topleft"
        PAGE_RADIO_BUTTON_VOL_MUTE["src"],
        xy=PAGE_RADIO_BUTTON_VOL_MUTE["xy"],
        scale=PAGE_RADIO_BUTTON_VOL_MUTE["scale"],
        align=PAGE_RADIO_BUTTON_VOL_MUTE["align"]
    )