def display_calendar_events(resp_events): # Display all calendar events for event_idx in range(len(resp_events)): event = resp_events[event_idx] # wrap event name around second line if necessary event_name = PyPortal.wrap_nicely(event["summary"], 25) event_name = "\n".join( event_name[0:2]) # only wrap 2 lines, truncate third.. event_start = event["start"]["dateTime"] print("-" * 40) print("Event Description: ", event_name) print("Event Time:", format_datetime(event_start)) print("-" * 40) # Generate labels holding event info label_event_time = label.Label( font_events, x=7, y=70 + (event_idx * 40), color=0x000000, text=format_datetime(event_start), ) pyportal.splash.append(label_event_time) label_event_desc = label.Label( font_events, x=88, y=70 + (event_idx * 40), color=0x000000, text=event_name, line_spacing=0.75, ) pyportal.splash.append(label_event_desc)
try: value = pyportal.fetch() break except RuntimeError as e: print("Some error occured, retrying! -", e) continue print("Response is", value) question = value[0] correct_answer = value[1] answers = shuffle(value[1:5]) loading_text_area.text = '' # Format text and wrap with display text library try: # sometimes gives a runtime error: Group full q_text_area.text = '\n'.join( pyportal.wrap_nicely(unescape(question), 35)) except RuntimeError as e: print("Group full", e) continue for k, answer in enumerate(answers): ans_text_areas[k].text = answer_choices[k] + ") " + unescape(answer) faceOff(10) # 10 seconds with question time.sleep(2) # pause for 2 seconds to show which player tapped first faceOff(5) # 5 seconds to answer timer_text_area.text = '' # Show the correct answer k = answers.index(correct_answer) reveal_text = ("Correct Answer:\n" + answer_choices[k] + ") " + unescape(answers[k]) + "\n(Tap for next question.)") print(reveal_text)
weather_values = [] gc.collect() try: gc.collect() json_data = json.loads(pyportal.fetch(refresh_url=url)) for path in json_path: weather_values.append(PyPortal._json_traverse(json_data, path)) del json_data del json_path gc.collect() # Update display weather_values[0] = ((weather_values[0] or 0.0) * 1.8) + 32 weather_values[1] = (weather_values[1] or 0.0) weather_values[2] = '\n'.join( PyPortal.wrap_nicely(weather_values[2], 12)) weather_data.text = 'Temperature: {}°F\nWind Speed: {:.1f} mph\nConditions: {}'.format( weather_values[0], weather_values[1], weather_values[2]) del weather_values gc.collect() except RuntimeError as exception: print("An error occured", exception) if 'json_data' in locals(): del json_data if 'json_path' in locals(): del json_path if 'weather_values' in locals(): del weather_values if 'url' in locals(): del url del exception
i = -1 for ic in icon_font_map: i += 1 if icon_font_map[i] == icon: c = icon_font_glyphs[i] icon_label.text = chr(c) temp_label.text = u"%.1f\u00b0F" % data["currently"]["temperature"] temp_label.x = 300 - temp_label.bounding_box[2] humid_label.text = u"%.0f%%" % (data["currently"]["humidity"] * 100) humid_label.x = 300 - humid_label.bounding_box[2] press_label.text = u"%.2finHg" % ( data["currently"]["pressure"] * 0.02952998751 + 1.07) press_label.x = 300 - press_label.bounding_box[2] gc.collect() desc = data["daily"]["summary"] desc = pyportal.wrap_nicely(desc, 24) desc_label.text = '\n'.join(desc) desc_label.x = 160 - int(desc_label.bounding_box[2] / 2) gc.collect() print("Free memory", gc.mem_free()) if prior_sec != time.localtime().tm_sec: t = time.localtime() prior_sec = t.tm_sec if prior_day != t.tm_mday: d = format_date(t) prior_day = t.tm_mday print(d) date_label.text = d date_label.x = 160 - int(date_label.bounding_box[2] / 2) gc.collect()
import board from strategies import strategies from adafruit_pyportal import PyPortal cwd = ("/"+__file__).rsplit('/', 1)[0] # the current working directory (where this file is) # create pyportal object w no data source (we'll feed it text later) pyportal = PyPortal(url = None, json_path = None, status_neopixel = board.NEOPIXEL, default_bg = None, text_font = cwd+"fonts/Arial-ItalicMT-17.bdf", text_position = (30, 120), text_color = 0xFFFFFF, ) pyportal.set_text("loading ...") # display while user waits pyportal.preload_font() # speed things up by preloading font pyportal.set_text("OBLIQUE STRATEGIES\nBrian Eno / Peter Schmidt") # show title while True: if pyportal.touchscreen.touch_point: # get random string from array and wrap w line breaks strat = pyportal.wrap_nicely(random.choice(strategies), 35) outstring = '\n'.join(strat) # display new text pyportal.set_text(outstring, 0) # don't repeat until a new touch begins while pyportal.touchscreen.touch_point: continue
if dsl_status["connected"]: status_icon_controller.set_dsl_status(True) current_dsl_check_period = 15 else: status_icon_controller.set_dsl_status(False) current_dsl_check_period = 2 last_dsl_check = time.monotonic() # Load new quote every hour if last_quote_check + 3600 < time.monotonic(): try: quote_json = pyportal.fetch() quote_text = '"' + quote_json[0] + '" - ' + quote_json[1] quote = pyportal.wrap_nicely(quote_text, 40) # Only show quotes with 4 lines ore less if len(quote) <= 4: new_quote = "" test = "" for w in quote: new_quote += "\n" + w test += "M\n" quote_font_hight.text = test # Odd things happen without this glyph_box = quote_font_hight.bounding_box quote_label.text = "" # Odd things happen without this quote_label.text = new_quote except MemoryError: supervisor.reload() except: