chore: initialize repository and staged implementation plan

This commit is contained in:
Mikhail committed 2026-11-26 15:23:50 +03:00
commit cb0e9d156f
48 files changed
+7343

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
from OKNA96.apps.terminal import TerminalApp
from OKNA96.apps.notepad import NotepadApp
from OKNA96.apps.clock import ClockApp
from OKNA96.apps.run import RunApp
from OKNA96.apps.about import AboutApp
from OKNA96.apps.error import ErrorApp
APP_CLASSES = [TerminalApp, NotepadApp, ClockApp, RunApp, AboutApp, ErrorApp]
def get_app(kind, **kwargs):
"""Создать новый экземпляр приложения по kind."""
for cls in APP_CLASSES:
if cls.kind == kind:
return cls(**kwargs)
return None
def get_app_class(kind):
for cls in APP_CLASSES:
if cls.kind == kind:
return cls
return None
def all_kinds():
return [cls.kind for cls in APP_CLASSES if cls.kind != 'error']
def sorted_kinds():
"""Порядок приложений в меню Пуск (по title)."""
return sorted(all_kinds(), key=lambda k: get_app_class(k).title)
def find_by_cmd(cmd):
"""Найти kind приложения по алиасу команды (для «Выполнить» и терминала)."""
if not cmd:
return None
cmd = cmd.lower()
for cls in APP_CLASSES:
if cls.cmd == cmd:
return cls.kind
return None
+55
View File
@@ -0,0 +1,55 @@
import os
from PIL import Image, ImageDraw
class AboutApp:
kind = 'about'
title = 'О системе'
icon = 'A'
cmd = 'about'
def __init__(self):
self.icon_img = None
self.logo_img = None
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
try:
self.icon_img = Image.open(os.path.join(base_dir, 'assets', 'icon.png')).convert('1')
if self.icon_img.size != (8, 8):
self.icon_img = self.icon_img.resize((8, 8), Image.Resampling.LANCZOS)
except Exception:
pass
try:
self.logo_img = Image.open(os.path.join(base_dir, 'assets', 'logo.png')).convert('1')
if self.logo_img.size != (40, 40):
self.logo_img = self.logo_img.resize((40, 40), Image.Resampling.LANCZOS)
except Exception:
pass
def render(self, fonts, bg, now):
img = Image.new('1', (128, 64), 1) # Белый фон
d = ImageDraw.Draw(img)
# Логотип 40x40 слева, по центру оставшегося места (высота панели 51, значит центр 25)
if self.logo_img:
img.paste(self.logo_img, (4, 5))
# Центр оставшегося места: от 48 до 127
center_x = (48 + 127) // 2
# Верхний текст (чуть больше)
d.text((center_x, 14), "OKNA 96 v1.0", font=fonts['small'], fill=0, anchor="mm")
d.text((center_x, 24), "RPi Alpha", font=fonts['small'], fill=0, anchor="mm")
# Нижний текст (меньше)
d.text((center_x, 36), "Адаптация для", font=fonts['tiny'], fill=0, anchor="mm")
d.text((center_x, 45), "LabStand 2.0", font=fonts['tiny'], fill=0, anchor="mm")
return img
def handle_key(self, code, mods, system):
if code == 1: # Esc
system._close_app('about')
return True
return False
+24
View File
@@ -0,0 +1,24 @@
from PIL import Image, ImageDraw
class ClockApp:
kind = 'clock'
title = 'Часы'
icon = 'C'
cmd = 'clock'
def __init__(self):
pass
def render(self, fonts, bg, now):
img = Image.new('1', (128, 64), 0)
d = ImageDraw.Draw(img)
d.text((64, 20), now.strftime("%H:%M:%S"),
font=fonts['big'], fill=1, anchor="mm")
d.text((64, 44), "Esc - выход",
font=fonts['small'], fill=1, anchor="mm")
return img
def handle_key(self, code, mods, system):
# Clock никаких клавиш не обрабатывает; Esc = system-level.
return False
+50
View File
@@ -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
+109
View File
@@ -0,0 +1,109 @@
from PIL import Image, ImageDraw
class NotepadApp:
kind = 'notepad'
title = 'Блокнот'
icon = 'N'
cmd = 'notepad'
ROWS = 5 # Не перекрывает панель задач
COLS = 20
def __init__(self):
self.lines = [""]
self.cx = 0
self.cy = 0
self.sx = 0
self.sy = 0
def render(self, fonts, bg, now):
img = Image.new('1', (128, 64), 1) # Белый фон
d = ImageDraw.Draw(img)
for i in range(self.ROWS):
idx = self.sy + i
if idx < len(self.lines):
line = self.lines[idx]
# Отступ убран, теперь как в терминале: y = i * 10
d.text((2, i * 10),
line[self.sx:self.sx + self.COLS],
font=fonts['term'], fill=0)
# Позиция курсора тоже без отступа +2
tw = d.textlength(self.lines[self.cy][self.sx:self.cx], font=fonts['term'])
cur_x = 2 + int(tw)
cur_y = (self.cy - self.sy) * 10
d.rectangle((cur_x, cur_y, cur_x + 1, cur_y + 8), fill=0)
return img
def handle_key(self, code, mods, system):
if code in (28, 96): self._new_line(); return True
if code == 14: self._backspace(); return True
if code == 103: self._move_up(); return True
if code == 108: self._move_down(); return True
if code == 105: self._move_left(); return True
if code == 106: self._move_right(); return True
ch = system._char_for(code, mods.get('shift', False))
if ch and len(ch) == 1:
self._insert(ch); return True
return False
def _insert(self, ch):
line = self.lines[self.cy]
self.lines[self.cy] = line[:self.cx] + ch + line[self.cx:]
self.cx += 1
self._update_scroll()
def _new_line(self):
line = self.lines[self.cy]
self.lines[self.cy] = line[:self.cx]
self.lines.insert(self.cy + 1, line[self.cx:])
self.cy += 1
self.cx = 0
self._update_scroll()
def _backspace(self):
line = self.lines[self.cy]
if self.cx > 0:
self.lines[self.cy] = line[:self.cx - 1] + line[self.cx:]
self.cx -= 1
elif self.cy > 0:
self.cx = len(self.lines[self.cy - 1])
self.lines[self.cy - 1] += line
del self.lines[self.cy]
self.cy -= 1
self._update_scroll()
def _move_up(self):
if self.cy > 0:
self.cy -= 1
self.cx = min(self.cx, len(self.lines[self.cy]))
self._update_scroll()
def _move_down(self):
if self.cy < len(self.lines) - 1:
self.cy += 1
self.cx = min(self.cx, len(self.lines[self.cy]))
self._update_scroll()
def _move_left(self):
if self.cx > 0:
self.cx -= 1
elif self.cy > 0:
self.cy -= 1
self.cx = len(self.lines[self.cy])
self._update_scroll()
def _move_right(self):
if self.cx < len(self.lines[self.cy]):
self.cx += 1
elif self.cy < len(self.lines) - 1:
self.cy += 1
self.cx = 0
self._update_scroll()
def _update_scroll(self):
if self.cy < self.sy: self.sy = self.cy
elif self.cy >= self.sy + self.ROWS: self.sy = self.cy - self.ROWS + 1
if self.cx < self.sx: self.sx = self.cx
elif self.cx >= self.sx + self.COLS: self.sx = self.cx - self.COLS + 1
+58
View File
@@ -0,0 +1,58 @@
from PIL import Image, ImageDraw
class RunApp:
kind = 'run'
title = 'Выполнить'
icon = 'R'
cmd = None
def __init__(self):
self.input = ""
def render(self, fonts, bg, now):
img = bg.copy()
d = ImageDraw.Draw(img)
# Белое окно с чёрной рамкой
d.rectangle((4, 17, 123, 46), fill=1, outline=0)
# Чёрный текст "Открыть:" (поднят на 3 пикселя вверх)
d.text((7, 18), "Открыть:", font=fonts['small'], fill=0)
# Чёрная рамка поля ввода
d.rectangle((7, 29, 120, 42), outline=0)
# Чёрный вводимый текст
shown = self.input[:16]
d.text((9, 30), shown, font=fonts['small'], fill=0)
# Чёрный курсор
cx = min(118, 9 + int(d.textlength(shown, font=fonts['small'])) + 1)
d.rectangle((cx, 32, cx + 1, 40), fill=0)
return img
def handle_key(self, code, mods, system):
if code in (28, 96):
self._execute(system)
return True
if code == 14:
self.input = self.input[:-1]
return True
ch = system._char_for(code, mods.get('shift', False))
if ch and len(ch) == 1:
self.input = (self.input + ch)[-32:]
return True
return False
def _execute(self, system):
from OKNA96.apps import find_by_cmd
cmd = self.input.strip().lower()
self.input = ""
kind = find_by_cmd(cmd)
system._close_app('run')
if kind:
system._open_app(kind)
else:
system.show_error("Несуществующая программа")
+134
View File
@@ -0,0 +1,134 @@
from PIL import Image, ImageDraw
class TerminalApp:
kind = 'terminal'
title = 'Терминал'
icon = 'T'
cmd = 'cmd'
VISIBLE_ROWS = 5
ROW_H = 10
COLS = 20
def __init__(self):
self.lines = []
self.input = ""
self.scroll_offset = 0
def _total_rows(self):
return len(self.lines) + 1
def _max_offset(self):
return max(0, self._total_rows() - self.VISIBLE_ROWS)
def _clamp(self):
if self.scroll_offset < 0:
self.scroll_offset = 0
mx = self._max_offset()
if self.scroll_offset > mx:
self.scroll_offset = mx
def _scroll(self, delta):
self.scroll_offset += delta
self._clamp()
def render(self, fonts, bg, now):
img = Image.new('1', (128, 64), 0)
d = ImageDraw.Draw(img)
font = fonts['term']
total = self._total_rows()
self._clamp()
off = self.scroll_offset
mx = self._max_offset()
if total <= self.VISIBLE_ROWS:
start = 0
else:
start = mx - off
prompt_idx = len(self.lines)
for i in range(self.VISIBLE_ROWS):
row = start + i
y = i * self.ROW_H
if row < len(self.lines):
d.text((2, y), self.lines[row][:self.COLS], font=font, fill=1)
elif row == prompt_idx:
full = "> " + self.input
shown = full if len(full) <= self.COLS else ">" + self.input[-(self.COLS - 1):]
d.text((2, y), shown, font=font, fill=1)
cx = min(122, 2 + int(d.textlength(shown, font=font)) + 1)
d.rectangle((cx, y + 8, cx + 3, y + 9), fill=1)
if off < mx:
d.polygon([(124, 3), (127, 3), (125, 0)], fill=1)
if off > 0:
d.polygon([(124, 47), (127, 47), (125, 49)], fill=1)
return img
def handle_key(self, code, mods, system):
if code == 103: self._scroll(1); return True
if code == 108: self._scroll(-1); return True
if code == 104: self._scroll(self.VISIBLE_ROWS); return True
if code == 109: self._scroll(-self.VISIBLE_ROWS); return True
if code in (28, 96):
self._execute(system)
self.scroll_offset = 0
return True
if code == 14:
self.input = self.input[:-1]
self.scroll_offset = 0
return True
ch = system._char_for(code, mods.get('shift', False))
if ch and len(ch) == 1:
self.input = (self.input + ch)[-64:]
self.scroll_offset = 0
return True
return False
def _execute(self, system):
cmd = self.input.strip()
self.input = ""
if not cmd:
return
self.lines.append("> " + cmd)
self.lines = self.lines[-50:]
if cmd == 'killall':
self.lines.append("Завершение...")
system.trigger_bsod()
return
if cmd == 'killallnet':
self.lines.append("Аварийное завершение...")
system.trigger_bsod()
system.killall_network()
return
if cmd == 'help':
self.lines.extend(["help справка", "time время", "clear очистить",
"exit выход", "killall BSOD", "killallnet BSOD всех",
"about о системе"])
return
elif cmd == 'time':
self.lines.append(system._now().strftime("%H:%M:%S"))
return
elif cmd == 'clear':
self.lines = []
self.scroll_offset = 0
return
elif cmd == 'exit':
system._close_app('terminal')
return
from OKNA96.apps import find_by_cmd
kind = find_by_cmd(cmd)
if kind:
system._open_app(kind)
else:
self.lines.append(f"Не найдена команда ({cmd})")