def init(): global text6,actualy,displayheight text6 = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=1000, point_size=128) count = 0 mystring = '' actualy = 0 for e in list(gcal.timeline.start_after(arrow.now().floor('day'))): if count < 5: size = 0.79 titles = pi3d.TextBlock(-390, ((displayheight/2) + actualy - (graphics.pointFont.height*size*0.5)), 0.1, 0.0, 30 ,text_format= e.begin.humanize(locale='de_de').title(), size=size, spacing="F", space=0.02, colour=(1,0,0,1)) text6.add_text_block(titles) actualy -= titles.size * graphics.pointFont.height size = 0.29 date = pi3d.TextBlock(-380, ((displayheight/2) + actualy - (graphics.pointFont.height*size*0.5)), 0.1, 0.0, 12 ,text_format= '(' + e.begin.format('DD.MM.YYYY') + ')', size=size,spacing="F", space= 0.02, colour=(1,1,1,1)) text6.add_text_block(date) actualy -= date.size * graphics.pointFont.height size = 0.4 width = 0 subtext = '' actualword = '' g_scale = float(text6.point_size) / graphics.pointFont.height for c in e.name: width += graphics.pointFont.glyph_table[c][0] * g_scale * size actualword += c if c in (' ','-',',','.','+',':'): subtext += actualword actualword = '' if width > 730: event = pi3d.TextBlock(-350, (displayheight/2) + actualy - (graphics.pointFont.height*size*0.5), 0.1, 0.0, 40, text_format = subtext, size=size,spacing="F",space =0.02,colour=(1,1,1,1)) text6.add_text_block(event) subtext = '' width = 0 actualy -= event.size * graphics.pointFont.height if (subtext != '') or (actualword != ''): event = pi3d.TextBlock(-350, (displayheight/2) + actualy - (graphics.pointFont.height*size*0.5), 0.1, 0.0, 40,text_format = subtext + actualword, size=size,spacing="F",space = 0.02,colour=(1,1,1,1)) text6.add_text_block(event) actualy -= event.size * graphics.pointFont.height actualy -= 20 count+=1 else: break
def _create(self): logging.info('Creating pi3d components') self.DISPLAY = pi3d.Display.create( frames_per_second=Constants.FPS, background=Constants.BACKGROUND_COLOR) self.CAMERA = pi3d.Camera(is_3d=False) self.SHADER = pi3d.Shader("blend_new") self.SLIDE = pi3d.Sprite(camera=self.CAMERA, w=self.DISPLAY.width, h=self.DISPLAY.height, z=5.0) self.SLIDE.set_shader(self.SHADER) self.SLIDE.unif[47] = Constants.EDGE_ALPHA self.FONT = pi3d.Font(Constants.FONT_FILE, codepoints=Constants.CODEPOINTS, grid_size=7, shadow_radius=4.0, shadow=(0, 0, 0, 128)) self.TEXT = pi3d.PointText(self.FONT, self.CAMERA, max_chars=200, point_size=50) self.TEXTBLOCK = pi3d.TextBlock(x=-self.DISPLAY.width * 0.5 + 50, y=-self.DISPLAY.height * 0.4, z=0.1, rot=0.0, char_count=199, size=0.99, text_format="{}".format(1), spacing="F", space=0.02, colour=(1.0, 1.0, 1.0, 1.0)) self.TEXT.add_text_block(self.TEXTBLOCK)
def display_list(self, display): current_y = self.y for item in display: newtxt = pi3d.TextBlock(self.x, current_y, 100, 0.0, len(item) , text_format=item, size=0.99, spacing="F", space=0.05, colour=(0.0, 1.0, 0.0, 1.0)) self.add_text_block(newtxt) current_y = current_y - 25
def make_text_block(x, y, txt): return pi3d.TextBlock(x, y, 0.1, 0.0, 8, text_format=txt, size=0.69, spacing="C", space=2.2, colour=(1.0, 1.0, 1.0, 1.0))
def add_to_text3(x, y, n_ch, text_format, attr=None, space=0.6, colour=(1.0, 1.0, 1.0, 1.0)): '''convenience function to avoid too much repitition''' newtxt = pi3d.TextBlock(x, y, 0.1, 0.0, n_ch, data_obj=peripherals.eg_object, attr=attr, text_format=text_format, size=0.5, spacing="C", space=space, colour=colour) text3.add_text_block(newtxt)
def __init__(self, x_values, y_values, width, height, font, title=None, line_width=2, axes_desc=None, legend=None, xpos=0, ypos=0, xmin=None, xmax=None, ymin=None, ymax=None, camera=None, shader=None): ''' Arguments: *x_values* 1D numpy array *y_values* 1 or 2D numpy array with size same as x_values in 2nd D draws a line graph or 3D numpy array with size same as x along axis=1 and last axis has 2 values. In this case the graph is drawn as vertical lines *width, height* as expected *font* pi3d.Font instance *title, line_width* as expected *axes_desc* tuple -> (x.axis.desc, y.axis.desc) *legend* tuple -> (y0.desc, y1.desc, y2.desc...) *xpos, ypos* offset relative to origin of display (centre) *xmin, xmax, ymin, ymax* override sampled values from init data *camera* if no other Shape to be drawn then a 2D Camera can be created here *shader* if no other Shape uses mat_flat shader then one will be created ''' if len(y_values.shape) < 2: y_values.shape = (1, ) + y_values.shape if x_values.shape[0] != y_values.shape[1]: LOGGER.error('mismatched array lengths') return if camera is None: camera = pi3d.Camera(is_3d=False) if shader is None: shader = pi3d.Shader('mat_flat') # title ########## point_size = max(min(48, int(height * 0.1)), 24) self.text = pi3d.PointText(font, camera, max_chars=400, point_size=point_size) if title is not None: title = pi3d.TextBlock(x=xpos, y=ypos + height / 2 - point_size + 5, z=0.1, rot=0.0, char_count=len(title) + 2, spacing='F', text_format=title, space=0.05, justify=0.5) self.text.add_text_block(title) # axes ########### axex, axey = width * 0.4, height * 0.4 # implies 10% margin all round self.axes = pi3d.Lines( vertices=[[axex, -axey - line_width, 0], [-axex - line_width, -axey - line_width, 0], [-axex - line_width, axey, 0]], x=xpos, y=ypos, z=5.0, line_width=line_width) self.axes.set_shader(shader) # lines to represent data n = x_values.shape[-1] if xmin is None: xmin = x_values.min() if xmax is None: xmax = x_values.max() x_factor = (2.0 * axex) / (xmax - xmin) x_offset = xmin if ymin is None: ymin = y_values.min() if ymax is None: ymax = y_values.max() y_factor = (2.0 * axey) / (ymax - ymin) y_offset = ymin self.lines = [] for i in range(y_values.shape[0]): data = np.zeros((n, 3)) data[:, 0] = (x_values - x_offset) * x_factor - axex + xpos if len(y_values[i].shape) == 1: # i.e. normal line graph data[:, 1] = (y_values[i] - y_offset) * y_factor - axey + ypos strip = True else: # has to be pairs of values for separate line segments xx_vals = np.stack([data[:, 0], data[:, 0]], axis=1).flatten() # make x into pairs data = np.zeros((n * 2, 3)) data[:, 0] = xx_vals data[:, 1] = (y_values[i].flatten() - y_offset) * y_factor - axey + ypos strip = False data[:, 2] = 4.0 # z value line = pi3d.Lines(vertices=data, line_width=line_width, strip=strip) line.set_shader(shader) j = i + 1 rgb_val = (0.913 * j % 1.0, 0.132 * j % 1.0, 0.484 * j % 1.0) line.set_material(rgb_val) self.lines.append(line) # axis values point_size *= 0.3 # first add the max and min vals vals = [(-axex + xpos, -axey + ypos - point_size, '{:.3g}'.format(xmin), 0.0), (axex + xpos, -axey + ypos - point_size, '{:.3g}'.format(xmax), 0.0), (-axex + xpos - point_size, -axey + ypos, '{:.3g}'.format(ymin), 90.0), (-axex + xpos - point_size, axey + ypos, '{:.3g}'.format(ymax), 90.0)] data = [ ] # use this to hold vertex positions for grid lines (called ticks) for val in self.tick_pos(xmin, xmax): x = (val - x_offset) * x_factor - axex vals.append((x + xpos, -axey + ypos - point_size, '{:.3g}'.format(val), 0.0)) data.extend([[x, -axey, 0], [x, axey, 0]]) # NB points in pairs to use GL_LINES option with strip=False below. for val in self.tick_pos(ymin, ymax): y = (val - y_offset) * y_factor - axey vals.append((-axex + xpos - point_size, y + ypos, '{:.3g}'.format(val), 90.0)) data.extend([[-axex, y, 0], [axex, y, 0]]) for val in vals: self.text.add_text_block( pi3d.TextBlock(val[0], val[1], 4.0, val[3], 8, size=0.7, text_format=val[2], spacing='F', space=0.05, justify=0.5)) self.ticks = pi3d.Lines(vertices=data, x=xpos, y=ypos, z=5.0, line_width=line_width, material=(0.5, 0.5, 0.5), strip=False) self.ticks.set_shader(shader) # axes descritions if axes_desc is not None: self.text.add_text_block( pi3d.TextBlock(xpos, ypos - 1.15 * axey, 4.0, 0.0, len(axes_desc[0]) + 2, size=0.7, text_format=axes_desc[0], spacing='F', space=0.05, justify=0.5)) self.text.add_text_block( pi3d.TextBlock(xpos - 1.15 * axex, ypos, 4.0, 90.0, len(axes_desc[1]) + 2, size=0.7, text_format=axes_desc[1], spacing='F', space=0.05, justify=0.5)) # legend ########## if legend is not None: if not hasattr(legend, '__iter__'): # single string, make into list legend = [legend] for i, lgd in enumerate(legend): self.text.add_text_block( pi3d.TextBlock( axex + xpos, axey + ypos - (i + 1) * point_size * 2.0, 4.0, 0.0, len(lgd) + 2, size=0.8, text_format=lgd, spacing='F', space=0.05, justify=1.0, colour=tuple(self.lines[i].buf[0].unib[3:6]) + (1.0, ))) # scale factors for use in update() so add to self self.y_offset = y_offset self.y_factor = y_factor self.axey = axey self.ypos = ypos
def init(): global snowline, rainline, seplines, degwind, weathericon, text, line global windneedle, acttemp, text, error #global baroneedle, linemin, linemax from pyowm.commons.enums import SubscriptionTypeEnum languagedict = { 'subscription_type': SubscriptionTypeEnum.FREE, 'language': config.OWMLANGUAGE, 'connection': { 'use_ssl': True, 'verify_ssl_certs': True, 'use_proxy': False, 'timeout_secs': 5 }, 'proxies': { 'http': 'http://*****:*****@host:port', 'https': 'socks5://user:pass@host:port' } } owm = pyowm.OWM(config.OWMKEY, config=languagedict) mgr = owm.weather_manager() place = mgr.weather_at_place(config.OWMCITY) weather = place.weather text.text_blocks = [] text._first_free_char = 0 if config.OWMLANGUAGE == 'de': # TODO this needs untangling from stuff in config weekdays = [ 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag' ] else: weekdays = [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ] file_path = resource_filename( "shpi", "sprites/{}.png".format(weather.weather_icon_name)) if os.path.exists(file_path): weathericon = pi3d.ImageSprite(file_path, shader=graphics.SHADER, camera=graphics.CAMERA, w=150, h=150, z=2, x=-220) # else: # import urllib.request # urllib.request.urlretrieve("http://openweathermap.org/img/wn/" + weather.get_weather_icon_name( # ) + "@2x.png", "sprites/" + weather.get_weather_icon_name() + ".png") city = pi3d.TextBlock(-390, 180, 0.1, 0.0, 150, text_format=place.location.name, size=0.7, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(city) city = pi3d.TextBlock(-220, 80, 0.1, 0.0, 30, justify=0.5, text_format=weather.detailed_status, size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(city) acttemp = pi3d.TextBlock( -350, -50, 0.1, 0.0, 10, text_format=str(weather.temperature('celsius')['temp']) + u'°C', size=0.9, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(acttemp) sunriset = weather.sunrise_time(timeformat='date') + datetime.timedelta( hours=2) sunsett = weather.sunset_time(timeformat='date') + datetime.timedelta( hours=2) sunset = pi3d.TextBlock(50, 100, 0.1, 0.0, 20, text_format="{} {}:{:02d} {} {}:{:02d}".format( unichr(0xE041), sunriset.hour, sunriset.minute, unichr(0xE042), sunsett.hour, sunsett.minute), size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(sunset) barometer = pi3d.TextBlock(50, -50, 0.1, 0.0, 10, text_format=unichr(0xE00B) + ' ' + str(weather.pressure['press']) + ' hPa', size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(barometer) # baroneedle = pi3d.Triangle(camera=graphics.CAMERA, corners=( # (-2, 0, 0), (0, 7, 0), (2, 0, 0)), x=barometer.x+16, y=barometer.y - 6, z=0.1) # baroneedle.set_shader(graphics.MATSH) normalizedpressure = (weather.pressure['press'] - 950) if normalizedpressure < 0: normalizedpressure = 0 if normalizedpressure > 100: normalizedpressure = 100 green = 0.02 * (normalizedpressure) if green > 1: green = 1 red = 0.02 * (100 - normalizedpressure) if red > 1: red = 1 barometer.colouring.set_colour([red, green, 0, 1.0]) #baroneedle.set_material([red, green, 0]) #baroneedle.rotateToZ(100 - (normalizedpressure*2)) humidity = pi3d.TextBlock(50, 0, 0.1, 0.0, 10, text_format=unichr(0xE003) + ' ' + str(weather.humidity) + '%', size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(humidity) if 'speed' in weather.wind(): wind = pi3d.TextBlock(50, 50, 0.1, 0.0, 10, text_format=unichr(0xE040) + ' ' + str(weather.wind()['speed']) + 'm/s', size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(wind) if 'deg' in weather.wind(): degwind = True windneedle = pi3d.Triangle(camera=graphics.CAMERA, corners=((-3, 0, 0), (0, 15, 0), (3, 0, 0)), x=wind.x + 180, y=wind.y, z=0.1) windneedle.set_shader(graphics.MATSH) windneedle.set_material([1, 1, 1]) windneedle.rotateToZ(weather.wind()['deg']) else: degwind = False #fc = owm.three_hours_forecast(config.OWMCITY) f = mgr.forecast_at_place(config.OWMCITY, '3h').forecast step = 780 / (len(f)) actualy = -400 + step temp_max = [] temp_min = [] temp = [] seplinesarr = [] icons = [] rainarr = [] snowarr = [] maxdaytemp = -100 mindaytemp = 100 for weather in f: file_path = resource_filename( "shpi", "sprites/{}.png".format(weather.weather_icon_name)) if not os.path.exists(file_path): import urllib.request # TODO py2 py3 fix urllib.request.urlretrieve( "http://openweathermap.org/img/wn/" + weather.get_weather_icon_name() + "@2x.png", file_path) icons.append( pi3d.ImageSprite(file_path, shader=graphics.SHADER, camera=graphics.CAMERA, w=20, h=20, z=1, x=actualy, y=-220)) if weather.reference_time('iso')[11:16] == '00:00': seplinesarr.append([actualy, -50, 2]) seplinesarr.append([actualy, 50, 2]) seplinesarr.append([actualy, -50, 2]) # if weather.get_reference_time('iso')[11:16] == '12:00': day = weather.reference_time(timeformat='date').weekday() if actualy < 300: city = pi3d.TextBlock(actualy + 65, -100, 0.1, 0.0, 30, text_format=weekdays[day], justify=0.5, size=0.23, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(city) if actualy > -300: city = pi3d.TextBlock(actualy - 6 * step, -150, 0.1, 0.0, 30, text_format=str(round(maxdaytemp, 1)) + u'°C', size=0.25, spacing="F", space=0.05, colour=(1.0, 0.0, 0.0, 1.0)) text.add_text_block(city) city = pi3d.TextBlock(actualy - 6 * step, -210, 0.1, 0.0, 30, text_format=str(round(mindaytemp, 1)) + u'°C', size=0.25, spacing="F", space=0.05, colour=(0.0, 0.0, 1.0, 1.0)) text.add_text_block(city) maxdaytemp = -100 mindaytemp = 100 if '3h' in weather.snow: snowarr.append([actualy, (-50 + weather.snow['3h'] * 30), 2]) else: snowarr.append([actualy, -50, 2]) if '3h' in weather.rain: rainarr.append([actualy, (-50 + weather.rain['3h'] * 30), 2]) else: rainarr.append([actualy, -50, 2]) temperatures = weather.temperature(unit='celsius') if temperatures['temp_max'] > maxdaytemp: maxdaytemp = temperatures['temp_max'] if temperatures['temp_min'] < mindaytemp: mindaytemp = temperatures['temp_min'] temp_max.append([actualy, temperatures['temp_max'] * 3, 2]) temp_min.append([actualy, temperatures['temp_min'] * 3, 2]) temp.append([actualy, temperatures['temp'] * 3, 2]) actualy += step snowline = pi3d.Lines(vertices=snowarr, line_width=3, y=-180, strip=True) snowline.set_shader(graphics.MATSH) snowline.set_material((0.5, 0.5, 1)) snowline.set_alpha(0.7) rainline = pi3d.Lines(vertices=rainarr, line_width=3, y=-180, strip=True) rainline.set_shader(graphics.MATSH) rainline.set_material((0, 0, 1)) rainline.set_alpha(0.7) seplines = pi3d.Lines(vertices=seplinesarr, line_width=1, y=-180, strip=True) seplines.set_shader(graphics.MATSH) seplines.set_material((0, 0, 0)) seplines.set_alpha(0.9) line = pi3d.Lines(vertices=temp, line_width=2, y=-220, strip=True) line.set_shader(graphics.MATSH) line.set_material((0, 0, 0)) line.set_alpha(0.9)
def weather_obj_create(width, height): icon_shader = pi3d.Shader("uv_flat") weatherobj = {} # This screen is optimized for a display size of FullHD 1920 x 1080 # So the ranges are ==> x +/-960 ; y +/-540 # You might need to adjust for other display dimensions y_top = height * 0.5 - cfg['W_MARGIN_TOP'] x_sunrise = -width * 0.5 + cfg['W_POINT_SIZE'] * 10 x_sunset = x_sunrise + cfg['W_STATIC_SIZE'] * 3 x_uvi = x_sunset + cfg['W_STATIC_SIZE'] * 3.5 x_cases7 = x_uvi + cfg['W_STATIC_SIZE'] * 5 weatherobj['static'] = {} weatherobj['static']['sunrise'] = pi3d.ImageSprite(os.path.join( cfg['W_ICON_DIR'], 'sunrise.png'), icon_shader, w=cfg['W_STATIC_SIZE'], h=cfg['W_STATIC_SIZE'], x=x_sunrise, y=y_top, z=1.0) weatherobj['static']['sunset'] = pi3d.ImageSprite(os.path.join( cfg['W_ICON_DIR'], 'sunset.png'), icon_shader, w=cfg['W_STATIC_SIZE'], h=cfg['W_STATIC_SIZE'], x=x_sunset, y=y_top, z=1.0) weatherobj['static']['uvidx'] = pi3d.ImageSprite(os.path.join( cfg['W_ICON_DIR'], 'uvidx.png'), icon_shader, w=cfg['W_STATIC_SIZE'], h=cfg['W_STATIC_SIZE'], x=x_uvi, y=y_top, z=1.0) weatherobj['static']['corona'] = pi3d.ImageSprite(os.path.join( cfg['W_ICON_DIR'], 'corona_g.png'), icon_shader, w=cfg['W_STATIC_SIZE'], h=cfg['W_STATIC_SIZE'], x=x_cases7, y=y_top, z=1.0) weatherobj['static']['hospitalization'] = pi3d.ImageSprite( os.path.join(cfg['W_ICON_DIR'], 'hospitalization_g.png'), icon_shader, w=cfg['W_STATIC_SIZE'] * 0.7, h=cfg['W_STATIC_SIZE'] * 0.7, x=x_cases7, y=y_top - cfg['W_STATIC_SIZE'], z=1.0) x = -width * 0.5 + cfg['W_MARGIN_LEFT'] + cfg['W_STATIC_SIZE'] * 0.5 x_dt = -width * 0.5 + cfg['W_MARGIN_LEFT'] y_date = y_top - cfg['W_STATIC_SIZE'] * 2.5 #1.5 y_icon = y_date - cfg['W_ICON_SIZE'] * 0.9 y_temp = 0 - cfg['W_STATIC_SIZE'] * 1.1 #0 y_pop = y_temp - cfg['W_STATIC_SIZE'] * 1.5 y_wind = y_pop - cfg['W_STATIC_SIZE'] * 1.1 y_humidity = y_wind - cfg['W_STATIC_SIZE'] * 1.1 y_pressure = y_humidity - cfg['W_STATIC_SIZE'] * 1.1 weatherobj['static']['temp'] = pi3d.ImageSprite( os.path.join(cfg['W_ICON_DIR'], 'temp.png'), icon_shader, w=cfg['W_STATIC_SIZE'] * 1.5, h=cfg['W_STATIC_SIZE'] * 1.5, x=x, y=y_temp, z=1.0) weatherobj['static']['pop'] = pi3d.ImageSprite(os.path.join( cfg['W_ICON_DIR'], 'rainprop.png'), icon_shader, w=cfg['W_STATIC_SIZE'], h=cfg['W_STATIC_SIZE'], x=x, y=y_pop, z=1.0) weatherobj['static']['wind'] = pi3d.ImageSprite(os.path.join( cfg['W_ICON_DIR'], 'wind.png'), icon_shader, w=cfg['W_STATIC_SIZE'], h=cfg['W_STATIC_SIZE'], x=x, y=y_wind, z=1.0) weatherobj['static']['humidity'] = pi3d.ImageSprite(os.path.join( cfg['W_ICON_DIR'], 'humidity.png'), icon_shader, w=cfg['W_STATIC_SIZE'], h=cfg['W_STATIC_SIZE'], x=x, y=y_humidity, z=1.0) weatherobj['static']['pressure'] = pi3d.ImageSprite(os.path.join( cfg['W_ICON_DIR'], 'pressure.png'), icon_shader, w=cfg['W_STATIC_SIZE'], h=cfg['W_STATIC_SIZE'], x=x, y=y_pressure, z=1.0) weatherobj['current'] = {} weatherobj['current']['dt'] = pi3d.TextBlock(x=x_dt, y=y_top, text_format=" ", z=0.0, rot=0.0, char_count=20, size=0.99, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) weatherobj['current']['sunrise'] = pi3d.TextBlock( x=x_sunrise + cfg['W_STATIC_SIZE'] * 0.7, y=y_top, text_format=" ", z=0.0, rot=0.0, char_count=10, size=0.6, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) weatherobj['current']['sunset'] = pi3d.TextBlock( x=x_sunset + cfg['W_STATIC_SIZE'] * 0.7, y=y_top, text_format=" ", z=0.0, rot=0.0, char_count=10, size=0.6, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) weatherobj['current']['uvi'] = pi3d.TextBlock(x=x_uvi + cfg['W_STATIC_SIZE'] * 0.7, y=y_top, text_format=" ", z=0.0, rot=0.0, char_count=20, size=0.6, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) weatherobj['current']['cases7_per_100k'] = pi3d.TextBlock( x=x_cases7 + cfg['W_STATIC_SIZE'] * 0.7, y=y_top, text_format=" ", z=0.0, rot=0.0, char_count=20, size=0.99, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) weatherobj['current']['hospitalization_idx'] = pi3d.TextBlock( x=x_cases7 + cfg['W_STATIC_SIZE'] * 0.7, y=y_top - cfg['W_STATIC_SIZE'], text_format=" ", z=0.0, rot=0.0, char_count=20, size=0.99, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) w_item_cnt = int((width - cfg['W_MARGIN_LEFT']) / (cfg['W_ICON_SIZE'] + cfg['W_SPACING'])) weatherobj['forecast'] = [] for i in range(w_item_cnt): item = {} x = -width * 0.5 + cfg['W_MARGIN_LEFT'] + 2 * cfg[ 'W_STATIC_SIZE'] + i * (cfg['W_ICON_SIZE'] + cfg['W_SPACING']) item['date'] = pi3d.TextBlock(x=x, y=y_date, text_format=" ", z=0.1, rot=0.0, char_count=20, size=0.8, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) item['daytime'] = pi3d.TextBlock(x=x, y=y_date - cfg['W_STATIC_SIZE'] * 0.7, text_format=" ", z=0.1, rot=0.0, char_count=15, size=0.6, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) item['temp'] = pi3d.TextBlock(x=x, y=y_temp + cfg['W_STATIC_SIZE'] * 0.4, text_format=" ", z=0.1, rot=0.0, char_count=10, size=0.99, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) item['feels_like'] = pi3d.TextBlock(x=x, y=y_temp - cfg['W_STATIC_SIZE'] * 0.4, text_format=" ", z=0.1, rot=0.0, char_count=10, size=0.6, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) item['pop'] = pi3d.TextBlock(x=x, y=y_pop, text_format=" ", z=0.1, rot=0.0, char_count=10, size=0.6, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) item['wind'] = pi3d.TextBlock(x=x, y=y_wind, text_format=" ", z=0.1, rot=0.0, char_count=10, size=0.6, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) item['humidity'] = pi3d.TextBlock(x=x, y=y_humidity, text_format=" ", z=0.1, rot=0.0, char_count=10, size=0.6, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) item['pressure'] = pi3d.TextBlock(x=x, y=y_pressure, text_format=" ", z=0.1, rot=0.0, char_count=10, size=0.6, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) item['icon'] = pi3d.ImageSprite(os.path.join(cfg['W_ICON_DIR'], '01d.png'), icon_shader, w=cfg['W_ICON_SIZE'], h=cfg['W_ICON_SIZE'], x=x + cfg['W_ICON_SIZE'] * 0.5, y=y_icon, z=1.0) weatherobj['forecast'].append(item) return weatherobj
import config import core.peripherals as peripherals import core.graphics as graphics import sys import os import pi3d sys.path.insert(1, os.path.join(sys.path[0], '..')) text5 = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=20, point_size=64) # slider5 Ammeter currents = pi3d.TextBlock(-350, 100, 0.1, 0.0, 15, data_obj=peripherals.eg_object, attr="relais1current", text_format="{:2.1f}A", size=0.99, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text5.add_text_block(currents) amperemeter = pi3d.ImageSprite(config.installpath + 'sprites/amperemeter.png', shader=graphics.SHADER, camera=graphics.CAMERA, w=400, h=400, x=0, y=0, z=2.0) ampereneedle = pi3d.Lines(camera=graphics.CAMERA, vertices=( (0, 0, 0), (0, 160, 0)), material=(1.0, 0.3, 0.0), line_width=5, x=0.0, y=-70.0, z=1.0) ampereneedle.set_shader(graphics.MATSH) def inloop(textchange=False, activity=False, offset=0): if offset != 0: offset = graphics.slider_change(amperemeter, offset) else: ampereneedle.rotateToZ(
try: unichr except NameError: unichr = chr text2 = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=500, point_size=128) title_block = pi3d.TextBlock(-200, 190, 0.1, 0.0, 15, text_format="Backlight", size=0.79, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text2.add_text_block(title_block) bllevel = pi3d.TextBlock(-50, 100, 0.1, 0.0, 15, data_obj=peripherals.eg_object, attr="max_backlight", text_format="{:d}", size=0.99,
line_width=15, strip=True) clock_hour.set_shader(graphics.MATSH) clock_hour.set_material((0, 0, 0)) text = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=80, point_size=128) press_block2 = pi3d.TextBlock(-70, -185, 0.1, 0.0, 6, justify=0.0, text_format=unichr(0xE00B), size=0.4, spacing="F", space=0.02, colour=(0.0, 1.0, 0.0, 0.7)) air_block2 = pi3d.TextBlock(30, -190, 0.1, 0.0, 6, justify=0.0, text_format=unichr(0xE002), size=0.4, spacing="F", space=0.02,
# images in iFiles list nexttm = 0.0 iFiles, nFi = get_files(date_from, date_to) next_pic_num = 0 sfg = None # slide for background sbg = None # slide for foreground if nFi == 0: print('No files selected!') exit() # PointText and TextBlock. If SHOW_NAMES is False then this is just used for no images message font = pi3d.Font(FONT_FILE, codepoints=CODEPOINTS, grid_size=7, shadow_radius=4.0, shadow=(0,0,0,128)) text = pi3d.PointText(font, CAMERA, max_chars=200, point_size=50) textblock = pi3d.TextBlock(x=-DISPLAY.width * 0.5 + 50, y=-DISPLAY.height * 0.4, z=0.1, rot=0.0, char_count=199, text_format="{}".format(" "), size=0.99, spacing="F", space=0.02, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(textblock) num_run_through = 0 while DISPLAY.loop_running(): tm = time.time() if nFi > 0: if (tm > nexttm and not paused) or (tm - nexttm) >= 86400.0: # this must run first iteration of loop nexttm = tm + time_delay a = 0.0 # alpha - proportion front image to back sbg = sfg sfg = None while sfg is None: # keep going through until a usable picture is found TODO break out how? pic_num = next_pic_num sfg = tex_load(iFiles[pic_num][0], iFiles[pic_num][1], (DISPLAY.width, DISPLAY.height))
xpos=0, ypos=0, z=1.0, ymax=50, ymin=10) i = 0 for varname in showvars: legend = pi3d.TextBlock(-340, (200 - (i * 30)), 0.1, 0.0, 30, data_obj=peripherals.eg_object, text_format=varname + " {:2.1f}", attr=varname, size=0.3, spacing="C", space=1.1, colour=(colors[i][0], colors[i][1], colors[i][2], 1)) text.add_text_block(legend) i += 1 grapharea = pi3d.Sprite(camera=graphics.CAMERA, w=780, h=460, z=3.0, x=0, y=0) grapharea.set_shader(graphics.MATSH) grapharea.set_material((1.0, 1.0, 1.0)) grapharea.set_alpha(0.6) def inloop(textchange=False, activity=False, offset=0):
try: unichr except NameError: unichr = chr text = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=220, point_size=128) temp_block = pi3d.TextBlock(-350, 50, 0.1, 0.0, 15, data_obj=peripherals.eg_object, attr="act_temp", text_format=unichr(0xE021) + u"{:2.1f}°C", size=0.99, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(temp_block) if config.heatingrelay or config.coolingrelay: set_temp_block = pi3d.TextBlock(-340, -30, 0.1, 0.0, 15, data_obj=peripherals.eg_object, text_format=unichr(0xE005) + u" {:2.1f}°C",
def init(): global text6, actualy, displayheight if config.icallink.startswith('http'): icalfile = requests.get(config.icallink).text else: icalfile = open(config.installpath + config.icallink, 'r') gcal = Calendar.from_ical(icalfile.read()) components = gcal.walk() now2 = datetime.now() components = filter(lambda c: c.name == 'VEVENT', components) components = filter(lambda c: c.get('dtstart').dt.replace( tzinfo=None) - now2 > timedelta(0), components) # filter out past events components = sorted( components, key=lambda c: c.get('dtstart').dt.replace(tzinfo=None) - now2, reverse=False) # order dates soonist to now to farthest text6 = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=1000, point_size=128) count = 0 mystring = '' actualy = -100 for e in components: if count < 5: start = arrow.get(e.get('dtstart').dt) size = 0.79 titles = pi3d.TextBlock(-390, ((displayheight / 2) + actualy - (graphics.pointFont.height * size * 0.5)), 0.1, 0.0, 30, text_format=start.humanize().title(), size=size, spacing="F", space=0.02, colour=(1, 0, 0, 1)) text6.add_text_block(titles) actualy -= titles.size * graphics.pointFont.height size = 0.29 date = pi3d.TextBlock( -380, ((displayheight / 2) + actualy - (graphics.pointFont.height * size * 0.5)), 0.1, 0.0, 12, text_format='(' + start.format('DD.MM.YYYY') + ')', size=size, spacing="F", space=0.02, colour=(1, 1, 1, 1)) text6.add_text_block(date) actualy -= date.size * graphics.pointFont.height size = 0.4 width = 0 subtext = '' actualword = '' g_scale = float(text6.point_size) / graphics.pointFont.height for c in e.get('summary'): width += graphics.pointFont.glyph_table[c][0] * g_scale * size actualword += c if c in (' ', '-', ',', '.', '+', ':'): subtext += actualword actualword = '' if width > 730: event = pi3d.TextBlock( -350, (displayheight / 2) + actualy - (graphics.pointFont.height * size * 0.5), 0.1, 0.0, 40, text_format=subtext, size=size, spacing="F", space=0.02, colour=(1, 1, 1, 1)) text6.add_text_block(event) subtext = '' width = 0 actualy -= event.size * graphics.pointFont.height if (subtext != '') or (actualword != ''): event = pi3d.TextBlock( -350, (displayheight / 2) + actualy - (graphics.pointFont.height * size * 0.5), 0.1, 0.0, 40, text_format=subtext + actualword, size=size, spacing="F", space=0.02, colour=(1, 1, 1, 1)) text6.add_text_block(event) actualy -= event.size * graphics.pointFont.height actualy -= 20 count += 1 else: break icalfile.close()
except NameError: unichr = chr text = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=220, point_size=128) if config.HEATINGRELAY != 0 or config.COOLINGRELAY != 0: offset_val_block = pi3d.TextBlock(0, -70, 0.1, 0.0, 15, data_obj=peripherals.eg_object, text_format=u"{:s}", attr="tempoffsetstr", size=0.5, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0), justify=0.5) text.add_text_block(offset_val_block) if peripherals.eg_object.tempoffset > 0: offset_val_block.colouring.set_colour([1, 0, 0]) elif peripherals.eg_object.tempoffset < 0: offset_val_block.colouring.set_colour([0, 0, 1]) else: offset_val_block.colouring.set_colour([1, 1, 1])
def __init__(self, x=0, y=0, inner=100, outer=200, values=[], colors=[], full_range=None, concentric=False, start=0.0, end=None, sides=36, text_format="{:.1f}", camera=graphics.CAMERA, shader=graphics.MATSH): self.x = x self.y = y self.inner = inner self.outer = outer self.full_range = full_range self.concentric = concentric self.start = start if end is None: self.end = start + 360 else: self.end = end if type(text_format) in (list, tuple): self.text_format = text_format else: self.text_format = [text_format] * len(values) self.slices = [] if full_range is None: full_range = sum(values) self.n = len(values) # simplest Shape only 3 vertices. z -1 so not drawn self.empty = pi3d.Triangle(x=x, y=y, z=-1.0) self.text = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=(self.n * 26), point_size=64) tot = self.start step = (outer - inner) / self.n for i in range(self.n): end = (self.end - self.start) * values[i] / full_range if concentric: a_slice = Slice( camera=camera, inner=inner + i * step, outer=inner + (i + 1) * step, sides=sides, start=self.start, end=end, z=3.0 ) #z=3 to compensate for empty set to -1 and draw behind labels else: a_slice = Slice(camera=camera, inner=inner, outer=outer, start=tot, end=tot + end, z=3.0) tot += end buf = a_slice.buf[0].array_buffer # alias for brevity midv = len( buf ) // 2 # text half way round curve, miday between inner and outer text_x = (buf[midv, 0] + buf[midv + 1, 0]) / 2 + self.x text_y = (buf[midv, 1] + buf[midv + 1, 1]) / 2 + self.y slice_text = pi3d.TextBlock(text_x, text_y, 0.0, 0.0, 25, text_format=self.text_format[i].format( values[i]), size=0.5, spacing="C", space=0.6, justify=0.5) self.text.add_text_block(slice_text) a_slice.set_shader(shader) a_slice.set_material(colors[i]) self.slices.append(a_slice) self.empty.add_child(a_slice)
eg_object = EgClass() # create an instance of the example class text_pos = QWIDTH working_directory = os.path.dirname(os.path.realpath(__file__)) font_path = os.path.abspath( os.path.join(working_directory, 'fonts', 'NotoSans-Regular.ttf')) pointFont = pi3d.Font(font_path, font_colour, codepoints=list(range(32, 128))) text = pi3d.PointText(pointFont, CAMERA, max_chars=200, point_size=64) newtxt = pi3d.TextBlock(510, 380, 0.1, 0.0, 10, data_obj=eg_object, attr="fps", text_format="fps:{:4.1f}", size=0.35, spacing="C", space=0.6, colour=(0.0, 1.0, 1.0, 1.0)) text.add_text_block(newtxt) newtxt = pi3d.TextBlock(510, 360, 0.1, 0.0, 10, data_obj=eg_object, attr="ms", text_format=" ms:{:4.2f}", size=0.35,
keyboardfield = pi3d.Sprite(camera=graphics.CAMERA, w=780, h=380, z=3, x=0, y=-40) keyboardfield.set_shader(graphics.MATSH) keyboardfield.set_material((0.0, 0.0, 0.0)) keyboardfield.set_alpha(0.7) textblock = pi3d.TextBlock(-370, 195, 0.1, 0.0, 27, data_obj=peripherals.eg_object, attr="usertextshow", text_format="{:s}", size=0.29, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) keyboardslide.add_text_block(textblock) chartype = 0 everysecond = 0 def inloop(textchange=False, activity=False, x=0, y=0, touch_pressed=False): global chartype, everysecond if peripherals.check_touch_pressed(): if 150 < peripherals.lasty < 240:
text_pos = QWIDTH working_directory = os.path.dirname(os.path.realpath(__file__)) font_path = os.path.abspath( os.path.join(working_directory, 'fonts', 'NotoSans-Regular.ttf')) # Create pointFont and the text manager to use it pointFont = pi3d.Font(font_path, font_colour, codepoints=list(range(32, 128))) text = pi3d.PointText(pointFont, CAMERA, max_chars=220, point_size=64) #Basic static text newtxt = pi3d.TextBlock(-100, -50, 0.1, 0.0, 14, text_format="Static string", size=0.99, spacing="F", space=0.05, colour=(0.0, 1.0, 0.0, 1.0)) text.add_text_block(newtxt) """The next three strings are formated with data from an object. When the object data changes and the text block is regenerated, the string is changed to the new data values.""" moving_text = pi3d.TextBlock(0, 0, 0.1, 0.0, 25, data_obj=eg_object, attr="strA",
def init(): global seplines, degwind, weathericon, text, line, baroneedle, windneedle, linemin, linemax, acttemp, text, error try: owm = pyowm.OWM(API_key=config.owmkey, language=config.owmlanguage) place = owm.weather_at_place(config.owmcity) weather = place.get_weather() text.text_blocks = [] text._first_free_char = 0 if config.owmlanguage == 'de': weekdays = [ 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag' ] else: weekdays = [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ] if not os.path.exists('sprites/' + weather.get_weather_icon_name() + '.png'): import urllib.request urllib.request.urlretrieve( "http://openweathermap.org/img/wn/" + weather.get_weather_icon_name() + "@2x.png", "sprites/" + weather.get_weather_icon_name() + ".png") weathericon = pi3d.ImageSprite(config.installpath + 'sprites/' + weather.get_weather_icon_name() + '.png', shader=graphics.SHADER, camera=graphics.CAMERA, w=150, h=150, z=2, x=-220) city = pi3d.TextBlock(-390, 180, 0.1, 0.0, 150, text_format=place.get_location().get_name(), size=0.7, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(city) city = pi3d.TextBlock(-220, 80, 0.1, 0.0, 30, justify=0.5, text_format=weather.get_detailed_status(), size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(city) acttemp = pi3d.TextBlock( -350, -50, 0.1, 0.0, 10, text_format=str(weather.get_temperature(unit='celsius')['temp']) + u'°C', size=0.9, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(acttemp) #acttemp = pi3d.FixedString(config.installpath + 'fonts/opensans.ttf', str(weather.get_temperature(unit='celsius')['temp']) + '°C' , font_size=42, shadow_radius=1,justify='L', color= (255,255,255,255),camera=graphics.CAMERA, shader=graphics.SHADER, f_type='SMOOTH') #acttemp.sprite.position(-210, -50, 1) sunriset = weather.get_sunrise_time( timeformat='date') + datetime.timedelta(hours=2) sunsett = weather.get_sunset_time( timeformat='date') + datetime.timedelta(hours=2) sunset = pi3d.TextBlock(50, 100, 0.1, 0.0, 20, text_format=unichr(0xE041) + " %s:%02d" % (sunriset.hour, sunriset.minute) + ' ' + unichr(0xE042) + " %s:%02d" % (sunsett.hour, sunsett.minute), size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(sunset) barometer = pi3d.TextBlock(50, -50, 0.1, 0.0, 10, text_format=unichr(0xE00B) + ' ' + str(weather.get_pressure()['press']) + ' hPa', size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(barometer) baroneedle = pi3d.Triangle(camera=graphics.CAMERA, corners=((-2, 0, 0), (0, 7, 0), (2, 0, 0)), x=barometer.x + 16, y=barometer.y - 6, z=0.1) baroneedle.set_shader(graphics.MATSH) normalizedpressure = (weather.get_pressure()['press'] - 950) if normalizedpressure < 0: normalizedpressure = 0 if normalizedpressure > 100: normalizedpressure = 100 green = 0.02 * (normalizedpressure) if green > 1: green = 1 red = 0.02 * (100 - normalizedpressure) if red > 1: red = 1 barometer.colouring.set_colour([red, green, 0, 1.0]) baroneedle.set_material([red, green, 0]) baroneedle.rotateToZ(100 - (normalizedpressure * 2)) humidity = pi3d.TextBlock(50, 0, 0.1, 0.0, 10, text_format=unichr(0xE003) + ' ' + str(weather.get_humidity()) + '%', size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(humidity) if 'speed' in weather.get_wind(): wind = pi3d.TextBlock(50, 50, 0.1, 0.0, 10, text_format=unichr(0xE040) + ' ' + str(weather.get_wind()['speed']) + 'm/s', size=0.3, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(wind) if 'deg' in weather.get_wind(): degwind = True windneedle = pi3d.Triangle(camera=graphics.CAMERA, corners=((-3, 0, 0), (0, 15, 0), (3, 0, 0)), x=wind.x + 180, y=wind.y, z=0.1) windneedle.set_shader(graphics.MATSH) windneedle.set_material([1, 1, 1]) windneedle.rotateToZ(weather.get_wind()['deg']) else: degwind = False fc = owm.three_hours_forecast(config.owmcity) f = fc.get_forecast() step = 780 / (len(f)) actualy = -400 + step temp_max = [] temp_min = [] temp = [] seplines = [] icons = [] maxdaytemp = -100 mindaytemp = 100 for weather in f: if not os.path.exists('sprites/' + weather.get_weather_icon_name() + '.png'): import urllib.request urllib.request.urlretrieve( "http://openweathermap.org/img/wn/" + weather.get_weather_icon_name() + "@2x.png", "sprites/" + weather.get_weather_icon_name() + ".png") icons.append( pi3d.ImageSprite('sprites/' + weather.get_weather_icon_name() + '.png', shader=graphics.SHADER, camera=graphics.CAMERA, w=20, h=20, z=1, x=actualy, y=-220)) if weather.get_reference_time('iso')[11:16] == '00:00': line = pi3d.Lines(vertices=[[actualy, -50, 2], [actualy, 50, 2]], line_width=1, y=-180, strip=True) line.set_shader(graphics.MATSH) line.set_material((0, 0, 0)) line.set_alpha(0.9) seplines.append(line) # if weather.get_reference_time('iso')[11:16] == '12:00': day = weather.get_reference_time(timeformat='date').weekday() if actualy < 300: city = pi3d.TextBlock(actualy + 65, -100, 0.1, 0.0, 30, text_format=weekdays[day], justify=0.5, size=0.23, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(city) if actualy > -300: city = pi3d.TextBlock( actualy - 6 * step, -150, 0.1, 0.0, 30, text_format=str(round(maxdaytemp, 1)) + u'°C', size=0.25, spacing="F", space=0.05, colour=(1.0, 0.0, 0.0, 1.0)) text.add_text_block(city) city = pi3d.TextBlock( actualy - 6 * step, -210, 0.1, 0.0, 30, text_format=str(round(mindaytemp, 1)) + u'°C', size=0.25, spacing="F", space=0.05, colour=(0.0, 0.0, 1.0, 1.0)) text.add_text_block(city) maxdaytemp = -100 mindaytemp = 100 if '3h' in weather.get_snow(): line = pi3d.Lines(vertices=[[ actualy, -50, 2 ], [actualy, (-50 + weather.get_snow()['3h'] * 30), 2]], line_width=3, y=-180, strip=True) line.set_shader(graphics.MATSH) line.set_material((0.5, 0.5, 1)) line.set_alpha(1) seplines.append(line) if '3h' in weather.get_rain(): line = pi3d.Lines(vertices=[[ actualy, -50, 2 ], [actualy, (-50 + weather.get_rain()['3h'] * 30), 2]], line_width=3, y=-180, strip=True) line.set_shader(graphics.MATSH) line.set_material((0, 0, 1)) line.set_alpha(1) seplines.append(line) temperatures = weather.get_temperature(unit='celsius') if temperatures['temp_max'] > maxdaytemp: maxdaytemp = temperatures['temp_max'] if temperatures['temp_min'] < mindaytemp: mindaytemp = temperatures['temp_min'] temp_max.append([actualy, temperatures['temp_max'] * 3, 2]) temp_min.append([actualy, temperatures['temp_min'] * 3, 2]) temp.append([actualy, temperatures['temp'] * 3, 2]) actualy += step lastvalue = 0 line = pi3d.Lines(vertices=temp, line_width=2, y=-220, strip=True) line.set_shader(graphics.MATSH) line.set_material((0, 0, 0)) line.set_alpha(0.9) #linemin = pi3d.Lines(vertices=temp_min, line_width=1,y=-220, strip=True) # linemin.set_shader(graphics.MATSH) # linemin.set_material((0,0,1)) # linemin.set_alpha(0.9) #linemax = pi3d.Lines(vertices=temp_max, line_width=1,y=-220, strip=True) # linemax.set_shader(graphics.MATSH) # linemax.set_material((1,0,0)) # linemax.set_alpha(0.9) except: error = pi3d.TextBlock(-390, 180, 0.1, 0.0, 150, text_format="OWM ERROR", size=0.7, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(error) error = True
pic_num = 0 sfg = tex_load(iFiles[pic_num]) # PointText and TextBlock font = pi3d.Font(FONT_FILE, codepoints=' 0123456789.s#', grid_size=4, shadow_radius=4.0, shadow=(0, 0, 0, 128)) text = pi3d.PointText(font, CAMERA, max_chars=50, point_size=200) textblock = pi3d.TextBlock(x=-DISPLAY.width * 0.5 + 50, y=0, z=0.1, rot=0.0, char_count=15, text_format="{:5.2f}s #{}".format( time.time() % 1000.0, pic_num), size=0.99, spacing="M", space=1.0, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(textblock) while DISPLAY.loop_running(): tm = time.time() if tm > nexttm: # this must run first iteration of loop nexttm = tm + TMDELAY a = 0.0 sbg = sfg sbg.positionZ(10.0)
except NameError: unichr = chr text2 = pi3d.PointText(graphics.pointFontbig, graphics.CAMERA, max_chars=35, point_size=256) # slider2 Time & shutter if config.shutterup or config.shutterdown: uhrzeit_block = pi3d.TextBlock(-70, 100, 0.1, 0.0, 15, justify=0.5, data_obj=peripherals.eg_object, attr="uhrzeit", text_format="{:s}", size=0.99, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text2.add_text_block(uhrzeit_block) shuttersymbol = pi3d.TextBlock(-100, -100, 0.1, 0.0, 15, text_format=unichr(0xE035), size=0.99, spacing="F",
import config import core.graphics as graphics import core.peripherals as peripherals try: import mqttclient except: import core.mqttclient as mqttclient text2 = pi3d.PointText(graphics.pointFontbig, graphics.CAMERA, max_chars=35, point_size=256) #slider2 Time & shutter if config.shutterup or config.shutterdown: uhrzeit_block = pi3d.TextBlock(-280, 100, 0.1, 0.0, 15, data_obj=peripherals.eg_object,attr="uhrzeit", text_format= "{:s}", size=0.99, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text2.add_text_block(uhrzeit_block) kugelswitch = pi3d.TextBlock(-100, -100, 0.1, 0.0, 15, text_format= chr(0xE00E),size=0.99, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text2.add_text_block(kugelswitch) shutterDown = pi3d.TextBlock(300, -100, 0.1, 0.0, 1, text_format= chr(0xE00E),size=0.69, spacing="C", space=0.6, colour=(1, 1, 1, 0.8)) text2.add_text_block(shutterDown) shutterUp = pi3d.TextBlock(-300, -100, 0.1, 180.0, 1, text_format= chr(0xE00E),size=0.69, spacing="C", space=0.6, colour=(1, 1, 1, 0.8)) text2.add_text_block(shutterUp) else: uhrzeit_block = pi3d.TextBlock(-280, 0, 0.1, 0.0, 15, data_obj=peripherals.eg_object,attr="uhrzeit", text_format= "{:s}", size=0.99, spacing="F", space=0.05, colour=(1.0, 1.0, 1.0, 1.0)) text2.add_text_block(uhrzeit_block) def inloop(textchange = False,activity = False, offset = 0): if textchange:
# PointText and TextBlock. If SHOW_TEXT_TM <= 0 then this is just used for no images message grid_size = math.ceil(len(config.CODEPOINTS)**0.5) font = pi3d.Font(config.FONT_FILE, codepoints=config.CODEPOINTS, grid_size=grid_size) text = pi3d.PointText(font, CAMERA, max_chars=200, point_size=config.SHOW_TEXT_SZ) textblock = pi3d.TextBlock(x=0, y=-DISPLAY.height // 2 + (config.SHOW_TEXT_SZ // 2) + 20, z=0.1, rot=0.0, char_count=199, text_format="{}".format(" "), size=0.99, spacing="F", justify=0.5, space=0.02, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(textblock) """ back_shader = pi3d.Shader("mat_flat") text_bkg = pi3d.Sprite(w=DISPLAY.width, h=90, y=-DISPLAY.height * 0.4 - 20, z=4.0) text_bkg.set_shader(back_shader) text_bkg.set_material((0, 0, 0)) """ bkg_ht = DISPLAY.height // 3 text_bkg_array = np.zeros((bkg_ht, 1, 4), dtype=np.uint8)
text_attr = TextAttr() font = pi3d.Font(FONT_FILE, FONT_COLOUR, codepoints=list(range(32, 128)), shadow_radius=4.0, shadow=(0, 0, 0, 128)) colourGradient = pi3d.TextBlockColourGradient((1.0, 0.0, 0.0, 1.0), (0.0, 1.0, 0.0, 1.0)) file_pt = pi3d.PointText(font, CAMERA, max_chars=216, point_size=80) dir_tb = pi3d.TextBlock(x=DISPLAY.width * -0.5 + 50, y=DISPLAY.height * -0.5 + 100, z=0.1, rot=0.0, char_count=100, text_format='{:100}', data_obj=text_attr, attr="dir", size=0.5, spacing="F", space=0.02, colour=colourGradient) file_pt.add_text_block(dir_tb) file_tb = pi3d.TextBlock(x=DISPLAY.width * -0.5 + 50, y=DISPLAY.height * -0.5 + 50, z=0.1, rot=0.0, char_count=100, text_format='{:100}', data_obj=text_attr, attr="fname",
except: from urllib2 import urlopen try: unichr except NameError: unichr = chr text = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=35, point_size=128) # also big font possible, higher resolution text2 = pi3d.PointText(graphics.pointFontbig, graphics.CAMERA, max_chars=35, point_size=256) # look for graphics in core/graphics.py 0xE00F -> light, 0xE001 -> circle httpbutton = pi3d.TextBlock(0, 0, 0.1, 0.0, 1, text_format=unichr( 0xE00F), size=0.99, spacing="C", space=0.6, colour=(1, 1, 1, 1)) circle = pi3d.TextBlock(-5, 15, 0.1, 0.0, 1, text_format=unichr(0xE001), size=0.99, spacing="C", space=0.6, colour=(1, 1, 1, 1)) text.add_text_block(httpbutton) text2.add_text_block(circle) httpbutton.status = 'unknown' # on init status is unknown def get_button_status(): try: a = urlopen('http://blabla/relay1') except: logging.error('Error httpbutton') httpbutton.status = 'error' else:
e = 4 elif -154 < y < -78: e = 3 elif -78 < y < -2: e = 2 elif -2 < y < 74: e = 1 elif 74 < y < 150: e = 0 if e > -1 and i > -1: return charmap[type][e][i] else: return (str)('') numberblock = pi3d.TextBlock(-345, 110, 0.1, 0.0, 8,text_format= charmap[0][0], size=0.69, spacing="C", space=2.2, colour=(1.0, 1.0, 1.0, 1.0)) chars[0].add_text_block(numberblock) numberblock = pi3d.TextBlock(-345, 35, 0.1, 0.0, 8,text_format= charmap[0][1], size=0.69, spacing="C", space=2.2, colour=(1.0, 1.0, 1.0, 1.0)) chars[0].add_text_block(numberblock) numberblock = pi3d.TextBlock(-345, -40, 0.1, 0.0, 8,text_format= charmap[0][2], size=0.69, spacing="C", space=2.2, colour=(1.0, 1.0, 1.0, 1.0)) chars[0].add_text_block(numberblock) numberblock = pi3d.TextBlock(-345, -115, 0.1, 0.0, 8,text_format= charmap[0][3], size=0.69, spacing="C", space=2.2, colour=(1.0, 1.0, 1.0, 1.0)) chars[0].add_text_block(numberblock) numberblock = pi3d.TextBlock(-345, -190, 0.1, 0.0, 8,text_format= charmap[0][4], size=0.69, spacing="C", space=2.2, colour=(1.0, 1.0, 1.0, 1.0)) chars[0].add_text_block(numberblock) letterblock = pi3d.TextBlock(-345, 110, 0.1, 0.0, 8,text_format= charmap[1][0], size=0.69, spacing="C", space=2.2, colour=(1.0, 1.0, 1.0, 1.0)) chars[1].add_text_block(letterblock) letterblock = pi3d.TextBlock(-345, 35, 0.1, 0.0, 8,text_format= charmap[1][1], size=0.69, spacing="C", space=2.2, colour=(1.0, 1.0, 1.0, 1.0)) chars[1].add_text_block(letterblock) letterblock = pi3d.TextBlock(-345, -40, 0.1, 0.0, 8,text_format= charmap[1][2], size=0.69, spacing="C", space=2.2, colour=(1.0, 1.0, 1.0, 1.0)) chars[1].add_text_block(letterblock)
def start_picframe(): global date_from, date_to, quit, paused, nexttm, next_pic_num, iFiles, nFi, monitor_status, pcache, w_show_now if cfg['KENBURNS']: kb_up = True cfg['FIT'] = False cfg['BLUR_EDGES'] = False if cfg['BLUR_ZOOM'] < 1.0: cfg['BLUR_ZOOM'] = 1.0 sfg = None # slide for background sbg = None # slide for foreground delta_alpha = 1.0 / (cfg['FPS'] * cfg['FADE_TIME']) # delta alpha # Initialize pi3d system DISPLAY = pi3d.Display.create(x=0, y=0, frames_per_second=cfg['FPS'], display_config=pi3d.DISPLAY_CONFIG_HIDE_CURSOR, background=cfg['BACKGROUND']) CAMERA = pi3d.Camera(is_3d=False) shader = pi3d.Shader(cfg['SHADER']) slide = pi3d.Sprite(camera=CAMERA, w=DISPLAY.width, h=DISPLAY.height, z=5.0) slide.set_shader(shader) slide.unif[47] = cfg['EDGE_ALPHA'] slide.unif[54] = cfg['BLEND_TYPE'] if cfg['KEYBOARD']: kbd = pi3d.Keyboard() # PointText and TextBlock. If INFO_TXT_TIME <= 0 then this is just used for no images message grid_size = math.ceil(len(cfg['CODEPOINTS']) ** 0.5) font = pi3d.Font(cfg['FONT_FILE'], codepoints=cfg['CODEPOINTS'], grid_size=grid_size, shadow_radius=5.0, shadow=(0,0,0,128)) text = pi3d.PointText(font, CAMERA, max_chars=1000, point_size=cfg['TEXT_POINT_SIZE']) textlines = [] textlines.append( pi3d.TextBlock(x=-DISPLAY.width * 0.5 + 50, y=DISPLAY.height * 0.45, text_format=" ", z=0.1, rot=0.0, char_count=100, size=0.8, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) ) textlines.append( pi3d.TextBlock(x=-DISPLAY.width * 0.5 + 50, y=DISPLAY.height * 0.45 - 40, text_format=" ", z=0.1, rot=0.0, char_count=100, size=0.8, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) ) textlines.append( pi3d.TextBlock(x=-DISPLAY.width * 0.5 + 50, y=-DISPLAY.height * 0.4, text_format=" ", z=0.1, rot=0.0, char_count=100, size=0.99, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) ) textlines.append( pi3d.TextBlock(x=-DISPLAY.width * 0.5 + 50, y=-DISPLAY.height * 0.4 - 50, text_format=" ", z=0.1, rot=0.0, char_count=100, size=0.99, spacing="F", space=0.0, colour=(1.0, 1.0, 1.0, 1.0)) ) for item in textlines: text.add_text_block(item) # prepare to display weather info weather_interstitial = 'OFF' next_weather_tm = 0.0 weatherinfo = pi3d.PointText(font, CAMERA, max_chars=2000, point_size=cfg['W_POINT_SIZE']) weatherobj = weatherscreen.weather_obj_create(DISPLAY.width, DISPLAY.height) for _, obj in weatherobj['current'].items(): weatherinfo.add_text_block( obj ) for item in weatherobj['forecast']: for key, obj in item.items(): if key != 'icon': weatherinfo.add_text_block( obj ) weatherscreen.weather_set_alpha(weatherobj=weatherobj, alpha=0) next_check_tm = time.time() + cfg['CHECK_DIR_TM'] # check for new files or directory in image dir every n seconds next_monitor_check_tm = 0.0 num_run_through = 0 # here comes the main loop while DISPLAY.loop_running(): tm = time.time() if (tm > nexttm and not paused) or (tm - nexttm) >= 86400.0: if nFi > 0: nexttm = tm + cfg['TIME_DELAY'] sbg = sfg sfg = None if (w_show_now or (cfg['W_SKIP_CNT'] > 0 and next_pic_num > 0 and (next_pic_num % cfg['W_SKIP_CNT'] == 0))) and weather_interstitial == 'OFF': # show weather interstitial weather_interstitial = 'ON' sfg = tex_load(cfg['W_BACK_IMG'], 1, (DISPLAY.width, DISPLAY.height)) if w_show_now: w_show_now = False for item in textlines: item.colouring.set_colour(alpha=0) else: # continue with next picture if weather_interstitial == 'ON': weather_interstitial = 'FADE' start_pic_num = next_pic_num while sfg is None: # keep going through until a usable picture is found pic_num = next_pic_num sfg = tex_load(pic_num, iFiles, (DISPLAY.width, DISPLAY.height)) next_pic_num += 1 if next_pic_num >= nFi: num_run_through += 1 next_pic_num = 0 if next_pic_num == start_pic_num: nFi = 0 break # set description if cfg['INFO_TXT_TIME'] > 0.0: set_text_overlay(iFiles, pic_num, textlines) else: # could have a NO IMAGES selected and being drawn for item in textlines: item.colouring.set_colour(alpha=0.0) mqtt_publish_status( status="running", pic_num=pic_num ) if sfg is None: sfg = tex_load(cfg['NO_FILES_IMG'], 1, (DISPLAY.width, DISPLAY.height)) sbg = sfg mqtt_publish_status( status="no pictures found" ) a = 0.0 # alpha - proportion front image to back name_tm = tm + cfg['INFO_TXT_TIME'] if sbg is None: # first time through sbg = sfg slide.set_textures([sfg, sbg]) slide.unif[45:47] = slide.unif[42:44] # transfer front width and height factors to back slide.unif[51:53] = slide.unif[48:50] # transfer front width and height offsets wh_rat = (DISPLAY.width * sfg.iy) / (DISPLAY.height * sfg.ix) if (wh_rat > 1.0 and cfg['FIT']) or (wh_rat <= 1.0 and not cfg['FIT']): sz1, sz2, os1, os2 = 42, 43, 48, 49 else: sz1, sz2, os1, os2 = 43, 42, 49, 48 wh_rat = 1.0 / wh_rat slide.unif[sz1] = wh_rat slide.unif[sz2] = 1.0 slide.unif[os1] = (wh_rat - 1.0) * 0.5 slide.unif[os2] = 0.0 if cfg['KENBURNS']: xstep, ystep = (slide.unif[i] * 2.0 / cfg['TIME_DELAY'] for i in (48, 49)) slide.unif[48] = 0.0 slide.unif[49] = 0.0 kb_up = not kb_up if cfg['KENBURNS']: t_factor = nexttm - tm if kb_up: t_factor = cfg['TIME_DELAY'] - t_factor slide.unif[48] = xstep * t_factor slide.unif[49] = ystep * t_factor transition_happening = False if monitor_status.startswith("ON"): if a < 1.0: # image transition is happening transition_happening = True a += delta_alpha if a > 1.0: a = 1.0 slide.unif[44] = a * a * (3.0 - 2.0 * a) if weather_interstitial == 'ON': # fade in weather weatherscreen.weather_set_alpha(weatherobj=weatherobj, alpha=a) else: # fade in picture -> fade in text for item in textlines: item.colouring.set_colour(alpha=a) if weather_interstitial == 'FADE': # fade out weather weatherscreen.weather_set_alpha(weatherobj=weatherobj, alpha=1-a) if a==1: weather_interstitial = 'OFF' if nFi <= 0: textlines[0].set_text("NO IMAGES SELECTED") textlines[0].colouring.set_colour(alpha=1.0) next_check_tm = tm + 10.0 text.regen() elif tm > name_tm and tm < name_tm + 2.0 and weather_interstitial != 'ON': # fade out text alpha = 1- (tm - name_tm)/2.0 for item in textlines: item.colouring.set_colour(alpha=alpha) transition_happening = True text.regen() slide.draw() text.draw() if weather_interstitial != 'OFF': weatherinfo.regen() weatherinfo.draw() for item in weatherobj['forecast']: item['icon'].draw() for _, obj in weatherobj['static'].items(): obj.draw() else: # monitor OFF -> minimize system activity to reduce power consumption time.sleep(10) if not transition_happening: # no transition effect safe to reshuffle etc if tm > next_monitor_check_tm: # Check if it's time to switch monitor status scheduled_status = check_monitor_status(tm) if monitor_status != scheduled_status and not monitor_status.endswith("-MANUAL"): switch_HDMI(scheduled_status) paused = True if scheduled_status.startswith("OFF") else False monitor_status = scheduled_status mqtt_publish_status( fields="monitor_status" ) next_monitor_check_tm = tm + 60 # check every minute if monitor_status.startswith("ON"): if tm > next_check_tm: # time to check picture directory if pcache.refresh_cache() or (cfg['SHUFFLE'] and num_run_through >= cfg['RESHUFFLE_NUM']): # refresh file list required if cfg['RECENT_DAYS'] > 0 and not cfg['DATE_FROM']: # reset data_from to reflect that time is proceeding date_from = datetime.datetime.now() - datetime.timedelta(cfg['RECENT_DAYS']) date_from = (date_from.year, date_from.month, date_from.day) iFiles, nFi = get_files(date_from, date_to) num_run_through = 0 next_pic_num = 0 next_check_tm = tm + cfg['CHECK_DIR_TM'] # next check if tm > next_weather_tm: # refresh weather info weatherscreen.weather_refresh( weatherobj ) next_weather_tm = tm + cfg['W_REFRESH_DELAY'] # next check if cfg['KEYBOARD']: k = kbd.read() if k != -1: nexttm = time.time() if k==27: #ESC break if k==ord(' '): paused = not paused if k==ord('b'): # go back a picture next_pic_num -= 2 if next_pic_num < -1: next_pic_num = -1 if quit or show_camera: # set by MQTT break if cfg['KEYBOARD']: kbd.close() DISPLAY.destroy()
try: unichr except NameError: unichr = chr text = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=35, point_size=256) temp_block = pi3d.TextBlock(-200, -100, 0.1, 0.0, 15, data_obj=peripherals.eg_object, attr="act_temp", text_format=unichr(0xE021) + u" {:2.1f}°C", size=0.2, spacing="F", space=0.02, colour=(1.0, 1.0, 1.0, 1.0)) text.add_text_block(temp_block) officearea = pi3d.Sprite(camera=graphics.CAMERA, w=380, h=220, z=3, x=-70, y=110) officearea.set_shader(graphics.MATSH) officearea.set_material((1.0, 0.0, 0.0))