def update_key_image(deck, key, state): if key % 2 == 0: filename = 'assets/sharingan.png' else: filename = 'assets/rinnegan.jpg' image = Image.open(filename) image = PILHelper.create_scaled_image(deck, image, margins=[0, 0, 0, 0]) image = PILHelper.to_native_format(deck, image) with deck: deck.set_key_image(key, image)
def render_key_image(self, streamdeck, page_name, key_number, icon_path, text): icon = Image.open(icon_path) image = PILHelper.create_scaled_image(streamdeck, icon, margins=[0, 0, 20, 0]) draw = ImageDraw.Draw(image) label_w, label_h = draw.textsize(text, font=self.font) label_pos = ((image.width - label_w) // 2, image.height - 20) draw.text(label_pos, text=text, font=self.font, fill="white") rendered_image = PILHelper.to_native_format(streamdeck, image) with streamdeck: streamdeck.set_key_image(key_number, rendered_image)
def render_key_image(deck, icon_filename, font_filename, label_text): # Resize the source image asset to best-fit the dimensions of a single key, # leaving a margin at the bottom so that we can draw the key title # afterwards. icon = Image.open(icon_filename) image = PILHelper.create_scaled_image(deck, icon, margins=[0, 0, 20, 0]) # Load a custom TrueType font and use it to overlay the key index, draw key # label onto the image. draw = ImageDraw.Draw(image) font = ImageFont.truetype(font_filename, 14) label_w, label_h = draw.textsize(label_text, font=font) label_pos = ((image.width - label_w) // 2, image.height - 20) draw.text(label_pos, text=label_text, font=font, fill="white") return PILHelper.to_native_format(deck, image)
def CargarGif(self, accion): """Extra frame de un gif y los guarda en una lista.""" # TODO: Errro con git con estado no se desactiva if "gif_cargado" in accion: self.ListaGif.append(accion) return DirecionGif = BuscarDirecionImagen(accion) if DirecionGif is not None and not DirecionGif.endswith("gif"): return Gif = list() ColorFondo = "black" if "imagen_opciones" in accion: opciones = accion["imagen_opciones"] if "fondo" in opciones: ColorFondo = opciones["fondo"] DirecionGif = RelativoAbsoluto(DirecionGif, self.Deck.Folder) DirecionGif = UnirPath(ObtenerFolderConfig(), DirecionGif) if os.path.exists(DirecionGif): GifArchivo = Image.open(DirecionGif) for frame in ImageSequence.Iterator(GifArchivo): Gif_frame = PILHelper.create_scaled_image( self.Deck, frame, background=ColorFondo) if "cargar_titulo" in accion: TextoCargar = accion["cargar_titulo"] if "archivo" in TextoCargar and "atributo" in TextoCargar: accion["titulo"] = ObtenerValor( TextoCargar["archivo"], TextoCargar["atributo"]) if "titulo" in accion: PonerTexto(Gif_frame, accion, True) ImagenNativa = PILHelper.to_native_format(self.Deck, Gif_frame) Gif.append(ImagenNativa) accion["gif_cargado"] = itertools.cycle(Gif) self.ListaGif.append(accion) else: logger.warning(f"Deck[No Gifs] {DirecionGif}")
def create_animation_frames(deck, image_filename): icon_frames = list() # Open the source image asset. icon = Image.open(os.path.join(ASSETS_PATH, image_filename)) # Iterate through each animation frame of the source image for frame in ImageSequence.Iterator(icon): # Create new key image of the correct dimensions, black background. frame_image = PILHelper.create_scaled_image(deck, frame) # Pre-convert the generated image to the native format of the StreamDeck # so we don't need to keep converting it when showing it on the device. native_frame_image = PILHelper.to_native_format(deck, frame_image) # Store the rendered animation frame for later user. icon_frames.append(native_frame_image) # Return an infinite cycle generator that returns the next animation frame # each time it is called. return itertools.cycle(icon_frames)
def test_pil_helpers(deck): test_scaled_image = PILHelper.create_scaled_image( deck, Image.new("RGB", (1, 1))) # noqa: F841 test_key_image = PILHelper.create_image(deck) test_key_image = PILHelper.to_native_format(deck, test_key_image)
streamdecks = manager.enumerate() logging.info("Got {} Dummy Stream Deck(s).\n".format(len(streamdecks))) for index, deck in enumerate(streamdecks): logging.info("Using Deck Type: {}".format(deck.deck_type())) with deck: deck.open() connected = deck.connected() deck_id = deck.id() key_count = deck.key_count() deck_type = deck.deck_type() key_layout = deck.key_layout() image_format = deck.key_image_format() key_states = deck.key_states() test_key_image = PILHelper.create_image(deck) test_key_image = PILHelper.to_native_format(deck, test_key_image) test_scaled_image = PILHelper.create_scaled_image( deck, Image.new("RGB", (5, 5))) deck.set_key_callback(None) deck.reset() deck.set_brightness(30) deck.set_key_image(0, test_key_image) deck.close()