def test_wrapped_text(): reference = 'quick_brown_fox_word_wrap.png' device = dummy() term = terminal(device, word_wrap=True, animate=False) assert_text(device, term, reference, ["The quick brown fox jumps over the lazy dog"])
def test_default_text(): reference = 'quick_brown_fox.png' device = dummy() term = terminal(device) assert_text(device, term, reference, ["The quick brown fox jumps over the lazy dog"])
def render(draw, width, height): device = Test3.device arrays = [] #global arrays #arrays.clear() res = requests.get('http://news.sina.com.cn/china/') res.encoding = 'utf-8' soup = BeautifulSoup(res.text, 'html.parser') for news in soup.select('.news-2'): i=0 for li_data in news.select('li'): li = news.select('li')[i].text arrays.append(li) i +=1 font = ImageFont.truetype("/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc",16) term = terminal(device, font) for data in arrays: term.println(">>"+data) time.sleep(2)
def test_control_chars(): reference = 'control_chars.png' device = dummy() term = terminal(device, animate=False) assert_text(device, term, reference, ['foo\rbar\bspam\teggs\n\nham and cheese on rye'])
def init_terminal(): try: device = get_device() device.contrast(255) font = make_font('Consolas.ttf', 12) term = terminal(device, font) return term except Exception as e: print("Error Initializing Display Driver : {0}".format(e))
def displayInfo(name, score): for fontname, size in [("miscfs_.ttf", 12)]: font = make_font(fontname, size) if fontname else None term = terminal(device, font) term.println(" Andon Monitor") term.println("---------------------") term.println("%s: %s" % (name, score)) term.puts("---------------------") time.sleep(30)
def main(): while True: for fontname, size in [("ProggyTiny.ttf", 16)]: font = make_font(fontname, size) if fontname else None term = terminal(device, font) term.println('Running...') term.println('\n'.join(ip4_addresses())) term.println('ayoooooooooooooooooo')
def __init__(self): for fontname, size in [("ProggyTiny.ttf", 16)]: font = ImageFont.truetype( os.path.abspath( os.path.join(os.path.dirname(__file__), 'fonts', fontname)), size) self.term = terminal(get_device(), font) def show_text_sm(self, text): self.term.println(text)
def welcome(): while True: for fontname, size in [("miscfs_.ttf", 16)]: font = make_font(fontname, size) if fontname else None term = terminal(device, font) term.println(" Welcome") term.println(" To") term.puts(" Andon Monitor") time.sleep(3) term.clear()
def test_ansi_colors_wrapped(): reference = 'ansi_colors_wrapped.png' device = dummy() term = terminal(device, word_wrap=True, animate=False) assert_text(device, term, reference, [ "hello \033[31mworld\033[0m ansi colors\t\033[32mwrap\033[0m\t?", "this is \033[7mreversed\033[7m!", "\033[43;30mYellow\033[0m \033[45;37mMagenta" ])
def sys_info(): # while True: for fontname, size in [("miscfs_.ttf", 12)]: font = make_font(fontname, size) if fontname else None term = terminal(device, font) term.println(" Andon Monitor") term.println("---------------------") term.println("IP : %s" % (get_ip_address())) term.puts("---------------------") time.sleep(10)
def test_ansi_colors(): reference = 'ansi_colors.png' device = dummy() term = terminal(device, animate=False) assert_text(device, term, reference, [ "hello \033[31mworld\033[0m ansi colors here!", "this is \033[7mreversed\033[7m!", "\033[44;37mBlue\033[0m \033[46;30mCyan" ])
def main(): (font_name, font_size) = font_set font = make_font(font_name, font_size) if font_name else None term = terminal(device, font) while True: term.println(get_ipaddr()) time.sleep(1) return
def main(): while True: for fontname, size in [(None, None), ("tiny.ttf", 6), ("ProggyTiny.ttf", 16), ("creep.bdf", 16), ("miscfs_.ttf", 12), ("FreePixel.ttf", 12)]: font = make_font(fontname, size) if fontname else None term = terminal(device, font) term.println("Terminal mode demo") term.println("------------------") term.println("Uses any font to output text using a number of different print methods.") term.println() time.sleep(2) term.println("The '{0}' font supports a terminal size of {1}x{2} characters.".format(fontname, term.width, term.height)) term.println() time.sleep(2) term.println("An animation effect is defaulted to give the appearance of spooling to a teletype device.") term.println() time.sleep(2) term.println("".join(chr(i) for i in range(32, 127))) time.sleep(2) term.clear() for i in range(30): term.println("Line {0:03d}".format(i)) term.animate = False time.sleep(2) term.clear() term.println("Progress bar") term.println("------------") for mill in range(0, 10001, 25): term.puts("\rPercent: {0:0.1f} %".format(mill / 100.0)) term.flush() time.sleep(2) term.clear() term.puts("Backspace test.") term.flush() time.sleep(2) for _ in range(17): term.backspace() time.sleep(0.2) time.sleep(2) term.clear() term.animate = True term.println("Tabs test") term.println("|...|...|...|...|...|") term.println("1\t2\t4\t11") term.println("992\t43\t9\t12") term.println("\t3\t99\t1") term.flush() time.sleep(2)
def test_ansi_colors_scroll(): reference = 'ansi_colors_scroll.png' device = dummy() term = terminal(device, word_wrap=True, animate=False) assert_text(device, term, reference, [ "hello \033[31mworld\033[0m ansi colors\t\033[32mwrap\033[0m\t?", "this is \033[7mreversed\033[7m!", "\033[43;30mYellow\033[0m \033[44;37mBlue abcdefg hijklmn", "\033[41;30mRed\033[0m \033[42;37mGreen" ])
def test_scrolling(): reference = 'scroll_text.png' device = dummy() term = terminal(device, animate=False) assert_text(device, term, reference, [ "it oozed over the blackness, and heard Harris's sleepy voice asking " "where we drew near it, so they spread their handkerchiefs on the back " "of Harris and Harris's friend as to avoid running down which, we managed " "to get out of here while this billing and cooing is on. We'll go down " "to eat vegetables. He said they were demons." ])
def mainscales(): #setup local OLED screen fontname = "ProggyTiny.ttf" size = 48 # 48 gives 7chars x 2lines font = make_font(fontname, size) if fontname else None # if i2c then use i2c() serial = spi(device=0, port=0) # change device type here if needed, this also rotates display 180 - i.e. if gpio connector on bottom of display device = sh1106(serial, rotate=2) term = terminal(device, font) # term.clear() term.animate = True processor = EventProcessor() board = Wiiboard(processor, term) dispTime = DispTime(term) while 1: address = Discover(board) didwegrabit = True if (address != None): print "Trying to connect..." term.animate = False try: board.connect( address) # The wii board must be in sync mode at this time board.wait(200) board.setLight(False) board.wait(500) board.setLight(True) # go weigh :) board.receive() except KeyboardInterrupt: #time.sleep(5) exit() except: # likely no board connected, print "No board connected" didwegrabit = False # display time during this idle phase dispTime.putToScreen() # need to sleep for a while to allow BT stack to not be hammered # and allow time for board to go into discover mode again # if we have a good address, then discovery is quicker, so add a longer sleep # if did have sucessfull weighing, then also can add longer sleep time.sleep(3) if (didwegrabit or (address != None)): time.sleep(3)
def test_accented_charset(): reference = 'accented_charset.png' unicode_font = get_reference_font('DejaVuSans.ttf') device = dummy() term = terminal(device, font=unicode_font, word_wrap=False, animate=False, color="blue", bgcolor="white") assert_text(device, term, reference, [u"\033[31mFußgängerunterführungen\033[0m Текст на русском"])
def main(): if not os.access(VIRTUAL_TERMINAL_DEVICE, os.R_OK): print "Unable to access %s, try running as root?" % (VIRTUAL_TERMINAL_DEVICE,) raise SystemExit fontname = "tiny.ttf" size = 6 font = make_font(fontname, size) if fontname else None term = terminal(device, font, animate=False) term.clear() for i in range(0, ROWS): term.puts(str(i) * COLS) term.flush() #time.sleep(1) while True: # Get terminal text; despite man page, `screendump` differs from reading vcs dev #data = file(VIRTUAL_TERMINAL_DEVICE).read() data = subprocess.check_output(["screendump"]) #print [data] # Clear, but don't flush to avoid flashing #term.clear() term._cx, term._cy = (0, 0) #term._canvas.rectangle(term._device.bounding_box, fill=term.bgcolor) term._canvas.rectangle(term._device.bounding_box, fill="black") # puts() flushes on newline(), so reimplement it ourselves #term.puts(data) for char in data: if char == '\r': term.carriage_return() elif char == '\n': #term.newline() # no scroll, no flush term.carriage_return() x = 0 term._cy += term._ch elif char == '\b': term.backspace() x =- 1 elif char == '\t': term.tab() else: term.putch(char) term.flush() time.sleep(0.01)
def on_message(ws, raw): message = json.loads(raw) print(json.dumps(message, indent=4)) type = message['type'] if (type == "push"): pushdata = message['push'] pushtype = pushdata['type'] if (pushtype == 'mirror'): package_name = pushdata['package_name'] app_name = normalize(pushdata['application_name']) title = normalize(pushdata['title']) body = normalize(pushdata['body']) icon_path = 'app_icons/' + package_name + '.png' if (os.path.isfile(icon_path)): icon = Image.open(icon_path).convert(device.mode) device.display(icon) else: with canvas(device) as draw: w, h = draw.textsize(app_name, font12) draw.text( ((device.width - w) / 2, (device.height - h) / 2), app_name, fill="white", font=font12) pass time.sleep(2) term = terminal(device, font12, animate=False) if (title is not None): term.println(title) term.font = font11 term.println('') time.sleep(1) if (body is not None): term.println(body) time.sleep(4) term.clear()
def main(): while True: #for fontname, size in [("ProggyTiny.ttf", 16), ("creep.bdf", 16), ("miscfs_.ttf", 12)]: fontname, size = ("miscfs_.ttf", 12) font = make_font(fontname, size) if fontname else None term = terminal(device, font) tweet = getLastTimelinePost() if tweet != False: term.println(tweet['data']['text']) else: term.println('Network error. Please check your internet connection.') term.flush() time.sleep(30)
def main(): def preexec_function(): signal.signal(signal.SIGINT, signal.SIG_IGN) global p global term font = make_font("tiny.ttf", 6) term = terminal(device, font) #p = subprocess.Popen(["sudo", "/usr/bin/python", #"/home/toby/oledterm/oledterm.py", "--display", "ssd1325", "--interface", #"spi", "--gpio-data-command", "7", "--gpio-reset","9"], #preexec_fn = preexec_function) aiy.audio.say('I\'m alive!') MyAssistant().start() atexit.register(on_exit) signal.signal(signal.SIGTERM, on_exit) signal.signal(signal.SIGINT, on_exit)
def __init__(self, bus, addr, size): """ Initialize """ self.log_level = LEVEL_NOTSET self.term = None self.bus = bus self.addr = addr self.line = 4 self.oled = None self.msg_list = [] self.max_msg_lines = 10 self.display_lines_array = [] self.font = self.make_font("ProggyTiny.ttf", 18) #self.font = self.make_font("tiny.ttf", 16) if size == "128x64": self.width = 128 self.height = 64 self.max_lines = 4 self.device = self.get_device([ '--display', 'ssd1306', '--width', str(self.width), '--height', str(self.height), '--i2c-port', str(self.bus), '--i2c-address', str(self.addr) ]) elif size == "128x128": self.width = 128 self.height = 128 self.max_lines = 8 self.device = self.get_device([ '--display', 'ssd1327', '--width', str(self.width), '--height', str(self.height), '--i2c-port', str(self.bus), '--i2c-address', str(self.addr) ]) # self.term = terminal(self.device, self.font, animate=False) self.term = terminal(self.device, None, animate=False)
def test_tab_alignment(): reference = 'tab_align.png' device = dummy() term = terminal(device, animate=False) assert_text(device, term, reference, ["1\t32\t999", "999\t1\t32"])
def write_to_terminal(device, text): term = terminal(device) term.println(text) time.sleep(0.1)
def welcome_frame(self): self.term = terminal(self.device) self.term.println("HandAssist V3.1") self.term.println("UAEU, IRI Lab") time.sleep(2) self.term.puts("Connecting ...")
""" port = int(os.environ.get('PORT', 5000)) ip = '0.0.0.0' try: # Not portable! But should be OK on RPi. ip = check_output(['hostname', '--all-ip-addresses']).decode().replace(' \n', '') except: pass logger = logging.getLogger(__name__) logging.basicConfig(stream=sys.stdout, level=logging.INFO) device = get_device() term = terminal(device, None) term.println( f"Display ready for POST requests to:\nhttp://{ip}:{port}/display") term.flush() controller = StageController(device) controller.add_stage(TrainDepartureBoardStage) controller.add_stage(MetricsStage) api = create_api("example_display_api", controller) if __name__ == "__main__": api.run(host="0.0.0.0", port=port, debug=False)
def ShowError(self): """Displays an error message.""" term = terminal(self.luma_device, self._font) print(self._last_error) term.println(self._last_error)
def __init__(self): self.font = make_font("miscfs_.ttf", 12) self.device = get_device() self.term = terminal(self.device, self.font)
def test_alt_colors(): reference = 'alt_colors.png' device = dummy() term = terminal(device, color="blue", bgcolor="grey", animate=False) assert_text(device, term, reference, ["blue on grey"])