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)
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")
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', )
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', )
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, )
from tingbot.graphics import Image ip_address = None @tingbot.every(seconds=10) def get_ip_address(): global ip_address try: import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('8.8.8.8', 1)) ip_address = s.getsockname()[0] except: ip_address = None screen.fill('black') no_network_image = Image.load('NetworkNotFound.jpg') ready_image = Image.load('ReadyScreen.gif') 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:
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)
def clear_screen(): screen.fill(color='black')
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) state = {'previous_xy': None} screen.fill(color='black') # TODO: Use Mid Left Button for something else than clearing the screen @midleft_button.hold def clear_screen(): screen.fill(color='black') # TODO: Use Touch screen for something useful other than just drawing @touch() def on_touch(xy, action): if state['previous_xy']: screen.line(state['previous_xy'], xy, width=5, color='blue') if action == 'up':
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
button = gui.Button((240, 200), (80, 30), align="top", label="Display", callback=display) gui.StaticText((190, 0), (50, 20), align="top", label="Red") gui.StaticText((240, 0), (50, 20), align="top", label="Green") gui.StaticText((290, 0), (50, 20), align="top", label="Blue") red_label = gui.StaticText((190, 180), (50, 20), label="0") green_label = gui.StaticText((240, 180), (50, 20), label="0") blue_label = gui.StaticText((290, 180), (50, 20), label="0") def update_label(label, value): label.label = str(int(value)) label.update() red.callback = lambda x: update_label(red_label, x) green.callback = lambda x: update_label(green_label, x) blue.callback = lambda x: update_label(blue_label, x) def loop(): pass screen.fill("black") gui.show_all() run(loop)
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)