Imported from matebook D:\BS (2026-03-11). Source only (no venv/build/dist). Added requirements.txt, .gitignore, README.md, IDEA.md.
91 lines
2.3 KiB
Python
91 lines
2.3 KiB
Python
import pygame
|
|
import sys
|
|
import os
|
|
import time
|
|
import screen_brightness_control as sbc
|
|
|
|
|
|
def get_current_brightness():
|
|
try:
|
|
current = sbc.get_brightness()
|
|
except Exception:
|
|
return None
|
|
|
|
if isinstance(current, list):
|
|
if not current:
|
|
return None
|
|
return current[0]
|
|
return current
|
|
|
|
|
|
def set_brightness_safe(value):
|
|
try:
|
|
sbc.set_brightness(int(value))
|
|
return True
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
def main():
|
|
# --- яркость: читаем текущую и ставим минимум ---
|
|
original_brightness = get_current_brightness()
|
|
if original_brightness is not None:
|
|
set_brightness_safe(0)
|
|
|
|
# --- чёрный экран ---
|
|
pygame.init()
|
|
|
|
info = pygame.display.Info()
|
|
width, height = info.current_w, info.current_h
|
|
|
|
os.environ["SDL_VIDEO_WINDOW_POS"] = "0,0"
|
|
screen = pygame.display.set_mode((width, height), pygame.NOFRAME)
|
|
pygame.display.set_caption("Black Screen Dim")
|
|
|
|
try:
|
|
icon = pygame.image.load("icon.ico")
|
|
pygame.display.set_icon(icon)
|
|
except Exception:
|
|
pass
|
|
|
|
pygame.mouse.set_visible(False)
|
|
|
|
font = pygame.font.SysFont(None, 48)
|
|
hint_text = "ESC - exit"
|
|
text_surf = font.render(hint_text, True, (255, 255, 255))
|
|
text_rect = text_surf.get_rect(center=(width // 2, height // 2))
|
|
show_hint_until = time.time() + 1.0 # ~1 секунда
|
|
|
|
running = True
|
|
while running:
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
running = False
|
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
|
running = False
|
|
|
|
screen.fill((0, 0, 0))
|
|
if time.time() < show_hint_until:
|
|
screen.blit(text_surf, text_rect)
|
|
|
|
pygame.display.flip()
|
|
|
|
# --- выходим: пытаемся вернуть яркость и курсор, без вылета ---
|
|
if original_brightness is not None:
|
|
try:
|
|
set_brightness_safe(original_brightness)
|
|
except Exception:
|
|
pass
|
|
|
|
try:
|
|
pygame.mouse.set_visible(True)
|
|
except Exception:
|
|
pass
|
|
|
|
pygame.quit()
|
|
sys.exit()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|