Implement tiling vs centering wallpaper

This commit is contained in:
Isaiah Odhner 2023-07-17 23:13:27 -04:00
parent 00e6dd70b0
commit 8fb561f457
2 changed files with 23 additions and 7 deletions

View File

@ -197,7 +197,6 @@ To preview ANSI art files in file managers like Nautilus, Thunar, Nemo, or Caja,
- Free-Form Select stamping/finalizing is incorrect when the selection is off-screen to the left or top.
- Status bar description can be left blank when selecting a menu item. (I think the `Leave` event can come after closing, once the mouse moves.)
- Menu items like Copy/Cut/Paste are not grayed out when inapplicable. Only unimplemented items are grayed out.
- Set As Wallpaper (Tiled) acts the same as Set As Wallpaper (Centered).
- ANSI files (.ans) are treated as UTF-8 when saving and loading, rather than CP437 or Windows-1252 or any other encodings. Unicode is nice and modern terminals support it, but it's not the standard for ANSI files. There isn't really a standard for ANSI files.
- ANSI files are loaded with a white background. This may make sense as a default for text files, but ANSI files either draw a background or assume a black background, being designed for terminals.
- Hitting Enter in View Bitmap mode exits the mode but may also trigger a menu item. Menu items ought to be disabled when hidden, and View Bitmap should prevent the key event from taking other actions if possible.

View File

@ -3555,10 +3555,12 @@ Columns: {len(palette) // 2}
self.message_box(_("Paint"), "Not implemented.", "ok")
def action_set_as_wallpaper_tiled(self) -> None:
"""Set the image as the wallpaper."""
# TODO: Differentiate between tiled and centered.
self.action_set_as_wallpaper_centered()
"""Tile the image as the wallpaper."""
self.set_as_wallpaper(tiled=True)
def action_set_as_wallpaper_centered(self) -> None:
"""Center the image as the wallpaper."""
self.set_as_wallpaper(tiled=False)
def set_as_wallpaper(self, tiled: bool) -> None:
"""Set the image as the wallpaper."""
try:
dir = os.path.join(get_config_dir("textual-paint"), "wallpaper")
@ -3568,12 +3570,27 @@ Columns: {len(palette) // 2}
# with open(image_path, "w", encoding="utf-8") as f:
# f.write(svg)
image_path = os.path.join(dir, "wallpaper.png")
pil_image = rasterize(self.image)
pil_image.save(image_path)
screen_size = self.get_screen_size()
im = rasterize(self.image)
im_w, im_h = im.size
if tiled:
new_im = Image.new('RGBA', screen_size)
w, h = new_im.size
for i in range(0, w, im_w):
for j in range(0, h, im_h):
new_im.paste(im, (i, j))
else:
new_im = Image.new('RGBA', screen_size)
w, h = new_im.size
new_im.paste(im, (w//2 - im_w//2, h//2 - im_h//2))
new_im.save(image_path)
set_wallpaper(image_path)
except Exception as e:
self.message_box(_("Paint"), _("Failed to set the wallpaper."), "ok", error=e)
def get_screen_size(self) -> tuple[int, int]:
"""Get the screen size."""
return 1920, 1080 # TODO: get the actual screen size
def action_recent_file(self) -> None:
self.message_box(_("Paint"), "Not implemented.", "ok")