Drop lots of legacy code. Support Python 3.7-3.11.
[librarian.git] / src / librarian / covers / widgets / base.py
1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 class Widget:
5     transparency = True
6     margin_top = 0
7
8     def __init__(self, cover):
9         self.cover = cover
10         self.setup()
11
12     def setup(self):
13         pass
14         
15     def build(self, w, h):
16         raise NotImplementedError()
17
18     def apply(self, img, x, y, w=None, h=None):
19         my_img = self.build(w, h)
20         if my_img is not None:
21             img.paste(
22                 my_img,
23                 (round(x), round(y - self.margin_top)),
24                 my_img if self.transparency else None
25             )