def demo_youpi(self, mt, opts): """ Youpi 2.0 demo home screen """ if not Image: logging.error('This demo requires the PIL library') return _parser = argparse.ArgumentParser() _parser.add_argument('-s', '--save', action='store_true') _parser.add_argument('-w', '--wait', type=int, default=10) _args = _parser.parse_args(opts) img = Image.open(os.path.join(self.images_dir, 'youpi-from-svg.png')) vt_img = VideotexImage(img) code = vt_img.to_videotex() if _args.save: img_file = 'image.vt' with file(img_file, 'wb') as fp: fp.write(''.join(code)) print("Videotex image saved as : %s" % img_file) mt.videotex_graphic_mode() mt.send(code) mt.display_text('YOUPI 2.0', x=3, y=18, char_width=2, char_height=2) mt.display_text('by POBOT', x=30, y=23) mt.wait_for_key(max_wait=_args.wait)
def teardown(self, exit_code): self._mt.clear_all() if Image: self.log_info('Displaying logo...') img_path = pkg_resources.resource_filename( _my_package, 'data/img/pobot-logo-small.png') self.log_info('.. loading image from %s', img_path) if os.path.exists(img_path): img = Image.open(img_path) self.log_info('.. converting it to Videotex') vt_img = VideotexImage(img) code = vt_img.to_videotex() self.log_info('.. sending stream to Minitel (%d bytes)', len(code)) self._mt.goto_xy(0, 0) self._mt.videotex_graphic_mode() self._mt.send(code) self.log_info('.. all done.') else: self.log_error('!! file not found') else: self.log_warning('PIL not installed. Unable to display logo.') self._mt.display_text(u"I'll be back...", 24, 23) self._mt.shutdown()
def demo_image(self, mt, opts): """ converts and display an image """ if not Image: logging.error('This demo requires the PIL library') return mt.clear_all() for img_name in (n for n in os.listdir(self.images_dir) if n.endswith('.png')): img = Image.open(os.path.join(self.images_dir, img_name)) vt_img = VideotexImage(img) code = vt_img.to_videotex() mt.videotex_graphic_mode() mt.send(code) mt.display_text('ENVOI', 34, 23) mt.wait_for_key(max_wait=60)