def __init__(self, arduino, camera): Scene.__init__(self) self.arduino = arduino self.camera = camera self.timer = None self.current_step = 0 self.callback = self._default_cb self.cheese_img = Screen.get_instance().create_image(self.get_name() + "_cheese") if not self.cheese_img.is_cached(): base_img = Screen.get_instance().create_empty_image(True) self.cheese_img.load_surface(base_img.img) surf_text = Screen.create_text( Strings.get("Cheese"), ResourceManager.get(Config.get("font")), 100, Config.get("text_color")) tw, th = surf_text.get_size() bw, bh = self.cheese_img.img.get_size() self.cheese_img.img.blit(surf_text, ((bw - tw) / 2, (bh - th) / 2)) self.cheese_img.save() self.wait_img = Screen.get_instance().create_image(self.get_name() + "_wait") if not self.wait_img.is_cached(): img = Screen.create_button(ResourceManager.get("empty.png"), Strings.get("Please wait..."), Config.get("text_color"), ResourceManager.get(Config.get("font")), 100) self.wait_img.load_surface(img) self.wait_img.save() self.imgs = [] wait_before = Config.get("wait_before_snap") for i in xrange(wait_before, 0, -1): cache_img = Screen.get_instance().create_image( "%s_%d" % (self.get_name(), i), True) if not cache_img.is_cached(): base_img = Screen.get_instance().create_empty_image(True) cache_img.load_surface(base_img.img) img = Screen.create_text(str(i), None, 200, (255, 0, 0)) iw, ih = img.get_size() w, h = base_img.size cache_img.img.blit(img, (10, 10)) cache_img.img.blit(img, (w - iw - 10, 10)) cache_img.img.blit(img, (10, h - ih - 10)) cache_img.img.blit(img, (w - iw - 10, h - ih - 10)) cache_img.save() self.imgs.append(cache_img) Screen.get_instance().register_callback("on_preview_starts", self._on_preview_starts)
def __init__(self, name, action=None, param=None): self.name = name self.action = action self.param = param img_file = ResourceManager.get("%s.png" % name) img_file_sel = ResourceManager.get("%s_sel.png" % name) if img_file and os.path.isfile(img_file): w, h = Screen.get_instance().get_size() screen_ratio = Config.get( "form_buttons")["normal"]["screen_height_ratio"] self.img = pygame.image.load(img_file) iw, ih = self.img.get_rect().size new_ih = h / screen_ratio self.img = pygame.transform.scale(self.img, ((new_ih * iw) / ih, new_ih)) if img_file_sel and os.path.isfile(img_file_sel): self.img_sel = pygame.image.load(img_file_sel) iw, ih = self.img_sel.get_rect().size new_ih = h / screen_ratio self.img_sel = pygame.transform.scale( self.img_sel, ((new_ih * iw) / ih, new_ih)) else: self.img_sel = self.img else: # Generate img button_font = Config.get("form_buttons")["normal"]["font"] button_font_size = Config.get( "form_buttons")["normal"]["font_size"] button_text_color = Config.get( "form_buttons")["normal"]["text_color"] self.img = Screen.create_text(name, ResourceManager.get(button_font), button_font_size, button_text_color) button_font = Config.get("form_buttons")["selected"]["font"] button_font_size = Config.get( "form_buttons")["selected"]["font_size"] button_text_color = Config.get( "form_buttons")["selected"]["text_color"] self.img_sel = Screen.create_text(name, ResourceManager.get(button_font), button_font_size, button_text_color) self.is_selected = False self.need_rendering = False
def show_msg(self): if self.msgs: from Screen import Screen if Screen.get_instance().initialized: pos = 0 for msg in self.msgs: txt = Screen.create_text(msg, None, 20, (255, 0, 0)) Screen.get_instance().get_window().blit( txt, (10, pos + 10)) pos += txt.get_size()[1] + 5 Screen.get_instance().update()
def show(self): Scene.show(self, self.img) qr_path = os.path.join("cache/last_qrcode.png") if os.path.exists(qr_path): qr = pygame.image.load(qr_path) iw, ih = qr.get_size() w, h = self.img.size l = (w - iw) / 2 t = h - ih - (h / 6) Screen.get_instance().get_window().blit(qr, (l, t)) txt = Screen.create_text(Strings.get("Last picture :"), ResourceManager.get(Config.get("font")), Config.get("qrcode")["text_size"], Config.get("text_color")) iw, ih = txt.get_size() l = (w - iw) / 2 t -= ih + 5 Screen.get_instance().get_window().blit(txt, (l, t)) Screen.get_instance().update() Logger.get_instance().show_msg()