def display(self): if self.online == 1: s = self.__str__() # make pixels text = txtlib.Text((WIDTH_SIDE, HEIGHT_TOTAL / (1.02 * NUM_ROBOTS)), self.font, font_size=self.fontsize) text.background_color = BLACK text.default_color = WHITE text.html(s) text.update() self.screen.blit(text.area, (self.posx, self.posy)) return # offline! text = txtlib.Text((WIDTH_SIDE, HEIGHT_TOTAL / (1.02 * NUM_ROBOTS)), self.font, font_size=2*self.fontsize) text.background_color = BLACK text.default_color = RED if self.online == 2: text.html("R%d : LOST CONNECTION" % self.robotnum) else: text.html("R%d : OFFLINE" % self.robotnum) text.update() self.screen.blit(text.area, (self.posx, self.posy))
def add_htmltext(self, html_text, color, pos, rectsize, fontsize, font=None): textobj = txtlib.Text(rectsize, font, fontsize) textobj.background_color = (255, 255, 255, 0) textobj.html(html_text) textobj.update() self.add_image(textobj.area, pos)
def get_lyrics(): global mode if artist is None or title is None: return "No artist or title" print artist, title url = get_url(artist, title) if not url: return "Can't find lyrics - url couldn't be found or had 'edit' " try: doc = lxml.html.parse(url) except IOError: return "Can't find lyrics - couldn't parse url - may be a cover" try: lyricbox = doc.getroot().cssselect(".lyricbox")[0] except IndexError: return "Can't find lyrics - couldn't find lyrics in page" # look for a sign that it's instrumental if len(doc.getroot().cssselect(".lyricbox a[title=\"Instrumental\"]")): return "No lyrics - appears to be instrumental" mode = 0 # switch to this mode since there appear to actually be lyrics lyrics = [] if lyricbox.text is not None: lyrics.append(lyricbox.text) for node in lyricbox: if str(node.tag).lower() == "br": lyrics.append("\n") if node.tail is not None: lyrics.append(node.tail) text = txtlib.Text((w, h), 'freesans', font_size=18) text.text = "".join(lyrics).strip() text.update() screen.fill((0, 0, 0)) screen.blit(text.area, (0, 0)) pygame.display.flip()
w, h = pygame.display.Info().current_w, pygame.display.Info().current_h if w > 1000: w = 1000 if h > 700: h = h - 100 screen = pygame.display.set_mode((w, h)) screen.fill((0, 0, 0)) # need a backup image that should be renamed backup #img = wand.image.Image(filename = "test.bmp") ######### #img.transform(resize = '320x240^')############# #img.save(filename = "test.bmp") img = pygame.image.load("test.bmp").convert() ################ text = txtlib.Text((w, h), 'freesans') text.text = "Sonos-Companion TFT Edition" text.update() screen.blit(text.area, (0, 0)) pygame.display.flip() sleep(5) font = pygame.font.SysFont('Sans', 20) text = font.render("Welcome to Sonos-Companion", True, (255, 0, 0)) img.blit(text, (0, 25)) screen.blit(img, (0, 0)) pygame.display.flip() config.CACHE_ENABLED = False
import txtlib from time import sleep if platform.system() == 'Windows': os.environ['SDL_VIDEODRIVER'] = 'windib' else: os.putenv('SDL_VIDEODRIVER', 'fbcon') os.putenv('SDL_FBDEV', '/dev/fb1') pygame.init() pygame.mouse.set_visible(0) screen = pygame.display.set_mode((320, 240)) #, pygame.FULLSCREEN) 320 240 screen.fill((0, 0, 0)) text = txtlib.Text((320, 240), 'freesans') text.text = '''This is the proof of txtlib. You can print lines like this one. \n\nYou can also make bold text, italic text and underline text. You can use colors: BLU, RED, GREEN, but you can use what color you want!!! Don't forget of different fonts or texts SIZES. Obviously you can combine different styles!!! And it support identations. This line has two tab character at the beginning. This line only one.''' text.add_style(84, 93, txtlib.BOLD) text.add_style(95, 106, txtlib.ITALIC) text.add_style(111, 126, txtlib.UNDERLINE) text.add_style(147, 150, txtlib.COLOR, (0, 0, 255))
#!/usr/bin/env python #-*- coding:utf-8 -*- import pygame import txtlib pygame.init() screen = pygame.display.set_mode((800, 600)) text = txtlib.Text((600, 400), 'freesans') text.text = '''This is the proof of txtlib. You can print lines like this one. \n\nYou can also make bold text, italic text and underline text. You can use colors: BLU, RED, GREEN, but you can use what color you want!!! Don't forget of different fonts or texts SIZES. Obviously you can combine different styles!!! And it support identations. This line has two tab character at the beginning. This line only one.''' text.add_style(84, 93, txtlib.BOLD) text.add_style(95, 106, txtlib.ITALIC) text.add_style(111, 126, txtlib.UNDERLINE) text.add_style(147, 150, txtlib.COLOR, (0, 0, 255)) text.add_style(152, 155, txtlib.COLOR, (255, 0, 0)) text.add_style(157, 162, txtlib.COLOR, (0, 255, 0)) text.add_style(229, 234, txtlib.FONT, 'freemono') text.add_style(244, 249, txtlib.SIZE, 32) text.add_style(252, 297, txtlib.SIZE, 24)
#!/usr/bin/env python #-*- coding:utf-8 -*- import pygame import txtlib pygame.init() screen = pygame.display.set_mode((800, 600)) text = txtlib.Text((600, 400), '') text.html('\n\nProviamo formattazione <U><i><b>html</B></i></U>. <color="255, 0, 0">Colore</color>, <size="10">size</s>, <foNt="azfhh">font</FONT>') text.update() screen.blit(text.area, (200, 100)) pygame.display.flip() while True: event = pygame.event.wait() if event.type == pygame.QUIT: exit(0)
# Should be (6,0) if pygame inits correctly r = pygame.init() print "pygame init",r if platform.machine() == 'armv6l': # and not args.display: pygame.mouse.set_visible(False) if platform.system() == 'Windows': w,h = 1000,700 else: w, h = pygame.display.Info().current_w, pygame.display.Info().current_h screen = pygame.display.set_mode((w, h)) screen.fill((0,0,0)) text = txtlib.Text((w, h), 'freesans', font_size=30) text.text = "Sonos-Companion TFT Edition" text.update() screen.blit(text.area, (0,0)) pygame.display.flip() # Early use of Soco had some funny things happening if the cache was on -- no idea if this is still necessary but solved problem at the time config.CACHE_ENABLED = False print "\n" print "program running ..." def display_artist_info(artist): artist_image_list = get_images(artist)