Files
seedsigner/tests/screenshot_generator/utils.py
T
Easy 40abf591d7 Icon font update
- Renamed `seedsigner-glyphs.otf` to `seedsigner-icons.otf`
- Updated `seedsigner-icons.otf`
- Renamed `SeedSignerCustomIconConstants` to `SeedSignerIconConstants`
- Updated `SeedSignerCustomIconConstants` names and Unicode values in src/seedsigner/gui/components.py
2023-08-03 16:43:42 -07:00

54 lines
1.5 KiB
Python

import os
from PIL import Image, ImageDraw
from seedsigner.gui.renderer import Renderer
class ScreenshotComplete(Exception):
pass
class ScreenshotRenderer(Renderer):
screenshot_path: str = None
screenshot_filename: str = None
@classmethod
def configure_instance(cls):
# Instantiate the one and only Renderer instance
renderer = cls.__new__(cls)
cls._instance = renderer
# Hard-coding output values for now
renderer.canvas_width = 240
renderer.canvas_height = 240
renderer.canvas = Image.new('RGB', (renderer.canvas_width, renderer.canvas_height))
renderer.draw = ImageDraw.Draw(renderer.canvas)
def set_screenshot_filename(self, filename:str):
self.screenshot_filename = filename
def set_screenshot_path(self, path):
if not os.path.exists(path):
os.makedirs(path)
self.screenshot_path = path
def show_image(self, image=None, alpha_overlay=None, is_background_thread: bool = False):
if is_background_thread:
return
if alpha_overlay:
if image == None:
image = self.canvas
image = Image.alpha_composite(image, alpha_overlay)
if image:
# Always write to the current canvas, rather than trying to replace it
self.canvas.paste(image)
self.canvas.save(os.path.join(self.screenshot_path, self.screenshot_filename))
raise ScreenshotComplete()