chore: initialize repository and staged implementation plan
This commit is contained in:
commit
cb0e9d156f
48 files changed
+7343
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import textwrap
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
|
||||
class ErrorApp:
|
||||
kind = 'error'
|
||||
title = 'Ошибка'
|
||||
icon = '!'
|
||||
cmd = None
|
||||
|
||||
def __init__(self, text="Неизвестная ошибка"):
|
||||
self.text = text
|
||||
|
||||
def render(self, fonts, bg, now):
|
||||
img = bg.copy() # Фон рабочего стола, чтобы окно было "поверх"
|
||||
d = ImageDraw.Draw(img)
|
||||
|
||||
# Окно по центру (высота до панели задач = 50px)
|
||||
d.rectangle((8, 4, 119, 46), fill=0, outline=1)
|
||||
|
||||
# Иконка (восклицательный знак в треугольнике)
|
||||
cx, cy = 22, 20
|
||||
d.polygon([(cx, cy - 8), (cx - 7, cy + 6), (cx + 7, cy + 6)], fill=0, outline=1)
|
||||
d.text((cx, cy), "!", font=fonts['tiny'], fill=1, anchor="mm")
|
||||
|
||||
# Текст (с переносом строк)
|
||||
wrapped = textwrap.wrap(self.text, width=18)
|
||||
if not wrapped:
|
||||
wrapped = [""]
|
||||
wrapped = wrapped[:3] # максимум 3 строки, чтобы влезло в окно
|
||||
|
||||
text_x = (36 + 118) // 2
|
||||
y_off = cy - (len(wrapped) - 1) * 5
|
||||
for line in wrapped:
|
||||
d.text((text_x, y_off), line, font=fonts['tiny'], fill=1, anchor="mm")
|
||||
y_off += 10
|
||||
|
||||
# Кнопка Ok
|
||||
btn_x1, btn_y1, btn_x2, btn_y2 = 52, 34, 76, 44
|
||||
d.rectangle((btn_x1, btn_y1, btn_x2, btn_y2), outline=1)
|
||||
d.text(((btn_x1 + btn_x2) // 2, (btn_y1 + btn_y2) // 2), "Ok",
|
||||
font=fonts['tiny'], fill=1, anchor="mm")
|
||||
|
||||
return img
|
||||
|
||||
def handle_key(self, code, mods, system):
|
||||
if code in (28, 96, 1): # Enter / Esc
|
||||
system._close_app('error')
|
||||
return True
|
||||
return False
|
||||
Reference in new issue
Block a user